LED BLINKING WITH PIC16f877A MICROCONTROLLER,to interface an LED with the Microcontroller, is the simplest and most commonly used example for the beginners. It acts as a stepping stone for microcontroller development. It gives the basic idea of working with the controllers in practical environment. In this LED blinking tutorial, you will learn how to use input and output ports of PIC16F877A microcontroller as a digital output. You can also use these pints as input. For example when we use keypad interfacing with microcontroller or we use switch with microcontroller we use pins as input. You should know how to program pic microcontroller

LED blinking circuit diagram

In this tutorial we will demonstrate the working of an LED Blinking circuit. The circuit diagram and the simulation will be done in Proteus.  Following circuit diagram shows we have connected LED with pin number one of PORTC. Resistor is used as current limiting resistor. Because maximum current a single pin can provide to LED is 30mA.

Video lecture on LED blinking

Simulation result of LED blinking

Simulation result of LED blinking


Select the PIC16F877A microcontroller and rest of the components as well from the Proteus built-in librariesas shown in the circuit diagram above.Make the following necessary connections:

  • Connect a pull-up resister R2 on MCLR pin of the controller, the other end of which will be tied to Vdd.
  • For oscillation, connect a 4MHz crystal across pin13 and pin14 of the microcontroller with 2 capacitors C1 and C2 on either side of the crystal.
  • The LED is connected to Pin RC1 of PortC via a 470R resister R1.

This is a complete circuit of an LED Blinking project.

To simulate the circuit as per our desired function i.e. for the LED to blink, the microcontroller PIC16F877A needs to be programmed with a relevant C-code.


Write the following LED Blinking code in the mikroC compiler:

  1. void main() {
  2. TRISC = 0x00; //configuring PORTC as output
  3. while(1) { //Loop executed infinite times
  4. PORTC=0b00000010; //Pin1 of PORTC high
  5. delay_ms(1000); //Delay of 1 sec
  6. PORTC=0b00000000; //Pin1 of PORTC low
  7. delay_ms(1000); //Delay of 1 sec
  8. }
  9. }

LED blinking Code Description :

The while loop will execute infinite times. The LED connected to pin RC1 of PORTC will keep on blinking with 1 second delay (1s=1000ms).TRISC in instruction 2 configures PORTC as an output port. Pin1 of PORTC is set to 1 (HIGH) in instruction 4 and after a delay of 1000ms, it is set to 0 (LOW) in instruction 6. This process is repeated until the program is aborted. This causes the blinking of the LED. The speed of the Blinking LED can be increased or decreased by varying the delay value.

The lines written next to the instruction after a “//” character, are the comment lines. These lines are not compiled with the program, instead they are used to explain the operation of the programming statement. For long comments, start the sentence with the character “/*” and end with the character “*/”.

LED blinking Simulation result in proretus :

Result of LED blinking code using circuit diagram is given below :

Simulation result of LED blinking

Simulation result of LED blinking



There are several applications of a blinking or flashing light. A flashing emergency LED light is used for capturing attention of the masses as it makes people to look up and pay attention with more consideration. Also, the devices installed on telecom sites, use a blinking LED to ensure that the communication is in progress.


  1. ayesha fatima April 7, 2016
    • BILAL Malik April 7, 2016
      • ayesha fatima April 8, 2016
        • ayesha fatima April 8, 2016
  2. ayesha fatima April 8, 2016
  3. ayesha fatima April 8, 2016
  4. Ebuka August 8, 2016
  5. Md. Nur-E-Alam November 9, 2016

Add Comment

Subscribe to our blog to get updates in your email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 1,376 other subscribers