|
大家?guī)臀铱纯窗�,長(zhǎng)按時(shí)間總是出錯(cuò),本來(lái)是3秒左右,很多時(shí)候調(diào)試查看延時(shí)一下就過(guò)去,感覺(jué)沒(méi)有延時(shí),
問(wèn)題找了很久了,不知道問(wèn)題在那?單片機(jī)是430F247,
/////兩個(gè)按鍵 長(zhǎng)按和短按 四種方式
/// key_value 1 測(cè)試短按 2 測(cè)試長(zhǎng)按 3 標(biāo)定短按 4 標(biāo)定長(zhǎng)按
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;
}
}
|
|