Guten Morgen zusammen,
ich habe schon öfter die Enprellroutine vom Peter benutzt nur brauchte
ich eine Möglichkeit 16 Tasten zu entprellen.
Ich habe mir den Code etwas abgeändert und durch den Simulator gejagt.
Es hat soweit auch alles funktioniert.
Kann sich das vieleicht mal noch jemand angucken ob ich mir nicht eine
Böse Falle gebaut habe ?
Das wäre super.
in der Header datei steht noch das hier:
#define KEY_PIN ( (PINA<<8) + (PINB) )
Hier der Code:
1 | volatile uint16_t key_state; // debounced and inverted key state:
|
2 | // bit = 1: key pressed
|
3 | volatile uint16_t key_press; // key press detect
|
4 |
|
5 | volatile uint16_t key_rpt; // key long press and repeat
|
6 |
|
7 | SIGNAL (SIG_OVERFLOW0) // every 10ms
|
8 | {
|
9 |
|
10 | static uint16_t ct0, ct1, rpt;
|
11 | uint16_t i;
|
12 |
|
13 | TCNT0 = (unsigned char)(signed short)-(XTAL / 1024 * 10e-3 + 0.5); // preload for 10ms
|
14 |
|
15 | i = key_state ^ KEY_PIN; // key changed ? Taste gedrückt = High
|
16 | ct0 = ~( ct0 & i ); // reset or count ct0
|
17 | ct1 = ct0 ^ (ct1 & i); // reset or count ct1
|
18 | i &= ct0 & ct1; // count until roll over ?
|
19 | key_state ^= i; // then toggle debounced state
|
20 | key_press |= key_state & i; // 0->1: key press detect
|
21 |
|
22 | if( (key_state & REPEAT_MASK) == 0 ) // check repeat function
|
23 | rpt = REPEAT_START; // start delay
|
24 | if( --rpt == 0 ){
|
25 | rpt = REPEAT_NEXT; // repeat delay
|
26 | key_rpt |= key_state & REPEAT_MASK;
|
27 | }
|
28 |
|
29 |
|
30 | }
|