標(biāo)題:
按鍵函數(shù)長按和短按問題
[打印本頁]
作者:
ll_cc
時(shí)間:
2016-8-13 17:11
標(biāo)題:
按鍵函數(shù)長按和短按問題
大家?guī)臀铱纯窗,長按時(shí)間總是出錯(cuò),本來是3秒左右,很多時(shí)候調(diào)試查看延時(shí)一下就過去,感覺沒有延時(shí),
問題找了很久了,不知道問題在那?單片機(jī)是430F247,
/////兩個(gè)按鍵 長按和短按 四種方式
/// key_value 1 測試短按 2 測試長按 3 標(biāo)定短按 4 標(biāo)定長按
void key_scan(void){
volatile unsigned char temp_counter;
key_value=0;
if(key1&&key2)return;
temp_counter=0;
if(key1==0)
{
delay_ms(8);
if(key1==1) return;
while(!key1)
{
delay_ms(20);
temp_counter++;
if(temp_counter>100)break;
}
if(temp_counter>50)key_value=2;
else key_value = 1;
}
if(key2==0)
{
delay_ms(8);
if(key2==1) return;
while(!key2)
{
delay_ms(20);
temp_counter++;
if(temp_counter>100)break;
}
if(temp_counter>50)key_value=4;
else key_value = 3;
}
}
作者:
ll_cc
時(shí)間:
2016-8-15 09:28
大家?guī)兔纯窗?hr noshade size="2" width="100%" color="#808080">
作者:
ll_cc
時(shí)間:
2016-8-15 09:28
大家?guī)兔纯窗?nbsp; 著急啊
作者:
不知道叫啥b
時(shí)間:
2016-8-16 17:23
temp_counter清零不及時(shí)的問題
作者:
ll_cc
時(shí)間:
2016-8-17 15:47
好像不是這個(gè)原因
作者:
justtalk
時(shí)間:
2016-8-18 13:33
先去抖,再計(jì)時(shí)。
歡迎光臨 (http://www.torrancerestoration.com/bbs/)
Powered by Discuz! X3.1