#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
uint temp,aa,num,num1;
sbit dula=P2^6;
sbit wela=P2^7;
sbit key1=P3^4;
sbit key2=P3^5;
sbit key3=P3^6;
sbit Key4=P3^7;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71};
void display(uint num);
void delay(uint z);
void init();
uchar keyscanf();
void main()
{
init();
while(1)
{
keyscanf();
display(num);
switch(num1)
{
case 1: TR0=0; display(num);
break;
case 2: TR0=1;
break;
case 3: init();
break;
}
}
}
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void display(uint temp)
{
uint bai,shi,ge;
bai = temp/100;
shi = temp%100/10;
ge = temp%10;
wela=1;
P0=0xfe;
wela=0;
P0=0x00;
dula=1;
P0=table[bai];
dula=0;
delay(10);
wela=1;
P0=0xfd;
wela=0;
P0=0x00;
dula=1;
P0=table[shi];
dula=0;
delay(10);
wela=1;
P0=0xfb;
wela=0;
P0=0x00;
dula=1;
P0=table[ge];
dula=0;
delay(10);
}
void init()
{
wela=0;
dula=0;
temp=0;
num=0;
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
}
uchar keyscanf()
{
if(key1 == 0)
{
delay(10);
if(key1 == 0)
{
num1 = 1;
}
while(!key1);
}
if(key2 == 0)
{
delay(10);
if(key2 == 0)
{
num1 = 2;
}
while(!key2);
}
if(key3 == 0)
{
delay(10);
if(key3 == 0)
{
num1 = 3;
}
while(!key3);
}
return num1;
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
aa++;
if(aa == 10)
{
aa = 0;
num++;
if(num == 999)
num = 0;
}
}
求教,为啥第三个按钮不能让程序复位重新开始计数呢?