Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Component Documentation

How to Use PIC16F877A: Examples, Pinouts, and Specs

Image of PIC16F877A
Cirkit Designer LogoDesign with PIC16F877A in Cirkit Designer

Introduction

The PIC16F877A is an 8-bit microcontroller developed by Microchip Technology. It features a 14-bit instruction set architecture, 368 bytes of RAM, 256 bytes of EEPROM, and a wide range of peripherals, making it a versatile choice for embedded systems. This microcontroller is widely used in control applications, automation, robotics, and other embedded systems due to its reliability, low power consumption, and ease of programming.

Explore Projects Built with PIC16F877A

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
ATMEGA328 Battery-Powered LED Blinker with FTDI Programming
Image of Homemade Arduino using ATmega328: A project utilizing PIC16F877A in a practical application
This circuit is a basic microcontroller setup using an ATMEGA328, powered by a 5V battery, and includes an FTDI programmer for serial communication. It features a pushbutton for reset functionality and two LEDs controlled by the microcontroller, with one LED blinking at a 1-second interval as programmed.
Cirkit Designer LogoOpen Project in Cirkit Designer
RTL8720DN-Based Interactive Button-Controlled TFT Display
Image of coba-coba: A project utilizing PIC16F877A in a practical application
This circuit features an RTL8720DN microcontroller interfaced with a China ST7735S 160x128 TFT LCD display and four pushbuttons. The microcontroller reads the states of the pushbuttons and displays their statuses on the TFT LCD, providing a visual feedback system for button presses.
Cirkit Designer LogoOpen Project in Cirkit Designer
STM32F103C8T6-Based Spectral Sensor with ST7735S Display and Pushbutton Control
Image of ColorSensor: A project utilizing PIC16F877A in a practical application
This circuit features an STM32F103C8T6 microcontroller interfaced with a China ST7735S 160x128 display and two spectral sensors (Adafruit AS7262 and AS7261). It also includes two pushbuttons for user input, with the microcontroller managing the display and sensor data processing.
Cirkit Designer LogoOpen Project in Cirkit Designer
STM32 and ESP32 CAN Bus Communication System with MCP2515
Image of CAR HACKING: A project utilizing PIC16F877A in a practical application
This circuit integrates multiple microcontrollers (STM32F103C8T6, ESP32, and Raspberry Pi Pico W) with MCP2515 CAN controllers to facilitate CAN bus communication. The microcontrollers are connected to the MCP2515 modules via SPI interfaces, and the circuit includes USB-to-serial converters for programming and debugging purposes.
Cirkit Designer LogoOpen Project in Cirkit Designer

Explore Projects Built with PIC16F877A

Use Cirkit Designer to design, explore, and prototype these projects online. Some projects support real-time simulation. Click "Open Project" to start designing instantly!
Image of Homemade Arduino using ATmega328: A project utilizing PIC16F877A in a practical application
ATMEGA328 Battery-Powered LED Blinker with FTDI Programming
This circuit is a basic microcontroller setup using an ATMEGA328, powered by a 5V battery, and includes an FTDI programmer for serial communication. It features a pushbutton for reset functionality and two LEDs controlled by the microcontroller, with one LED blinking at a 1-second interval as programmed.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of coba-coba: A project utilizing PIC16F877A in a practical application
RTL8720DN-Based Interactive Button-Controlled TFT Display
This circuit features an RTL8720DN microcontroller interfaced with a China ST7735S 160x128 TFT LCD display and four pushbuttons. The microcontroller reads the states of the pushbuttons and displays their statuses on the TFT LCD, providing a visual feedback system for button presses.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of ColorSensor: A project utilizing PIC16F877A in a practical application
STM32F103C8T6-Based Spectral Sensor with ST7735S Display and Pushbutton Control
This circuit features an STM32F103C8T6 microcontroller interfaced with a China ST7735S 160x128 display and two spectral sensors (Adafruit AS7262 and AS7261). It also includes two pushbuttons for user input, with the microcontroller managing the display and sensor data processing.
Cirkit Designer LogoOpen Project in Cirkit Designer
Image of CAR HACKING: A project utilizing PIC16F877A in a practical application
STM32 and ESP32 CAN Bus Communication System with MCP2515
This circuit integrates multiple microcontrollers (STM32F103C8T6, ESP32, and Raspberry Pi Pico W) with MCP2515 CAN controllers to facilitate CAN bus communication. The microcontrollers are connected to the MCP2515 modules via SPI interfaces, and the circuit includes USB-to-serial converters for programming and debugging purposes.
Cirkit Designer LogoOpen Project in Cirkit Designer

Common Applications and Use Cases

  • Industrial automation and control systems
  • Home automation devices
  • Robotics and motor control
  • Data acquisition systems
  • IoT (Internet of Things) devices
  • Educational projects and prototyping

Technical Specifications

