51单片机制作八路抢答器
#include<AT89X52.H>
unsigned char code Tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c};
unsigned char Dat[]={0,0};
unsigned char Second,t;
void Delay()
{
unsigned char i;
for(i=0;i<50;i++);
}
void main()
{
EA=1;
ET0=1;
TMOD=0x01;
TH0=-50000/256;
TL0=-50000%256;
TR0=1;
while(1)
{
Dat[0]=Second/10;
Dat[1]=Second%10;
P0=Tab[Dat[0]];
P1=0xfe;
Delay()
P1=0xff;
P0=Tab[Dat[1]];
P1=0xfd;
Delay()
P1=0xff;
}
}
void intservl (void) interrupt 1 unsig 1
{
TH0=-50000/256;
TL0=-50000%256;
t++;
if(t==20)
{
t=0;
Second++;
if(Second>=60) Second=0;
}
}