共阴极数码管码表:
0x3f , 0x06 , 0x5b , 0x4f ,0x66 , 0x6d ,
0 1 2 3 4 5
0x7d , 0x07 , 0x7f , 0x6f , 0x77 , 0x7c ,
6 7 8 9 A B
0x39 , 0x5e , 0x79 , 0x71 , 0x00
C D E F 无显现
实践使用中,界说一个数组即可:
unsigned charcodeDIG_CODE[17]={0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71,0x00};
#include< reg51.h >
void delay_10_ms(unsigned char t);//声明延时函数
unsigned char code digit_code[17]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F,0x77,0x7C,0x39,0x5E,0x79,0x71,0x00};
void main(void)
{
unsigned char i;
P0=0x00; //开始点亮全管
delay_10_ms(100); //延时1s
for(i=0;i<17;i++)
{
P0=~digit_code[i];//取反点亮
delay_10_ms(100);
}
}
void delay_10_ms(unsigned char t)//10ms延时程序
{
unsigned char i,j;
for(;t>0;t–)
for(i=38;i>0;i–)
for(j=130;j>0;j–);
}
参阅链接:
http://www.21ic.com/jichuzhishi/mcu/program/2013-05-22/182240_2.html
http://www.cnblogs.com/zhliao/archive/2012/05/22/2513886.html