]> cloudbase.mooo.com Git - irmp.git/blame - irmp-main-avr.c
Add support for libopencm3 (STM32F1)
[irmp.git] / irmp-main-avr.c
CommitLineData
4225a882 1/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
ea29682a 2 * irmp-main-avr.c - demo main module to test IRMP decoder on AVR\r
4225a882 3 *\r
7365350c 4 * Copyright (c) 2009-2016 Frank Meyer - frank(at)fli4l.de\r
ea29682a 5 *\r
7365350c 6 * $Id: irmp-main-avr.c,v 1.2 2016/01/12 21:15:16 fm Exp $\r
ea29682a 7 *\r
8 * This demo module is runnable on AVRs\r
4225a882 9 *\r
775fabfa 10 * ATMEGA88 @ 8 MHz internal RC Osc with BODLEVEL 4.3V: lfuse: 0xE2 hfuse: 0xDC efuse: 0xF9\r
11 * ATMEGA88 @ 8 MHz external Crystal Osc with BODLEVEL 4.3V: lfuse: 0xFF hfuse: 0xDC efuse: 0xF9\r
4225a882 12 *\r
13 * This program is free software; you can redistribute it and/or modify\r
14 * it under the terms of the GNU General Public License as published by\r
15 * the Free Software Foundation; either version 2 of the License, or\r
16 * (at your option) any later version.\r
17 *---------------------------------------------------------------------------------------------------------------------------------------------------\r
18 */\r
ea29682a 19\r
20#include "irmp.h"\r
4225a882 21\r
4225a882 22#ifndef F_CPU\r
ea29682a 23#error F_CPU unknown\r
4225a882 24#endif\r
25\r
ea29682a 26static void\r
1f54e86c 27timer1_init (void)\r
4225a882 28{\r
476267f4 29#if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85:\r
ea29682a 30\r
31#if F_CPU >= 16000000L\r
32 OCR1C = (F_CPU / F_INTERRUPTS / 8) - 1; // compare value: 1/15000 of CPU frequency, presc = 8\r
33 TCCR1 = (1 << CTC1) | (1 << CS12); // switch CTC Mode on, set prescaler to 8\r
34#else\r
b743217b 35 OCR1C = (F_CPU / F_INTERRUPTS / 4) - 1; // compare value: 1/15000 of CPU frequency, presc = 4\r
476267f4 36 TCCR1 = (1 << CTC1) | (1 << CS11) | (1 << CS10); // switch CTC Mode on, set prescaler to 4\r
ea29682a 37#endif\r
38\r
476267f4 39#else // ATmegaXX:\r
40 OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/15000 of CPU frequency\r
41 TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1\r
1f54e86c 42#endif\r
4225a882 43\r
1f54e86c 44#ifdef TIMSK1\r
476267f4 45 TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare\r
4225a882 46#else\r
476267f4 47 TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare\r
1f54e86c 48#endif\r
4225a882 49}\r
50\r
775fabfa 51#ifdef TIM1_COMPA_vect // ATtiny84\r
52#define COMPA_VECT TIM1_COMPA_vect\r
53#else\r
54#define COMPA_VECT TIMER1_COMPA_vect // ATmega\r
55#endif\r
56\r
775fabfa 57ISR(COMPA_VECT) // Timer1 output compare A interrupt service routine, called every 1/15000 sec\r
4225a882 58{\r
ea29682a 59 (void) irmp_ISR(); // call irmp ISR\r
60 // call other timer interrupt routines...\r
4225a882 61}\r
62\r
4225a882 63int\r
64main (void)\r
65{\r
ea29682a 66 IRMP_DATA irmp_data;\r
67\r
68 irmp_init(); // initialize IRMP\r
69 timer1_init(); // initialize timer1\r
1f54e86c 70\r
775fabfa 71 sei (); // enable interrupts\r
1f54e86c 72\r
73 for (;;)\r
74 {\r
ea29682a 75 if (irmp_get_data (&irmp_data))\r
76 {\r
77 ; // got an IR message, do something\r
78 }\r
1f54e86c 79 }\r
4225a882 80}\r