#include “extern.h”
typedef byte u8;
typedef word u16;
typedef EWORD u24;
typedef DWORD u32;
#define Key PA.0//定义按键的脚位
bit Work_Off_Sign;
bit Key_Keep;
bit Key_Long_Sign;
byte Delay1;
byte Delay0;
void Scankey(void)
{
if(Key_Keep0)
{
Delay1 = 100;
if(Key0)//判断是否有可能有按键
{
.delay 200;
Delay0–;
if(Delay00)//判断按键是否确定触发
{
Key_Keep = 1;
Key_Long_Sign = 0;
u16 Delay_Icnt = 0;
while(!Key)//等待,判断按键是否有长按
{
.delay 2000;
Delay_Icnt++;
if(Delay_Icnt >= 500)//大于一定时间确定长按
{
Key_Long_Sign = 1;
break;//确定长按后退出按键扫描进行下面的程序
}
}
if(Key_Long_Sign)//长按
{
Work_Off_Sign = 1;
}
else//短按
{
Work_Off_Sign = 0;
}
}
}
else
{
Delay0 = 100;
}
}
else
{
Delay0 = 100;
if(Key)
{
.delay 200;
Delay1–;
if(Delay10)
{
Key_Keep = 0;
}
}
else
{
Delay1 = 100;
}
}
}
void FPPA0 (void)
{
.ADJUST_IC SYSCLK=IHRC/8, IHRC=16MHz, VDD=5V;
$ Key in,pull;//对按键进行输入上拉设置,无按键为高,有按键为低
.delay 100;
while (1)
{
Scankey();
}
}
void Interrupt (void)
{
pushaf;
if (Intrq.T16)
{ // T16 Trig
// User can add code
Intrq.T16 = 0;
//...
}
popaf;
}