In this Tutorial we will learn how to blinking LED use PIC Microcontroller. Here I am use PIC16F877A Microcontroller and MikroC compiler. 

You can watch the flowing video tutorial and read the written bellow.

 

 

 

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.

PORTB Register 

PORTB PIC16F877A

The TRIS 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.
 




Circuit diagram:        
                   

led interfacing with pic16f877a microcontroller

 



Component needed for this Project
 

 

  1. PIC16F877A Microcontroller
  2. 8MHz Quartz Crystal
  3. Push button
  4. LED 5mm
  5. Resister: 10k ,1k
  6. Breadboard
  7. Jumper Wire
  8. 5V DC Supplay 

 

MikroC Project Code

void main(){ 
 TRISB0_bit = 0;                               //  RB0 pin is output
 PORTB = 0;                                      // PORTB is clear 
 while(1) {                                        // endless loop
         RB0_bit = 1;                              // RB0  is high
         delay_ms(1000);                      // 1second delay
         RB0_bit = 0;                            // RB1 is low
         delay_ms(1000);                       // 1second delay
        }
}


Code Explain:
Here I am use Mikro C compiler for code editing. In void main function I define RB0 pin is output by clearing TRISB register. Then we clear the PORTB register. In next, here I am use while loop for continues program execution. And then close the program.

LED blinking program flow

 

 
Download free source code

download