]>
Commit | Line | Data |
---|---|---|
1 | /*---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
2 | * irsndmain.c - demo main module to test irmp decoder\r | |
3 | *\r | |
4 | * Copyright (c) 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 "isnd.h"\r | |
39 | #include "irmp.c"\r | |
40 | #include "isnd.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 | |
50 | #include "irsndconfig.h"\r | |
51 | #include "irsnd.h"\r | |
52 | \r | |
53 | #endif // CODEVISION\r | |
54 | \r | |
55 | #ifndef F_CPU\r | |
56 | #error F_CPU unkown\r | |
57 | #endif\r | |
58 | \r | |
59 | void\r | |
60 | timer_init (void)\r | |
61 | {\r | |
62 | #ifdef CODEVISION\r | |
63 | OCR1AH = ((F_CPU / F_INTERRUPTS) >> 8) & 0xFF; // compare value: 1/10000 of CPU frequency (upper byte)\r | |
64 | OCR1AL = ((F_CPU / F_INTERRUPTS) - 1) & 0xFF; // compare value: 1/10000 of CPU frequency (lower byte)\r | |
65 | #else // gcc\r | |
66 | OCR1A = (F_CPU / F_INTERRUPTS) - 1; // compare value: 1/10000 of CPU frequency\r | |
67 | #endif // CODEVISION\r | |
68 | TCCR1B = (1 << WGM12) | (1 << CS10); // switch CTC Mode on, set prescaler to 1\r | |
69 | \r | |
70 | #if defined (__AVR_ATmega8__) || defined (__AVR_ATmega16__) || defined (__AVR_ATmega32__) || defined (__AVR_ATmega64__) || defined (__AVR_ATmega162__)\r | |
71 | TIMSK = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare (use TIMSK for ATMEGA162)\r | |
72 | #else\r | |
73 | TIMSK1 = 1 << OCIE1A; // OCIE1A: Interrupt by timer compare (use TIMSK for ATMEGA162)\r | |
74 | #endif // __AVR...\r | |
75 | }\r | |
76 | \r | |
77 | /*---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
78 | * timer 1 compare handler, called every 1/10000 sec\r | |
79 | *---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
80 | */\r | |
81 | // Timer 1 output compare A interrupt service routine\r | |
82 | #ifdef CODEVISION\r | |
83 | interrupt [TIM1_COMPA] void timer1_compa_isr(void)\r | |
84 | #else // CODEVISION\r | |
85 | ISR(TIMER1_COMPA_vect)\r | |
86 | #endif // CODEVISION\r | |
87 | {\r | |
88 | (void) irsnd_ISR(); // call irsnd ISR\r | |
89 | // call other timer interrupt routines...\r | |
90 | }\r | |
91 | \r | |
92 | /*---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
93 | * MAIN: main routine\r | |
94 | *---------------------------------------------------------------------------------------------------------------------------------------------------\r | |
95 | */\r | |
96 | #ifdef CODEVISION\r | |
97 | // This is the main routine if you use Codevision C Compiler\r | |
98 | void\r | |
99 | main (void)\r | |
100 | {\r | |
101 | IRMP_DATA irmp_data;\r | |
102 | \r | |
103 | #pragma optsize-\r | |
104 | // crystal oscillator division factor: 1\r | |
105 | CLKPR=0x80;\r | |
106 | CLKPR=0x00;\r | |
107 | #ifdef _OPTIMIZE_SIZE_\r | |
108 | #pragma optsize+\r | |
109 | #endif\r | |
110 | \r | |
111 | irsnd_init(); // initialize irsnd\r | |
112 | timer_init(); // initialize timer\r | |
113 | #asm("sei"); // enable interrupts\r | |
114 | \r | |
115 | for (;;)\r | |
116 | {\r | |
117 | irmp_data.protocol = IRMP_NEC_PROTOCOL;\r | |
118 | irmp_data.address = 0x00FF;\r | |
119 | irmp_data.command = 0x0001;\r | |
120 | \r | |
121 | irsnd_send_data (&irmp_data);\r | |
122 | _delay_ms (1000);\r | |
123 | }\r | |
124 | }\r | |
125 | \r | |
126 | #else // gcc\r | |
127 | \r | |
128 | // This is the main routine if you use GCC Compiler\r | |
129 | int\r | |
130 | main (void)\r | |
131 | {\r | |
132 | IRMP_DATA irmp_data;\r | |
133 | \r | |
134 | irsnd_init(); // initialize irsnd\r | |
135 | timer_init(); // initialize timer\r | |
136 | sei (); // enable interrupts\r | |
137 | \r | |
138 | for (;;)\r | |
139 | {\r | |
140 | irmp_data.protocol = IRMP_NEC_PROTOCOL;\r | |
141 | irmp_data.address = 0x00FF;\r | |
142 | irmp_data.command = 0x0001;\r | |
143 | \r | |
144 | irsnd_send_data (&irmp_data);\r | |
145 | _delay_ms (1000);\r | |
146 | }\r | |
147 | }\r | |
148 | \r | |
149 | #endif // CODEVISION / gcc\r |