You are currently viewing How to Interface LEDs with PIC16F877A PIC Evaluation Board

How to Interface LEDs with PIC16F877A PIC Evaluation Board

Spread the love

The PIC16F/18F Evaluation board is specifically designed to help students to master the required skills in the area of embedded systems. The kit is designed in such way that all the possible features of the microcontroller will be easily used by the students. The kit supports in system programming (ISP) which is done through USB port.

Microchip’s PIC (PIC16F877A), PIC16F/18F Evaluation Kit is proposed to smooth the progress of developing and debugging of various designs encompassing of High speed 8-bit Microcontrollers.

LED (Light Emitting Diodes)

Light Emitting Diodes (LED) is the most commonly used components, usually for displaying pins digital states. Typical uses of LEDs include alarm devices, timers and confirmation of user input such as a mouse click or keystroke.

Interfacing LED

Fig. 1 shows how to interface the LED to microcontroller. As you can see the Anode is connected through a resistor to GND . the Cathode is connected to the Microcontroller pin. So when the Port Pin is HIGH the LED is OFF. when the Port Pin is LOW the LED is turned ON.

Interfacing LED with PIC16F877A

We now want to flash a LED in PIC16F/18F Evaluation board. It works by turning ON a LED & then turning it OFF & then looping back to START. However the operating speed of microcontroller is very the flashing frequency will also be very fast to be detected by human eye.

The PIC16F/18F Evaluation board has eight numbers of point LEDs. That 8 pins connected with I/O Port lines (PORTx.0 – PORTx.7) to make port pins high.

Pin Assignment with PIC16F877A

Circuit Diagram to Interface LED with PIC16F877A

Source Code

The Interfacing LED with PIC16F877A program is very simple and straight forward, that uses a delay procedure loop based software delay. In C programs you cannot be sure of delay, because it depends on compiler how it optimizes the loops as soon as you make changes in the options the delay changes.

C Program to switch ON and OFF LED using PIC16F

//Define PIC Registers __CONFIG(0x3f72);
//Select HS oscillator, Enable(PWRTE,BOREN),
//Turn OFF (CPD,CP,WDTEN,In-circuit Debugger). void DelayMs(unsigned int);
void main()
ADCON1 = 7;
//Select all the PORTA as Digital I/O pins TRISA = 0x00;
//PORTA Configured as O/P while(1)
PORTA = 0xff;
//Enable all the LED's connected to PORTA DelayMs(500);
//Half second Delay PORTA = 0;
//Turn OFF all the LED's connected to PORTA DelayMs(500);
//Half second Delay
void DelayMs(unsigned int Ms)
int delay_cnst;
for(delay_cnst = 0;
delay_cnst <220;delay_cnst++);

To compile the above C code you must need the Mplab software & Hi-Tech C Compiler. They must be properly set up and a project with correct settings must be created in order to compile the code. To compile the above code, the C file must be added to the project.

In Mplab, you want to develop or debug the project without any hardware setup. You must compile the code for generating HEX file. In debugging Mode, you want to check the port output without PIC16F/18F Evaluation board.

The PICKIT2 software is used to download the hex file into your microcontroller IC PIC16F877A through USB port.

Testing the LED with PIC16F877A

Give +12V power supply to PIC16F/18F Evaluation board; the LED is connected with PIC16F/18F Evaluation board. When the program is downloading into PIC16F877A in Evaluation Board, the LED output is working that the LED is ON some time period and the LED is OFF some other time period.

If you are not reading any output from LED, then you just check the jumper connections & check the LED is working. Otherwise you just check it with debugging mode in Mplab. If you want to see more details about debugging just see the videos in below link.

General Information

  • For proper working use the components of exact values as shown in Circuit file. Wherever possible use new components.
  • Solder everything in a clean way. A major problem arises due to improper soldering, solder jumps and loose joints.
  • Use the exact value crystal shown in schematic.
  • More instructions are available in following Tutorials,

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.