实现8个数码管依次显示12345678数字
用stc生成的1ms的延时函数,并通过快速的循环12345678实现其让我们看着像同时显示这些数字,并通过延时1ms,将p0口清零达到消影的效果。同时将之前学的while,do while语句加以运用,巩固知识
#include <REGX52.H>标签:P2,case,char,单片机,51,Nixie,break,数码管,while From: https://blog.51cto.com/u_15890798/5900742
unsigned char Nixietable[] = {0X3F,0X06,0X5B,0X4F,0X66,0X6D,0X7D,0X07,0X7F,0X6F,0X77,0X7C,0X39,0X5E,0X79,0X71,0X00};
void Delay() //@12.000MHz
{
unsigned char i, j;
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();
P0=0x00;
}
void main()
{
while(1)
{
Nixie(1,1);
Nixie(2,2);
Nixie(3,3);
Nixie(4,4);
Nixie(5,5);
Nixie(6,6);
Nixie(7,7);
Nixie(8,8);
}
}