跪求单片机AT89C51程序

跪求单片机AT89C51程序3、99秒秒表设计
P0口低7位做数码管段选端,P2口低2位做数码管位选端,SP1接P1.7。
(1)开始时,显示“00”,第1次按下SP1后就开始计时。
(2)第2次按SP1后,计时暂停。
(3)第3次按SP1后,计时归零

#include<reg52.h>
sbit key =P1^7;

sbit LED1=P2^0;
sbit LED2=P2^1;
unsigned char keycnt;

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];
LED1=1;
delay(5);
LED1=0;

P0=Tab[second%10];
LED2=1;
delay(5);
LED2=0;
}

main()
{
unsigned char i,j;
P0=0xff;
P1=0xff;
TMOD=0x01;
// TH0=0x3c;
// TL0=0xb0;
EA=1;
ET0=1;
// TR0=1;
while(1)
{
display();
if(key==0)
{
for(i=20;i>0;i--)
for(j=248;j>0;j--);
if(key==0)
{
keycnt++;
switch(keycnt)
{
case 1:
TH0=0x3c;
TL0=0xb0;
TR0=1;
break;
case 2:
TR0=0;
break;
case 3:
second=0;
msecond=0;
minute=0;
keycnt=0;
break;
}
while(P3_5==0);
}
}
}
}

void time0() interrupt 1
{
TH0=0x3c;
TL0=0xb0;
counet++;
if(counet==20)
{
msecond++;

counet=0;
if(msecond==100)
{
msecond=0;

}
}
温馨提示:答案为网友推荐,仅供参考
相似回答