#include <REGX52.H>
unsigned char Nixie_Buffer[9];
unsigned char count, count1;
void UART_Init(void) //4800bps@11.0592MHz
{
PCON &= 0x7F; //波特率不倍速
SCON = 0x50; //8位数据,可变波特率,与串口发送的区别是这里打开了接收控制位REN
TMOD &= 0x0F; //清除定时器1模式位
TMOD |= 0x20; //设定定时器1为8位自动重装方式
TL1 = 0xFA; //设定定时初值
TH1 = 0xFA; //设定定时器重装值
ET1 = 0; //禁止定时器1中断
TR1 = 1; //启动定时器1
EA = 1;
ES = 1;
}
unsigned char NixieTable[] = {0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0x7f};//0~F,还有小数点
sbit DP1 = P0^0;
sbit DP2 = P0^1;
sbit DP3 = P0^2;
sbit DP4 = P0^3;
sbit DP5 = P0^4;
sbit DP6 = P0^5;
void Delay(unsigned int xms)
{
unsigned char i, j;
while(xms)
{
i = 2;
j = 199;
do
{
while (--j);
} while (--i);
xms--;
}
}
void Nixie(unsigned char Location,Number)
{
switch(Location)
{
case 1:DP1 = 0;break;
case 2:DP2 = 0;break;
case 3:DP3 = 0;break;
case 4:DP4 = 0;break;
case 5:DP5 = 0;break;
case 6:DP6 = 0;break;
}
P1 = NixieTable[Number];
Delay(1);//先延时1毫米,为避免过早清零让数码管太暗
//P1 = 0x00;//将上一位段选清零,避免上一位段选的数据进入下一位的位选,且让清零的数据进入位选,就没影响,不过这里好像没啥用
//计算机进行:位选 段选 位选 段选.......
P0 = 0xff;
}
void Nixie_showentitle(unsigned char *str)
{
while(*str != '\0')
{
if (*str >= '0' && *str <= '9')
{
Nixie(count1, *str++ - 48);//显示数字
count1++;
}
else if(*str == '.')
{
Nixie(count1 - 1, 16);//显示小数点
*str++;
}
}
}//数码管为6位共阳极
void main()
{
UART_Init();
while(1)
{
Nixie_showentitle(Nixie_Buffer);
}
}
void UART_Routine() interrupt 4
{
if(RI)
{
Nixie_Buffer[count] = SBUF;//从发送缓冲区发送文本,例如18.46.23
RI = 0;
count++;
count %= 9;
}
else
{
TI = 0;
}
}
|