源代码
#include
unsigned char DIG4_TABLE[]={0x3f,0x06,0x5b,0x4f, 0x66,0x6d,0x7d,0x07, 0x7f,0x6f,0x77,0x7c, 0x39,0x5e,0x79,0x71};
void Delay10ms()//@11.0592MHz
{
unsigned char i, j;
i = 108;
j = 145;
do
{
while (--j);
} while (--i);
}
void Delay1ms()//@11.0592MHz
{
unsigned char i, j;
i = 11;
j = 190;
do
{
while (--j);
} while (--i);
}
void Delay334us()//@11.0592MHz
{
unsigned char i, j;
i = 4;
j = 148;
do
{
while (--j);
} while (--i);
}
void Dig_OutPut(int i)
{
unsigned char a , b ,c ,d;
a = i%10;
b = (i/10)%10;
c = (i/100)%10;
d = (i/1000)%10;
if(i<=9)
{
P2 = 0x07;
P0 = DIG4_TABLE[a];
Delay1ms();
Delay1ms();
Delay1ms();
}
if((i<=99)&&(i>9))
{
P2 = 0x07;
P0 = DIG4_TABLE[a];
Delay1ms();
Delay1ms();
P2 = 0x0b;
P0 = DIG4_TABLE[b];
Delay1ms();
Delay1ms();
}
if((i<=999)&&(i>99))
{
P2 = 0x07;
P0 = DIG4_TABLE[a];
Delay1ms();
Delay334us();
P2 = 0x0b;
P0 = DIG4_TABLE[b];
Delay1ms();
Delay334us();
P2 = 0x0d;
P0 = DIG4_TABLE[c];
Delay1ms();
Delay334us();
}
if((i<=9999)&&(i>999))
{
P2 = 0x07;
P0 = DIG4_TABLE[a];
Delay1ms();
P2 = 0x0b;
P0 = DIG4_TABLE[b];
Delay1ms();
P2 = 0x0d;
P0 = DIG4_TABLE[c];
Delay1ms();
P2 = 0x0e;
P0 = DIG4_TABLE[d];
Delay1ms();
}
}
void main()
{
int i,j;
P0M0 = 0xff;
P0M1 = 0x00;
P2M0 = 0x00;
P2M1 = 0x00;
while(1)
{
i++;
j = 99;
while(j--)
{
Dig_OutPut(i);
}
}
没有找到添加源代码的位置,所以将整个代码放在了一个文件内。实际操作中,可以分成多个文件便于管理调用。