51单片机——动态数码管显示

代码

#include <REGX52.H>
unsigned char table[]={0x3F,0x06,0x5B,0x4F,0x66,0x6D,0x7D,0x07,0x7F,0x6F};
void Delay(unsigned int xms)		
{
	while(xms--)
	{
		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=table[number];
	Delay(1);
	P0=0x00;
}
void main()
{
	
	while(1)
	{
		nixie(1,1);
		nixie(2,2);
		nixie(3,3);
	}
}

解释说明

消影

位选 段选 位选 段选 位选 段选

在前一个的段选和下一个数据的位选之间会出现显示数据的串味问题,即下一个位选之后的段选数据未到达会显示前一个的段选数据。所以为了解决这个问题,我们需要在上一个段选之后实施清零操作。

位选 段选 清零 位选 段选 清零 位选 段选 清零

	P0=table[number];
	Delay(1);//先延迟1ms让当前数据先稳定显示
	P0=0x00;//1ms之后清零

上一篇
下一篇