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

Comments (34)

  • Rohit Kamat

    grt tutorial to learn pic….post …more

    January 19, 2013 at 6:57 pm
  • Ligo George

    Thank you ………

    January 19, 2013 at 10:57 pm
  • Khaba

    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;


    March 15, 2013 at 9:27 pm
  • Khaba

    P.S.- with the same circuit!

    March 15, 2013 at 9:28 pm
  • Ligo George

    Thanks for the feedback….

    March 15, 2013 at 9:38 pm
  • GAZ


    April 7, 2013 at 7:46 pm
  • Ligo George

    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 ?

    April 7, 2013 at 8:37 pm
  • GAZ

    i will try the first project now
    thx you sir for the reply

    April 7, 2013 at 9:20 pm
  • GAZ

    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

    April 7, 2013 at 9:41 pm
  • Ligo George

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

    April 8, 2013 at 2:15 am
  • GAZ

    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

    April 8, 2013 at 10:59 am
  • Ligo George

    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

    April 8, 2013 at 1:53 pm
  • Gautam

    How to program insert in the pic ?

    July 28, 2013 at 3:18 am
  • Gautam

    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.

    July 28, 2013 at 3:42 am
  • Ligo George

    This is a mikroC project.. not mplab hi tech c………

    July 28, 2013 at 10:20 am
  • Ligo George

    you need a pic programmer to write this program to pic microcontroller.. .Try making one.. here is the link..


    July 28, 2013 at 10:21 am
  • Gautam

    Dear sir ,
    i have pic kit 3 device and mp lab ide software is free with pic kit 3 .

    July 28, 2013 at 12:52 pm
  • Ligo George

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

    July 30, 2013 at 6:11 pm
  • Gautam

    Dear sir ,

    My Mp lab software does not generate the hex file .

    August 1, 2013 at 7:20 pm
  • Gautam

    Dear sir ,

    u have any procedure for generating the hex file ?

    August 1, 2013 at 7:21 pm
  • Gautam

    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 .

    August 1, 2013 at 7:58 pm
  • Gautam

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

    August 1, 2013 at 8:00 pm
  • Ligo George

    Hello, this code is meant for MikroC,.. not for MPLAB as given in the article..

    August 1, 2013 at 8:40 pm
  • Gautam

    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 ?

    August 2, 2013 at 11:08 pm
  • Ligo George

    Hope this article might help you to start a new project in mikro c

    August 3, 2013 at 7:28 am
  • mani

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

    August 13, 2013 at 12:42 pm
  • arun

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

    February 17, 2014 at 9:32 am
  • vikneswaran

    this program some error i need your help sir

    March 9, 2016 at 5:22 pm
  • vikneswaran


    March 9, 2016 at 5:41 pm
  • vikneswaran


    March 9, 2016 at 5:43 pm
  • Ligo George

    What error ?

    March 19, 2016 at 11:08 am
  • jabesa

    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 ….

    April 25, 2016 at 12:53 pm
  • Ligo George

    Sorry your question is outside the scope of above article. Please use our forums ( https://electrosome.com/forums ) for asking such doubts.

    June 2, 2016 at 6:15 pm
  • yogesh

    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

    October 2, 2017 at 12:41 pm

Leave a Reply

Your email address will not be published. Required fields are marked *