我是刚学习程序的新人,现在想自己做个跑马灯硬件的很简单
但软件我不知道怎么弄 跑马灯龙舞花样
具体的程序代码如下:
/**********************************************
* File: TheLEDsDragon.c
* Description: LEDs Gragon 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_Gragon();
/**********************************************
* 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)
{
// 程序主任务区
//LEDs_Move();
// ............
// 程序主任务区
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;
}
怎么才弄这程序才完整?
谢谢了? |