All Categories

Cart 0 item

Shopping cart 0 item

Mfr Part # Quantity
SUBMIT (0)

Select Language

Current Language

English

  • English
  • Deutsch
  • Italia
  • Français
  • 한국의
  • русский
  • Svenska
  • Nederland
  • español
  • Português
  • polski
  • Suomi
  • Gaeilge
  • Slovenská
  • Slovenija
  • Čeština
  • Melayu
  • Magyarország
  • Hrvatska
  • Dansk
  • românesc
  • Indonesia
  • Ελλάδα
  • Български език
  • Afrikaans
  • IsiXhosa
  • isiZulu
  • lietuvių
  • Maori
  • Kongeriket
  • Монголулс
  • O'zbek
  • Tiếng Việt
  • हिंदी
  • اردو
  • Kurdî
  • Català
  • Bosna
  • Euskera
  • العربية
  • فارسی
  • Corsa
  • Chicheŵa
  • עִבְרִית
  • Latviešu
  • Hausa
  • Беларусь
  • አማርኛ
  • Republika e Shqipërisë
  • Eesti Vabariik
  • íslenska
  • မြန်မာ
  • Македонски
  • Lëtzebuergesch
  • საქართველო
  • Cambodia
  • Pilipino
  • Azərbaycan
  • ພາສາລາວ
  • বাংলা ভাষার
  • پښتو
  • malaɡasʲ
  • Кыргыз тили
  • Ayiti
  • Қазақша
  • Samoa
  • සිංහල
  • ภาษาไทย
  • Україна
  • Kiswahili
  • Cрпски
  • Galego
  • नेपाली
  • Sesotho
  • Тоҷикӣ
  • Türk dili
  • ગુજરાતી
  • ಕನ್ನಡkannaḍa
  • मराठी
HomeBlogPIC16F877A: Pinout, Datasheet, Programming and Projects

IN-STOCK ELECTRONIC COMPONENTS.
FAST QUOTES.

Integrated Circuits, Power Devices & Passive Components
Immediate Sourcing Support

GET QUOTE NOW

PIC16F877A: Pinout, Datasheet, Programming and Projects

Time: August 25th, 2026

Browse: 882

The PIC16F877A is an 8-bit Flash microcontroller from Microchip designed for embedded control and monitoring. Available in 40- and 44-pin packages, it supports clock frequencies up to 20 MHz and provides 33 I/O pins for connecting sensors, switches, displays, alarms, motors and communication modules. Programs can be developed in C using MPLAB X IDE and the XC8 compiler, then loaded through In-Circuit Serial Programming (ICSP) with a compatible programmer such as a PICkit. PIC16F877A remains In Production, although Microchip lists the PIC16F18877 as the newer device. This article explains its pinout, specifications, practical testing, programming, real-world results, common problems and alternatives.

Catalog

PIC16F877A Microcontroller

Figure 1. PIC16F877A Microcontroller

PIC16F877A Microcontroller Pinout

 PIC16F877A Microcontroller Pinout

Figure 2. PIC16F877A Microcontroller Pinout

