OS_EVENT *KeyQEvent;
INT8U err;
INT8U *Qmsg_Key1 = "Key1";
INT8U *Qmsg_Key2 = "Key2";
INT8U *Qmsg_Key3 = "Key3";
INT8U *Qmsg_Key4 = "Key4";
/****************************************************************************
* 名 称:static void AppTaskLED(void *p_arg)
* 功 能:LED任务
* 入口参数:无
* 出口参数:无
* 优先级 :5
* 调用方法:无
****************************************************************************/
static void AppTaskLED(void *p_arg)
{
INT8U *q_keymsg;
(void) p_arg;
while(1)
{
q_keymsg = (INT8U*)OSQPend(KeyQEvent,10,&err);/*扫描消息队列*/
if(err == OS_NO_ERR)
{
if(q_keymsg == Qmsg_Key2)/*如果按键2被按键,则相应相关处理函数*/
{
LED2_ON();
}
else if(q_keymsg == Qmsg_Key1)
{
LED1_ON();
}
else if(q_keymsg == Qmsg_Key3)
{
LED3_ON();
}
else if(q_keymsg == Qmsg_Key4)
{
LED3_OFF();
LED2_OFF();
LED1_OFF();
}
}
}
}
/****************************************************************************
* 名 称:static void AppTaskKey(void *pdata)
* 功 能:按键扫描任务
* 入口参数:无
* 出口参数:无
* 优先级 :3
* 调用方法:无
****************************************************************************/
static void AppTaskKey(void *pdata)
{
void *Qstart[10]; //用户创建消息队列,能够存放10条消息
INT8U Key1State;
INT8U Key2State;
INT8U Key3State;
INT8U Key4State;
INT8U key1_release = 0;
INT8U key2_release = 0;
INT8U key3_release = 0;
INT8U key4_release = 0;
KeyQEvent = OSQCreate(&Qstart[0],10);
while(1)
{
OSTimeDlyHMSM(0,0,0,50);
Key1State = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5);
Key2State = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_2);
Key3State = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_3);
Key4State = GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_6);
if(Key1State ==0)
{
OSTimeDlyHMSM(0,0,0,20);
Key1State = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_5);
if (Key1State == 0)
{
key1_release =1;
}
}
if(Key1State ==0&&key1_release==1)
{
OSQPost(KeyQEvent, Qmsg_Key1);
key1_release=0;
}
if (Key2State == 0)
{
OSTimeDlyHMSM(0,0,0,20);
Key2State = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_2);
if (Key2State == 0)
{
key2_release =1;
}
}
if(Key2State ==0&&key2_release==1)
{
OSQPost(KeyQEvent, Qmsg_Key2);
key2_release=0;
}
if (Key3State == 0)
{
OSTimeDlyHMSM(0,0,0,20);
Key3State = GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_3);
if (Key3State == 0)
{
key3_release =1;
}
}
if(Key3State ==0&&key3_release==1)
{
OSQPost(KeyQEvent, Qmsg_Key3);
key3_release=0;
}
if (Key4State == 0)
{
OSTimeDlyHMSM(0,0,0,20);
Key4State = GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_6);
if (Key4State == 0)
{
key4_release =1;
}
}
if(Key4State ==0&&key4_release==1)
{
OSQPost(KeyQEvent, Qmsg_Key4);
key4_release=0;
}
}
}