]> cloudbase.mooo.com Git - irmp.git/blob - main.c
Version 2.0.3:
[irmp.git] / main.c
1 /*---------------------------------------------------------------------------------------------------------------------------------------------------
2 * main.c - demo main module to test irmp decoder
3 *
4 * Copyright (c) 2009-2011 Frank Meyer - frank(at)fli4l.de
5 *
6 * $Id: main.c,v 1.12 2012/02/13 10:59:07 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 <inttypes.h>
20 #include <avr/io.h>
21 #include <util/delay.h>
22 #include <avr/pgmspace.h>
23 #include <avr/interrupt.h>
24
25 #include "irmpconfig.h"
26 #include "irmp.h"
27
28 #ifndef F_CPU
29 #error F_CPU unkown
30 #endif
31
32 void
33 timer1_init (void)
34 {
35 #if defined (__AVR_ATtiny45__) || defined (__AVR_ATtiny85__) // ATtiny45 / ATtiny85:
36
37 #if F_CPU >= 16000000L
38 OCR1C = (F_CPU / F_INTERRUPTS / 8) - 1; // compare value: 1/15000 of CPU frequency, presc = 8
39 TCCR1 = (1 << CTC1) | (1 << CS12); // switch CTC Mode on, set prescaler to 8
40 #else
41 OCR1C = (F_CPU / F_INTERRUPTS / 4) - 1; // compare value: 1/15000 of CPU frequency, presc = 4
42 TCCR1 = (1 << CTC1) | (1 << CS11) | (1 << CS10); // switch CTC Mode on, set prescaler to 4
43 #endif
44
45 #else // ATmegaXX:
46 OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/15000 of CPU frequency
47 TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1
48 #endif
49
50 #ifdef TIMSK1
51 TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
52 #else
53 TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare
54 #endif
55 }
56
57 /*---------------------------------------------------------------------------------------------------------------------------------------------------
58 * Timer 1 output compare A interrupt service routine, called every 1/15000 sec
59 *---------------------------------------------------------------------------------------------------------------------------------------------------
60 */
61 #ifdef TIM1_COMPA_vect // ATtiny84
62 ISR(TIM1_COMPA_vect)
63 #else
64 ISR(TIMER1_COMPA_vect)
65 #endif
66 {
67 (void) irmp_ISR(); // call irmp ISR
68 // call other timer interrupt routines...
69 }
70
71
72 int
73 main (void)
74 {
75 IRMP_DATA irmp_data;
76
77 irmp_init(); // initialize irmp
78 timer1_init(); // initialize timer 1
79 sei (); // enable interrupts
80
81 for (;;)
82 {
83 if (irmp_get_data (&irmp_data))
84 {
85 // ir signal decoded, do something here...
86 // irmp_data.protocol is the protocol, see irmp.h
87 // irmp_data.address is the address/manufacturer code of ir sender
88 // irmp_data.command is the command code
89 // irmp_protocol_names[irmp_data.protocol] is the protocol name (if enabled, see irmpconfig.h)
90 }
91 }
92 }