0-123,需要三位数码管。
#include<reg51.h>
#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<<number;
P0=distab[dat[number]];
cnt++;
if(cnt>99)
{
cnt=0;
nn++;
nn%=124;
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);
}