??? 07/19/04 17:20 Read: times |
#74471 - RE: Push Button Bouncing Time Method Responding to: ???'s previous message |
A way to do this without interrupts:
<pre> #define BUTTON_PRESSED (!debounce_ctr) uint debounce_ctr = 1000; if (!pushb) debounce_ctr = 1000; //reload if not pressed if (debounce_ctr) debounce_ctr--; // count down if pressed if (BUTTON_PRESSED) ..... so something if button is pressed The value of 1000 here should depend on the cycle time of this program: if this is 50 uS you get a debounce time of 50 mS. Of course, a better way is to do the count down in a timer interrupt routine, so the cycle time is not important anymore. Lex. |