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

  • grt tutorial to learn pic….post …more

  • Thank you ………

  • 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;


  • Khaba

    P.S.- with the same circuit!

  • Thanks for the feedback….

  • GAZ


  • 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 ?

  • GAZ

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

  • 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

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

  • 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

  • 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

  • Gautam

    How to program insert in the pic ?

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

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

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


  • Gautam

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

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

  • Gautam

    Dear sir ,

    My Mp lab software does not generate the hex file .

  • Gautam

    Dear sir ,

    u have any procedure for generating the hex file ?

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

  • Gautam

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

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

  • 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 ?

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

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

  • arun

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

  • vikneswaran

    this program some error i need your help sir

  • vikneswaran


  • vikneswaran


  • What error ?

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

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