The 51 MCU digital tube dynamic refresh display program is packaged as a function, and the main function call is incremented from 00000001 to 1 and displayed to 99999999

Writing the display program of the 51 single-chip digital tube display is a most basic learning process, and it is not difficult. It has been written many times before. This time the teacher asked to encapsulate the display function program and call it with the main function. Then there will be a problem. That is, the dynamic display of the digital tube requires fast dynamic scanning, but it does not want the main function to send it as fast as possible. Of course, it can be solved by using interrupts, but the teacher does not allow the use of interrupts (because we have not learned about interrupts).
At the beginning, I had been debugging the delay function. I naively believed that as long as I continued debugging, I would be able to succeed, but then I thought that this is unrealistic, and I must think of another way.
Therefore, a for loop can be used to continuously send repeatedly. Hahahaha

  for(num=1;num<100000000;num++)
	{
	    for(i=0;i<=50;i++)//在不影响动态扫描的情况下重复发送
		{
			display(num);
		}
		  delay(5);
	}`

I do not know if you have encountered such a problem, and how to solve it. The following is the complete code.

#include<reg52.h>
#include<intrins.h>
#define uint  unsigned int 
#define ulong  unsigned long
#define uchar  unsigned char
sbit we=P2^7;
sbit du=P2^6;
uchar ledtable[]= {0x3F, 0x06, 0x5B, 0x4F, 0x66, 0x6D, 0x7D, 0x07, 0x7F, 0x6F,};
void delay(uint z)
{
	uint x,y;
	for(x = z; x > 0; x--)
		for(y = 114; y > 0 ; y--);
}

void display(ulong number)
{
	int i=0;
	while(number)
	{	
    P0=_cror_(0X7F,i);
		we=1;
		we=0;
		
		P0=ledtable[number%10];
		du=1;
		du=0;
		
		delay(5);

		P0=0x0;
		du=1;
		du=0;
		
		number=number/10;
		i++;
		if(i==8)  i=0;
	}

}

void main()
{
	ulong num;
	int i;
	for(num=1;num<100000000;num++)
	{
	    for(i=0;i<=50;i++)
		{
			display(num);
		}
		  delay(5);
	}
		

}

Published 9 original articles · won 7 · visited 1767

Guess you like

Origin blog.csdn.net/weixin_44906810/article/details/102768587