I want to use the code below from embedded.com for my switch debouncing.
The problems is that my version of the code works only after releasing the button. It's supposed to detect only the last change. Full explanation here: My favourite software debouncers (Listing 2)
// Service routine called by a timer interrupt bool_t DebounceSwitch2() { static uint16_t State = 0; // Current debounce status State=(State<<1) | !RawKeyPressed() | 0xe000; if(State==0xf000)return TRUE; return FALSE; }
My version for CodevisionAVR:
char DebounceNollaa() { static int State = 0; // Current debounce status State=(State<<1) | !nollaa | 0xe000; if(State==0xf000)return 1; return 0; }
And it gets called by timer0 isr like this:
if (DebounceNollaa()) { nollaus(); paivita = 1; }
My coding skills aren't that good, so I'm (again) in need of help.