4.1静态数码管显示
1.数码管介绍
LED数码管:数码管是一种简单,廉价的显示器,是由多个发光二极管封装在一起组成“8”字型的器件。
2.数码管原理图
位选:选中哪个数码管;段选:显示数字;138译码器控制位选,a~dp控制段选
3.C51数组
4.C51子函数
5.静态数码管的代码
#include <REGX52.H>
unsigned int NixieTable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void Nixie(unsigned int Location,Number)
{
switch(Location)
{
case 1:P2_4=1;P2_3=1;P2_2=1;break;
case 2:P2_4=1;P2_3=1;P2_2=0;break;
case 3:P2_4=1;P2_3=0;P2_2=1;break;
case 4:P2_4=1;P2_3=0;P2_2=0;break;
case 5:P2_4=0;P2_3=1;P2_2=1;break;
case 6:P2_4=0;P2_3=1;P2_2=0;break;
case 7:P2_4=0;P2_3=0;P2_2=1;break;
case 8:P2_4=0;P2_3=0;P2_2=0;break;
}
P0=NixieTable[Number];
}
void main()
{
Nixie(3,4);
while(1)
{
}
}
4.2动态数码管显示
5.动态数码管的代码
功能:前三位数码管显示123
消影
位选 段选 清零 位选 段选 位选 段选
#include <REGX52.H>
void Delay(unsigned int xms) //@11.0592MHz
{
unsigned char data i, j;
while(xms--)
{
//_nop_();
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
}
}
unsigned int NixieTable[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f};
void Nixie(unsigned int Location,Number)
{
switch(Location)
{
case 1:P2_4=1;P2_3=1;P2_2=1;break;
case 2:P2_4=1;P2_3=1;P2_2=0;break;
case 3:P2_4=1;P2_3=0;P2_2=1;break;
case 4:P2_4=1;P2_3=0;P2_2=0;break;
case 5:P2_4=0;P2_3=1;P2_2=1;break;
case 6:P2_4=0;P2_3=1;P2_2=0;break;
case 7:P2_4=0;P2_3=0;P2_2=1;break;
case 8:P2_4=0;P2_3=0;P2_2=0;break;
}
P0=NixieTable[Number];
Delay(1);//稳定显示数字
P0=0x00;//数码管清零
}
void main()
{
while(1)
{
Nixie(1,1);
//Delay(200);
Nixie(2,2);
//Delay(200);
Nixie(3,3);
//Delay(200);
}
}