]> cloudbase.mooo.com Git - irmp.git/blob - main.c
28bbe145d6c8f789fed1e35f7096abf9bef3a989
[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.11 2011/09/20 10:45:28 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 OCR1C = (F_CPU / F_INTERRUPTS / 4) - 1; // compare value: 1/15000 of CPU frequency, presc = 4
37 TCCR1 = (1 << CTC1) | (1 << CS11) | (1 << CS10); // switch CTC Mode on, set prescaler to 4
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 }