From e67c988824f5ec0c965beb412f8ee5953dfd3c8c Mon Sep 17 00:00:00 2001 From: tmk Date: Sat, 17 Sep 2011 22:39:50 +0900 Subject: Added Bulegiga iWRAP support into HHKB.(Bluetooth) --- timer.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'timer.c') diff --git a/timer.c b/timer.c index edbb4409d..48a38c9b6 100644 --- a/timer.c +++ b/timer.c @@ -20,17 +20,31 @@ along with this program. If not, see . #include #include "timer.h" + +// counter resolution 1ms volatile uint16_t timer_count = 0; -// Configure timer 0 to generate a timer overflow interrupt every -// 256*1024 clock cycles, or approx 61 Hz when using 16 MHz clock -// This demonstrates how to use interrupts to implement a simple -// inactivity timeout. void timer_init(void) { - TCCR0A = 0x00; + // Timer0 CTC mode + TCCR0A = 0x02; + +#if TIMER_PRESCALER == 1 + TCCR0B = 0x01; +#elif TIMER_PRESCALER == 8 + TCCR0B = 0x02; +#elif TIMER_PRESCALER == 64 + TCCR0B = 0x03; +#elif TIMER_PRESCALER == 256 + TCCR0B = 0x04; +#elif TIMER_PRESCALER == 1024 TCCR0B = 0x05; - TIMSK0 = (1<