#include 'global.h '
# define u8无符号char
#define u16 unsigned int
按#define WaitStatus 0 //按钮的进程状态
#定义press status 1
#定义发行版status 2
#定义idestatus 3
#定义密钥时间800//长按超时时间
#define KEY_TIME 1
#define KEY_UP 2
#define KEY_SWITCH 3
#define KEY_DOWN 4
#define KEY_SLEEP 5
u16关键点=0;
u8 KeyVal=0;
u8 KeyPress=0; //1按,长按2
//获取各键的状态
u8 getkey () ) ) )。
{
//DATA_BUF[0]的bit7-bit0表示触摸键KEY8-KEY1
//DATA_BUF[1]的bit7-bit0表示触摸键KEY16-KEY9
GET_KEY_BITMAP (; //将包装器扫描的结果复制到DATA_BUF
if(data_buf[0]0x20 )==0x20 ) return 1; //TK1
ELSEif () data_buf[0]0x01 )==0x01 ) return 2; //TK2
ELSEif () data_buf[0]0x02 )==0x02 ) return 3; //TK1
ELSEif () data_buf[0]0x80 )==0x80 ) return 4; //TK4
ELSEif () data_buf[1]0x01 )==0x01 ) return 5; //TK5
返回0;
}
void密钥扫描(
{
静态u8i=0;
u8 temp;
temp=getkey (;
切换(密钥状态) )。
{
等待状态://
if(temp!=0x00 )
{
if(I=3) )
{
i=0;
}
}
else
{
i=0;
}
布雷克;
case PressStatus: //按下状态
if(temp!=0x00 )
{
KeyVal=temp;
}
else
{
}
布雷克;
case ReleaseStatus: //发行等待状态
if(temp!=0x00 )
{
if(HSDjy==keytime )//长按检查
{
KeyPress=2;
}
}
else
{
KeyPress=1;
}
布雷克;
case IDEStatus:
if(temp==0x )
00){
break;
}
}
//#define KEY_TIME 1
//#define KEY_UP 2
//#define KEY_SWITCH 3
//#define KEY_DOWN 4
//#define KEY_SLEEP 5
//函数库的主循环 相当于不用函数库时while(1)里面的循环
void Task_key(void)
{
_BEGIN(100);
keyscan();//按键扫描
if(KeyPress==1)//短按
{
switch(KeyVal)
{
case KEY_TIME:
device_status = SET_TIME_STUTAS;
break;
case KEY_UP:
if(device_status == SET_TIME_STUTAS)
{
set_time ++;
}
else if((device_status == RUN_STATUS)|(device_status == WAIT_STUTAS))
{
set_temperature ++;
device_status = SET_TEM_STUTAS;
}
break;
case KEY_SWITCH:
if(device_status == WAIT_STUTAS)
{
device_status = RUN_STATUS;
}
else if(device_status == RUN_STATUS)
{
device_status = WAIT_STUTAS;
}
break;
case KEY_DOWN:
if(device_status == SET_TIME_STUTAS)
{
set_time --;
}
else if((device_status == RUN_STATUS)|(device_status == WAIT_STUTAS))
{
set_temperature --;
device_status = SET_TEM_STUTAS;
}
break;
case KEY_SLEEP:
break;
}
KeyPress=0;
}
else if(KeyPress==2)//长按
{
switch(KeyVal)
{
case 1:break;
case 2:break;
case 3:break;
case 4:break;
}
KeyPress=0;
}
_END();
}