Pin
Pin name
Main functions
1
MCLR/VPP
Active-low master reset input and programming-voltage input.
2
RA0/AN0
Port A digital I/O and ADC analog input channel 0.
3
RA1/AN1
Port A digital I/O and ADC analog input channel 1.
4
RA2/AN2/VREF−/CVREF
Digital I/O, ADC channel 2, low ADC reference input and comparator reference output.
5
RA3/AN3/VREF+
Digital I/O, ADC channel 3 and high ADC reference input.
6
RA4/T0CKI/C1OUT
Digital I/O, Timer0 external clock input and Comparator 1 output. RA4 uses an open-drain output.
7
RA5/AN4/SS/C2OUT
Digital I/O, ADC channel 4, active-low SPI Slave Select input and Comparator 2 output.
8
RE0/RD/AN5
Port E digital I/O, active-low Parallel Slave Port read control and ADC channel 5.
9
RE1/WR/AN6
Port E digital I/O, active-low Parallel Slave Port write control and ADC channel 6.
10
RE2/CS/AN7
Port E digital I/O, active-low Parallel Slave Port chip select and ADC channel 7.
11
VDD
Positive power-supply connection.
12
VSS
Ground connection.
13
OSC1/CLKI
Crystal, resonator or external clock input.
14
OSC2/CLKO
Crystal or resonator output. In RC mode, CLKO outputs one-quarter of the oscillator frequency.
15
RC0/T1OSO/T1CKI
Port C digital I/O, Timer1 oscillator output and Timer1 external clock input.
16
RC1/T1OSI/CCP2
Digital I/O, Timer1 oscillator input and CCP2 capture, compare or PWM connection.
17
RC2/CCP1
Digital I/O and CCP1 capture, compare or PWM connection.
18
RC3/SCK/SCL
Digital I/O, SPI clock input/output and I²C clock input/output.
19
RD0/PSP0
Port D digital I/O and Parallel Slave Port data bit 0.
20
RD1/PSP1
Port D digital I/O and Parallel Slave Port data bit 1.
21
RD2/PSP2
Port D digital I/O and Parallel Slave Port data bit 2.
22
RD3/PSP3
Port D digital I/O and Parallel Slave Port data bit 3.
23
RC4/SDI/SDA
Digital I/O, SPI data input and I²C data input/output.
24
RC5/SDO
Digital I/O and SPI data output.
25
RC6/TX/CK
Digital I/O, USART asynchronous transmit and synchronous clock input/output.
26
RC7/RX/DT
Digital I/O, USART asynchronous receive and synchronous data input/output.
27
RD4/PSP4
Port D digital I/O and Parallel Slave Port data bit 4.
28
RD5/PSP5
Port D digital I/O and Parallel Slave Port data bit 5.
29
RD6/PSP6
Port D digital I/O and Parallel Slave Port data bit 6.
30
RD7/PSP7
Port D digital I/O and Parallel Slave Port data bit 7.
31
VSS
Ground connection.
32
VDD
Positive power-supply connection.
33
RB0/INT
Port B digital I/O and external interrupt input.
34
RB1
Port B digital I/O.
35
RB2
Port B digital I/O.
36
RB3/PGM
Digital I/O and low-voltage ICSP programming-enable input.
37
RB4
Digital I/O with interrupt-on-change capability.
38
RB5
Digital I/O with interrupt-on-change capability.
39
RB6/PGC
Digital I/O, interrupt-on-change, ICSP programming clock and debugging clock.
40
RB7/PGD
Digital I/O, interrupt-on-change, ICSP programming data and debugging data.

Both VDD pins and both VSS pins must be connected. PORTB pins support software-controlled weak pull-ups, while RB4–RB7 support interrupt-on-change. Analog-capable pins must be configured correctly before being used as digital I/O.

PIC16F877A Orderable Part Numbers and Packages

The temperature suffix identifies the operating range: I mean industrial, while E means extended. The package code after the slash identifies either P for PDIP or PT for TQFP.

Orderable part number
Package type
Pin count
Operating temperature
PIC16F877A-I/P
PDIP
40
−40 °C to +85 °C, industrial
PIC16F877A-I/PT
TQFP
44
−40 °C to +85 °C, industrial
PIC16F877A-E/P
PDIP
40
−40 °C to +125 °C, extended
PIC16F877A-E/PT
TQFP
44
−40 °C to +125 °C, extended

All four versions provide the same 8K × 14-word program memory, 368 bytes of SRAM, 256 bytes of EEPROM and 33 I/O pins. These specifications are therefore stated once instead of being repeated in the table.

PIC16F877A Architecture and Working Principle

PIC16F877A Architecture

The PIC16F877A uses an 8-bit RISC CPU with Harvard architecture. Its 14-bit program bus and 8-bit data bus are separate, allowing the CPU to fetch instructions while accessing data. It contains 8K × 14-bit Flash program memory, 368 bytes of RAM and 256 bytes of data EEPROM.

The 13-bit program counter selects instructions, while the eight-level hardware stack stores return addresses for subroutines and interrupts. The ALU, W register and STATUS register process data. PORTA through PORTE provide 33 I/O pins.

