采用非中断按钮,长时间按按钮,如何取最后一次的信息。[mw_shl_code=c,true]u8 KEY_Scan(u8 mode)
{
static u8 key_up=1;
if(mode)key_up=1;
if(key_up&&((WARING_KEY==0 && close_judge==0)||(WARING_KEY==1 && close_judge==1)||(INTRUDE_KEY==1 && Relay12==1)||(DOOR_KEY==0)))
{
delay_ms(10);
key_up=0;
if(WARING_KEY==0 && close_judge==0) return 3;
else if(WARING_KEY==1 && close_judge==1) return 4;
else if(INTRUDE_KEY==1 && Relay12==1) return 2;
else if(DOOR_KEY==0) return 1;
}
else if((WARING_KEY==0 && close_judge==1)||(WARING_KEY==1 && close_judge==0)||(INTRUDE_KEY==1 && Relay12==1)||(DOOR_KEY==1))
key_up=1;
return 0;
}
void Button_watch(void)
{
static u8 key;
key=KEY_Scan(1);
if(key)
{
switch(key)
{
case DOOR_PRES:
if(close_judge)
return;
state_door[0]=1;
state_door[1]=1;
state_door[2]=1;
return;
case WAR_INT:
if(close_judge || close_intrude || time_out_war)
return;
state_door[0]=1;
state_door[1]=3;
state_door[2]=1;
close_intrude=1;
return;
case WAR_STA:
state_door[0]=1;
state_door[1]=4;
state_door[2]=0;
close_judge=1;
OPEN_ALL_DOOR(2048);
return;
case WAR_END:
state_door[0]=1;
state_door[1]=4;
state_door[2]=1;
close_judge=0;
close_intrude=0;
time_out_war=0;
CLOSE_ALL_DOOR(2048);
return;
}
}
}[/mw_shl_code]
主程序
[mw_shl_code=applescript,true]while(1)
{
……
Button_watch();
……
}[/mw_shl_code]
怎么做到连续按下按钮,只触发一次
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
长按不松开,但主循环检测到多次触发
只能用
while(按钮闭合){};
去掉长按吗?有没有不影响时间的方法
当然有了.你这个方法是怎么来的.
一周热门 更多>