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

📄 theledsgragon.c

📁 用跑马灯指示单片机的工作状态
💻 C
字号:
/**********************************************
*		File: TheLEDsSnake.c
*	  Description: LEDs Snake Animation
*	  Created Date:  2007-09-12
*   Last Modified: 2007-09-12
*   Author: Jeffrey - Schicksal@126.com
*   Notes: None
**********************************************/

#include <REGX51.h>
#define LED_FLASH_T 10000;

void LEDs_Move();
void LEDs_Error();
void LEDs_Snake();

/**********************************************
*		Function: delay(unsigned int t)
*	  Input Variables: t
*   Return Variables: None
*   Usage: Common Delay Routine, t as the delay time ticks
**********************************************/
void delay(unsigned int t)
{
		for(;t>0;t--);		// 延时循环
}

#ifndef true
	#define true 1
#endif

#define TASK_1 1
#define TASK_2 2

/**********************************************
*		Function: main()
*	  Input Variables: None
*   Return Variables: None
*   Usage: Program Entry
*********************************************/
void main()
{
		unsigned char System_Status = true;
		unsigned char System_Task = TASK_2;		
		while(1)
		{
				// 程序主任务区
				// ............
				// 程序主任务区
				if(System_Status == true)			// 当系统处于正常状态
				{
						if(System_Task == TASK_1)	// 程序分支一
						{
								LEDs_Move();							  // 跑马灯指示系统正常
						}
						else if(System_Task == TASK_2)	// 程序分支二
						{
								LEDs_Dragon();					// 跑马灯龙舞花样指示
						}
				}
				else													// 当系统发生错误
				{
						LEDs_Error();							// 跑马灯指示错误
				}
				
		}
}

/**********************************************
*		Function: LEDs_Move
*	  Input Variables: None
*   Return Variables: None
*   Usage: System Normal Status Report
*********************************************/
void LEDs_Move()
{
	 	static unsigned char LEDs = 0x55;		// 静态变量用于存储LEDs发光状态
	 	P0 = LEDs;						// LED间隔亮灭并移位
		delay(LED_FLASH_T);		// 延时
		LEDs = ~LEDs;					// 状态改变
}

/**********************************************
*		Function: LEDs_Error
*	  Input Variables: None
*   Return Variables: None
*   Usage: System Error Status Report
*********************************************/
void LEDs_Error()
{
	 	static unsigned char LEDs = 0x00;   // 静态变量用于存储LEDs发光状态
	 	P0 = LEDs;						// LED警告报警亮灭
		delay(LED_FLASH_T);		// 延时
		LEDs = ~LEDs;					// 状态改变
}

/**********************************************
*		Function: LEDs_Dragon
*	  Input Variables: None
*   Return Variables: None
*   Usage: System Dragon LED Animation
*********************************************/
void LEDs_Dragon()
{
	static unsigned char Direction = 1;         // 静态变量用于存储龙舞方向
	static unsigned char LED_status = 0x0F;     // 静态变量用于存储LEDs发光状态
	if(Direction==1)
	{
		if(LED_status>=0x0F)
			LED_status=LED_status<<1;
		else if(LED_status==0x07)
			LED_status=0x0F;
		else if(LED_status==0x03)
			LED_status=0x07;
		else 
			LED_status=0x03;
		if(LED_status==0xC0)
			Direction=0;
	}
	else 
	{ 
		if(LED_status==0xE0)
			LED_status=0xF0;
		if(LED_status==0xC0)
			LED_status=0xE0;
		else if(LED_status<=0xF0)
			LED_status=LED_status>>1;
		if(LED_status==0x03)
			Direction=1;
	}
	
	P0=~LED_status;
}

⌨️ 快捷键说明

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