51单片机的60秒数码管倒计时缘由https://ask.csdn.net/questions/7859269
cpp
`#include <REGX52.H>
#define uchar unsigned char
#define uint unsigned int
uchar code table_du[]={0x3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F};
void delay(){ uint m;for(m=0;m<255;m++);}
uchar j=0,sum=60;
void main(){
TMOD=0x01;
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
TR0=1;
EA=1;
ET0=1;
while(1){
P2=255-1;
P0=table_du[sum/10];
delay();P0=P2=255;
P2=255-2;
P0=table_du[sum%10];
delay();P0=P2=255;
}
}
void time0() interrupt 1{
TH0=(65535-50000)/256;
TL0=(65535-50000)%256;
j++;
if(j==20){
j=0;
sum--;
if(sum==0)
sum=60;
}
}`
计时器中断1秒计时在程序简单的时候还是比较准确的,一旦程序复杂则定时时间不准确,因此程序返回主函数周期越小则用定时器作为1秒时钟的准确率就至关重要,也就是响应中断的时间能否尽量小,若能尽量小则1秒的计时误差也相对小则计时精度就高。