共2条
1/1 1 跳转至页
ucos 请求帮助,简单的ucos但是无法实现???
问
想实现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操作是否正确
#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 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】分享技术经验,兑换京东卡 | |
话不多说,快进群! | |
请大声喊出:我要开发板! | |
【有奖活动】EEPW网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |