#include <REGX52.H>
//数码管段码表
unsigned char NixieTable[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71};
//延时子函数
void Delay(unsigned int xms)
{
unsigned char i, j;
while(xms--)
{
i = 2;
j = 239;
do
{
while (--j);
} while (--i);
}
}
//数码管显示子函数
void Nixie(unsigned char 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()
{
unsigned char hexNum = 0; // 用于存储当前要显示的十六进制数
//Nixie(2,3); //在数码管的第2位置显示3
unsigned char location = 1;
while(1)
{
/*
Nixie(1,0); //在数码管的第1位置显示0
Nixie(2,0);
Nixie(3,0);
Nixie(4,0);
Nixie(5,0);
Nixie(6,0);
Nixie(7,0);
Nixie(8,0);
*/
for (location = 1; location <= 8; location++) {
Nixie(location, hexNum);
hexNum++;
}
hexNum = 0;
}
}
12-12
1516

06-26