PIC16F877A Architecture Block Diagram. Source: Microchip PIC16F87XA Data Sheet, Figure 1-2.

Figure 3. PIC16F877A Architecture Block Diagram

PIC16F877A Instruction Cycle

The oscillator clock is divided into four phases, Q1 through Q4. Therefore, the instruction clock runs at , and one instruction cycle lasts. At 20 MHz, this equals 200 ns. A two-stage pipeline fetches the next instruction while executing the previous one. Most instructions take one cycle, while branches require two cycles because the pipeline must be cleared.

 PIC16F877A Instruction Cycle

Figure 4. PIC16F877A Instruction Cycle

Interrupt and Peripheral Operation

When an enabled interrupt occurs, the CPU stores the return address on the hardware stack, clears the global interrupt enable bit and jumps to address 0004h. The interrupt routine checks and clears the relevant flag before RETFIE restores normal execution. Firmware must save important registers such as W, STATUS and PCLATH when required.

Timers, ADC, CCP/PWM, USART, SPI, I²C, comparators and the Parallel Slave Port are controlled through special function registers. These peripherals can operate alongside the CPU, set status flags and generate interrupts when enabled.

PIC16F877A Technical Specifications

Specification
PIC16F877A
CPU Architecture
8-bit RISC
Maximum Clock Frequency
20 MHz
Maximum Performance
5 MIPS
Program Memory
8K × 14-bit words
SRAM
368 bytes
Data EEPROM
256 bytes
I/O Pins
33
Operating Voltage
4.0–5.5 V
ADC
10-bit, 8 channels
Timers
Two 8-bit and one 16-bit
CCP/PWM Modules
2 modules, PWM resolution up to 10 bits
Communication Interfaces
USART, SPI and I²C
Interrupt Sources
15
Comparators
2
Package Options
40-pin PDIP and 44-pin surface-mount packages
Operating Temperature
−40°C to +85°C or −40°C to +125°C, depending on model

PIC16F877A Minimum Circuit and Test Procedure

 PIC16F877A minimum operating circuit, ICSP header and RD0 test LED

Figure 5. PIC16F877A minimum operating circuit, ICSP header and RB0 test LED

Figure 5 shows the minimum connections required to operate and program a 40-pin PIC16F877A. Both VDD pins, 11 and 32, connect to the regulated +5 V rail, while VSS pins 12 and 31 connect to ground. A separate 100 nF ceramic capacitor must be placed close to each VDD–VSS pair. The optional 4.7–10 µF capacitor near J2 provides additional supply filtering. The RB0 test LED matches the programming example in C6.

The MCLR/VPP pin is pulled up to +5 V through a 10 kΩ resistor. A 20 MHz parallel-cut crystal connects between OSC1 on pin 13 and OSC2 on pin 14. Each oscillator pin connects to ground through a load capacitor. The illustrated 22 pF values are starting values; the final values should follow the crystal manufacturer’s load-capacitance specification. The oscillator configuration must be set to HS.

The ICSP header connects as follows:

ICSP signal
PIC16F877A connection
MCLR/VPP
Pin 1
VDD Target/Sense
+5 V rail
VSS
Ground
PGD
RB7, pin 40
PGC
RB6, pin 39
PGM/AUX
RB3, pin 36

For high-voltage ICSP, pins 1–5 are used and the LVP configuration bit should be disabled. If low-voltage programming is used, RB3/PGM must remain connected and cannot be used as a normal output. Only one source should power the circuit at a time: either J2 or the PICkit.

RB0 on pin 33 drives the test LED through a 470 Ω current-limiting resistor. Connect RB0 to the resistor, connect the resistor to the LED anode, and connect the LED cathode to VSS. The LED turns on when RB0 is high.

Proposed Test Procedure

• With power disconnected, inspect the wiring, capacitor connections, crystal, LED polarity and IC orientation.

• Check that the +5 V rail is not shorted to ground.

• Apply a regulated, current-limited +5 V supply. Confirm that both VDD–VSS pairs receive the correct voltage.

