#include<reg52.h> #define uc unsigned char sbit key=P2^0; uc start=1;m=0,i=0; void delay(uc c) { uc a,b; for(;c>0;c--) for(a=38;a>0;a--) for(b=130;b>0;b--); } void ss() interrupt 3 { TH1=15536/256; TL1=15536%256; i++; if(i%20==0) { if(m>60) m=0; P1=m/10*16+m%10; m++; } TF1=0; } void main() { TMOD=0x10; TH1=15536/256; TL1=15536%256; ET1=1; EA=1; TR1=0; while(1) { if(key==0) { TR1=!TR1; if(TR1==1) { TH1=15536/256; TL1=15536%256; i=0;m=0; P1=m/10*16+m%10; } delay(1); while(key==0); delay(1); } } }
- 接线:
- key接P2^0
- P1接两位数码管
注:如果没有两位数码管,可以改成用动态数码管显示