#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit key1=P3^0;
sbit key2=P3^1;
sbit key3=P3^2;
sbit duan=P2^2;
sbit wei=P2^3;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
uchar t,qian,bai,shi,ge,flag;
uint num;
void delay(uint);
void display(uchar qian,uchar bai,uchar shi,uchar ge);
void inittimer();
void main()
{
inittimer();
while(1)
{
if(key1==0)
{
delay(3);
TR0=1;
while(!key1)
display(qian,bai,shi,ge);
}
if(key2==0)
{
delay(3);
TR0=0;
while(!key2)
display(qian,bai,shi,ge);
}
if(key3==0)
{
delay(3);
TR0=0;
num=0;
t=0;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
TR0=1;
while(!key3)
display(qian,bai,shi,ge);
}
display(qian,bai,shi,ge);
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=125;y>0;y--);
}
void inittimer()
{
num=0;
TMOD=0x01;
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
EA=1;
ET0=1;
// TR0=1;
}
void timer() interrupt 1
{
TH0=(65536-1000)/256;
TL0=(65536-1000)%256;
t++;
if(t==10)
{
t=0;
num++;
if(num==10000)
num=0;
qian=num/1000;
bai=num/100%10;
shi=num%100/10;
ge=num%100%10;
}
}
void display(uchar qian,uchar bai,uchar shi,uchar ge)
{
duan=1;
P0=table[qian];
duan=0;
P0=0xff;
wei=1;
P0=0xef;
wei=0;
delay(3);
duan=1;
P0=table[bai]|0x80;
duan=0;
P0=0xff;
wei=1;
P0=0xdf;
wei=0;
delay(3);
duan=1;
P0=table[shi];
duan=0;
P0=0xff;
wei=1;
P0=0xbf;
wei=0;
delay(3);
duan=1;
P0=table[ge];
duan=0;
P0=0xff;
wei=1;
P0=0x7f;
wei=0;
delay(3);
}
当我按下KEY3时,秒表重置并自动开始计时,如何修改程序让它重置后按KEY2开始计时
|