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

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

LED Chaser Using PIC



You may also like...

  • http://www.facebook.com/rohit.kamat.121 Rohit Kamat

    grt tutorial to learn pic….post …more

  • http://www.electrosome.com/ Ligo George

    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 = 0×06; // switching off ADC
    TRISB = 0×00;
    PORTB = 0×01;

    while(1)
    {
    Delay_ms(300);
    do
    {
    PORTB = PORTB<>1;
    Delay_ms(300);
    }while(!PORTB.F0);
    }

    }

  • Khaba

    P.S.- with the same circuit!

  • http://www.electrosome.com/ Ligo George

    Thanks for the feedback….

  • GAZ

    PLEASE TELL ME SIR WHY THIS PROJECT WORK ON ISIS AND IT DOESEN4T WORK IN REAL LIFE
    THERES SOME CONFIGURATION WE HAVE TO DO??
    PLEASE HELP ME SIR
    ALL MY REGARDS

  • http://www.electrosome.com/ 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 ?

  • 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

  • http://www.electrosome.com/ 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..

  • 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

  • http://www.electrosome.com/ 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

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

  • http://www.electrosome.com/ Ligo George

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

  • http://www.electrosome.com/ Ligo George

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

    http://www.electrosome.com/pickit2/

  • Gautam

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

  • http://www.electrosome.com/ 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..

  • 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 …………………….
    Etc
    How to run this project plz help me .

  • Gautam

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

  • http://www.electrosome.com/ Ligo George

    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 ?

  • http://www.electrosome.com/ Ligo George

    Hope this article might help you to start a new project in mikro c
    http://www.electrosome.com/led-blinking-pic/

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