自学内容网 自学内容网

【51单片机计时器1中断的60秒数码管倒计时】2023-1-23

51单片机的60秒数码管倒计时缘由https://ask.csdn.net/questions/7859269

#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秒的计时误差也相对小则计时精度就高。


原文地址:https://blog.csdn.net/xianfajushi/article/details/128753831

免责声明:本站文章内容转载自网络资源,如侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!