]> cloudbase.mooo.com Git - irmp.git/blame - main.c
version 1.9.3: added thomson protocol
[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
f50e01e7 6 * $Id: main.c,v 1.9 2011/04/11 12:54:25 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
19/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
20 * uncomment this for codevision compiler:\r
21 *---------------------------------------------------------------------------------------------------------------------------------------------------\r
22 */\r
23// #define CODEVISION // to use Codevision Compiler instead of gcc\r
24 \r
25#ifdef CODEVISION \r
26#include <mega88.h>\r
27#include <stdio.h>\r
28#define uint8_t unsigned char\r
29#define uint16_t unsigned int\r
30#define F_CPU 8000000 // change for Codevision here, if you use WinAVR, use Project -> Configuration Options instead\r
31\r
32// register values from datasheet for ATMega88\r
33#define OCIE1A 1\r
34#define WGM12 3\r
35#define CS10 0\r
36#define UDRE0 5\r
37#define TXEN0 3\r
38\r
39#include "irmp.h"\r
40#include "irmp.c"\r
41\r
42#else // gcc compiler\r
43\r
44#include <inttypes.h>\r
45#include <avr/io.h>\r
46#include <util/delay.h>\r
47#include <avr/pgmspace.h>\r
48#include <avr/interrupt.h>\r
49#include "irmp.h"\r
cb8474cc 50#include "irmpconfig.h"\r
51\r
4225a882 52\r
53#endif // CODEVISION\r
54\r
55\r
56#ifndef F_CPU\r
57#error F_CPU unkown\r
58#endif\r
59\r
60void\r
61timer_init (void)\r
62{\r
63#ifdef CODEVISION\r
64 OCR1AH = ((F_CPU / F_INTERRUPTS) >> 8) & 0xFF; // compare value: 1/10000 of CPU frequency (upper byte)\r
65 OCR1AL = ((F_CPU / F_INTERRUPTS) - 1) & 0xFF; // compare value: 1/10000 of CPU frequency (lower byte)\r
66#else // gcc\r
67 OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/10000 of CPU frequency\r
68#endif // CODEVISION\r
69 TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1\r
70\r
71#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega64__) || defined (__AVR_ATmega162__) \r
72 TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare\r
73#else\r
74 TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare\r
6f750020 75#endif // __AVR...\r
4225a882 76}\r
77\r
78/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
79 * timer 1 compare handler, called every 1/10000 sec\r
80 *---------------------------------------------------------------------------------------------------------------------------------------------------\r
81 */\r
82// Timer 1 output compare A interrupt service routine\r
83#ifdef CODEVISION\r
84interrupt [TIM1_COMPA] void timer1_compa_isr(void)\r
85#else // CODEVISION\r
86ISR(TIMER1_COMPA_vect)\r
87#endif // CODEVISION\r
88{\r
879b06c2 89 (void) irmp_ISR(); // call irmp ISR\r
4225a882 90 // call other timer interrupt routines...\r
91}\r
92\r
93/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
94 * MAIN: main routine\r
95 *---------------------------------------------------------------------------------------------------------------------------------------------------\r
96 */\r
97#ifdef CODEVISION\r
98// This is the main routine if you use Codevision C Compiler\r
99void\r
100main (void)\r
101{\r
102 IRMP_DATA irmp_data;\r
103\r
104 #pragma optsize-\r
105 // crystal oscillator division factor: 1\r
106 CLKPR=0x80;\r
107 CLKPR=0x00;\r
108 #ifdef _OPTIMIZE_SIZE_\r
109 #pragma optsize+\r
110 #endif\r
c7a47e89 111 static uint8_t *Proto[]={"SIRCS","NEC","SAMSUNG","MATSUSH","KASEIKYO","RECS80","RC5(x)","DENON","RC6","SAMSG32","APPLE","RECS80X","NUBERT","B&O","GRUNDIG","NOKIA","SIEMENS","FDC","RCCAR","JVC","RC6A"};\r
4225a882 112\r
113 #if IRMP_LOGGING == 0\r
114 // USART initialization has to be done here if Logging is off\r
115 // Communication Parameters: 8 Data, 1 Stop, No Parity\r
116 // USART Receiver: Off\r
117 // USART Transmitter: On\r
118 // USART0 Mode: Asynchronous\r
119 // USART Baud Rate: 9600\r
120 #define BAUDRATE 9600L\r
121 UCSR0A=0x00;\r
122 UCSR0B=0x08;\r
123 UCSR0C=0x06;\r
124 UBRR0H = ((F_CPU+BAUDRATE*8)/(BAUDRATE*16)-1) >> 8; // store baudrate (upper byte)\r
125 UBRR0L = ((F_CPU+BAUDRATE*8)/(BAUDRATE*16)-1) & 0xFF; \r
126 #endif\r
127\r
128 irmp_init(); // initialize rc5\r
129\r
130 printf("IRMP V1.0\n");\r
131 #if IRMP_LOGGING == 1\r
132 printf("Logging Mode\n");\r
133 #endif\r
134\r
135 timer_init(); // initialize timer\r
136 #asm("sei"); // enable interrupts\r
137\r
138 for (;;)\r
139 {\r
140 if (irmp_get_data (&irmp_data))\r
141 {\r
142 // ir signal decoded, do something here...\r
143 // irmp_data.protocol is the protocol, see irmp.h\r
144 // irmp_data.address is the address/manufacturer code of ir sender\r
145 // irmp_data.command is the command code\r
146 #if IRMP_LOGGING != 1\r
c7a47e89 147 printf("Code: %s\n",Proto[irmp_data.protocol-1]);\r
4225a882 148 printf("Address: 0x%.2X\n",irmp_data.address);\r
149 printf("Command: 0x%.2X\n\n",irmp_data.command);\r
150 #endif\r
151 }\r
152 }\r
153}\r
154\r
155#else // gcc\r
156\r
157// This is the main routine if you use GCC Compiler\r
158int\r
159main (void)\r
160{\r
161 IRMP_DATA irmp_data;\r
162\r
163 irmp_init(); // initialize rc5\r
164 timer_init(); // initialize timer\r
165 sei (); // enable interrupts\r
166\r
167 for (;;)\r
168 {\r
169 if (irmp_get_data (&irmp_data))\r
170 {\r
171 // ir signal decoded, do something here...\r
172 // irmp_data.protocol is the protocol, see irmp.h\r
173 // irmp_data.address is the address/manufacturer code of ir sender\r
174 // irmp_data.command is the command code\r
175 }\r
176 }\r
177}\r
178\r
179#endif // CODEVISION / gcc\r