⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main7221_1.c

📁 自己做的单片机Proteus仿真实例
💻 C
字号:
//*************************************************************************************************
//*************************************************************************************************
//**<程序名>:7221 LED动态扫描显示																	 **
//**<功能>:LED动态显示1s计数。																	 **
//**<作者>:lah																		 **
//**<完成时间>:2010年12月14日																			 **
//*************************************************************************************************
//*************************************************************************************************



//*************************************************************************************************
//*																								  *
//*			 ******************************头文件及宏定义**************************				  *
//*																								  *
//*************************************************************************************************

#include "at89X51.h"
#include "LED6Show1.h"
#include "intrins.h"
#include "absacc.h"
#include "Max7221.h"
unsigned char DisplayBuffer[8]={0,1,2,3,4,5,6,7};//显示缓冲区
#define TIME0H 0xFC
#define TIME0L 0x18//定时器0溢出时间:5ms,用于刷新LED。

#define TIME1H 0x80
#define TIME1L 0x98		//定时器1溢出时间:49ms,用于计时模式的计数增加。


//*************************************************************************************************
//*																								  *
//*			  ********************************全局变量******************************			  *
//*																								  *
//*************************************************************************************************

unsigned char uc_DisCount=5;		//定时器0定时刷新LED计数。

unsigned char uc_TimeCount=0;		//定时器1定时计数。

unsigned char uc_Count=0;		//定时器0定时计数。
unsigned long ul_Number=123456;			//LED显示数字。
unsigned char uca_LedNum[8];

//*************************************************************************************************
//*																								  *
//*			  ********************************主函数******************************				  *
//*																								  *
//*************************************************************************************************
void Delay1ms(unsigned int count)
{
	unsigned int i,j;
	for(i=0;i<count;i++)
	for(j=0;j<120;j++);
}

unsigned char * pucLedNum(unsigned long ulNumber)
{
	if(ulNumber>999999)
		ulNumber=999999;
	if(ulNumber<0)
		ulNumber=0;
	uca_LedNum[0] = ulNumber/100000;								   //最高位

	uca_LedNum[1] = (ulNumber-100000*(long)uca_LedNum[0])/10000;

	uca_LedNum[2] = (ulNumber-100000*(long)uca_LedNum[0]-10000*(long)uca_LedNum[1])/1000;

	uca_LedNum[3] = (ulNumber-100000*(long)uca_LedNum[0]-10000*(long)uca_LedNum[1]
					-1000*(long)uca_LedNum[2])/100;

	uca_LedNum[4] = (ulNumber-100000*(long)uca_LedNum[0]-10000*(long)uca_LedNum[1]
					-1000*(long)uca_LedNum[2]-100*(long)uca_LedNum[3])/10;

	uca_LedNum[5] = (ulNumber-100000*(long)uca_LedNum[0]-10000*(long)uca_LedNum[1]
					-1000*(long)uca_LedNum[2]-100*(long)uca_LedNum[3]-10*(long)uca_LedNum[4]);
	uca_LedNum[6] =0x0a;
	uca_LedNum[7] =0x0a;
	return uca_LedNum;
}



void main()
{
	TMOD=0x11;		  //定时器0:模式一;定时器0:模式一.


//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<定时器0,用于LCD刷新>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	TH0=TIME0H;
	TL0=TIME0L;
	TR0=1;			 //开启定时器0
//	ET0=1;			 //开定时器0中断


//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<定时器1,用于1s计时 >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
	TH1=TIME1H;
	TL1=TIME1L;
	TR1=1;			 //开启定时器1
	ET1=1;			 //开定时器1中断


    EA=1;			// 开启总中断
	
	InitialMax7221();
	Max7221Display(&DisplayBuffer[0]);


	while(1)
	{
	Delay1ms(200);
	pucLedNum(ul_Number);
	Max7221Display(&uca_LedNum[0]);
	}
}


//*************************************************************************************************
//*																								  *
//*		*****************************定时器1中断,用于计时功能******************************	  *
//*																								  *
//*************************************************************************************************
void vTimer1(void) interrupt 3
{

		if(uc_TimeCount==19)
			{
			uc_TimeCount=0;
			ul_Number++;
			}
		else uc_TimeCount++;

	TH1=TIME1H;
	TL1=TIME1L;
}
//*************************************************************************************************
//*																								  *
//*		***************************定时器0,定时刷新LED*************************				  *
//*																								  *
//*************************************************************************************************
void vTimer0(void) interrupt 1

{
			
			if(uc_DisCount<5)
			uc_DisCount++;						//定时器0在每次被触发时,改变LED显示。
			else uc_DisCount=0;						//从第一位到第六位循环显示。
		 
	TH0=TIME0H;		   						//恢复定时器0初始值。
	TL0=TIME0L;
	
}	  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -