我写的按键驱动,大家鉴赏一下!!!

2019-07-20 12:44发布

欢迎大家指正,
#define KEY0  PEin(4)
#define KEY1  PEin(3)
#define KEY2  PEin(2)
#define KEY_WP  PAin(0)
#define NO_KEY   0x00
#define KEY0_OK  0X01
#define KEY1_OK  0X02
#define KEY2_OK  0X04
#define KEY_WP_OK 0X08

int key_scanf(u8 mode)
{
u8 key = NO_KEY ;

static u8 key_sta = 1;    //1ÔÊÐí°´½¨Ê¶±ð
static u8 key1,key2,key3,time = 0;

key3 = key2;
key2 = key1;
time++;

if(mode)
{
  key_sta = 1;
}
if ((!KEY1 || !KEY2 || KEY_WP || !KEY0)&&(key_sta ))
{
  if(!KEY0)
  {
   key1 = KEY0_OK;
  }
  else if(!KEY1)
  {
   key1 = KEY1_OK;
  }
  else if(!KEY2)
  {
   key1 = KEY2_OK;
  }
  else if(KEY_WP)
  {
   key1 =KEY_WP_OK;
  }
  else if(time == 3)
  {
   if(key3 == key2 && key2 == key1)
   {
    key = key1;
    key_sta = 0;
   }
  }
}
else if (KEY1 && KEY2 && KEY0 && KEY_WP)
{
  key_sta = 1;
  time =0;
}
return key;
}
        

        
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。