Zbotic Logo Zbotic Logo
  • Home
  • Shop
  • Sale
  • 3D Printing
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

  • Shop
  • About Us
  • Contact Us
  • Reseller
  • Blogs
020 69134444
1800 209 0998
[email protected]
Help Desk
Facebook Twitter Instagram Linkedin YouTube
Zbotic Logo Zbotic Logo
0 0

View Wishlist Add all to cart

0 0
0 Shopping Cart
Shopping cart (0)
Subtotal: ₹0.00

View cartCheckout

All departments
  • 3D Printing
  • 3D Printer
  • Batteries & Chargers
  • Development Boards
  • Drone Parts
  • EBike parts
  • Sensor Modules
  • Electronic Components
  • Electronic Modules
  • IoT and Wireless
  • Mechanical Parts and Workbench Tools
  • Motors & Drivers & Pumps & Actuators
  • DIY and Robot Kits
  • Show more
  • Home
  • Shop
  • Sale
  • 3D Printing
  • PCB Service
  • B2B
  • Blogs
  • Contact Us
Return to previous page
Home Development Boards & SBCs

PIC16F877A Tutorial: MPLAB X and XC8 for Beginners India

PIC16F877A Tutorial: MPLAB X and XC8 for Beginners India

March 11, 2026 /Posted byJayesh Jain / 0

The PIC16F877A microcontroller with MPLAB X IDE and XC8 compiler is a foundational combination for embedded systems education in India. PIC microcontrollers from Microchip Technology are widely used in Indian engineering curricula alongside 8051, and the PIC16F877A specifically is covered in numerous BE/BTech, diploma, and AMIE examinations. This tutorial guides Indian beginners through setting up MPLAB X and writing their first XC8 C programs for PIC16F877A.

Table of Contents

  • Why PIC16F877A in India
  • PIC16F877A Specifications
  • MPLAB X IDE Installation
  • Creating Your First Project
  • LED Blink Program in XC8
  • ADC and UART Examples
  • Programming with PICkit
  • Frequently Asked Questions

Why PIC16F877A in India

PIC16F877A is one of the most taught microcontrollers in Indian technical education for several reasons:

  • Curriculum coverage: Featured in RGPV, SPPU, VTU, and most Indian university syllabi for Microcontroller courses
  • Rich peripherals: Has ADC, UART, SPI, I2C, PWM and timers all in one 40-pin DIP package
  • Cost-effective: Available in India for ₹80–₹150 per chip
  • Industry usage: Widely deployed in industrial control, consumer electronics, and automotive applications
  • Proteus simulation: Excellent Proteus ISIS support for simulation before hardware testing

PIC16F877A Specifications

  • Architecture: 8-bit RISC PIC mid-range
  • Clock: Up to 20 MHz (4 MHz internal oscillator available)
  • Program Memory: 14,336 words (14KB) flash
  • Data Memory: 368 bytes RAM + 256 bytes EEPROM
  • I/O Pins: 33 across PORTA–PORTE
  • ADC: 8-channel, 10-bit
  • Timers: Timer0 (8/16-bit), Timer1 (16-bit), Timer2 (8-bit)
  • Communication: UART (USART), SPI, I2C (MSSP module)
  • PWM: 2 CCP modules for PWM/Compare/Capture
  • Package: 40-pin DIP
Recommended: Arduino Uno R3 Beginners Kit — Learn prototyping and electronics fundamentals with Arduino to complement PIC16F877A programming studies.

MPLAB X IDE Installation

  1. Download MPLAB X IDE from microchip.com/mplab/mplab-x-ide (free, ~1.5GB)
  2. Download XC8 Compiler from microchip.com/mplab/compilers (free community version)
  3. Install MPLAB X first, then XC8
  4. Launch MPLAB X — it should detect XC8 automatically
  5. Create New Project → Standalone Project → select PIC16F877A
  6. Select XC8 as compiler
  7. Select PICkit 3 or 4 as programmer (or Simulator for testing)

Note: The free XC8 compiler optimisation level is “0” (no optimisation). Pro licence enables optimisation but is not required for learning and most projects.

Creating Your First Project

Every PIC16F877A project needs configuration bits set. In MPLAB X, go to Window → PIC Memory Views → Configuration Bits:

// Configuration bits for PIC16F877A
// Typical settings for 20 MHz crystal with MPLAB X
// pragma config generates the configuration words

