#include<reg52.h>
#define uchar unsigned char
#define uint unsigned int
sbit dula = P2^6;
sbit wela = P2^7;
sbit key1 = P3^0;
sbit key2 = P3^1;
sbit key3 = P3^2;
sbit key4 = P3^3;
uchar tt,num,bai,shi,ge;
uchar code table[] = {
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,
0x39,0x5e,0x79,0x71
};
void init();
void keys();
void delay(uint z);
void display(uchar bai,uchar shi,uchar ge);
void main(){
init();
while(1);
}
void init(){
TMOD = 0x01;
TH0 = (65536 - 1000)/256;
TL0 = (65536 - 1000)%256;
EA = 1;
ET0 = 1;
TR0 = 1;
num = 0;
tt = 0;
bai = 0;
shi = 0;
ge = 0;
wela = 1;
P0 = 0xf8;
wela = 0;
P0 = 0xff;
dula = 1;
P0 = 0x3f;
dula = 0;
delay(5);
}
void time0() interrupt 1 {
TH0 = (65536 - 1000)/256;
TL0 = (65536 - 1000)%256;
tt++;
if(tt == 1) {
num++;
if(num == 99)
bai++;
if(bai == 10){bai = 0;}
if(num == 100){
num = 0;
}
tt = 0;
shi = num/10;
ge = num%10;
display(bai,shi,ge);
keys();
}
}
void keys(){
if(key1 == 0){
delay(5);
if(key1 == 0){
TR0 = 0;
while(!key1)
display(bai,shi,ge);
delay(5);
if(key1 == 1){TR0 = 1;}
}
}
if(key2 == 0){
delay(5);
if(key2 == 0){
TR0 = 0;
while(!key2)
display(bai,shi,ge);
delay(5);
while(!key2);
//display(bai,shi,ge);
while(key2!=0&&key3!=0)
display(bai,shi,ge);
}
}
if(key3 == 0){
delay(5);
if(key3 == 0){
display(bai,shi,ge);
num = shi * 10 + ge;
TR0 = 1;
while(!key3)
display(bai,shi,ge);
delay(5);
while(!key3);
}
}
if(key4 == 0){
delay(5);
if(key4 == 0){
wela = 1;
P0 = 0xf8;
wela = 0;
P0 = 0xff;
dula = 1;
P0 = 0x3f;
dula = 0;
delay(5);
num = -1;
bai = 0;
while(!key4);
delay(5);
while(!key4);
}
}
}
void display(uchar bai,uchar shi,uchar ge){
dula = 1;
P0 = table[bai];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfe;
wela = 0;
delay(5);
dula = 1;
P0 = table[shi];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfd;
wela = 0;
delay(5);
dula = 1;
P0 = table[ge];
dula = 0;
P0 = 0xff;
wela = 1;
P0 = 0xfb;
wela = 0;
delay(5);
}
void delay(uint z){
uint x,y;
for(x = z;x > 0;x--)
for(y = 110; y > 0;y--);
} |