LED Chaser using PIC Microcontroller

LED Chaser using PIC Microcontroller


LED Chaser is a simple project for beginners that can build using PIC microcontroller. In this 8 LED are running like a Ring Counter. It is very simple and you can create different patterns as you like just by modifying the MikroC program. Here I am using PIC16F877A, one of the most popular PIC microcontroller.

This tutorial is on the assumption that, you have basic knowledge in mikroC and Proteus. If you haven’t please go to this tutorial.

MikroC Code

void main()
  CMCON = 0x07; // To turn off comparators
  ADCON1 = 0x06; // To turn off adc
  TRISB = 0x00; // Sets all pins in PORTB as output
  PORTB = 1; // Set RB0 to high 00000001
  do // To set infinite loop
    Delay_ms(300); // 300 mili seconds delay
    PORTB = PORTB<<1; //Shifting right by one bit
    if(PORTB >= 0b10000000) //To reset to 00000001
    {                          //when the count becomes 10000000
       Delay_ms(350); // 350 mili seconds delay
       PORTB = 1;
  }while(1); // To set infinite loop

Here we first set the output of PORTB as 0000001, then by shifting we get 00000010, 00000100….. When the count reaches 10000000 we reset it to 00000001 in the conditional block.

Circuit Diagram

Note: VDD and VSS of the pic microcontroller is not shown in the circuit diagram. VDD should be connected to +5V and VSS to GND.

LED is connected in series with a resistor of 1K ohm to limit the current through it.

Download Here

You can download the Hex file, MikroC file, Proteus etc from here…

Share this post

  • hi sir,
    i m using above code, it is working but delay what you have mentioned is not exact 300 msec. if i change it to 1000msec, my led will take 3sec turn on…can u pls suggest how to generate exact delay time

  • hey sir please help me.. i have lab exercise to develop a micro c code for the system by using the port B pin change interrupt method . the system is when students are going to the presentation they push the buttons related to the project type (cptp,mini,final project). two seven segment displays will decrease from 20 or 15 or 10 minutes and when they zero led will flash indicating the end of presentation.. please give some hint for c code ….

  • sir i have one problum “4 324 Undeclared identifier ‘ADCON1’ in expression MyProject.c” wt i do?

  • hi sir,
    my project is WINDMILL POWER BASED IRRIGATION SYSTEM.please help me how to develop using pic controller,& how to develop code for it..

  • Dear sir ,

    I download the Micro c Free ware version compiler and program is not generate the hex file how to generate the hex file ?

  • Ha Ha Ha Ha …………………………………….
    Sir Led is not glowing Ha Ha Ha Ha ………………………

  • Dear sir ,

    Start again , which type of the tools are required in this project like as

    1. Pic kit 3
    2. Mp lab software
    3 ……………………..
    4 …………………….
    How to run this project plz help me .

  • It should also contains a software called PICKit3.. use that software…
    Connect the VPP, VDD, VSS, PGD, PGC of the pic microcontroller to the corresponding pins of PICKit3 .. then connect it to your pc.. open the software….. erase the pic… load the hex file.. write……. verify it..

  • Dear sir ,
    I have try many time progrme is save in the editor. or go to the mp lab IDE project wizard and open the file and selct the compler or micocontroller enter
    this file not runnign and i select the left click an doptation is Compile it then i do it and a message is compiling or outout is bulding sucesfuul
    but afte puting the mico inproject then led not blinking. pin vdd and vcc also check.

  • Nothing wrong with it…

    I already said that you should connect Vdd and Vss of the pic microcontroller to +5 and Gnd respectively.. which is not shown in the above circuit diagram…

    PINs 11,32 – Vdd – +5V

    pins 12,31- Vss – GND

  • i changed the microcontroller but still doesn’t work and i test the microcontroller it work good the problem is that i got no signal out from portB but when pin 11 is connected to +5V i recieve +5V on pin 32 i dont know whats wrong with that
    thank you again sir im beginner and i need you help please

  • Then you burned your microcontroller… probably you may have some error in connection………. connect +5 to Vdd and GND to Vss…… … if you connect it in wrong way .. it will burn your pic..

  • soory sir even with one led it doesn’t work maybe should i have change the microcontroller??
    because after long time on +5V it will be very hot and had abnormal smell??
    thx again sir

  • No, there is no other configurations…
    Did you connect Vdd and Vss of the pic microcontroller to 5V and Gnd respectively?
    Didn’t you tried the first project of blinking Led ?


  • This is a great tutorial! I am using the 16f877 and it works fine too! I just had to omit switching off the comparators. It even made me think of this:

    void main()

    ADCON1 = 0x06; // switching off ADC
    TRISB = 0x00;
    PORTB = 0x01;

    PORTB = PORTB<>1;


  • >