• Connect the ICSP programmer and select the PIC16F877A. Configure FOSC = HS and, for high-voltage ICSP, LVP = OFF.

• Program and verify the C6 example, which configures RB0 as an output and changes its state every 500 ms.

• Apply power and observe the LED. A repeating flash is the expected indication that the power, reset, oscillator, programming and RB0 output circuits are working together.

Note: This is a proposed verification procedure only. No physical test or measured result is claimed. Any reported test should identify the board, firmware, supply, instruments, probe settings and measured values.

PIC16F877A Programming with MPLAB and XC8

The PIC16F877A can be programmed in C using MPLAB X IDE and the MPLAB XC8 compiler. MPLAB X manages the project and programming tool, while XC8 generates the HEX file.

This example targets MPLAB X IDE v6.35 and MPLAB XC8 v4.00. No local compilation or hardware test was performed while preparing this example, so no successful-build or measured result is claimed. These were the current official versions as of August 2026. If PICkit 3 is used, note that MPLAB X v6.20 is its final supported version.

• Install MPLAB X IDE and MPLAB XC8.

• Select File > New Project > Microchip Embedded > Standalone Project.

• Select PIC16F877A, the connected programmer, and XC8.

• Create a main.c source file and enter the following program.

• Build the project, then select Make and Program Device.

Connect the test LED as follows:

RB0 (pin 33) → 330 Ω–1 kΩ resistor → LED anode → LED cathode → VSS

#include

#define _XTAL_FREQ 20000000UL

#pragma config FOSC = HS

#pragma config WDTE = OFF

#pragma config PWRTE = ON

#pragma config BOREN = ON

#pragma config LVP = OFF

#pragma config CPD = OFF

#pragma config WRT = OFF

#pragma config CP = OFF

void main(void)

{

PORTBbits.RB0 = 0;

TRISBbits.TRISB0 = 0;

while (1)

{

PORTBbits.RB0 = 1;

__delay_ms(500);

PORTBbits.RB0 = 0;

__delay_ms(500);

}

}

For ICSP programming, connect MCLR/VPP, RB6/PGC, RB7/PGD, VDD and VSS. The FOSC = HS setting and _XTAL_FREQ value must match the installed 20 MHz crystal.

Version information: Microchip Technology Inc., MPLAB X IDE, v6.35, released 24 July 2026; and MPLAB XC8 Compiler, v4.00, released 8 July 2026. Accessed 24 August 2026.

Published PIC16F877A Project Case Studies

The following case studies summarize results reported by independent researchers.

Published Solar-Tracking Study

Manju and Katoch (2014) developed a PIC16F877A single-axis solar tracker using three LDRs, a geared stepper motor, voltage and current sensing, an LCD and RS-232 communication.

During a one-day test at NIT Hamirpur on 19 February 2014, the researchers recorded nine hourly comparisons under irradiance levels of 96.423–810.295 W/m². They summed the sampled power readings as 4.6388 W for the fixed panel and 5.5071 W for the tracker, reporting an improvement of 18.7167%.

This third-party result was based on one day and did not include uncertainty, repeated-day testing or the tracker’s operating energy. Because instantaneous power readings were added rather than energy being measured in watt-hours, the reported improvement should not be interpreted as a universal daily energy gain.

Published Remote Temperature-Monitoring Study

Gharghan (2017) developed a PIC16F877A temperature-monitoring system using an LM35 sensor, LCD, buzzer and SmartG100 GSM modem. The controller periodically measured temperature and sent SMS alerts for urgent conditions.

The published comparison with a digital thermometer reported a mean absolute error of 0.205°C and an R² value of 0.987. Using measured active and sleep-mode currents, the study calculated an average current of 3.087 mA with its sleep/wake algorithm, compared with 315.138 mA during continuous operation. For a 1,000 mAh battery, the researcher estimated approximately 324 hours of operation instead of three hours.

These third-party findings were not reproduced here. The paper did not clearly report the number of patients or SMS-delivery trials, and the estimated battery life was calculated rather than confirmed through a complete discharge test. The prototype demonstrates technical feasibility but does not constitute clinical validation.

