/* * Simple minute timer. Toggles the output LED every minute. * * 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 0x8F // ck/16384 = 300 ticks/sec #define TIMER1_VALUE 0x60 // 150 ticks to overflow: 2 overflows/sec #define TIMER1_COMP 150 // 150 ticks to overflow: 2 overflows/sec volatile int count; int main(void) { // Set the data direction bits on port B DDRB = _BV(LED_LINE) | _BV(OUTPUT_LINE); PORTB = _BV(LED_LINE); count = 0; TCNT1 = 0; OCR1A = TIMER1_COMP; OCR1C = TIMER1_COMP; TIMSK |= _BV(OCIE1A); TCCR1 = TIMER1_TCCR1; TCNT0 = TIMER0_VALUE; TIMSK |= _BV(TOIE0); TCCR0B = TIMER0_TCCR0B; sei(); while(1) { sleep_mode(); } return 0; } ISR(SIG_OVERFLOW0) { TCNT0 = TIMER0_VALUE; } ISR(SIG_OUTPUT_COMPARE1A) { count++; if ( count == 120 ) { PORTB = PORTB ^ _BV(LED_LINE); count = 0; } }