1.利用动态扫描和定时器1在数码管上显示出从765432开始以1⼀10秒的速度往下递减直至765398并保持显示此数。

麻烦帮忙把这个程序改一下啊~和这个不一样就行~谢谢了~
2024-12-29 21:35:42
推荐回答(1个)
回答1:

最近我刚才做过。
#include
#include
#define uchar unsigned char
#define uint unsigned int

uchar temp,t0,t1,flag,flag1,swan,wan,qian,bai,shi,ge;
uint num;
uchar code table[]={
0x3f,0x06,0x5b,0x4f,
0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x76,0x79,
0x38,0x3f,0};

sbit dula=P2^6;
sbit wela=P2^7;

void display(uchar swan,uchar wan,uchar qian,uchar bai,uchar shi,uchar ge);

void init();

void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}

void main()
{
num=440;
temp=0xfe;
init();
while(1)
{
if(flag1!=1)
{
display(7,6,5,bai,shi,ge);
}
else
{
display(10,11,12,12,13,14);
}

}
}

void init()
{
TMOD=0x11;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
EA=1;
ET0=1;
ET1=1;
TR0=1;
TR1=1;
}

void int0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
t0++;
if(flag!=1)
else
{
if(t0==10)
{
t0=0;
P1=temp;
temp=_crol_(temp,1);
}
}
else
{
if(t0%4==0)
P1=~P1;
if(t0==60)
{
TR0=0;
P1=0xff;
flag1=1;
}
}
}

void int1() interrupt 3
{
TH1=(65536-50000)/256;
TL1=(65536-50000)%256;
t1++;
if(t1==2)
{
t1=0;
num--;
bai=num/100;
shi=num%100/10;
ge=num%10;
if(num==398)
{
TR0=0;
P1=0xff;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
flag=1; t0=0;
TR1=0;
}
}

}

void display(uchar swan,uchar wan,uchar qian,uchar bai,uchar shi,uchar ge)
{
dula=1;
P0=table[swan];
dula=0;
P0=0xff;
wela=1;
P0=0xfe;
wela=0;
delay(4);

dula=1;
P0=table[wan];
dula=0;
P0=0xff;
wela=1;
P0=0xfd;
wela=0;
delay(4);

dula=1;
P0=table[qian];
dula=0;
P0=0xff;
wela=1;
P0=0xfb;
wela=0;
delay(4);

dula=1;
P0=table[bai];
dula=0;
P0=0xff;
wela=1;
P0=0xf7;
wela=0;
delay(4);

dula=1;
P0=table[shi];
dula=0;
P0=0xff;
wela=1;
P0=0xef;
wela=0;
delay(4);

dula=1;
P0=table[ge];
dula=0;
P0=0xff;
wela=1;
P0=0xdf;
wela=0;
delay(4);
}