]> cloudbase.mooo.com Git - irmp.git/blob - main.c
Version 2.3.0: some timer and variable name corrections
[irmp.git] / main.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * main.c - demo main module to test irmp decoder
3 *
4 * Copyright (c) 2009-2012 Frank Meyer - frank(at)fli4l.de
5 *
6 * $Id: main.c,v 1.14 2012/05/15 10:25:21 fm Exp $
7 *
8 * ATMEGA88 @ 8 MHz
9 *
10 * Fuses: lfuse: 0xE2 hfuse: 0xDC efuse: 0xF9
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *---------------------------------------------------------------------------------------------------------------------------------------------------
17 */
18
19 #include "irmp.h"
20
21 #ifndef F_CPU
22 #error F_CPU unkown
23 #endif
24
25 void
26 timer1_init (void)
27 {
28 #if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85:
29
30 #if F_CPU >= 16000000L
31 OCR1C = (F_CPU / F_INTERRUPTS / 8) - 1; // compare value: 1/15000 of CPU frequency, presc = 8
32 TCCR1 = (1 << CTC1) | (1 << CS12); // switch CTC Mode on, set prescaler to 8
33 #else
34 OCR1C = (F_CPU / F_INTERRUPTS / 4) - 1; // compare value: 1/15000 of CPU frequency, presc = 4
35 TCCR1 = (1 << CTC1) | (1 << CS11) | (1 << CS10); // switch CTC Mode on, set prescaler to 4
36 #endif
37
38 #else // ATmegaXX:
39 OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/15000 of CPU frequency
40 TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1
41 #endif
42
43 #ifdef TIMSK1
44 TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
45 #else
46 TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
47 #endif
48 }
49
50 /*---------------------------------------------------------------------------------------------------------------------------------------------------
51 * Timer 1 output compare A interrupt service routine, called every 1/15000 sec
52 *---------------------------------------------------------------------------------------------------------------------------------------------------
53 */
54 #ifdef TIM1_COMPA_vect // ATtiny84
55 ISR(TIM1_COMPA_vect)
56 #else
57 ISR(TIMER1_COMPA_vect)
58 #endif
59 {
60 (void) irmp_ISR(); // call irmp ISR
61 // call other timer interrupt routines...
62 }
63
64
65 int
66 main (void)
67 {
68 IRMP_DATA irmp_data;
69
70 irmp_init(); // initialize irmp
71 timer1_init(); // initialize timer 1
72 sei (); // enable interrupts
73
74 for (;;)
75 {
76 if (irmp_get_data (&irmp_data))
77 {
78 // ir signal decoded, do something here...
79 // irmp_data.protocol is the protocol, see irmp.h
80 // irmp_data.address is the address/manufacturer code of ir sender
81 // irmp_data.command is the command code
82 // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)
83 }
84 }
85 }