跪求,51单片机的LED动态显示 程序 ,急啊。。。。

2024-11-25 10:00:09
推荐回答(1个)
回答1:

#include
#define uint unsigned int
#define uchar unsigned char
sbit dula=P1;
sbit wela=P2;
uchar bai,shi,ge;
uint tt;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void display(uchar,uchar,uchar);
void delay(uint z)
{
uint i,j;
for(j=z;j>0;j--)
for(i=0;i<110;i++);
}
void main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
while(1)
{
display(bai,shi,ge);
}
}
void display(uchar a,uchar b,uchar c)
{
dula=1;
P1=table[a];
dula=0;
P1=0xff;
wela=1;
P2=0xfe;
wela=0;
delay(5);

dula=1;
P1=table[b];
dula=0;
P1=0xff;
wela=1;
P2=0xfd;
wela=0;
delay(5);

dula=1;
P1=table[c];
dula=0;
P1=0xff;
wela=1;
P2=0xfb;
wela=0;
delay(5);
}
void timer() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
tt++;
if(tt==1000)
tt=0;
bai=tt/100;
shi=tt%100/10;
ge=tt%10;
}