]> cloudbase.mooo.com Git - irmp.git/blame - main.c
removed CVS folder from SVN
[irmp.git] / main.c
CommitLineData
4225a882 1/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
2 * main.c - demo main module to test irmp decoder\r
3 *\r
4 * Copyright (c) 2009-2010 Frank Meyer - frank(at)fli4l.de\r
5 *\r
6 * ATMEGA88 @ 8 MHz\r
7 *\r
8 * Fuses: lfuse: 0xE2 hfuse: 0xDC efuse: 0xF9\r
9 *\r
10 * This program is free software; you can redistribute it and/or modify\r
11 * it under the terms of the GNU General Public License as published by\r
12 * the Free Software Foundation; either version 2 of the License, or\r
13 * (at your option) any later version.\r
14 *---------------------------------------------------------------------------------------------------------------------------------------------------\r
15 */\r
16\r
17/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
18 * uncomment this for codevision compiler:\r
19 *---------------------------------------------------------------------------------------------------------------------------------------------------\r
20 */\r
21// #define CODEVISION // to use Codevision Compiler instead of gcc\r
22 \r
23#ifdef CODEVISION \r
24#include <mega88.h>\r
25#include <stdio.h>\r
26#define uint8_t unsigned char\r
27#define uint16_t unsigned int\r
28#define F_CPU 8000000 // change for Codevision here, if you use WinAVR, use Project -> Configuration Options instead\r
29\r
30// register values from datasheet for ATMega88\r
31#define OCIE1A 1\r
32#define WGM12 3\r
33#define CS10 0\r
34#define UDRE0 5\r
35#define TXEN0 3\r
36\r
37#include "irmp.h"\r
38#include "irmp.c"\r
39\r
40#else // gcc compiler\r
41\r
42#include <inttypes.h>\r
43#include <avr/io.h>\r
44#include <util/delay.h>\r
45#include <avr/pgmspace.h>\r
46#include <avr/interrupt.h>\r
47#include "irmp.h"\r
48\r
49#endif // CODEVISION\r
50\r
51\r
52#ifndef F_CPU\r
53#error F_CPU unkown\r
54#endif\r
55\r
56void\r
57timer_init (void)\r
58{\r
59#ifdef CODEVISION\r
60 OCR1AH = ((F_CPU / F_INTERRUPTS) >> 8) & 0xFF; // compare value: 1/10000 of CPU frequency (upper byte)\r
61 OCR1AL = ((F_CPU / F_INTERRUPTS) - 1) & 0xFF; // compare value: 1/10000 of CPU frequency (lower byte)\r
62#else // gcc\r
63 OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/10000 of CPU frequency\r
64#endif // CODEVISION\r
65 TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1\r
66\r
67#if defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega64__) || defined (__AVR_ATmega162__) \r
68 TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare\r
69#else\r
70 TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare\r
71#endif // __AVR...\r
72}\r
73\r
74/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
75 * timer 1 compare handler, called every 1/10000 sec\r
76 *---------------------------------------------------------------------------------------------------------------------------------------------------\r
77 */\r
78// Timer 1 output compare A interrupt service routine\r
79#ifdef CODEVISION\r
80interrupt [TIM1_COMPA] void timer1_compa_isr(void)\r
81#else // CODEVISION\r
82ISR(TIMER1_COMPA_vect)\r
83#endif // CODEVISION\r
84{\r
85 irmp_ISR(); // call irmp ISR\r
86 // call other timer interrupt routines...\r
87}\r
88\r
89/*---------------------------------------------------------------------------------------------------------------------------------------------------\r
90 * MAIN: main routine\r
91 *---------------------------------------------------------------------------------------------------------------------------------------------------\r
92 */\r
93#ifdef CODEVISION\r
94// This is the main routine if you use Codevision C Compiler\r
95void\r
96main (void)\r
97{\r
98 IRMP_DATA irmp_data;\r
99\r
100 #pragma optsize-\r
101 // crystal oscillator division factor: 1\r
102 CLKPR=0x80;\r
103 CLKPR=0x00;\r
104 #ifdef _OPTIMIZE_SIZE_\r
105 #pragma optsize+\r
106 #endif\r
107 static uint8_t *Proto[]={"SIRCS","NEC","SAMSUNG","MATSUSH","KASEIKYO","RECS80","RC5(x)","DENON","RC6","SAMSG32","APPLE"};\r
108 #define IRMP_APPLE_ADDRESS 0x77E1 \r
109\r
110\r
111 #if IRMP_LOGGING == 0\r
112 // USART initialization has to be done here if Logging is off\r
113 // Communication Parameters: 8 Data, 1 Stop, No Parity\r
114 // USART Receiver: Off\r
115 // USART Transmitter: On\r
116 // USART0 Mode: Asynchronous\r
117 // USART Baud Rate: 9600\r
118 #define BAUDRATE 9600L\r
119 UCSR0A=0x00;\r
120 UCSR0B=0x08;\r
121 UCSR0C=0x06;\r
122 UBRR0H = ((F_CPU+BAUDRATE*8)/(BAUDRATE*16)-1) >> 8; // store baudrate (upper byte)\r
123 UBRR0L = ((F_CPU+BAUDRATE*8)/(BAUDRATE*16)-1) & 0xFF; \r
124 #endif\r
125\r
126 irmp_init(); // initialize rc5\r
127\r
128 printf("IRMP V1.0\n");\r
129 #if IRMP_LOGGING == 1\r
130 printf("Logging Mode\n");\r
131 #endif\r
132\r
133 timer_init(); // initialize timer\r
134 #asm("sei"); // enable interrupts\r
135\r
136 for (;;)\r
137 {\r
138 if (irmp_get_data (&irmp_data))\r
139 {\r
140 // ir signal decoded, do something here...\r
141 // irmp_data.protocol is the protocol, see irmp.h\r
142 // irmp_data.address is the address/manufacturer code of ir sender\r
143 // irmp_data.command is the command code\r
144 #if IRMP_LOGGING != 1\r
145 if((irmp_data.protocol == IRMP_NEC_PROTOCOL) && (irmp_data.address == IRMP_APPLE_ADDRESS))\r
146 printf("Code: Apple\n");\r
147 else printf("Code: %s\n",Proto[irmp_data.protocol-1]);\r
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