#include<reg52.h>
sbit LED1=P2^0;
sbit LED2=P2^1;
sbit LED3=P2^2;
sbit LED4=P2^3;
sbit P3_5 =P3^5;
//unsigned char key;
void send(unsigned char re);
unsigned char Tab[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
unsigned int counet,second,msecond,minute;
void delay(unsigned int m)
{
unsigned char s;
for(;m>0;m--)
for(s=124;s>0;s--);
}
void display()
{
P0=Tab[msecond%10];
LED4=1;
delay(5);
LED4=0;
P0=Tab[second%10]+0x80;
LED3=1;
delay(5);
LED3=0;
P0=Tab[second/10];
LED2=1;
delay(5);
LED2=0;
P0=Tab[minute%10];
LED1=1;
delay(5);
LED1=0;
}
int main(void)
{
unsigned char i,j;
TMOD=0x21;
SCON=0x50;
PCON=0x00;
TH1=0xfd;
TL1=0xfd;
TR1=1;
TH0=(65535-10000)/256;
TL0=(65535-10000)%256;
EA=1;
ET0=1;
ES=1;
while(1)
{
display();
if(P3_5==0)
{
for(i=20;i>0;i--)
for(j=248;j>0;j--);
/*if(P3_5==0)
{
key++;
switch(key)
{
case 1:TH0=0x3c; TL0=0xb0; TR0=1;break;
case 2:TR0=0;break;
case 3:second=0;msecond=0;minute=0;key=0;break;
}
while(P3_5==0);
} */
}
}
return 0;
}
void time0() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
counet++;
if(counet==2)
{
counet=0; msecond++;
if(msecond==10)
{
msecond=0; second++;
if(second==60)
{
second=0; minute++;
if(minute==10)
{
minute=0;
}
}
}
}
}
void send(unsigned char re)
{
SBUF=re;
while(TI==0);
TI=0;
}
void ayy(void) interrupt 4
{
unsigned char sb;
if(RI==1)
{
RI=0;
sb=SBUF;
P2=sb;
send(sb);
switch (sb)
{
case 'A':TR0=1;break;
case 'B':TR0=0;break;
case 'C':second=0;msecond=0;minute=0;break;
}
}
}
是共阳极的数码管,老师说因为真实电路的电平和仿真的不一样,所以要改电平