51单片机数码管秒表动态显示问题

2025-01-31 14:19:00
推荐回答(4个)
回答1:

只修改void refresh_led()函数即可

void refresh_led()
{
static uint8 j = 0;
P0=0x00;//要先关灯在调整输出位
switch(j)
{
case 0:ADDR0 = 0;ADDR1 = 0;ADDR2 = 0;break;
case 1:ADDR0 = 1;ADDR1 = 0;ADDR2 = 0;break;
case 2:ADDR0 = 0;ADDR1 = 1;ADDR2 = 0;break;
case 3:ADDR0 = 1;ADDR1 = 1;ADDR2 = 0;break;
case 4:ADDR0 = 0;ADDR1 = 0;ADDR2 = 1;break;
case 5:ADDR0 = 1;ADDR1 = 0;ADDR2 = 1;break;
default:break;
}
P0=number[a[j]];/调整到此处可以节省代码,便于管理
if(5>j)j++;
else j=0;
}

回答2:

void refresh(void)
{
static uint8 j = 0;
static uint32 k=1;
switch(j)
{
case 0 : ADDR0 = 0; ADDR1 = 0; ADDR2 = 0;P0 = NL[liu[j]];break;
case 1 : ADDR0 = 1; ADDR1 = 0; ADDR2 = 0;P0 = NL[liu[j]];break;
case 2 : ADDR0 = 0; ADDR1 = 1; ADDR2 = 0;P0 = NL[liu[j]];break;
case 3 : ADDR0 = 1; ADDR1 = 1; ADDR2 = 0;P0 = NL[liu[j]];break;
case 4 : ADDR0 = 0; ADDR1 = 0; ADDR2 = 1;P0 = NL[liu[j]];break;
case 5 : ADDR0 = 1; ADDR1 = 0; ADDR2 = 1;P0 = NL[liu[j]];break;
default: break;
}
if(i>=(k*=10))
j++;
else
{j=0;k=1;};

}
你修改成上面的就OK了

回答3:

void interrupt_timer1() interrupt 3
{
static uint32 sec = 0;
TH1 = 0xFC;
TL1 = 0x66;
counter++;
if(1000 == counter)
{
sec++;
counter = 0;
a[0] = sec%10;
a[1] = sec/10%10;
a[2] = sec/100%10;
a[3] = sec/1000%10;
a[4] = sec/10000%10;
a[5] = sec/100000%10;
}
refresh_led();
}
上面这一部分改成下面, 假设数码管暗的段码为 0xff

code uint8 number[]={0xC0,0xF9,0xA4,0xB0,0x99,
0x92,0x82,0xF8,0x80,0x90,
0x88,0x83,0xA7,0xA1,0x86,
0x8E,0xff}; // 假设数码管暗的段码为 0xff

void interrupt_timer1() interrupt 3
{

static uint32 sec = 0;
TH1 = 0xFC;
TL1 = 0x66;
counter++;
if(1000 == counter)
{
sec++;
counter = 0;

a[0] = sec%10;
a[1] = sec/10%10;
a[2] = sec/100%10;
a[3] = sec/1000%10;
a[4] = sec/10000%10;
a[5] = sec/100000%10;

if (a[5] ==0)
{
a[5] =16; // 0xff 在段码中第16位
if (a[4] ==0)
{
a[4] =16;
if (a[3] ==0)
{
a[3] =16;
if (a[2] ==0)
{
a[2] =16;
if (a[1] ==0)
{
a[1] =16;
}
}
}
}
};

}
refresh_led();
}

回答4:

楼主的意思是9秒以下的时候十位不亮呗?那只要在9秒之前这段时间关掉十位LED的位选码就好了啊。