#include "entprell.h" volatile uint8_t key_state; // debounced and inverted key state: // bit = 1: key pressed volatile uint8_t key_press; // key press detect volatile uint8_t key_rpt; // key long press and repeat ISR( TIMER1_COMPA_vect ) { // every 10ms static uint8_t ct0 = 0xFF, ct1 = 0xFF, rpt; uint8_t i; i = key_state ^ ~KEY_PIN; // 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 press detect if ( (key_state & REPEAT_MASK) == 0 ) { // check repeat function rpt = REPEAT_START; // start delay } if ( --rpt == 0 ) { rpt = REPEAT_NEXT; // repeat delay key_rpt |= key_state & REPEAT_MASK; } } void init_entprell(void) { KEY_DDR &= ~ALL_KEYS; // configure key port for input KEY_PORT |= ALL_KEYS; // and turn on pull up resistors // Timer 1, CTC mode 4, prescaler 256 TCCR1A = 0; TCCR1B = (1<