This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

keymatrix debounce example

Hi all
Does any one have keymatrix debounce example on keil c.
Thanx

Parents
  • Hi Mahmood!

    I usually do that in an timer interrupt routine.

    if (--tsec_counter == 0) {
        tsec_counter = DEF_10TH;
        if (t0_10thcnt > 0) {
          --t0_10thcnt;
        }
        if (((~INPORT) | 0xc0) != input_new_state) {
           input_new_state = (~INPORT) | 0xc0;
           t0_bounce = bounce_time;
        }
        if (t0_bounce != 0) {
          --t0_bounce;
        }
        if ((input_new_state != input_old_state) && (t0_bounce == 0)) {
          input_active |= input_pedge & (input_old_state ^ input_new_state) & (input_new_state & ~input_old_state);
          input_active |= input_nedge & (input_old_state ^ input_new_state) & (input_old_state & ~input_new_state);
          input_old_state = input_new_state;
          input_triggered |= input_active;
        }
      }
      
    

    This is from a very slow input (debounce time 0.3sec).

    It is part of the interrupt service routine of timer 0. It is called every 1/1024 second. If a tenth second is reached, I will check the INPORT for it's state and when it is the same for 0.3 secs it triggers some action.

    If you ahve something like a real keyboard, I would suggest a stack of key codes that is processed outside the timer ISR.

    Take care,
    Sven

Reply
  • Hi Mahmood!

    I usually do that in an timer interrupt routine.

    if (--tsec_counter == 0) {
        tsec_counter = DEF_10TH;
        if (t0_10thcnt > 0) {
          --t0_10thcnt;
        }
        if (((~INPORT) | 0xc0) != input_new_state) {
           input_new_state = (~INPORT) | 0xc0;
           t0_bounce = bounce_time;
        }
        if (t0_bounce != 0) {
          --t0_bounce;
        }
        if ((input_new_state != input_old_state) && (t0_bounce == 0)) {
          input_active |= input_pedge & (input_old_state ^ input_new_state) & (input_new_state & ~input_old_state);
          input_active |= input_nedge & (input_old_state ^ input_new_state) & (input_old_state & ~input_new_state);
          input_old_state = input_new_state;
          input_triggered |= input_active;
        }
      }
      
    

    This is from a very slow input (debounce time 0.3sec).

    It is part of the interrupt service routine of timer 0. It is called every 1/1024 second. If a tenth second is reached, I will check the INPORT for it's state and when it is the same for 0.3 secs it triggers some action.

    If you ahve something like a real keyboard, I would suggest a stack of key codes that is processed outside the timer ISR.

    Take care,
    Sven

Children