LED Interfacing with PIC Microcontroller: Embedded C program with circuit using pic microcontoller




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.

LED Interfacing with PIC Microcontroller Embedded C program with circuit using pic microcontoller

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 [email protected] laboratory.

Read further: Loops in C programming

LED Interfacing with PIC Microcontroller Embedded C program with circuit using pic microcontoller

Circuit diagram of PIC project

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

 

For more detail: LED Interfacing with PIC Microcontroller: Embedded C program with circuit




Leave a Comment

*
= 5 + 7

Read previous post:
Microcontroller Schematic Design Software

Microcontroller Schematic Design Software Microcontroller Schematic Design Software is a electronics design software(EDS) that is used for the prototyping and...

Close
Scroll to top