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