PIC16F877A Functions and Applications

• Analog sensing: The eight-channel, 10-bit ADC can monitor temperature, light, pressure, voltage and other analog signals.

• PWM and motor control: Two CCP/PWM modules can regulate motor speed, LED brightness, pumps, fans and valves through suitable driver circuits.

• Serial communication: USART, SPI and I²C interfaces support communication with computers, sensors, GSM or GPS modules, EEPROMs and real-time clocks.

• Display interfacing: Its 33 shared-function I/O pins can connect to LCDs, seven-segment displays, keypads, switches, LEDs and buzzers.

• Data storage: The 256-byte EEPROM retains settings, calibration values and small records after power is removed.

• Timing: Three hardware timers and interrupt functions support delays, pulse measurement, event counting and fast responses to external events.

• System protection: The watchdog timer, brown-out reset, power-up timer and MCLR input help the controller recover from program or supply-voltage faults.

These functions suit water-level controllers, alarms, data loggers, temperature controllers and small automation systems. Motors, relays and other high-current loads require external drivers. The PIC16F877A also has no built-in Wi-Fi, Bluetooth or USB.

Common PIC16F877A Problems and Fixes

Problem
Likely Cause
Recommended Fix
Microcontroller does not start
Incorrect power, floating MCLR or missing clock
Check both VDD–VSS pairs, use a regulated supply, add a 10 kΩ MCLR pull-up and verify the external oscillator
Programmer cannot detect the IC
Incorrect ICSP wiring or heavily loaded programming pins
Check MCLR/VPP, RB6/PGC, RB7/PGD, VDD and VSS connections
Program runs at the wrong speed
Oscillator setting does not match the hardware
Select the correct oscillator configuration and set _XTAL_FREQ to the actual clock frequency
PORTA or PORTE does not work digitally
Pins remain configured as analog inputs
Configure the ADCON1 register for the required digital or analog functions
RB3 does not work as GPIO
Low-voltage programming is enabled
Disable the LVP configuration bit when RB3/PGM is needed as normal GPIO
RA4 does not produce a high output
RA4 uses an open-drain output structure
Add an external pull-up resistor to RA4
ADC readings are unstable
Noisy supply, poor grounding or insufficient acquisition time
Add decoupling, use a stable reference, reduce source impedance and allow enough acquisition time
UART data is corrupted
Incorrect baud-rate or oscillator setting
Recalculate SPBRG using the actual clock frequency and confirm matching baud rates
I²C communication fails
Missing pull-up resistors or incorrect pin direction
Add pull-ups to RC3/SCL and RC4/SDA and configure both pins correctly
PWM output is missing
CCP or Timer2 is not configured correctly
Configure the CCP module, PR2, Timer2 prescaler and PWM output pin
Random resets occur
Supply dips, electrical noise, Watchdog Timer or unstable MCLR
Improve decoupling, check reset settings and protect MCLR from noise
Motor or relay causes resets
Load is connected directly to a GPIO pin
Use a transistor or MOSFET driver and add a flyback diode across inductive loads
Sleep current is too high
External loads, floating inputs or programmer remains connected
Disconnect unnecessary loads, set unused pins to defined levels and remove the programmer during measurement

PIC16F877A Compared with Alternatives

