]>
Commit | Line | Data |
---|---|---|
4225a882 | 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 | |
46dd89b7 | 50 | #include "irsndconfig.h"\r |
4225a882 | 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 | |
a7054daf | 118 | irmp_data.address = 0x00FF;\r |
119 | irmp_data.command = 0x0001;\r | |
120 | irmp_data.flags = 0;\r | |
4225a882 | 121 | \r |
122 | irsnd_send_data (&irmp_data);\r | |
123 | _delay_ms (1000);\r | |
124 | }\r | |
125 | }\r | |
126 | \r | |
127 | #else // gcc\r | |
128 | \r | |
129 | // This is the main routine if you use GCC Compiler\r | |
130 | int\r | |
131 | main (void)\r | |
132 | {\r | |
133 | IRMP_DATA irmp_data;\r | |
134 | \r | |
135 | irsnd_init(); // initialize irsnd\r | |
136 | timer_init(); // initialize timer\r | |
137 | sei (); // enable interrupts\r | |
138 | \r | |
139 | for (;;)\r | |
140 | {\r | |
141 | irmp_data.protocol = IRMP_NEC_PROTOCOL;\r | |
a7054daf | 142 | irmp_data.address = 0x00FF;\r |
143 | irmp_data.command = 0x0001;\r | |
144 | irmp_data.flags = 0;\r | |
4225a882 | 145 | \r |
879b06c2 | 146 | irsnd_send_data (&irmp_data, TRUE);\r |
4225a882 | 147 | _delay_ms (1000);\r |
148 | }\r | |
149 | }\r | |
150 | \r | |
151 | #endif // CODEVISION / gcc\r |