]>
Commit | Line | Data |
---|---|---|
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 | |
cb8474cc | 6 | * $Id: main.c,v 1.5 2010/03/29 09:33:29 fm Exp $\r |
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 | |
60 | void\r | |
61 | timer_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 | |
75 | #endif // __AVR...\r | |
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 | |
84 | interrupt [TIM1_COMPA] void timer1_compa_isr(void)\r | |
85 | #else // CODEVISION\r | |
86 | ISR(TIMER1_COMPA_vect)\r | |
87 | #endif // CODEVISION\r | |
88 | {\r | |
89 | irmp_ISR(); // call irmp ISR\r | |
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 | |
99 | void\r | |
100 | main (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 | |
111 | static uint8_t *Proto[]={"SIRCS","NEC","SAMSUNG","MATSUSH","KASEIKYO","RECS80","RC5(x)","DENON","RC6","SAMSG32","APPLE"};\r | |
112 | #define IRMP_APPLE_ADDRESS 0x77E1 \r | |
113 | \r | |
114 | \r | |
115 | #if IRMP_LOGGING == 0\r | |
116 | // USART initialization has to be done here if Logging is off\r | |
117 | // Communication Parameters: 8 Data, 1 Stop, No Parity\r | |
118 | // USART Receiver: Off\r | |
119 | // USART Transmitter: On\r | |
120 | // USART0 Mode: Asynchronous\r | |
121 | // USART Baud Rate: 9600\r | |
122 | #define BAUDRATE 9600L\r | |
123 | UCSR0A=0x00;\r | |
124 | UCSR0B=0x08;\r | |
125 | UCSR0C=0x06;\r | |
126 | UBRR0H = ((F_CPU+BAUDRATE*8)/(BAUDRATE*16)-1) >> 8; // store baudrate (upper byte)\r | |
127 | UBRR0L = ((F_CPU+BAUDRATE*8)/(BAUDRATE*16)-1) & 0xFF; \r | |
128 | #endif\r | |
129 | \r | |
130 | irmp_init(); // initialize rc5\r | |
131 | \r | |
132 | printf("IRMP V1.0\n");\r | |
133 | #if IRMP_LOGGING == 1\r | |
134 | printf("Logging Mode\n");\r | |
135 | #endif\r | |
136 | \r | |
137 | timer_init(); // initialize timer\r | |
138 | #asm("sei"); // enable interrupts\r | |
139 | \r | |
140 | for (;;)\r | |
141 | {\r | |
142 | if (irmp_get_data (&irmp_data))\r | |
143 | {\r | |
144 | // ir signal decoded, do something here...\r | |
145 | // irmp_data.protocol is the protocol, see irmp.h\r | |
146 | // irmp_data.address is the address/manufacturer code of ir sender\r | |
147 | // irmp_data.command is the command code\r | |
148 | #if IRMP_LOGGING != 1\r | |
149 | if((irmp_data.protocol == IRMP_NEC_PROTOCOL) && (irmp_data.address == IRMP_APPLE_ADDRESS))\r | |
150 | printf("Code: Apple\n");\r | |
151 | else printf("Code: %s\n",Proto[irmp_data.protocol-1]);\r | |
152 | printf("Address: 0x%.2X\n",irmp_data.address);\r | |
153 | printf("Command: 0x%.2X\n\n",irmp_data.command);\r | |
154 | #endif\r | |
155 | }\r | |
156 | }\r | |
157 | }\r | |
158 | \r | |
159 | #else // gcc\r | |
160 | \r | |
161 | // This is the main routine if you use GCC Compiler\r | |
162 | int\r | |
163 | main (void)\r | |
164 | {\r | |
165 | IRMP_DATA irmp_data;\r | |
166 | \r | |
167 | irmp_init(); // initialize rc5\r | |
168 | timer_init(); // initialize timer\r | |
169 | sei (); // enable interrupts\r | |
170 | \r | |
171 | for (;;)\r | |
172 | {\r | |
173 | if (irmp_get_data (&irmp_data))\r | |
174 | {\r | |
175 | // ir signal decoded, do something here...\r | |
176 | // irmp_data.protocol is the protocol, see irmp.h\r | |
177 | // irmp_data.address is the address/manufacturer code of ir sender\r | |
178 | // irmp_data.command is the command code\r | |
179 | }\r | |
180 | }\r | |
181 | }\r | |
182 | \r | |
183 | #endif // CODEVISION / gcc\r |