Multiple blinking LED use PIC Microcontroller and Mikro C
In this Tutorial we will learn how to blinking multiple LED using PIC Microcontroller. Here I we are using PIC16F877A Microcontroller and MikroC pro for PIC compiler for this project. You con watch the following video or read the written tutorial below.
I/O pin of PIC16F877A microcontroller
PIC16F877A Microcontroller has A0-A7, B0-B7, C0-C7, D0-D7 and E0-E2 input/output port. Some pins for these I/O port are multiplex with an alternative function for the peripheral feature on the device. In general, when a peripheral is enable, that pin may not used as a general purpose I/O pin.
In this project we will use PORTB for blinking LED. For controlling PORTB it has two register TRISB and PORTB.
The TRISB Register controls the direction of Input/Output port. Here PORTB is 8bit wide, bi-directional port. The corresponding data direction register is TRISB. Setting a TRISB bit (= 1) will make the corresponding PORTB pin an Input. Clearing a TRISB bit (=0) will make the corresponding PORTB pin an Output.
Blinking LED project source code
void main( ) {
TRISB = 0X00; // PORTB is output
PORTB = 0X00; // clear PORTB
while(1) { // endless loop
PORTB= 0X00; // PORTB is active high
delay_ms(500); // 500 ms delay
PORTB = 0XFF; // PORTB is active low
delay_ms(500); // 500 ms delay
}
}
Code Explain
Here I am use Mikro C pro for PIC compiler for code editing. In void main function I define PORTB is output by clearing TRISB register. Then we clear the PORTB register the B0-B7 all pins are output 0. In next, here I am use while loop for continues program execution and blinking LEDs. And then close the program.
Program Flowchart
Circuit Diagram
Download free source code
Post Comments