Serial LEDs using 8051
connecting LEDS to P2 pins and SWITCHES to P1 pins.
#include<reg51.h>
sfr leds=0xA0;
sfr SW=0x90;
unsigned int x;
int main ()
{
while(1)
{
if(SW==0xFE)
{
leds=0x08 ; //"1000"
for( x=0;x<20000;x++); // providing some random delay
leds=0x04; //"0100"
for( x=0;x<20000;x++);
leds=0x02; //"0010"
for( x=0;x<20000;x++);
leds=0x01; //"0001"
for( x=0;x<20000;x++);
}
else if(SW==0xFD)
{
leds=0x01; //"0001"
for( x=0;x<20000;x++);
leds=0x02; //"0010"
for( x=0;x<20000;x++);
leds=0x04; //"0100"
for( x=0;x<20000;x++);
leds=0x08; //"1000"
for( x=0;x<20000;x++);
}
else if(SW==0xFB)
{
leds=0x09; //"1001"
for( x=0;x<20000;x++);
leds=0x06; //"0110"
for( x=0;x<20000;x++);
}
else if(SW==0xF7)
{
leds=0x06; //"0110"
for( x=0;x<20000;x++);
leds=0x09; //"1001"
for( x=0;x<20000;x++);
}
else
leds=0x00;
}
}
to see output
Serial LEDs using 8051
Reviewed by haru
on
May 13, 2013
Rating:
No comments