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.
void main()
{
TRISB=0x00;
while(1)
{
PORTB=0x00;
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
Algorithm for implementing this PIC project
- Specify the output port [here PORT B is used to connect LEDs, So TRISB=0x00; comment is used for specifying the output port]
- Start infinite loop [while(1){} is used here]
- Pass 0x00 value to the output port [PORTB=0x00;]
- 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.
- Pass 0xFF value to the output port [PORTB=0xFF;]
- Provide a delay [delay_ms(1000);]
- Repeat the loop.
LED interfacing embedded C Program for PIC microcontroller
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
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
Really helpfull
ReplyDeleteI 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?
ReplyDelete