Jotrin Electronics
Carrello
arrow
Descrizione Quantità Totale (USD) Operazione
loading
Carrello della spesa prodotti
Carrello della spesa prodotti : 0
Home > Other > PIC16F877A Microcontroller Pinout, Datasheet and Programming

PIC16F877A Microcontroller Pinout, Datasheet and Programming

tempo di aggiornamento: 2024-05-16 14:26:51

Contents

The PIC microcontroller PIC16F877A is highly regarded in the industry for its convenience and ease of use in coding or programming. It offers the advantage of being write-eraseable many times due to its use of FLASH memory technology. With a total of 40 pins, including 33 for input and output, the PIC16F877A is a versatile choice for various projects in digital electronics circuits.


This microcontroller is widely applied in remote sensors, security and safety devices, home automation, and numerous industrial instruments. Its EEPROM feature allows for permanent storage of information, such as transmitter codes and receiver frequencies. Despite its low cost, the PIC16F877A is capable and easy to handle, offering flexibility for use in various applications, including microprocessor applications and timer functions. In this article, we'll explore the PIC16F877A microcontroller, including its pinout, circuit, features, programming, datasheet, and more details.


What is PIC16F877A?


The PIC16F877A is a 40-pin microcontroller designed with RISC architecture and manufactured by Microchip, commonly used in embedded projects. It features five ports, labeled from Port A to Port E, and includes three timers, two of which are 8-bit timers and one is a 16-bit timer.


pic16f877a.jpg

This microcontroller supports various communication protocols, including serial, parallel, and I2C protocols. It also supports both hardware pin interrupts and timer interrupts.


The provided PIC16F877A pin diagram shows the names of all the pins, with different colors indicating different ports. Each pin of the PIC can perform multiple tasks, as illustrated by the example of Pin #25, which can function as digital Port C Pin #6 (RC6) and as a transmitter (TX) for serial communication. In programming, you must specify how you want to use these pins.


For further comparison, consider looking into the Atmega328 microcontroller.


PIC16F877A Pinout


As previously stated, the microcontroller IC has a total of 40 pins. It includes two 8-bit timers, one 16-bit timer, capture and compare modules, serial and parallel ports, and five input/output ports. The following picture displays the pinout diagram of the PIC16F877A.


pic16f877a pinout.png



Pin Configuration


Pin Number

Pin Name

Description

1

MCLR/Vpp

MCLR is used during programming, mostly connected to programmer like PicKit

2

RA0/AN0

Analog pin 0 or 0th pin of PORTA

3

RA1/AN1

Analog pin 1 or 1st pin of PORTA

4

RA2/AN2/Vref-

Analog pin 2 or 2nd pin of PORTA

5

RA3/AN3/Vref+

Analog pin 3 or 3rd pin of PORTA

6

RA4/T0CKI/C1out

4th pin of PORTA

7

RA5/AN4/SS/C2out

Analog pin 4 or 5th pin of PORTA

8

RE0/RD/AN5

Analog pin 5 or 0th pin of PORTE

9

RE1/WR/AN6

Analog pin 6 or 1st pin of PORTE

10

RE2/CS/AN7

7th pin of PORTE

11

Vdd

Ground pin of MCU

12

Vss

Positive pin of MCU (+5V)

13

OSC1/CLKI

External Oscillator/clock input pin

14

OSC2/CLKO

External Oscillator/clock output pin

15

RC0/T1OSO/T1CKI

0th pin of PORT C

16

RC1/T1OSI/CCP2

1st pin of POCTC or Timer/PWM pin

17

RC2/CCP1

2nd pin of POCTC or Timer/PWM pin

18

RC3/SCK/SCL

3rd pin of POCTC

19

RD0/PSP0

0th pin of POCTD

20

RD1/PSPI

1st pin of POCTD

21

RD2/PSP2

2nd pin of POCTD

22

RD3/PSP3

3rd pin of POCTD

23

RC4/SDI/SDA

4th pin of POCTC or Serial Data in pin

