1. 程式人生 > >51微控制器實現數碼管滾動顯示

51微控制器實現數碼管滾動顯示

#include <REGX51.H>
void main()
{
	const unsigned char design[16]={0xc0,0xf9,0xa4,0xb0,0x99,0x82,0xf8,0x80,0x90};//0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71
	unsigned char DisplayBuffer[8]={1,2,3,4,5,6,7,8};
	unsigned int a;
	unsigned char b;
	unsigned char w;
	unsigned char w1=0;
	unsigned int t=0;
	unsigned int t1=0;
	do{
		w=254;
		for(b=0;b<8;b++)
		{
			for(a=0;a<500;a++);
			P0=255;
			
			if(b<t1)
			P2=~design[DisplayBuffer[b]];
			else if(b+w1<8+t1)
				P2=0;
			else if(b+w1>8+t1)P2=0;
			else
				P2=~design[DisplayBuffer[b+w1-8]];

			P0=w;
			w =(w<<1)+1;
		}
		if(t++>7)
		{	if(w1++>7)
			{
				if(t1++>7)
					t1=0;
				w1=0;
			}
			t=0;
		}

	}while(1);

}
// 			if(!P3_0)
// 				P2=design[DisplayBuffer[b]];

在這裡插入圖片描述