以下程式的设想为,根据按按键时间的长短,返回不同值给主函数,不管时间长短,实际返回值都是4.
#define o_ms 1000
#define t_ms 3000
#define th_ms 5000
#define f_ms 8000
#define fi_ms 10000
uint keynum=0;
uint keytime=0;
uint ucKeyLock1=0;
uchar keyscan2()
{
uchar scode;
int t=0;
SW1=1;
if(SW1==1)
{
keytime=0;
keynum=0;
ucKeyLock1=0;
}
if(SW1==0)
{
keytime++;
if(keytime>=f_ms)
{
// scode=P0^0X0F;
keytime=0;
ucKeyLock1=1;
keynum=4;
return(keynum);
}
if(keytime>=th_ms)
{
// scode=P0^0X0F;
keytime=0;
ucKeyLock1=1;
keynum=3;
return(keynum);
}
if(keytime>=t_ms)
{
// scode=P0^0X0F;
keytime=0;
ucKeyLock1=1;
keynum=2;
return(keynum);
}
if(keytime>=o_ms)
{
// scode=P0^0X0F;
keytime=0;
ucKeyLock1=1;
keynum=1;
return(keynum);
}
}
}
|