共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网站征稿正在进行时,欢迎踊跃投稿啦 | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
【笔记】生成报错synthdesignERROR被打赏50分 | |
【STM32H7S78-DK评测】LTDC+DMA2D驱动RGBLCD屏幕被打赏50分 | |
【STM32H7S78-DK评测】Coremark基准测试被打赏50分 | |
【STM32H7S78-DK评测】浮点数计算性能测试被打赏50分 | |
【STM32H7S78-DK评测】Execute in place(XIP)模式学习笔记被打赏50分 | |
每周了解几个硬件知识+buckboost电路(五)被打赏10分 | |
【换取逻辑分析仪】RA8 PMU 模块功能寄存器功能说明被打赏20分 | |
野火启明6M5适配SPI被打赏20分 | |
NUCLEO-U083RC学习历程2-串口输出测试被打赏20分 | |
【笔记】STM32CUBEIDE的Noruletomaketarget编译问题被打赏50分 |