How to Blink LED with PIC16F877A
The following code demonstrate, how to write a program to blink LED. LED is connected to PORTB bit-1. The code is written in “mikroC PRO for PIC v.5.6.1” IDE and simulation is done with Proteus 8.0 SP0. At the end of code, you can find complete project files for download.
Code in mikroC
// direction signal
sbit LED_dir at TRISB.B1;
// bit labels portb
sbit LED at PORTB.B1;
void main(void)
{
// set direction as output
LED_dir = 0;
// init LED
LED = 0;
while(1)
{
LED = 0;
Delay_ms(500);
LED = 1;
Delay_ms(500);
}
}
sbit LED_dir at TRISB.B1;
// bit labels portb
sbit LED at PORTB.B1;
void main(void)
{
// set direction as output
LED_dir = 0;
// init LED
LED = 0;
while(1)
{
LED = 0;
Delay_ms(500);
LED = 1;
Delay_ms(500);
}
}
Download Files
For download “mikroC PRO for PIC” project and “Proteus 8.0” simulation files, click here.
Comments
Post a Comment