//-------------------------------------------------------------------------
//两按键处理程序,有效解决了长按键,短按键和单双击的问题
//-------------------------------------------------------------------------
struct GSF_KEY
{
U08 cyc_short :1;
U08 cyc_long :1;
U08 pro_short :1;
U08 pro_long :1;
U08 double_key :1;
U08 :3;
};
extern struct GSF_KEY gsflag_key;
extern U16 gcount_cyckey;
extern U16 gcount_prokey;
static void time0_int (void) small interrupt TMR0_IV // 10ms中断程序
{
// 装入初值 10ms
TL0 = TIMER_TL0;
TH0 = TIMER_TH0;
//---------------------------------------------------------------------
// 按键检测
//---------------------------------------------------------------------
if(KEY_CYC_DISP)
{
gcount_cyckey++;
if(gcount_cyckey>200)
{
//长按键
gsflag_key.cyc_long = 1;
}
}
else
{
if((gcount_cyckey>5)&&(gcount_cyckey<200)) //短按键
{
if(!gsflag_key.double_key )
{
if(gcount_prokey>5) //双击键
gsflag_key.double_key = 1;
else
gsflag_key.cyc_short = 1;
}
}
gcount_cyckey = 0;
}
if(KEY_PROG)
{
gcount_prokey++;
if(gcount_prokey>200) //长按键
{
gsflag_key.pro_long = 1;
}
}
else
{
if((gcount_prokey>5)&&(gcount_prokey<200)) //短按键
{
if(!gsflag_key.double_key) //如果是双击,则不处理单击
{
if(gcount_cyckey>5)
gsflag_key.double_key = 1;
else
gsflag_key.pro_short = 1;
}
gcount_prokey = 0;
}
}
//按键事件响应程序
void System_event(void)
{
if(gsflag_key.cyc_short)
{
System_event_CYCKEY();
gsflag_key.cyc_short = 0;
}
if(gsflag_key.pro_short)
{
System_event_proKEY();
gsflag_key.pro_short = 0;
}
if(gsflag_key.pro_long)
{
gsflag_key.pro_long = 0;
}
}