Key Technical Details

  • Architecture: 8-bit
  • Instruction Set: 14-bit
  • Operating Voltage: 2.0V to 5.5V
  • Clock Speed: Up to 20 MHz
  • RAM: 368 bytes
  • EEPROM: 256 bytes
  • Flash Program Memory: 8 KB
  • I/O Pins: 33 (5 ports: PORTA, PORTB, PORTC, PORTD, PORTE)
  • Timers: 3 (Timer0, Timer1, Timer2)
  • ADC: 10-bit, 8 channels
  • Communication Interfaces: USART, SPI, I2C
  • PWM Channels: 2
  • Watchdog Timer: Yes
  • Package Types: DIP, QFP, PLCC

Pin Configuration and Descriptions

The PIC16F877A has 40 pins in the DIP package. Below is a summary of the pin configuration:

Pin Number Pin Name Description
1 MCLR/VPP Master Clear (Reset) / Programming Voltage
2-7 RA0-RA5 PORTA: Analog/Digital I/O
8 VSS Ground (0V)
9-10 OSC1/OSC2 Oscillator Input/Output
11-18 RB0-RB7 PORTB: Digital I/O, Interrupt-on-Change
19 VDD Positive Supply Voltage
20-27 RC0-RC7 PORTC: Digital I/O, Communication Pins
28-35 RD0-RD7 PORTD: Digital I/O
36-40 RE0-RE2 PORTE: Digital I/O, Analog Inputs

Usage Instructions

How to Use the PIC16F877A in a Circuit

  1. Power Supply: Connect the VDD pin to a 5V power source and the VSS pin to ground.
  2. Oscillator Setup: Connect a crystal oscillator (e.g., 20 MHz) between OSC1 and OSC2 pins, along with two capacitors (typically 22 pF) to stabilize the clock signal.
  3. Reset Circuit: Connect a pull-up resistor (10 kΩ) to the MCLR pin for proper reset functionality.
  4. I/O Configuration: Configure the I/O pins (PORTA, PORTB, etc.) as input or output in the program code.
  5. Programming: Use an ICSP (In-Circuit Serial Programming) tool or a PIC programmer to upload the firmware.

Important Considerations and Best Practices

  • Use decoupling capacitors (0.1 µF) near the VDD and VSS pins to reduce noise.
  • Ensure proper grounding to avoid signal interference.
  • Avoid leaving unused pins floating; configure them as inputs with pull-up resistors or as outputs.
  • Use appropriate pull-up or pull-down resistors for input pins to prevent erratic behavior.
  • For ADC applications, ensure the analog reference voltage (VREF) is stable and noise-free.

Example Code for Interfacing with an LED

Below is an example of how to blink an LED connected to PORTB pin RB0 using the PIC16F877A:

// Include the header file for the PIC16F877A microcontroller
#include <xc.h>

// Configuration bits
#pragma config FOSC = HS        // High-speed oscillator
#pragma config WDTE = OFF       // Watchdog Timer disabled
#pragma config PWRTE = ON       // Power-up Timer enabled
#pragma config BOREN = ON       // Brown-out Reset enabled
#pragma config LVP = OFF        // Low-Voltage Programming disabled
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection disabled
#pragma config WRT = OFF        // Flash Program Memory Write Protection disabled
#pragma config CP = OFF         // Flash Program Memory Code Protection disabled

#define _XTAL_FREQ 20000000     // Define the oscillator frequency (20 MHz)

void main() {
    TRISB0 = 0;                 // Set RB0 as output
    while (1) {
        RB0 = 1;                // Turn on the LED
        __delay_ms(500);        // Delay for 500 ms
        RB0 = 0;                // Turn off the LED
        __delay_ms(500);        // Delay for 500 ms
    }
}

Interfacing with Arduino UNO

The PIC16F877A is not directly compatible with Arduino IDE, but it can communicate with an Arduino UNO via UART (USART). Use the Arduino's Serial library to send and receive data.

Troubleshooting and FAQs

Common Issues and Solutions

  1. Microcontroller Not Responding

    • Cause: Incorrect power supply or oscillator configuration.
    • Solution: Verify the power supply voltage (2.0V to 5.5V) and ensure the crystal oscillator and capacitors are properly connected.
  2. Program Not Uploading

    • Cause: Faulty ICSP connection or incorrect programmer settings.
    • Solution: Check the ICSP connections and ensure the programmer is configured for the PIC16F877A.
  3. I/O Pins Not Working

    • Cause: Pins not configured correctly in the code.
    • Solution: Verify the TRIS register settings to ensure pins are set as input or output as required.
  4. ADC Not Functioning

    • Cause: Improper analog reference voltage or configuration.
    • Solution: Ensure the VREF pin is connected to a stable voltage and configure the ADCON registers correctly.

FAQs

  • Q: Can the PIC16F877A operate at 3.3V?
    A: Yes, the PIC16F877A can operate at voltages as low as 2.0V, but ensure the clock speed is adjusted accordingly.

  • Q: How many times can the EEPROM be written?
    A: The EEPROM can be written up to 1,000,000 times.

  • Q: Can I use the PIC16F877A for low-power applications?
    A: Yes, the microcontroller has low-power modes such as Sleep mode to conserve energy.

  • Q: What is the maximum clock speed of the PIC16F877A?
    A: The maximum clock speed is 20 MHz.

This documentation provides a comprehensive guide to using the PIC16F877A microcontroller effectively in your projects.