#include <reg52.h> #define uchar unsigned char #define uint unsigned int sbit key1=P3^3; sbit key2=P3^4; sbit key3=P3^5; uchar t,a,b,c,flag; uint temp; uchar code table[]={0xc0,0xf9,0xa4,0xb0, 0x99,0x92,0x82,0xf8, 0x80,0x90}; void init(); void key_scan(); void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=110;y>0;y--); } void display(uchar a, uchar b, uchar c); void main() { init(); while(1) { a=temp/100; b=temp%100/10; c=temp%10; key_scan(); display(a,b,c); } } void init() { t=0; temp=0; P2=0x1f; P0=0xc0; TMOD=0X01; TH0=(65536-10000)/256; TL0=(65536-10000)%256; EA=1; ET0=1; } void display(uchar a,uchar b,uchar c) { P2=0x7f; P0=table[a]; delay(10); P2=0xbf; P0=table; delay(10); P2=0xdf; P0=table[c]; delay(10);
} void timer() interrupt 1 { TH0=(65536-10000)/256; TL0=(65536-10000)%256; t++; if(t==10) { t=0; temp++; } } void key_scan() { if(key1==0&&flag==0) { delay(5); if(key1==0&&flag==0) { TR0=1; flag++; } while(!key1); delay(5); while(!key1); } if(flag==1&&key1==0) { delay(5); if(flag==1&&key1==0) { TR0=0; flag++; } while(!key1); delay(5); while(!key1); } if(flag==2&&key1==0) { delay(5); if(flag==2&&key1==0) { init(); flag=0; } while(!key1); delay(5); while(!key1); } }
|