X-Git-Url: http://cloudbase.mooo.com/gitweb/irmp.git/blobdiff_plain/1f54e86cd05ee6e47b5da32107d191f0983ccf04..4038f0212d7eeaaf1977c5cc57b41c6db89f6e44:/main.c diff --git a/main.c b/main.c index 9877762..dbcd57f 100644 --- a/main.c +++ b/main.c @@ -1,9 +1,9 @@ /*--------------------------------------------------------------------------------------------------------------------------------------------------- * main.c - demo main module to test irmp decoder * - * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de + * Copyright (c) 2009-2012 Frank Meyer - frank(at)fli4l.de * - * $Id: main.c,v 1.9 2011/04/11 12:54:25 fm Exp $ + * $Id: main.c,v 1.14 2012/05/15 10:25:21 fm Exp $ * * ATMEGA88 @ 8 MHz * @@ -16,13 +16,6 @@ *--------------------------------------------------------------------------------------------------------------------------------------------------- */ -#include -#include -#include -#include -#include - -#include "irmpconfig.h" #include "irmp.h" #ifndef F_CPU @@ -32,21 +25,43 @@ void timer1_init (void) { -#if defined (__AVR_ATtiny85__) // ATtiny85: - OCR1A = (F_CPU / (2 * F_INTERRUPTS) / 2) - 1; // compare value: 1/28800 of CPU frequency, presc = 2 - TCCR1 = (1 << CTC1) | (1 << CS11); // switch CTC Mode on, set prescaler to 2 -#else // ATmegaXX: - OCR1A = (F_CPU / (2 * F_INTERRUPTS)) - 1; // compare value: 1/28800 of CPU frequency - TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1 +#if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85: + +#if F_CPU >= 16000000L + OCR1C = (F_CPU / F_INTERRUPTS / 8) - 1; // compare value: 1/15000 of CPU frequency, presc = 8 + TCCR1 = (1 << CTC1) | (1 << CS12); // switch CTC Mode on, set prescaler to 8 +#else + OCR1C = (F_CPU / F_INTERRUPTS / 4) - 1; // compare value: 1/15000 of CPU frequency, presc = 4 + TCCR1 = (1 << CTC1) | (1 << CS11) | (1 << CS10); // switch CTC Mode on, set prescaler to 4 +#endif + +#else // ATmegaXX: + OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/15000 of CPU frequency + TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1 #endif #ifdef TIMSK1 - TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare + TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare +#else + TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare +#endif +} + +/*--------------------------------------------------------------------------------------------------------------------------------------------------- + * Timer 1 output compare A interrupt service routine, called every 1/15000 sec + *--------------------------------------------------------------------------------------------------------------------------------------------------- + */ +#ifdef TIM1_COMPA_vect // ATtiny84 +ISR(TIM1_COMPA_vect) #else - TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare +ISR(TIMER1_COMPA_vect) #endif +{ + (void) irmp_ISR(); // call irmp ISR + // call other timer interrupt routines... } + int main (void) {