C51单片机0~60计数器

源码

#include<reg51.h>
unsigned char code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
unsigned char second=0;
bit a=0;
char t=0;
int0_srv() interrupt 1{
    t++;
    if(t==20){t=0;a=1;}
    TH0=0x3c;
	TL0=0xb0;    
}
main(){
    P0=P2=table[0];
    TMOD=0x01;
    TH0=0x3c;
	TL0=0xb0;
    ET0=1;
    EA=1;
    TR0=1;
    while(1){
        if(a){
            a=0;
    if(second==60) second=0;
    P0=table[second/10];
    P2=table[second%10]; 
    second++;    } }
}

原理图

image.png

原文地址:https://www.cnblogs.com/xgcl/p/14698068.html