Feature
PIC16F877A
PIC16F887
PIC16F18877
ATmega328P
Architecture
Classic mid-range 8-bit PIC
Classic mid-range 8-bit PIC
Enhanced mid-range 8-bit PIC
8-bit AVR
Maximum clock and instruction rate
20 MHz, 5 MIPS at 4.0–5.5 V
20 MHz, 5 MIPS at 4.5–5.5 V; lower supply voltages require lower clock rates
32 MHz, 8 MIPS at 2.5–5.5 V; up to 16 MHz at 2.3–5.5 V
20 MHz, up to 20 MIPS at 4.5–5.5 V; 10 MHz at 2.7–5.5 V; 4 MHz at 1.8–5.5 V
Program memory
8K × 14-bit words
8K × 14-bit words
32K × 14-bit words
32 KB
SRAM
368 bytes
368 bytes
4,096 bytes
2,048 bytes
EEPROM
256 bytes
256 bytes
256 bytes
1,024 bytes
I/O pins
33
35
Up to 36
23
ADC
10-bit, 8 channels
10-bit, 14 channels
10-bit ADC with computation, up to 35 channels
10-bit, 6 channels in PDIP or 8 in TQFP/QFN
Internal main oscillator
No
Yes, up to 8 MHz
Yes, up to 32 MHz
Yes, 8 MHz
Operating voltage
4.0–5.5 V
2.0–5.5 V
2.3–5.5 V
1.8–5.5 V
Communication
USART, SPI and I²C
EUSART, SPI and I²C
EUSART, two SPI and two I²C modules
USART, SPI and TWI/I²C
Main advantage
Simple and widely documented
More ADC channels and an internal oscillator
More memory and modern peripherals
Extensive Arduino and AVR support
Main limitation
Very limited RAM and no internal main oscillator
Limited memory and older architecture
Not a direct replacement for PIC16F877A designs
Not recommended for new designs
Best suited to
Existing boards and learning projects
Simple 40-pin control projects
New PIC-based products
Existing Arduino or AVR projects

Microchip identifies PIC16F18877 as the newer device for PIC16F877A, but migration requires firmware, peripheral and pinout verification.




Technical References

• Microchip Technology Inc. (2013). PIC16F87XA Data Sheet (DS39582C).

• Microchip Technology Inc. (2026). MPLAB XC8 C Compiler User’s Guide for PIC MCU (DS50002737L).

• Microchip Technology Inc. (2021). PIC16(L)F18857/77 Data Sheet (DS40001825F).

• Microchip PIC16F87XA Data Sheet, DS39582C; PIC16F87XA Flash Programming Specification, DS39589B.

• Manju, S., and Katoch, S. S. (2014). “Design of Photo-voltaic Solar Tracking System Based on Peripheral Interface Controller.” International Journal of Current Engineering and Technology, 4(3), 1800–1805.

• Gharghan, S. K. (2017). “Energy-Efficient Remote Temperature Monitoring System for Patients Based on GSM Modem and Microcontroller.” Journal of Communications, 12(8), 433–442.






Frequently Asked Questions [FAQ]

1. Why is the program memory listed as 8K × 14-bit words instead of 8 KB?

The PIC16F877A stores instructions in 14-bit words. It provides 8,192 instruction words, equivalent to approximately 14.3 KB of physical Flash storage. It should not be described simply as 8 KB.

2. Can firmware be updated without an ICSP programmer?

Yes, but a compatible bootloader must first be installed through ICSP. The bootloader can then receive new firmware through USART, although it uses part of the available program memory.

3. How accurate is the 10-bit ADC?

With a 5.0 V reference, the ideal ADC step size is approximately 4.88 mV. Actual accuracy also depends on reference stability, electrical noise, source impedance, acquisition time and calibration.

4. Can the ADC measure voltages above 5 V?

Not directly. Use a correctly calculated voltage divider, buffer or signal-conditioning circuit to keep the ADC input within its reference-voltage range. Input protection may also be required.

5. Can the PIC16F877A run an RTOS?

A small scheduler is possible, but its 368-byte RAM and eight-level hardware stack make a full RTOS impractical. Timer interrupts and cooperative task scheduling are usually more suitable.

6. How can larger amounts of data be logged?

The internal 256-byte EEPROM is suitable only for small settings and records. Use external EEPROM, FRAM or an SD card for larger logs, and apply wear leveling when data is written frequently.

7. Can the PIC16F877A run PID control algorithms?

Yes, especially for relatively slow systems such as temperature, speed and level control. Fixed-point arithmetic is usually preferable because floating-point calculations require more processing time and program memory.

8. Do code-protection bits fully secure the firmware?

The CP and CPD configuration bits block normal program and data-memory reading through standard programming tools. However, they do not guarantee protection against advanced physical extraction methods.

Related Article

Online RFQ submissions: Fast responses, Better prices!

RFQ