Vaughn
Junior Member level 2
Can anyone please help me to understand this key debounce method, I've implemented this from http://www.ganssle.com/debouncing-pt2.htm with small changes in my code here is the code:
I am using the above code and it is working well, toggling the LED on each key press (one toggle on one key press). Here what I understood is as soon the keyState value reaches to 0x1000 ORing with 0xE0000 produces 0xF000 and the key command is executed inside main(). Now what I didn't understand is why the key command is getting executed only once on each key press while the keyState value is changing on each 2 ms (millisecond range) and on the other side loop is running in micro-second range. Why don't it toggles the LED continuously on a single key press? or it is by luck?
Code C - [expand] 1 2 3 4 ISR(TIMER0_OVF_vect) //2 ms interval { keyState = (keyState << 1) | !KeyPressed() | 0xE000; }
Code C - [expand] 1 2 3 4 5 while(1) //inside main() { if(keyState == 0xF000); LED_PORT ^= (1<<LED); }
I am using the above code and it is working well, toggling the LED on each key press (one toggle on one key press). Here what I understood is as soon the keyState value reaches to 0x1000 ORing with 0xE0000 produces 0xF000 and the key command is executed inside main(). Now what I didn't understand is why the key command is getting executed only once on each key press while the keyState value is changing on each 2 ms (millisecond range) and on the other side loop is running in micro-second range. Why don't it toggles the LED continuously on a single key press? or it is by luck?