双数码管显示
模拟十字路口的两位信号灯显示计数(00-99),数字间隔时间不做特殊要求
#include<reg51.h>
#define uchar unsigned char
#define uint unsigned int
char code table[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e};
//共阳极数码管
void delay(uchar c) //延时程序
{
uchar a,b;
for(;c>0;c--)
for(a=142;a>0;a--)
for(b=2;b>0;b--);
}
void main()
{
uchar num=100;
while(1)
{
uchar shi,ge;
shi=num/10;
ge=num%10;
P2=0xc0;P0=0x01;P2=0x00;
P2=0xe0;P0=table[shi];P2=0x00; //显示十位
delay(30);
P2=0xc0;P0=0x02;P2=0x00;
P2=0xe0;P0=table[ge];P2=0x00; //显示个位
delay(30);
num--;
if(num==0)num=100;
}
}