89C51单片机数码管,动态显示0到199怎么用C语言编程?

初学C语言,请尽可能简单,谢谢!
2025-04-05 11:27:25
推荐回答(1个)
回答1:

#include
#define uchar unsigned char;
uchar distab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71,0x00};  //0到f
uchar number,dat[3],nn=0,cnt=0;;
void t0isr() interrupt 1
{
    TH0=(65536-5000)/256;
    TL0=(65536-5000)%256;
    number++;
    number%=3;
    P2=0x01<    P0=distab[dat[number]];
    cnt++;
    if(cnt>99)
        {
        cnt=0;
        nn++;
        nn%=200;
        dat[0]=nn/100;
        dat[1]=(nn%100)/10;
        dat[2]=nn%10;
        }
}
main()
{
        TMOD=0x01;
        TH0=(65536-5000)/256;
        TL0=(65536-5000)%256;
        TR0=1;
        ET0=1;
        EA=1;
        while(1);
}