The project below is for absolute beginners for people that are just starting microcontroller programming it is a led chaser that follow as regular pattern by which a led is chasing another led but the project is design to blink each bit in portB at 1 seconds interval and each bit in portc is shifted at 125ms.
the project is simulated with proteus 8.0
//LED CHASER WITH BITWISE OPERATOR
//PROGRAMMER:AKINGUNSOLA CALEB
//FREE TO USE BY ALL
//compiler mikroc pro for pic
int lednumber[4];
int a;
void main() {
CMCON|=0x07; //disable comparator
TRISB=0x00; //set as output
TRISC=0x00; //set as output
PORTB=0x00; //set all pin low
PORTC=0x00; //set all pin low
do
{
PORTC=1<<lednumber[0]; //start from bit 0
lednumber[0]++; //increment bit
delay_ms(125); //wait 1 seceonds
if(lednumber[0]>7) //if shifting is on rc7
{
lednumber[0]=0; //reset lednumber[0]
PORTB=1<<lednumber[1]; //start from bit o
lednumber[1]++; //increment bit
if(lednumber[1]>7) //if shifting is on rb7
{
lednumber[1]=0; //reset lednumber[1]
}
}
}while(1);
}
The above code can be ported to any microcontroller provided the correct register and syntax is been used
Comments