LED Chaser Using Microcontroller
Introduction
This project is so simple,it's particularly for beginners. In this project 8 LED are running successively It is very simple and you can create different patterns as you like just by modifying the MikroC program.We will use PIC16F877A, one of the most popular PIC Microcontroller.
This tutorial is for beginners who have simple idea about MikroC Compiler and Proteus.If not try this tutorial.
This tutorial is for beginners who have simple idea about MikroC Compiler and Proteus.If not try this tutorial.
Learn more about Microcontroller connections at MikroElectronika
Schematic
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.
PIC 16F877A has no internal oscillator, so we should connect external oscillator. Two 22pF capacitors are used to stabilize the operation of the Crystal Oscillator. A low on MCLR pin will reset the PIC, so we tie it to VDD to avoid accidental RESET.
LED is connected in series with a resistor of 1K ohm to limit the current through it.
PIC 16F877A has no internal oscillator, so we should connect external oscillator. Two 22pF capacitors are used to stabilize the operation of the Crystal Oscillator. A low on MCLR pin will reset the PIC, so we tie it to VDD to avoid accidental RESET.
LED is connected in series with a resistor of 1K ohm to limit the current through it.
MikroC Program
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 milli seconds delay
PORTB = 1;
}
}while(1); // To set infinite loop
}
{
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 milli seconds delay
PORTB = 1;
}
}while(1); // To set infinite loop
}