# 51 # MCU digital control static and dynamic display

Digital tube display static and dynamic display

Learning digital tube display static and dynamic, we must first clear the same time, the microcontroller can enable a digital control.

Dynamic Display: LED lights in turn, using the human visual persistence phenomenon, resulting in multiple LED is lit visual experience.

Static Display: non understood dynamic display, i.e. not light up LED turns. In displaying a plurality of digital control, the static display of little significance.

Remember: 100Hz flicker-free! ! !

As long as the refresh frequency is greater than 100Hz, i.e., the refresh time is less than 10ms, can be done without flicker, which is hard targets dynamic scan.

Static demo code shown:

#include <reg52.h>

//数码管静态显示

unsigned char code LedChar[10]={//数码管显示的数字0~9
0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90};

unsigned char cnt = 0;
unsigned char sec = 0;

sbit DigitalTube = P1^0;;

void main()
{
   //点亮数码管
   DigitalTube = 0;
   //设置定时器
   TMOD = 0X01;
   TH0 = 0XB8;
   TL0 = 0X00;
   TR0 = 1;

   while(1)
   {
		P0 = LedChar[sec];

   		if(TF0 == 1)
  		{
   			TF0 = 0;
			TH0 = 0XB8;
   			TL0 = 0X00;
		
			cnt++;
			if(cnt>=50)
			{
				cnt = 0;
				sec++;
				if(sec>=10)
				{
					sec = 0;
				}
			}			
 		}
	}
}

Dynamic display demo code

#include <reg52.h>

//数码管动态显示

unsigned char code LedChar[10]={//数码管显示的数字0~9
0XC0,0XF9,0XA4,0XB0,0X99,0X92,0X82,0XF8,0X80,0X90};

unsigned char flag ;

sbit DigitalTube1 = P1^0;
sbit DigitalTube2 = P1^1;

void main()
{
	TMOD = 0X01;
	TH0 = 0Xe7b8;
	TL0 = 0X0000;
	TR0 = 1;

	flag = 0;

	while(1)
	{		
		if(flag == 0)
		{
			DigitalTube1 = 0;
			DigitalTube2 = 1;
			P0 = LedChar[1];	
		}
		else if(flag == 1)
		{
			DigitalTube1 = 1;
			DigitalTube2 = 0;
			P0 = LedChar[2];	
		}

		if(TF0 == 1)
		{
			TF0 = 0;
			TH0 = 0Xe7b8;
			TL0 = 0X0000;

			flag = !flag;
		}	
	}	
}

FIG dynamic display:
Here Insert Picture Description

Released nine original articles · won praise 0 · Views 160

Guess you like

Origin blog.csdn.net/kkkkkkc1/article/details/104360302