24

RC5/SDO

5th pin of POCTC or Serial Data Out pin

25

RC6/Tx/CK

6th pin of POCTC or Transmitter pin of Microcontroller

26

RC7/Rx/DT

7th pin of POCTC or Receiver pin of Microcontroller

27

RD4/PSP4

4th pin of POCTD

28

RD5/PSP5

5th pin of POCTD

29

RD6/PSP6

6th pin of POCTD

30

RD7/PSP7

7th pin of POCTD

31

Vss

Positive pin of MCU (+5V)

32

Vdd

Ground pin of MCU

33

RB0/INT

0th pin of POCTB or External Interrupt pin

34

RB1

1st pin of POCTB

35

RB2

2nd pin of POCTB

36

RB3/PGM

3rd pin of POCTB or connected to programmer

37

RB4

4th pin of POCTB

38

RB5

5th pin of POCTB

39

RB6/PGC

6th pin of POCTB or connected to programmer

40

RB7/PGD

7th pin of POCTB or connected to programmer


PIC16F877A Features


  • Analog to Digital Converter (ADC): The microcontroller features an 8-bit ADC module with 8 channels, allowing for the connection of 8 analog sensors.


  • Timers: It offers three timers - timer0, timer1, and timer2 - which can be used in timer or counter mode. These timers are utilized for generating delays, pulse width modulation (PWM), counting external events, and handling timer interrupts. TIMER0 is an 8-bit timer, operable with internal or external clock frequency. TIMER1 is a 16-bit timer, also operable in both modes. TIMER2 is an 8-bit timer used with PWM as a time base for the CCP module.


  • EEPROM: The microcontroller includes built-in Electrically Erasable Read-Only Memory (EEPROM) of 256 x 8 bytes, enabling the storage of data permanently even when the microcontroller is powered off, making it useful for electronic lock projects.


  • PWM Modules: It provides 2 Capture/Compares/PWM (CCP) modules, allowing for the generation of two PWM signals with a maximum resolution of 10 bits.


  • Serial Communication: The microcontroller supports one UART channel for serial communication between digital devices. Pin RC7 (pin 26) serves as the transmitter (TX) pin, while pin RC6 (pin 25) serves as the receiver (RX) pin.


  • I2C Communication: It supports I2C communication through one module, with pins 18 (RC3) and 23 (RC4) serving as SCL (serial clock line) and SDA (serial data line) pins, respectively.


  • Interrupts: The PIC16F877A provides 8 types of interrupts, including external interrupts, timer interrupts, PORT state change interrupts, UART interrupts, I2C interrupts, and PWM interrupts.


  • Comparator Module: The microcontroller features a comparator module with two comparators, used for comparing analog signals. Input pins for these comparators are RA0, RA1, RA2, and RA3, while outputs can be measured through RA4 and RA5.


  • Watchdog Timer (WDT): It includes a separate on-chip oscillator, the WDT, which runs independently of the main oscillator. The WDT operates even in sleep mode and is used to wake up the device from sleep mode and generate watchdog timer resets.


  • Sleep Mode: The microcontroller offers sleep mode operation, allowing the device to operate at very low power, with all peripherals drawing minimal current. Wake-up from sleep mode can be triggered by interrupts from resources such as timer1, UART, EEPROM write completion, and others.


  • Brown Out Detection: It features a brown-out detection circuit that detects a significant drop in power supply voltage and generates interrupt signals. The BODEN configuration bit is used to turn this circuitry on or off.


  • Brown Out Reset: This option resets the device upon detecting a brown-out interrupt signal from the BODEN signal if the supply voltage drops below a certain threshold for more than 100 microseconds.


Other notable features include Power-on Reset, multiple oscillator groups, In-Circuit Debugger (ICD), In-Circuit Serial Programming (ICSP), and low-voltage ICSP programming.


PIC16F877A Specification


SpecificationValue

CPU

8-bit PIC

Number of  Pins

40

Operating Voltage (V)

2 to 5.5 V

