#include<reg52.h> #define uchar unsigned char #define uint unsigned int uchar code led[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0xff}; uchar code act[]={0xfe,0xfd,0xfb,0xf7}; uchar hour,msec,sec,min,temp,flag,ftimes1,ftimes2,ftimes3,datatime,min_flag,hour_flag,timedata; void delay(uint z) { uint x,y; for(x=z;x>0;x--) for(y=200;y>0;y--); } void initial() { TMOD=0x01; TH0=(65536-50000)/256; TL0=(65536-50000)%256; EA=1; ET0=1; TR0=1; } void display(uchar t1,uchar t2) { P2=0x7f; P0=led[t1/10]; delay(5); P2=0xbf; P0=led[t1%10]; delay(5); P2=0xbf; P0=led[10]; delay(5); P2=0xdf; P0=led[t2/10]; delay(5); P2=0xef; P0=led[t2%10]; delay(5); } void itner0() interrupt 1 { TH0=(65536-50000)/256; TL0=(65536-50000)%256; msec++; if(msec==20) { sec++; msec=0; } if(sec==60) { min++; sec=0; } if(min==60) { min=0; hour++; } if(hour==24) hour=0; } void ftimes1() { TR0=0; timedata++; if(timedata==1) { min_flag=1; } if(timedata==2) { hour_flag=1; } void ftimes2() { if(min_flag==1) { min++; } if(min==60) { min=0; } if(hour_flag==1); { hour++; } if(hour==24) { hour=0; } } void ftimes3() { timedata=0; min_flag=0; hour_flag=0; TR0=1; } void key() { P2=0xff; if(P2!=0xff) { delay(1); if(P2!=0xff) { temp=P2; } } switch(temp) { case 0xfe:ftimes1;break; case 0xfd:ftimes3;break; case 0xfb:ftimes3;break; } } void main() { initial(); while(1) { key(); display(hour,min); } }
|