如何让8位动态数码管默认显示11003324,再按下启动键开始计时呢
时间: 2024-03-25 22:40:27 浏览: 47
8位数码管做24小时倒计时
可以在主函数中加入以下代码,实现8位动态数码管默认显示11003324:
```
void main()
{
//...省略计时器和按键初始化代码
P0 = table[1]; //显示1
dula = 0;
dula = 1;
P0 = 0xff;
P0 = 0x7f;
wela = 0;
wela = 1;
P0 = table[1]; //显示1
dula = 0;
dula = 1;
P0 = 0xff;
P0 = 0xbf;
wela = 0;
wela = 1;
P0 = table[0]; //显示0
dula = 0;
dula = 1;
P0 = 0xff;
P0 = 0xdf;
wela = 0;
wela = 1;
P0 = table[0]; //显示0
dula = 0;
dula = 1;
P0 = 0xff;
P0 = 0xef;
wela = 0;
wela = 1;
P0 = table[3]; //显示3
dula = 0;
dula = 1;
P0 = 0xff;
P0 = 0xf7;
wela = 0;
wela = 1;
P0 = table[3]; //显示3
dula = 0;
dula = 1;
P0 = 0xff;
P0 = 0xfb;
wela = 0;
wela = 1;
P0 = table[2]; //显示2
dula = 0;
dula = 1;
P0 = 0xff;
P0 = 0xfd;
wela = 0;
wela = 1;
P0 = table[4]; //显示4
dula = 0;
dula = 1;
P0 = 0xff;
P0 = 0xfe;
wela = 0;
wela = 1;
while(1)
{
if(!key_start) //启动计时
{
flag = 1;
beep_flag = 1;
}
//...省略其他按键处理代码
}
}
```
其中,`table`数组为数码管显示0-9的编码表,共阴极数码管连接在P0口,段选控制引脚为P2.6,位选控制引脚为P2.7。以上代码按照顺序依次将11003324的每一位数码发送到数码管上,实现默认显示。在按下启动键后,计时器开始计时并控制蜂鸣器,同时更新数码管显示。
阅读全文