求救,单片机c51 用四位七段数码管动态显示一个数字,怎么不行呢????

2024-12-17 08:05:35
推荐回答(1个)
回答1:

程序错了吧。看看这个程序,可以参考一下。

#include
#define uchar unsigned char
uchar tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x00};  //0到9
uchar num;
uchar led[]={1,2,3,4};

void t0isr() interrupt 1
{
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
switch(num)
{
case 0:P2=0x01;break;
case 1:P2=0x02;break;
case 2:P2=0x04;break;
case 3:P2=0x08;break;
default:break;
}
P0=~tab[led[num]];
num++;
num&=0x03;
}

main()
{
TMOD=0x11;
TH0=(65536-5000)/256;
TL0=(65536-5000)%256;
TR0=1;
ET0=1;
EA=1;
while(1);
}