Summary of Getting Started with MPLAB XC8 Compiler – LED Blinking
Summary (under 100 words): This tutorial explains how to blink an LED using a PIC16F877A microcontroller with MPLAB X IDE and MPLAB XC8 compiler. It covers installing MPLAB X and XC8, the role of TRIS and PORT registers for GPIO direction and data, writing registers bitwise or whole, and numeric literal formats (binary, octal, hex, decimal). Examples show setting TRIS and PORT bits to configure pins as inputs/outputs and drive output levels.
Parts used in the PIC 16F877A LED Blinking Project:
- PIC16F877A microcontroller
- LED
- Current-limiting resistor for LED
- Power supply (5V VDD and 0V VSS)
- Programmer/debugger compatible with MPLAB X (e.g., PICkit)
- Computer with MPLAB X IDE installed
- MPLAB XC8 Compiler
- Wiring/breadboard or PCB for connections
In this tutorial we will learn How to Blink an LED with PIC Microcontroller using MPAB XC8 Compiler. Recently Microchip released a series of development tools including MPLAB X IDE and MPAB XC Compilers. MPLAB X IDE is a software that runs on a computer intended to develop applications for Microchip’s Microcontrollers and Digital Signal Controllers. It can be used with Windows, Mac and Linux Operating Systems. It is called an Integrated Development Environment as it provides comprehensive facilities to the developers. Unlike previous versions of MPLAB, MPLAB X IDE is based on open source NetBeans IDE by Oracle.

In this example project we will blink an LED using PIC 16F877A Microcontroller. For that we will use MPLAB X IDE and MPLAB XC8 Compiler. You can download MPLAB X IDE and XC8 Compiler from the respective pages.
You should install Java before installing MPLAB X.
- Download and Install MPLAB X IDE.
- Download and Install MPLAB XC8 Compiler.
MPLAB XC8 Programming
- Input Outputs pins of a PIC Microcontroller is divided into different PORTS containing a group of GPIO (General Purpose Input Output) pins.
- Since PIC 16F877A is an 8-bit microcontroller, each PORT contains 8 Input Output pins.
- In 16F Microcontrollers, each port is associated with two registers : TRIS and PORT. Eg : TRISB, PORTB, TRISD, PORTD.
- TRIS stands for Tri-State, it determines the direction of each GPIO pins. Logic 1 at a particular bit of TRIS register makes the corresponding pin Input while Logic 0 at a particular bit makes the corresponding pin Output.
- All Input pins will be in Hi-Impedance state.
- PORT Register is used to Read Data from or Write Data to Input Output pins.
- For an Output pin (TRIS bit is 0), Logic 1 at PORT register makes the corresponding pin Logic High (VDD) and Logic 0 at PORT register makes the corresponding pin Logic Low (VSS).
- Since PIC 16F877A is a 5V device, VDD = 5V and VSS = 0V.
- PORT Read operation reads the Physical State (actual Voltage Level) of IO pins. If an IO pin is at a potential near to VDD, corresponding PORT bit will be Logic 1 and if it at a potential near to VSS, corresponding PORT bit will be Logic 0.
Writing Registers
You can write to PORT and TRIS Registers entirely or bit by bit.
Writing Bit by Bit :
TRISC0 = 1; //Makes 0th bit of PORTC Input TRISC5 = 0; //Makes 5th bit of PORTC Output RB3 = 1; //Makes 3ed bit of PORTB at Logic High RB7 = 0; //Makes 7th bit of PORTB at Logic Low
Writing Entire Register
You should be familiar with following C Programming concepts.
- A number with a prefix ‘0b’ indicates a binary number.
- A number with a prefix ‘0’ indicates an octal number.
- A number with a prefix ‘0x’ indicates a hexadecimal number.
- A number without prefix is a decimal number.
Let’s see some examples…
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 0 | 0b00000000 | 00 | 0x00 |
| 1 | 0b00000001 | 01 | 0x01 |
| 128 | 0b10000000 | 0200 | 0x80 |
| 255 | 0b11111111 | 0377 | 0xFF |
PORTB = 0xFF; //Makes all pins of PORTB Logic High TRISC = 0x00; //Makes all pins of TRISC Output PORTD = 128; //Makes 7th bit of PORTD Logic High
For more detail: Getting Started with MPLAB XC8 Compiler – LED Blinking
- What software is required to develop and compile code for this project?
MPLAB X IDE and MPLAB XC8 Compiler are required. - Do I need to install anything before MPLAB X?
You should install Java before installing MPLAB X. - Which microcontroller is used in this example?
The example uses the PIC16F877A microcontroller. - How do you configure a PIC pin as an output?
Write 0 to the corresponding TRIS bit (for example TRISC5 = 0 sets PORTC pin 5 as output). - How do you set an output pin high or low?
Write 1 or 0 to the corresponding PORT bit (for example RB3 = 1 sets PORTB pin 3 high). - What do TRIS and PORT registers represent?
TRIS registers determine pin directions (1=input, 0=output) and PORT registers read or write pin logic levels. - Can you write to registers bit by bit and entirely?
Yes; you can assign individual bits like TRISC0 = 1 or assign entire registers like TRISC = 0x00. - What voltage levels correspond to logic high and low on PIC16F877A?
VDD = 5V corresponds to logic high and VSS = 0V corresponds to logic low. - How are numeric literals represented in C for binary, octal, and hex?
Binary uses 0b prefix, octal uses leading 0, hexadecimal uses 0x prefix; plain numbers are decimal.
