打印

急,关于跑马灯程序

[复制链接]
3217|10
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
我是刚学习程序的新人,现在想自己做个跑马灯硬件的很简单
但软件我不知道怎么弄 跑马灯龙舞花样
具体的程序代码如下:
/**********************************************
*   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;
}

怎么才弄这程序才完整?
谢谢了?

相关帖子

沙发
千古寸心| | 2009-12-8 21:48 | 只看该作者
呵呵,本人眼拙,不知道你要问啥

使用特权

评论回复
板凳
houfire007| | 2009-12-8 22:22 | 只看该作者
函数可正确?

使用特权

评论回复
地板
zhuliang1125|  楼主 | 2009-12-9 08:30 | 只看该作者
就是怎么把上面的程序写正确,呵呵我是初学者,希望大家指导

使用特权

评论回复
5
auzxj| | 2009-12-9 08:34 | 只看该作者
就是怎么把上面的程序写正确,呵呵我是初学者,希望大家指导
zhuliang1125 发表于 2009-12-9 08:30

你的意思是上面的程序有问题???

和2楼一样不知道你在问什么

使用特权

评论回复
6
zhuliang1125|  楼主 | 2009-12-9 09:12 | 只看该作者
是的  那程序有问题 更重要的是 我不知道void LEDs_Error()
{
        static unsigned char LEDs = 0x00;        // 静态变量用于存储LEDs发光状态
        P0 = LEDs;                              // LED警告报警亮灭
        delay(LED_FLASH_T);                     // 延时
        LEDs = ~LEDs;                           // 状态改变
}
void LEDs_Move()
{
        static unsigned char LEDs = 0x55;       // 静态变量用于存储LEDs发光状态
        P0 = LEDs;                              // LED间隔亮灭并移位
        delay(LED_FLASH_T);                     // 延时
        LEDs = ~LEDs;                           // 状态改变
}
这2个子程序的作用

使用特权

评论回复
7
zhuliang1125|  楼主 | 2009-12-9 09:13 | 只看该作者
希望大家能教我这只笨鸟

使用特权

评论回复
8
auzxj| | 2009-12-9 10:25 | 只看该作者
这是C语言问题啊

LEDs_Error()用来指示系统错误的
LEDs_Move()用来指示系统正常
从这个程序看,这两个函数都不会被调用,只会一只调用 LEDs_Dragon();
若想调用LEDs_Error()LEDs_Move()需要把 unsigned char System_Status = true;unsigned char System_Task = TASK_2;    改一下,怎么改看下程序就会懂了,努力学习一下C语言吧,这里连中断都没有,纯语言的东西
这两个函数中注意一下“static unsigned char”,看一下C的课本,理解一下这个变量时如何变化的

使用特权

评论回复
9
chunyisihai| | 2009-12-9 11:40 | 只看该作者
如楼上所说!System_Task没变化,LEDs_Error(),LEDs_Move()根本没调用,楼主去多看看C语言。

使用特权

评论回复
10
auzxj| | 2009-12-9 11:42 | 只看该作者
这是这个程序的流程图,你看下吧
[img] [/img]

使用特权

评论回复
11
zhuliang1125|  楼主 | 2009-12-9 12:27 | 只看该作者
谢谢大家

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

7

帖子

0

粉丝