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