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