- #include<reg51.h>
- sbit S1 = P1^0;//K1模式选择键,按一次为设置倒计时间模式,按第二次为启动倒计时模式
- sbit S2 = P1^1;//K2调整秒值的个位
- sbit S3 = P1^2;//K3调整秒值的十位
- unsigned char code Tab[10]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90};
- unsigned char int_time;
- unsigned char second;
- void delay(void)
- {
- unsigned char i;
- for(i=0;i<200;i++) ;
- }
- void DisplaySecond(unsigned char k)
- {
- P0=Tab[k/10];
- P2=0x01;
- delay();
- P2=0xfc;
- P0=Tab[k%10];
- P2=0x02;
- delay();
- P2=0xfc;
- }
- void main(void)
- {
- TMOD=0x01;
- TH0=(65536-5000)/256;
- TL0=(65536-5000)%256;
- EA=1;
- ET0=1;
- TR0=1;
- int_time=0;
- second=99;
- while(1)
- {
- DisplaySecond(second);
- while(second==0)
- DisplaySecond(second);
- }
- }
- void interserve(void ) interrupt 1 using 1
- {
- TR0=0;
- int_time ++;
- if(int_time==20)
- {
- int_time=0;
- second--;
- }
- TH0=(65536-5000)/256;
- TL0=(65536-5000)%256;
- TR0=1;
- if(second==0)
- TR0=0;
- }
复制代码 |