/* TCCR0A 0000xx00 //timer counter control register TCCR0B 00xx0101 //timer counter control register TCNT0 xxxxxxxx //timer counter register OCR0A xxxxxxxx //output comare register A OCR0B xxxxxxxx //output comare register B TIMSK0 xxxxx010 //timer counter interrupt mask register TIFR0 xxxxxxxx //timer counter 0 interrupt flag register */ void init_timer0() { //===================================== timer 0 =========================================================== //normal port operation OC0A and OC0B: COM0A1 = 0, COM0A0 = 0, COM0B1 = 0, COM0B0 = 0 TCCR0A &= ~((1 << COM0A1) | (1 << COM0A0) | (1 << COM0B1) | (1 << COM0B0)); //operate in nomal mode: WGM02 = 0, WGM01 = 0, WGM00 = 0 TCCR0A &= ~((1 << WGM01) | (1 << WGM00)); TCCR0B &= ~(1 << WGM02); //force output compare A and B is disabled: FOC0A = 0, FOC0B = 0 TCCR0B &= ~((1 << FOC0A) | (1 << FOC0B)); //initially turn the clock off. STOP_TIMER0; //OCR0A needs to be set to a value which will influence the time of the timer OCR0A = DEBOUNCE_TIME0; //timer counter output compare match A interrupt enabled: OCIE0B = 0, OCIE0A = 1, TOIE0 = 0 TIMSK0 |= (1 << OCIE0A); TIMSK0 &= ~((1 << OCIE0B) | (1 << TOIE0)); } ISR(TIMER0_COMPA_vect) { STOP_TIMER0; CLEAR_TIMER0; debounceMem &= ~(1<<0); if (!(PIND & KEY_1_PORT)) { Keyboard.release(KEY_1_CHAR); } }