?? theledssnake.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;
unsigned char System_Task;
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 + -