#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
uchar code tab[] = {0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07};
sbit one = P1^0;
sbit two = P1^1;
sbit three = P1^2;
sbit four = P1^3;
sbit five = P1^4;
sbit six = P1^5;
sbit seven = P1^6;
sbit eight = P1^7;
uchar count;
void delay(int i)
{
uint j;
while(i--)
{
for(j=0;j<125;j++) {;}
}
}
void display()
{
P2 = tab[count];
delay(1000);
}
void getcount()
{
if(one ==0)
count = 0;
else if(two ==0)
count = 1;
else if(three ==0)
count = 2;
else if(four ==0)
count = 3;
else if(five ==0)
count = 4;
else if(six ==0)
count = 5;
else if(seven ==0)
count = 6;
else if(eight ==0)
count = 7;
}
void main()
{
P2 = 0x00;
while(1)
{
getcount();
display();
}
}
|