#pragma config FOSC = HS      // High-Speed crystal/resonator
#pragma config WDTE = OFF     // Watchdog Timer disabled
#pragma config PWRTE = OFF    // Power-up Timer disabled
#pragma config BOREN = ON     // Brown-out Reset enabled
#pragma config LVP = OFF      // Low-Voltage Programming disabled
#pragma config CPD = OFF      // Data EEPROM code protection off
#pragma config WRT = OFF      // Flash Write protection off
#pragma config CP = OFF       // Code protection off

#include <xc.h>
#define _XTAL_FREQ 20000000  // Define crystal frequency for __delay_ms

LED Blink Program in XC8

// PIC16F877A LED Blink - MPLAB X / XC8
#pragma config FOSC = HS
#pragma config WDTE = OFF
#pragma config PWRTE = OFF
#pragma config BOREN = ON
#pragma config LVP = OFF
#pragma config CPD = OFF
#pragma config WRT = OFF
#pragma config CP = OFF

#include <xc.h>
#define _XTAL_FREQ 20000000

void main(void) {
    TRISB = 0;   // PORTB as output (all pins)
    PORTB = 0;   // Clear all outputs
    
    while(1) {
        PORTB = 0xFF;    // All LEDs ON
        __delay_ms(500); // 500ms delay
        PORTB = 0x00;    // All LEDs OFF
        __delay_ms(500);
    }
}

// Individual bit manipulation
void main(void) {
    TRISBbits.TRISB0 = 0;  // RB0 as output
    TRISBbits.TRISB1 = 1;  // RB1 as input (button)
    
    while(1) {
        if (PORTBbits.RB1 == 0) {  // Button pressed
            LATBbits.LATB0 = 1;   // LED ON
        } else {
            LATBbits.LATB0 = 0;   // LED OFF
        }
    }
}

ADC and UART Examples

// ADC Reading on PIC16F877A
void ADC_Init() {
    ADCON1 = 0x80;   // Right justify, all pins analog, Vref=VDD
    ADCON0 = 0x41;   // ADC ON, channel 0 (RA0), Fosc/16
}

unsigned int ADC_Read(unsigned char channel) {
    ADCON0 &= 0xC5;            // Clear channel bits
    ADCON0 |= (channel << 3);  // Select channel
    __delay_us(20);            // Acquisition time
    GO_nDONE = 1;              // Start conversion
    while(GO_nDONE);           // Wait for completion
    return ((ADRESH << 8) | ADRESL);
}

// UART on PIC16F877A at 9600 baud with 20 MHz crystal
void UART_Init() {
    TRISC6 = 0;   // TX as output
    TRISC7 = 1;   // RX as input
    SPBRG = 129;  // Baud rate 9600 @ 20MHz: SPBRG = (20MHz/(64*9600))-1 = 32... use 129 for high speed
    BRGH = 1;     // High baud rate mode: SPBRG = (Fosc/(16*baud))-1 = 129
    TXEN = 1;     // Enable transmitter
    SPEN = 1;     // Enable serial port
}

void UART_TxChar(char c) {
    while(!TXIF);  // Wait until transmit buffer empty
    TXREG = c;
}

void UART_SendString(const char *str) {
    while(*str) UART_TxChar(*str++);
}
Recommended: Arduino UNO R3 CH340G Development Board — Arduino’s easier programming model helps you understand ADC and UART concepts before implementing them on PIC16F877A.

Programming with PICkit

Microchip’s PICkit 3 or PICkit 4 are the standard programming tools for PIC microcontrollers:

  • PICkit 3: Available in India for ₹800–₹1200 (original) or ₹300–₹600 (clone). MPLAB X supports it.
  • PICkit 4: Faster, supports more devices. ₹3000–₹5000 for original.
  • Clone PICkit 3 tools from India work for basic programming but may have issues with some newer devices.

ICSP (In-Circuit Serial Programming) connections for PIC16F877A:

  • MCLR/VPP (pin 1) → PICkit VPP
  • PGD (RB7, pin 40) → PICkit ICSPDAT
  • PGC (RB6, pin 39) → PICkit ICSPCLK
  • VDD (pin 11, 32) → PICkit VDD
  • VSS (pin 12, 31) → PICkit GND