Number of I/O pins

33

ADC Module

8ch, 10-bit

Timer Module

8-bit(2), 16-bit(1)

Comparators

2

DAC Module

Nil

Communication Peripherals

UART(1), SPI(1), I2C(1), MSSP(SPI/I2C)

External Oscillator

Up to 20Mhz

Internal Oscillator

Nil

Program Memory Type

Flash

Program Memory (KB)

14KB

CPU Speed (MIPS)

5 MIPS

RAM Bytes

368

Data EEPROM

256 bytes

Operating Temperature-40°C~125°C TA
Package TypePDIP



PIC16F877A CAD Model


PIC16F877A Symbol.png

PIC16F877A Footprint.png

PIC16F877A 3D Model.png


PIC16F877A Basic Circuit


Every microcontroller requires a basic circuit to function, similar to providing power to a fan to make it work. For the PIC16F877A, it operates on a +5V level.


To design the basic circuit, we need to provide both power and the operating frequency. We use a crystal oscillator for this purpose, and for the PIC16F877A, a crystal oscillator with a frequency range of 4MHz to 40MHz can be used.


Here's the basic circuit for the PIC16F877A:


PIC16F877a Basic Circuit.png


  1. MCLR (Master Clear) Pin (Pin #1): Connect a 10k-ohm resistor to this pin and provide 5V.

  2. Vdd Pins (Pin #11 & Pin #32): Connect these pins to +5V.

  3. Vss Pins (Pin #12 & Pin #31): Connect these pins to GND.

  4. OSC1 (Oscillator 1) & OSC2 (Oscillator 2) Pins (Pin #13 & Pin #14): Connect a 16MHz Crystal Oscillator to these pins. Use 33pF capacitors connected to the ground after the crystal oscillator.


Additionally, an LED is connected to Pin #21 to indicate the microcontroller's operation status.


This basic circuit setup ensures that the PIC16F877A is ready to operate. You can refer to an LED Blinking Project for the PIC Microcontroller to see how to blink the LED using the PIC16F877A.


How to Program The Input and Output Ports


  • In our study, we have explored 5 input and output ports, namely PORTA, PORTB, PORTC, PORTD, and PORTE, which can function in both digital and analog modes. These ports are configured based on our specific requirements. However, in analog mode, the ports can only serve as inputs, as there is a built-in Analog to Digital (A to D) converter used in such cases, along with multiplexer circuits.

  • In digital mode, there are no such restrictions. We can configure the ports as either outputs or inputs through programming. For PIC microcontrollers, the preferred compiler is mikroC Pro, which can be downloaded from their website.

  • There is a register known as 'TRIS' that controls the direction of ports. Each port has its corresponding register, such as TRISA, TRISB, and so on. Setting a bit of the TRIS register to 0 makes the corresponding port bit act as a digital output while setting it to 1 makes it act as a digital input.

  • For example, to set the entire PORTB to output, the program statement would be:

TRISB = 0;

  • Now, PORTB will act as the output port, and we can send any value to the output, such as:

PORTB = 0xFF;

  • Here, FF represents all 1's in binary (i.e., FF = 11111111), so all the pins of PORTB are set to high. If we connect LEDs to all the pins, they will all start glowing in this state.

  • To invert the values of PORTB, we can use the statement:

PORTB = ~PORTB;

  • Now, all the pins of PORTB will be set to low.


Programming PIC Microcontroller


PIC microcontrollers can be programmed using various software available in the market. Some users still opt for Assembly language for programming PIC MCUs. The following details pertain to one of the most advanced and common software and compilers developed by Microchip.


To program the PIC microcontroller, we require an IDE (Integrated Development Environment) for programming, a compiler to convert our program into a format readable by the MCU (called HEX files), and an IPE (Integrated Programming Environment) to load our HEX file into the PIC MCUs.


IDE: MPLABX v3.35


IPE: MPLAB IPE v3.35


Compiler: XC8


Microchip provides all three software tools for free, available for download from their official website. Links are provided for your convenience. After downloading, install them on your computer. If you encounter any issues during installation, feel free to ask in the comments below.


To load or upload our code into the PIC, we need a device called PICkit 3. The PICkit 3 programmer/debugger is an affordable, in-circuit debugger controlled by a PC running MPLAB IDE (version 8.20 or higher) on a Windows platform. It is an essential tool for development engineers. Additionally, other hardware, such as Perf boards or breadboards, a soldering station, PIC ICs, crystal oscillators, capacitors, etc., are also required.


Components associated with PIC: 


PICkit3, PIC Development Board, Crystal oscillators, capacitors, 12V Adapter, 7805 Voltage Regulator.


PIC16F877A Compiler


MPLAB XC8, Mikro C for PIC, PIC CCS compiler, and Hi-Tech compiler are the three commonly used compilers for programming PIC microcontrollers.


The official compiler, developed by the manufacturers of PIC16F877A, is the MPLAB XC8 compiler. For beginners, we typically recommend Mikro C for the PIC compiler, while the MPLAB XC8 compiler is more suitable for those interested in learning PIC microcontroller programming from a register-level bare metal perspective.


PIC16F877A Serial Port


The PIC16F877A features a single serial port for data communication.

In the diagram below, the serial pins of the PIC16F877A are indicated.


Serial Pins of PIC16F877a.png


As shown in the diagram:

  • Pin #25 serves as TX, so it is used for transmitting serial data during serial communication.

  • Pin #26 serves as RX, so it is used for receiving serial data during serial communication.



PIC16F877A I2C Communication


The PIC16F877A also includes an I2C port for I2C communication.

The I2C communication pins for the PIC16F877A are illustrated in the diagram below:


PIC16F877a I2C Communication Pins.png


In the diagram above, the I2C communication pins for the PIC16F877A are as follows:

  • Pin #18: Functions as SCL, which stands for Serial Clock Line.

  • Pin #23: Functions as SDA, which stands for Serial Data Line.

Port C can be used as a simple port or for both serial and I2C communications, providing flexibility to the programmer.


How to Interrupt PIC16F877A


I assume you're familiar with interrupts, but if not, you can learn about them in our "Interrupts in PIC Microcontroller" guide.

The PIC16F877A has 8 interrupt sources. An interrupt source is an event that triggers an interrupt. This source could be a timer, such as interrupts generated every second, or a pin state change event, where a change in pin state triggers an interrupt.

The 8 ways in which interrupts can be generated on the PIC16F877A are:


  1. External Interrupts.

  2. Timer Interrupts (Timer0 / Timer1).

  3. Port B State Change.

  4. Parallel enslaved person Port Read/Write.

  5. A/D Converter.

  6. Serial Receive / Transmit.

  7. PWM (CCP1 / CCP2).

  8. EEPROM Write Operation.


These interrupts are associated with the following 5 registers:

  • INTCON

  • PIE1

  • PIR1

  • PIE2

  • PIR2



PIC16F877A Applications


  • Various DIY projects

  • Excellent for learning PIC programming

  • Projects needing multiple I/O interfaces and communications

  • Substitute for Arduino modules

  • Ideal for advanced A/D applications in automotive, industrial, appliances, and consumer electronics.



Code to Light Up A Single Led/ Flashing Led


Here's a simple tutorial for blinking an LED with the PIC16F877A microcontroller using the Mikro C for the PIC compiler:


void main()

{

    TRISB.F0 = 0; // Set RB0 as an output pin


    do

    {

        PORTB.F0 = 1; // Set RB0 high (LED ON)

        Delay_ms(500); // Delay of 500 milliseconds


        PORTB.F0 = 0; // Set RB0 low (LED OFF)

        Delay_ms(500); // Delay of 500 milliseconds

    } while(1); // Infinite loop

}


This code toggles the RB0 pin with a 500ms delay. The TRISB.F0 = 0 line initializes RB0 as a digital output pin. The do-while loop is used to toggle the LED repeatedly. Inside the loop, PORTB.F0 = 1 sets RB0 high (LED ON) for 500ms, followed by setting it low (LED OFF) for another 500ms.


Circuit Diagram for Flashing Led With Pic16f877A


Circuit diagram for flashing LED WITH PIC16F877A.png


Create this circuit in Proteus, ensuring the pins are connected to the power source, ground, and oscillator as described in the pin description section. Use an 8MHz oscillator connected to OSCI and OSC2 with two 22-potofarad capacitors.


Connect a 10k ohm resistor to provide 5 volts to the Reset pin. Note that the resistor is not shown in the simulation but should be included in the practical circuit.


An LED is connected to pin 33 (RB0), with a resistor to limit the current and protect the LED from damage. Write and compile the program using MikroC Pro.


Upload the hex file to the microcontroller by double-clicking on the controller in Proteus. Use a PicKit3 programmer to run the circuit successfully.




How to Select Your PIC Microcontroller


Microchip offers a wide variety of microcontrollers from the PIC family, each with its advantages and disadvantages. Several factors should be considered before selecting a microcontroller for your project. The following points are suggestions that may help you choose the right microcontroller:


  • For beginners learning PIC, selecting a microcontroller with good online community support and wide applications is a wise choice. Examples include PIC16F877A and PIC18F4520.

  • Consider the operating voltage of your system. If it operates at 5V, choose a 5V microcontroller. Some sensors or devices work and communicate at 3.3V; in such cases, a 3.3V MCU may be more suitable.

  • If size and price are limiting factors, you can opt for small 8-pin MCUs like the PIC12F508, which are also relatively inexpensive.

  • Based on the sensors and actuators used in your project, determine which modules you might need in your MCU. For example, if you are reading many analog voltages, ensure the PIC has enough ADC channels and the required resolution. Details of all modules are provided in the table above.

  • If your project involves communication protocols such as UART, SPI, I2C, CAN, etc., ensure that your PIC can support them. Some MCUs can support multiple modules of the same protocol.





PIC16F877A Package



PIC16F877A Package.png


PIC16F877A Datasheet


Download PIC16F877A Datasheet PDF.


Conclusion


In conclusion, the PIC16F877A microcontroller stands as a versatile and reliable choice for embedded systems. With its robust architecture, ample I/O options, and efficient programming capabilities, it continues to be a popular choice among developers and hobbyists alike. Its ease of use, coupled with a wide range of applications, makes it a go-to option for various projects, from simple LED blinking to complex automation systems. Despite its age, the PIC16F877A remains a relevant and valuable component in the world of embedded systems, showcasing the enduring legacy of Microchip's PIC microcontroller series.


Read More


Precedente: CR123 vs. CR123A Batteries: How to Choose the Better One?

Prossimo: TL081 Op Amp Pinout, Datasheet, Equivalent, and Application

FAQ

  • What is PIC16F877A used for?
  • The PIC16F877A, known for its range of peripherals and low power usage, is ideal for home automation projects. It can effectively manage tasks such as controlling lighting, HVAC systems, security systems, and other smart home applications.

  • What is the difference between PIC16F877 and PIC16F877A?
  • The 16F877A is a more recent component. Its FLASH programming is faster and differs from that of the 16F877. Both versions are the same in terms of in-circuit debugging (ICD), but the 'A' version programs slightly faster, making the non-'A' version unnecessary.

  • What are the advantages of the PIC16F877A microcontroller?
  • The 16F877A features 14 KB of Flash program memory, providing ample space for storing and running code efficiently. This capacity allows for complex algorithms and firmware updates without extra external storage components.

  • Which architecture does PIC16F877A follow?
  • RISC architecture.

  • What is special about the PIC Microcontroller?
  • The PIC microcontroller is one of the smallest microcontrollers in the world, yet it can be designed to perform a wide range of tasks.

Ratings and Reviews

Reviews
 

Carrello

Acconto

jotrin03

Chat dal vivo

sales@jotrin.com