avatar

LED Interfacing with PIC Microcontroller: Embedded C program with circuit

How to interface LED with Microchip’s PIC microcontroller? How to connect LEDs to a PIC microcontroller? LED interfacing is the stepping stone for microcontroller development. This is a simple embedded program for PIC 16F877A to interface LEDs, suitable for beginners who wish to study basics of embedded microcontroller programming. The program is developed through Micro C compiler, one of the best solutions for embedded programming in PIC family. It is compatible for Windows XP and Windows 7 platforms and comes with internal burning tools. This PIC circuit is a beginner circuit, do this PIC project to explore the world of microcontrollers.

Algorithm for implementing this PIC project

  1. Specify the output port [here PORT B is used to connect LEDs, So TRISB=0×00; comment is used for specifying the output port]
  2. Start infinite loop [while(1){} is used here]
  3. Pass 0×00 value to the output port [PORTB=0×00;]
  4. Provide a delay. The inbuilt delay function, that is delay_ms(); gives some delay. You can change the duration of LED blinking by giving any value to the calling field of this function. For example delay_ms(1000); will give 1 second delay.
  5. Pass 0xFF value to the output port [PORTB=0xFF;]
  6. Provide a delay [delay_ms(1000);]
  7. Repeat the loop.

LED interfacing embedded C Program for PIC microcontroller

void main()
{
TRISB=0×00;
while(1)
{
PORTB=0×00;
delay_ms(1000);
PORTB=0xFF;
delay_ms(1000);
}
}
The while loop will execute infinitely. So all 8 LEDs connected to PORT B starts blinking with 1 sec delay. This program is tested and verified under i-St@r laboratory.

Read further: Loops in C programming

Circuit diagram of PIC project

PIC+LED+interface LED Interfacing with PIC Microcontroller: Embedded C program with circuit

What is Next?

Now we want to build a .HEX file for this program and then burn it in to our PIC microcontroller..! Dig further

Ads

2 thoughts on “LED Interfacing with PIC Microcontroller: Embedded C program with circuit

  1. I looked online for this compiler, but only found the commercial version, which is expensive for my budget. Is there a freeware or inexpensive (< $80) version?

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>