Recommended: Waveshare ESP32-S3-Nano Development Board — After mastering PIC16F877A, ESP32-S3 brings WiFi, BT, and AI capabilities to your embedded skills.

Frequently Asked Questions

Is PIC16F877A still used in industries in India?

Yes — PIC16F877A is still actively used in Indian industrial equipment, medical devices, and consumer electronics for its proven reliability, extensive documentation, and long production lifecycle. Microchip continues manufacturing it, making it a safe choice for production designs.

Can I use MPLAB X on Linux for PIC16F877A development?

Yes — MPLAB X runs on Linux, macOS, and Windows. The XC8 compiler also supports Linux. This makes it accessible for Indian students using Linux-based college systems or personal laptops running Ubuntu.

What is the difference between XC8 and HITECH-C for PIC?

Microchip acquired HI-TECH Software and their PICC compiler evolved into XC8. XC8 is the current supported compiler. Legacy code written in HITECH-C is largely compatible with XC8 with minor changes. New projects should use XC8.

How to debug PIC16F877A programs in MPLAB X without hardware?

MPLAB X has a built-in software simulator. Go to Project Properties → select “Simulator” as Hardware Tool. You can set breakpoints, watch variables, and single-step through code. Proteus ISIS provides more realistic simulation including virtual LCD, UART terminal, and external components.

What oscillator should I use for PIC16F877A in Indian college projects?

Use a 20 MHz crystal oscillator with two 22pF capacitors connected to OSC1 and OSC2 pins with the other ends to ground. This gives you maximum speed. For projects needing accurate UART timing, 4 MHz or 8 MHz with appropriate SPBRG calculation also works well.

Shop Development Boards at Zbotic →

Tags: embedded India, MPLAB X, PIC microcontroller, PIC16F877A, XC8 compiler
Share Post
  • Facebook
  • Linkedin
  • Whatsapp
Conveyor Belt Speed Control wi...
blog conveyor belt speed control with vfd and plc 598157
blog net metering application process india state wise guide 2026 598164
Net Metering Application Proce...

Related posts

Svg%3E
Read more

Battery Charger Module TP4056: LiPo and 18650 Charging Guide

April 1, 2026 0
The TP4056 battery charger module is one of the most essential components for any battery-powered electronics project. Costing under ₹30,... Continue reading
Svg%3E
Read more

Buck Converter vs Boost Converter: Voltage Regulation Guide

April 1, 2026 0
Understanding buck converters vs boost converters is essential for every electronics project involving power management. Whether you are stepping down... Continue reading
Svg%3E
Read more

Google Coral TPU: Accelerating AI Projects on Raspberry Pi

April 1, 2026 0
The Google Coral TPU (Tensor Processing Unit) transforms a Raspberry Pi from a sluggish AI hobbyist tool into a real-time... Continue reading
Svg%3E
Read more

NVIDIA Jetson Nano Projects India: Getting Started Guide

April 1, 2026 0
The NVIDIA Jetson Nano is the most accessible GPU-accelerated AI computer for developers in India. With 128 CUDA cores, a... Continue reading
Svg%3E
Read more

ATtiny85 Projects: Tiny Microcontroller for Space-Constrained Builds

April 1, 2026 0
The ATtiny85 is the Swiss Army knife of tiny microcontrollers — just 8 pins, 8 KB of flash, and a... Continue reading

Add comment Cancel reply

Your email address will not be published. Required fields are marked

Facebook Twitter Instagram Pinterest Linkedin Youtube

Get the latest deals and more.

Download on Google Play Download on the App Store

Call us: 020 69134444 / 1800 209 0998

Monday - Saturday 09:30 AM - 06:00 PM
For Customer Support Email: [email protected]
WhatsApp: 020 6913 4444

  • My Account

    • Cart

    • Wishlist

    • Checkout

    • My Orders

    • Track Order

    • My Account

  • Information

    • FAQs

    • Blogs

    • Career

    • About Us

    • Contact Us

    • Payment Options

  • Policies

    • Privacy Policy

    • Terms & Conditions

    • GST Input Tax Credit

    • Shipping Return Policy

    • E-Waste Collection Points

    • Our Sitemap

© Zbotic.in is registered trademark of Moxie Supply Pvt Ltd – All Rights Reserved
Login
Use Phone Number
Use Email Address
Not a member yet? Register Now
Reset Password
Use Phone Number
Use Email Address
Register
Already a member? Login Now
Chat with us