这些小活动你都参加了吗?快来围观一下吧!>>
电子产品世界 » 论坛首页 » 综合技术 » 基础知识 » ucos 请求帮助,简单的ucos但是无法实现???

共2条 1/1 1 跳转至

ucos 请求帮助,简单的ucos但是无法实现???

院士
2006-09-17 18:14:16     打赏
ucos 请求帮助,简单的ucos但是无法实现???



关键词: 请求     帮助     简单     但是     无法     实现    

院士
2006-12-22 22:43:00     打赏
2楼
问 想实现KEY1按键控制LED1闪烁,但是结果却KEY1不起作用,运行后LED1亮,按复位键LED1会闪烁。代码如下,还望各位帮忙,谢谢!

#include "Config.h"
#include "Target.h"

#define KEY1   (1<<16)
#define LED1   (1<<22)

#define OSStkLen  64

OS_STK  task0Stk[OSStkLen];
OS_STK  task1Stk[OSStkLen];

void task0(void *pdata);
void task1(void *pdata);

int main(void)
{
IO0DIR = LED1;                                                 
PINSEL0 =0x00000000;

OSInit();
OSTaskCreate(task0,(void *)0,&task0Stk[OSStkLen-1],4);
OSTaskCreate(task1,(void *)0,&task1Stk[OSStkLen-1],5);
OSStart();
return 0;
}


void task0(void *pdata)
{
   pdata=pdata;
   TargetInit ();                         
    for(;;)
    {
        OSTaskSuspend(OS_PRIO_SELF);                  
                
        IO0CLR = LED1;                                 
        OSTimeDly(OS_TICKS_PER_SEC / 8);               
        IO0SET = LED1;                                 
        OSTimeDly(OS_TICKS_PER_SEC / 4);               
        IO0CLR = LED1;                                 
        OSTimeDly(OS_TICKS_PER_SEC / 8);               
        IO0SET = LED1;                                 
        OSTimeDly(OS_TICKS_PER_SEC / 4);               
    }
    
}


void task1(void *pdata)
{
    pdata = pdata;
   
    for(;;)
    {
        OSTimeDly(OS_TICKS_PER_SEC / 50);        
        if((IO0PIN & KEY1) != 0)                 
        {
            continue;
        }
        
        OSTimeDly(OS_TICKS_PER_SEC / 50);        
        if((IO0PIN & KEY1) != 0)
        {
            continue;
        }
        
        OSTaskResume(4);                         
        while((IO0PIN & KEY1) == 0)             
        {
            OSTimeDly(OS_TICKS_PER_SEC / 50);    
        }
    }
} 1: 建议你先测试一下你的IO操作是否正确

共2条 1/1 1 跳转至

回复

匿名不能发帖!请先 [ 登陆 注册 ]