
unsigned char Data[8]={2,4,16,1,2,16,1,7};for(location=1;location<=8;location++){if(location==3||location==6){NixieX(location,0x40);}else{Nixie(location,Data[location-1]);}}
#include <REGX52.H>// 数码管段码表
unsigned char NixieTable[] = {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F, 0x77, 0x7C, 0x39, 0x5E, 0x79, 0x71};
unsigned char Start = 0;
// 初始时间
unsigned char Data[8]={1,1,16,5,9,16,5,0};void Timer0Init(void) // 1毫秒@12.000MHz
{// AUXR |= 0x80; //定时器时钟1T模式TMOD &= 0xF0; // 设置定时器模式TMOD |= 0x01;TL0 = 0x18; // 设置定时初值TH0 = 0xFC; // 设置定时初值TF0 = 0; // 清除TF0标志TR0 = 1; // 定时器0开始计时ET0 = 1;EA = 1;PT0 = 0;
}// 延时子函数
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 NixieX(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 = Number; // 段码输出Delay(1);P0 = 0x00;
}void Timer0_Routine() interrupt 1
{static unsigned int T0Count;TL0 = 0x18; // 设置定时初值TH0 = 0xFC; // 设置定时初值T0Count++;if (T0Count >= 1000){T0Count = 0;Start++;if (Start == 16){Start = 0;}Data[7]++;if(Data[7]==10){ Data[7]=0;Data[6]++;};if(Data[6]==6){ Data[6]=0;Data[4]++;};if(Data[4]==10){ Data[4]=0;Data[3]++;};if(Data[3]==6) { Data[3]=0;Data[1]++;};if(Data[1]==10) {Data[1]=0;Data[0]++;};if(Data[0]==12){ Data[0]=0;};}
}void main()
{unsigned char hexNum = 0; // 用于存储当前要显示的十六进制数// Nixie(2,3); //在数码管的第2位置显示3unsigned char location = 1;Timer0Init();while (1){/*Nixie(1,0); //在数码管的第1位置显示0Nixie(2,0);Nixie(3,0);Nixie(4,0);Nixie(5,0);Nixie(6,0);Nixie(7,0);Nixie(8,0);*//*hexNum = Start;for (location = 1; location <= 8; location++) {if(hexNum==16){hexNum=0;}Nixie(location, hexNum);hexNum++;}*/for(location=1;location<=8;location++){if(location==3||location==6){NixieX(location,0x40);}else{Nixie(location,Data[location-1]);}}}
}