/************************************************************************/ /* */ /* Debouncing 8 Keys */ /* Sampling 4 Times */ /* */ /* Author: Peter Dannegger */ /* danni@specs.de */ /* */ /************************************************************************/ #pragma cd pl(9999) #include #define KEY_INPUT P2 char key_state, key_press; void to_int( void ) interrupt INT_T0 { static char ct0, ct1; char i; i = key_state ^ ~KEY_INPUT; // key changed ? ct0 = ~( ct0 & i ); // reset or count ct0 ct1 = ct0 ^ ct1 & i; // reset or count ct1 i &= ct0 & ct1; // count until roll over key_state ^= i; // then toggle debounced state key_press |= key_state & i; // 0->1: key pressing detect }