/* * Hardware timer test app. * * Copyright 2007, Jon McClintock. * * This software is licensed under the CC-GNU GPL. */ #define F_CPU 4915200UL #include #include #include #include #define BUTTON_LINE 2 #define LED_LINE 1 #define OUTPUT_LINE 0 #define TIMER0_TCCR0B 0x05 // ck/1024 = 4800 ticks/sec #define TIMER0_VALUE 0x56 // 160 ticks to overflow: 30 overflows/sec #define TIMER1_TCCR1 0x0F // ck/16384 = 300 ticks/sec #define TIMER1_VALUE 0x60 // 150 ticks to overflow: 2 overflows/sec int main(void) { // Set the data direction bits on port B DDRB = _BV(LED_LINE) | _BV(OUTPUT_LINE); PORTB = 0; /* TCNT1 = TIMER1_VALUE; TIMSK |= _BV(TOIE1); TCCR1 = TIMER1_TCCR1; */ TCNT0 = TIMER0_VALUE; TIMSK |= _BV(TOIE0); TCCR0B = TIMER0_TCCR0B; sei(); while(1) { sleep_mode(); PORTB = PORTB ^ _BV(LED_LINE); } return 0; } ISR(SIG_OVERFLOW0) { TCNT0 = TIMER0_VALUE; } ISR(SIG_OVERFLOW1) { TCNT1 = TIMER1_VALUE; }