目录
问题描述:模拟十字路口的两位信号灯显示计数(00-99),要求采用动态显示,数字间隔时间不做特殊要求。
一.用proteus绘制原理图
二.用keil编写代码
#include<reg51.h>
#define uchar unsigned char
uchar code table[]={0xfc,0x60,0xda,0xf2,0x66,0xb6,0xbe,0xe0,0xfe,0xf6,0xee,0x3e,0x9c,0x7a,0x9e,0x8e};//码表
void delay(uchar c)//延时程序
{
uchar a,b;
for(;c>0;c--)
for(b=142;b>0;b--)
for(a=2;a>0;a--);
}
int main()
{
int sw,gw;
int t=0;
while(1)
{
sw=t/10;//表示十位
gw=t%10;//表示个位
P2=0xfe;//P2口选中对应的数码管
P1=table[gw];//P1输出要输出的个位数字
delay(50);
P2=0xfd;//P2口选中对应的数码管
P1=table[sw];//输出十位的数字
delay(50);
if(++t==100)
t=0;
}
return 0;
}
proteus、keil软件使用方法可参考:https://blog.csdn.net/weixin_47664463/article/details/120551043