#include "config.h" #include "stdlib.h"
#define KEY1 (1 << 20) /* P0.20为KEY1 */ #define BEEP (1 << 7) /* P0.07为蜂鸣器 */
#define TaskStkLengh 64 //Define the Task0 stack length 定义用户任务0的堆栈长度 OS_STK TaskStk0[TaskStkLengh]; //Define the Task0 stack 定义用户任务0的堆栈 OS_STK TaskStk1[TaskStkLengh]; //Define the Task1 stack 定义用户任务1的堆栈
void Task0(void *pdata); //Task0 任务0 void Task1(void *pdata); //Task0 任务1
int main(void) { OSInit (); OSTaskCreate (Task0,(void *)0, &TaskStk0[TaskStkLengh - 1], 2); OSStart (); return 0; }
/********************************************************************************************************* ** Task0 任务0 ********************************************************************************************************/ void Task0(void *pdata) { pdata = pdata;
TargetInit (); PINSEL0 = PINSEL0 & 0xffff3fff; // 管教选择模块初始化 PINSEL1 = PINSEL1 & 0xfffffcff; IO0DIR &= ~KEY1; // 设置KEY1的控制I/O为输入 IO0DIR |= BEEP; // 设置蜂鸣器为输出 IO0SET = BEEP; OSTaskCreate (Task1,(void *)0, &TaskStk1[TaskStkLengh - 1], 5); for (;;) { OSTaskSuspend(OS_PRIO_SELF); IO0CLR = BEEP; OSTimeDly(OS_TICKS_PER_SEC / 8); IO0SET = BEEP; OSTimeDly(OS_TICKS_PER_SEC / 4);
IO0CLR = BEEP; OSTimeDly(OS_TICKS_PER_SEC / 8); IO0SET = BEEP; OSTimeDly(OS_TICKS_PER_SEC / 4); } }
/********************************************************************************************************* ** Task1 任务1 ********************************************************************************************************/ void Task1(void *pdata) { pdata = pdata; /* 避免编译警告 */
for (;;) { OSTimeDly(OS_TICKS_PER_SEC / 50); /* 延时20毫秒 */ if ((IO0PIN & KEY1) != 0) { continue; } OSTimeDly(OS_TICKS_PER_SEC / 50); /* 延时20毫秒 */ if ((IO0PIN & KEY1) != 0) { continue; } OSTaskResume(2); while ((IO0PIN & KEY1) == 0) { OSTimeDly(OS_TICKS_PER_SEC / 50); /* 延时20毫秒 */ } } } |