|
1黑幣
下面程序在裸機(jī)上正常,在OS任務(wù)中只能識別短按,無法得到長按值,不知為何,請高手指點(diǎn)
#define const_key_time_short1 20 //短按的按鍵去抖動延時(shí)的時(shí)間
#define const_key_time_long1 400 //長按的按鍵去抖動延時(shí)的時(shí)間
#define const_key_time_short2 20 //短按的按鍵去抖動延時(shí)的時(shí)間
#define const_key_time_long2 400 //長按的按鍵去抖動延時(shí)的時(shí)間
void task4_task(void * pvParameters) //OS任務(wù)
{
static int uiKeyTimeCnt1=0;
static u8 ucKeyLock1=0;
static u8 ucShortTouchFlag1=0;
while(1)
{
if(KEY2==1)//IO是高電平,說明兩個(gè)按鍵沒有全部被按下,這時(shí)要及時(shí)清零一些標(biāo)志位
{
ucKeyLock1=0; //按鍵自鎖標(biāo)志清零
uiKeyTimeCnt1=0;//按鍵去抖動延時(shí)計(jì)數(shù)器清零,此行非常巧妙,是我實(shí)戰(zhàn)中摸索出來的。
if(ucShortTouchFlag1==1) //短按觸發(fā)標(biāo)志
{
ucShortTouchFlag1=0;
K2Sec_1=1; //觸發(fā)一號鍵的短按
}
}
else if(ucKeyLock1==0)//有按鍵按下,且是第一次被按下
{
uiKeyTimeCnt1++; //累加定時(shí)中斷次數(shù)
if(uiKeyTimeCnt1>const_key_time_short1)
{
ucShortTouchFlag1=1; //激活按鍵短按的有效標(biāo)志
}
if(uiKeyTimeCnt1>const_key_time_long1)
{
ucShortTouchFlag1=0; //清除按鍵短按的有效標(biāo)志
uiKeyTimeCnt1=0;
ucKeyLock1=1; //自鎖按鍵置位,避免一直觸發(fā)
K2Sec_1=2; //觸發(fā)1號鍵的長按
}
}
printf("task-2:%d\r\n",K2Sec_1);
vTaskDelay(100 / portTICK_RATE_MS); //增加延時(shí)節(jié)拍函數(shù)
}
}
|
|