要显示00到60,就要用两位数码管,用两位一体的共阴数码管画仿真图如下:
程序如下:
#include
unsigned char code tab[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};//共阴数码管段码表
unsigned char num;
void delay()
{
unsigned int j;
for(j=400;j>0;j--);
}
void display()
{
P3=0x7F;
P1=tab[num/10];
delay();
P3=0xBF;
P1=tab[num%10];
delay();
}
void main()
{
unsigned char x;
while(1)
{
display();
x++;
if(x>=80)
{
x=0;
num++;
if(num>=61)
num=0;
}
}
}