Double-click the button and do not double-click

A concept statement:

  Double-click: it is similar to + remote control - as long as you hold down the volume keys he has been let go + or -

  Not even the press: the process by going to bounce count as a valid key, if not press down bounce will not carry out any operation

 

 

// key handler
 // returns the key value
 // MODE: 0, not supported by the continuous; 1, support continuous press;
 // 0, no buttons pressed
 // 1, the WKUP press WK_UP
 // Note that this function has in response to the priority, KEY0 on> KEY1> the KEY2> WK_UP !! 
U8 KEY_Scan (U8 MODE)
{
    static U8 = KEY_UP . 1 ;      // key release flag 
    IF (MODE == . 1 ) = KEY_UP . 1 ;     // enable connection by 
    IF (KEY_UP && (KEY0 on == 0 || KEY1 == 0 || the KEY2 == 0 || == WK_UP 1 ))
    {
        delay_ms(10);
        key_up=0;
        if(KEY0==0)       return KEY0_PRES;
        else if(KEY1==0)  return KEY1_PRES;
        else if(KEY2==0)  return KEY2_PRES;
        else if(WK_UP==1) return WKUP_PRES;          
    }else if(KEY0==1&&KEY1==1&&KEY2==1&&WK_UP==0)key_up=1;
    return 0;   //无按键按下
}

 

 

Code explanation: when the mode == 0, the pressing time, pressing the first detected triggers, but press the second test case key_up == 0 0 no action return value is varied until changed a key state, will change the value of the flag bit key_up, the brightness of the lamp will be changed

    When 1, key_up modified static mode ==, this initialized value does not repeat, when the second press is detected to enter key_up becomes 1 if condition, a return key is detected the return value.

 

This magical code is a long time when you press a key, a different mode, choose whether to back a second time (back many times) Returns the value of the detection.

If you give back the return value indicates that it is not even detected by

r

Guess you like

Origin www.cnblogs.com/qifeng1024/p/12026666.html