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

📄 led_loopon.c

📁 EasyStudy51-II单片机开发系统的库函数源代码.包含了EasyStudy51-II硬件的全部驱动.
💻 C
字号:

#include "AT89X52.h"
#include "ES51_II.h"
#include "ES51_II_LIB.h"



unsigned char code LEDTABLE[4][8] = {
									{0x00,0xff,0x00,0xff,0x00,0xff,0x00,0xff},		//	全亮->全灭	
									{0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f},		//	自右向左
									{0x7f,0xbf,0xdf,0xef,0xf7,0xfb,0xfd,0xfe},		//	自左向右
									{0xe7,0xdb,0xbd,0x7e,0xbd,0xdb}					//	中间散开->向中间靠拢
									};

//	流水灯样式选择
static unsigned char data LoopLEDType;

//	流水的灯的间隔时间,50毫秒单位
static unsigned char data LoopDelay;

//	列索引值
static unsigned char Index;			

//	用定时器0实现流水灯	
//	delay100ms:	100毫秒单位
void LoopLEDON(unsigned char type,unsigned char delay100ms)
{
	if( type < 4 )				//	判断是否在合法范围内
		LoopLEDType = type;
	else 						//	若不在合法范围内跑马灯类型为LEDALLLOOP
		LoopLEDType = LEDALLLOOP;
	LoopDelay = delay100ms*2;	//	

	Index = 0;					//	执行新的跑马灯,清列索引值,

	TMOD &= 0xf0;				//	Timer0 方式1,定时
	TMOD |= 0x01;				//	保持T1状态不变

	TH0 = 0x3c;					//	定时初值50ms/12MHZ									
	TL0 = 0xb0;
	//EA = 1;						
	ET0 = 1;					//	允许T0溢出中断
	TR0 = 1;					//	启动T0
}


//	T0中断函数
//	假设时钟为12MHZ
void Timer0LoopLED(void) interrupt 1 using 0
{	
	static unsigned char count50ms;

	TH0 = 0x3c;							//	重装定时初值									
	TL0 = 0xb0;

	if( count50ms == LoopDelay )		//	延时
		{
		count50ms = 0;
		LEDPORT = LEDTABLE[LoopLEDType][Index];	
		Index++;
		if( (LoopLEDType == 3) && (Index > 5) )
			Index = 0;
		else if( Index > 7)
			Index = 0;
		}
	count50ms++;						//	定时累加
}



⌨️ 快捷键说明

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