Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
96 | gunterl | 1 | /***************************************************************************** |
2 | Project : Video Overlay for RC Planes |
||
3 | Date : 1/14/2007 |
||
4 | Author : Gunter Logemann (C) ALL RIGHTS RESERVED |
||
5 | |||
6 | Comments: |
||
7 | This project is optimized to work with the Mikrocopter (www.mikrokopter.de) |
||
8 | Many Thanks to Gary Dion who created the first basic implementation |
||
9 | Data communication decoder and encoder functions are taken from the |
||
10 | mikrokopter (www.mikrokopter.de) project. |
||
11 | |||
12 | Redistributions of this source code (with or without modifications) or parts |
||
13 | of this sourcode must retain the above copyright notice, this list of |
||
14 | conditions and the following disclaimer. |
||
15 | * Neither the name of the copyright holders nor the names of contributors may |
||
16 | be used to endorse or promote products derived from this software without |
||
17 | specific prior written permission. |
||
18 | * The use of this source code permittet for non-commercial use (directly |
||
19 | or indirectly) only. |
||
20 | * Commercial use Is only permitted with our written permission by |
||
21 | Gunter Logemann (gunter@pccon.de) |
||
22 | |||
23 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
24 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
25 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
26 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
27 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
28 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
29 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
30 | INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
31 | CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
33 | POSSIBILITY OF SUCH DAMAGE. |
||
34 | |||
35 | Chip type : ATmega88 |
||
36 | Program type : Application |
||
37 | Clock frequency : 20,000000 MHz |
||
38 | *****************************************************************************/ |
||
39 | |||
40 | #include <avr/interrupt.h> |
||
41 | #include <avr/sleep.h> |
||
42 | #include <avr/io.h> |
||
43 | #include "Main.h" |
||
44 | |||
45 | #define CPUSPEED_20 |
||
46 | //#define CPUSPEED_16 |
||
47 | //#define CPUSPEED_11059 |
||
48 | |||
49 | // Macros |
||
50 | #define WatchdogReset() asm("wdr") |
||
51 | #define Wait() while(!(SPSR & (1<<SPIF))) |
||
52 | |||
53 | // Define CPU speed dependant constants: |
||
54 | #ifdef CPUSPEED_20 |
||
55 | #define LINESTART 200 |
||
56 | #define COPYRIGHTSTART 0 |
||
57 | #define HEADINGSTART 200 |
||
58 | #endif |
||
59 | |||
60 | #ifdef CPUSPEED_16 |
||
61 | #define LINESTART 150 |
||
62 | #define COPYRIGHTSTART 0 |
||
63 | #define HEADINGSTART 200 |
||
64 | #endif |
||
65 | |||
66 | #ifdef CPUSPEED_11059 |
||
67 | #define LINESTART 130 |
||
68 | #define COPYRIGHTSTART 0 |
||
69 | #endif |
||
70 | |||
71 | // Static functions and variables |
||
72 | unsigned int line; // current line to be drawed |
||
73 | unsigned char lowbat = 0; |
||
74 | unsigned char showmessage1 = 0; |
||
75 | unsigned char framecounter = 0; |
||
76 | unsigned char showgraphic = 1; |
||
77 | unsigned char showgraphicb = 1; |
||
78 | |||
79 | static unsigned char head[17] = {'C','@','G','U','N','T','E','R','@','L','O','G','E','M','A','N','N'}; |
||
80 | static unsigned char Message_LowBat[15] = {'@','@','L','O','W','@','B','A','T','T','E','R','Y','@','@'}; |
||
81 | unsigned char rxtx[ 9] = {'T','X','D',0x01,'@','R','X','D',0x01}; |
||
82 | unsigned char heading[5] = { 0x02, '0', '0', '0',0x03}; |
||
83 | unsigned char bat[8] = { 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08}; |
||
84 | unsigned char ubat[8] = { 'U', ':', '@', '0', '0', '.', '0', 'V'}; |
||
85 | unsigned char rx[8] = { 0x08,0x08,0x08,0x08,0x08,0x08,0x08,0x08}; |
||
86 | unsigned char urx[8] = { 'R', 'X', ':', '@', '1', '0', '0', '/'}; |
||
87 | unsigned char altv[6] = { '+','0', '0', '0', '0', '0'}; |
||
88 | unsigned char bar0 = 0x00; |
||
89 | unsigned char bar1 = 0xfe; |
||
90 | |||
91 | int old_alt; |
||
92 | unsigned int alt_delta = 0; |
||
93 | char alt_inc = 0; |
||
94 | char alt_dec = 0; |
||
95 | |||
96 | // define Graphic Area (56x40 pixel) |
||
97 | #define GR_MaxGraph 280 |
||
98 | #define GR_BytePerLine 7 |
||
99 | #define GR_Lines 40 |
||
100 | |||
101 | unsigned char dmem[280] = { 0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
||
102 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
||
103 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
||
104 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00, |
||
105 | |||
106 | 0x00,0x55,0x00,0xff,0x00,0xff,0x00, |
||
107 | 0x00,0xff,0x00,0xff,0x00,0xff,0x00, |
||
108 | 0x00,0xff,0x00,0xff,0x00,0xff,0x00, |
||
109 | 0x00,0xff,0x00,0xff,0x00,0xff,0x00, |
||
110 | |||
111 | 0x00,0xff,0x00,0xff,0x00,0xff,0x00, |
||
112 | 0x00,0xff,0x00,0xff,0x00,0xff,0x00, |
||
113 | 0x00,0xff,0x00,0xff,0x00,0xff,0x00, |
||
114 | 0x00,0xff,0x00,0xff,0x00,0xff,0x00, |
||
115 | |||
116 | 0x00,0xff,0x00,0xff,0x00,0xff,0x00, |
||
117 | 0x00,0xff,0x00,0xff,0x00,0xff,0x00, |
||
118 | 0x00,0xff,0x00,0xff,0x00,0xff,0x00, |
||
119 | 0x00,0xff,0x00,0xff,0x00,0xff,0x00, |
||
120 | |||
121 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
122 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
123 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
124 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
125 | |||
126 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
127 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
128 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
129 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
130 | |||
131 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
132 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
133 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
134 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
135 | |||
136 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
137 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
138 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
139 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
140 | |||
141 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
142 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
143 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
144 | 0xff,0x00,0xff,0x00,0xff,0x00,0xff, |
||
145 | |||
146 | 0xff,0x00,0xff,0x00,0xff,0x00,0x55, |
||
147 | 0xff,0x00,0xff,0x00,0xff,0x00,0xAA, |
||
148 | 0xff,0x00,0xff,0x00,0xff,0x00,0x55, |
||
149 | 0xff,0x00,0xff,0x00,0xff,0x00,0xAA, |
||
150 | }; |
||
151 | |||
152 | // ' ' A B C D E F G H I J K L M N O P Q R S T U V W X Y Z |
||
153 | |||
154 | static unsigned char ltrs[189] = { 0, 24,124, 60,120,126,126, 60, 66,124,126, 66, 64,130,130, 60,124, 60,124, 60,124, 66, 66,130,130,130,254, |
||
155 | 0, 36, 66, 66, 68, 64, 64, 66, 66, 16, 8, 68, 64,198,194, 66, 66, 66, 66, 66, 16, 66, 66,130, 68, 68, 4, |
||
156 | 0, 66, 66, 64, 66, 64, 64, 64, 66, 16, 8, 72, 64,170,162, 66, 66, 66, 66, 64, 16, 66, 66,146, 40, 40, 8, |
||
157 | 0, 66,124, 64, 66,124,124, 78,126, 16, 8,112, 64,146,146, 66,124, 66,124, 60, 16, 66, 36,146, 16, 16, 16, |
||
158 | 0,126, 66, 64, 66, 64, 64, 66, 66, 16, 8, 72, 64,130,138, 66, 64, 76, 72, 2, 16, 66, 36,146, 40, 16, 32, |
||
159 | 0, 66, 66, 66, 68, 64, 64, 66, 66, 16, 72, 68,126,130,134, 66, 64, 70, 68, 66, 16, 66, 36,108, 68, 16, 64, |
||
160 | 0, 66,124, 60,120,126, 64, 60, 66,124, 48, 66,126,130,130, 60, 64, 50, 66, 60, 16, 60, 24,108,130, 16,254}; |
||
161 | |||
162 | // + , - . / 0 1 2 3 4 5 6 7 8 9 : |
||
163 | static unsigned char nums[112] = { 0, 0, 0, 0, 48,124, 16,124,124, 28,254,124,254,124,124, 0, |
||
164 | 16, 0, 0, 0, 68,130, 48,130,130, 36,128,128, 2,130,130, 16, |
||
165 | 16, 0, 0, 0, 68,130, 16, 2, 2, 68,128,128, 4,130,130, 0, |
||
166 | 124, 0,124, 0, 48,130, 16, 12, 28,132,124,252, 8,124,126, 0, |
||
167 | 16, 24, 0, 0, 0,130, 16, 48, 2,254, 2,130, 16,130, 4, 0, |
||
168 | 16, 24, 0, 24, 0,130, 16, 64,130, 4,130,130, 16,130, 8, 16, |
||
169 | 0, 0, 0, 24, 0,124, 56,254,124, 4,124,124, 16,124, 48, 0}; |
||
170 | |||
171 | |||
172 | static unsigned char infos[63] = { 0xfe,0xfe,0x18,0x30,0x00,0x80,0xa0,0xa8,0xaa, |
||
173 | 0xfe,0x82,0x38,0x38,0x00,0x80,0xa0,0xa8,0xaa, |
||
174 | 0xfe,0x82,0x78,0x3c,0x00,0x80,0xa0,0xa8,0xaa, |
||
175 | 0xfe,0x82,0xfe,0xfe,0x00,0x80,0xa0,0xa8,0xaa, |
||
176 | 0xfe,0x82,0x7e,0x3c,0x00,0x80,0xa0,0xa8,0xaa, |
||
177 | 0xfe,0x82,0x38,0x38,0x00,0x80,0xa0,0xa8,0xaa, |
||
178 | 0xfe,0xfe,0x18,0x30,0x00,0x80,0xa0,0xa8,0xaa}; |
||
179 | |||
180 | |||
181 | |||
182 | unsigned char display_line1[10]; |
||
183 | unsigned char templine[5]; |
||
184 | |||
185 | unsigned char mode = 0; |
||
186 | |||
187 | #define MAX_RX_BUF 100 |
||
188 | unsigned volatile char SioTmp = 0; |
||
189 | unsigned volatile char RxdBuffer[MAX_RX_BUF]; |
||
190 | unsigned volatile char NeuerDatensatzEmpfangen = 0; |
||
191 | unsigned volatile char CntCrcError = 0; |
||
192 | unsigned volatile char AnzahlEmpfangsBytes = 0; |
||
193 | |||
194 | struct str_DebugOut DebugOut; |
||
195 | |||
196 | |||
197 | static unsigned char grlevel[21] = { 0x00,0x00,0x00,0x18,0x00,0x00,0x00, |
||
198 | 0xff,0xff,0xff,0x24,0xff,0xff,0xff, |
||
199 | 0x00,0x00,0x00,0x18,0x00,0x00,0x00}; |
||
200 | static unsigned char grlevel0[7] = { 0xAA,0xAA,0xAA,0xFF,0x55,0x55,0x55}; |
||
201 | |||
202 | |||
203 | //----------------------------------------------------------------------------- |
||
204 | // copy bitmap |
||
205 | //----------------------------------------------------------------------------- |
||
206 | extern void GR_Copy(unsigned char* source,int start,int max) |
||
207 | { |
||
208 | int i; |
||
209 | for(i=0;i<max;i++) |
||
210 | { |
||
211 | dmem[start+i]=*source; |
||
212 | source++; |
||
213 | } |
||
214 | } |
||
215 | |||
216 | //----------------------------------------------------------------------------- |
||
217 | // Clear Graphic Area |
||
218 | //----------------------------------------------------------------------------- |
||
219 | extern void GR_Clear() |
||
220 | { |
||
221 | int i; |
||
222 | for(i=0;i<GR_MaxGraph;i++) |
||
223 | { |
||
224 | dmem[i]=0; |
||
225 | } |
||
226 | } |
||
227 | |||
228 | //----------------------------------------------------------------------------- |
||
229 | // Show and Hide Graphic area and Background |
||
230 | //----------------------------------------------------------------------------- |
||
231 | #define SHOWGRAPHIC showgraphic=1 |
||
232 | #define HIDEGRAPHIC showgraphic=0 |
||
233 | #define SHOWGRAPHICBACK showgraphicb=1 |
||
234 | #define HIDEGRAPHICBACK showgraphicb=0 |
||
235 | |||
236 | |||
237 | //----------------------------------------------------------------------------- |
||
238 | // Decode64 |
||
239 | //----------------------------------------------------------------------------- |
||
240 | extern void Decode64(unsigned char *ptrOut, unsigned char len, unsigned char ptrIn,unsigned char max) |
||
241 | { |
||
242 | unsigned char a,b,c,d; |
||
243 | unsigned char ptr = 0; |
||
244 | unsigned char x,y,z; |
||
245 | while(len) |
||
246 | { |
||
247 | a = RxdBuffer[ptrIn++] - '='; |
||
248 | b = RxdBuffer[ptrIn++] - '='; |
||
249 | c = RxdBuffer[ptrIn++] - '='; |
||
250 | d = RxdBuffer[ptrIn++] - '='; |
||
251 | if(ptrIn > max - 2) break; |
||
252 | |||
253 | x = (a << 2) | (b >> 4); |
||
254 | y = ((b & 0x0f) << 4) | (c >> 2); |
||
255 | z = ((c & 0x03) << 6) | d; |
||
256 | |||
257 | if(len--) ptrOut[ptr++] = x; else break; |
||
258 | if(len--) ptrOut[ptr++] = y; else break; |
||
259 | if(len--) ptrOut[ptr++] = z; else break; |
||
260 | } |
||
261 | } |
||
262 | |||
263 | //----------------------------------------------------------------------------- |
||
264 | // process RX Data |
||
265 | //----------------------------------------------------------------------------- |
||
266 | extern void process_rxdata(unsigned char c) |
||
267 | { |
||
268 | static unsigned int crc; |
||
269 | static unsigned char crc1,crc2,buf_ptr; |
||
270 | static unsigned char UartState = 0; |
||
271 | unsigned char CrcOkay = 0; |
||
272 | |||
273 | SioTmp=c; |
||
274 | |||
275 | if(buf_ptr >= MAX_RX_BUF) |
||
276 | UartState = 0; |
||
277 | if(SioTmp == '\r' && UartState == 2) |
||
278 | { |
||
279 | UartState = 0; |
||
280 | crc -= RxdBuffer[buf_ptr-2]; |
||
281 | crc -= RxdBuffer[buf_ptr-1]; |
||
282 | crc %= 4096; |
||
283 | crc1 = '=' + crc / 64; |
||
284 | crc2 = '=' + crc % 64; |
||
285 | CrcOkay = 0; |
||
286 | if((crc1 == RxdBuffer[buf_ptr-2]) && (crc2 == RxdBuffer[buf_ptr-1])) |
||
287 | { |
||
288 | CrcOkay = 1; |
||
289 | } |
||
290 | else |
||
291 | { |
||
292 | CrcOkay = 0; |
||
293 | CntCrcError++; |
||
294 | display_line1[1]='E'; |
||
295 | |||
296 | } |
||
297 | if(!NeuerDatensatzEmpfangen && CrcOkay) // Datensatz schon verarbeitet |
||
298 | { |
||
299 | NeuerDatensatzEmpfangen = 1; |
||
300 | AnzahlEmpfangsBytes = buf_ptr; |
||
301 | RxdBuffer[buf_ptr] = '\r'; |
||
302 | display_line1[1]='R'; |
||
303 | } |
||
304 | } |
||
305 | else |
||
306 | switch(UartState) |
||
307 | { |
||
308 | case 0: |
||
309 | if(SioTmp == '#' && !NeuerDatensatzEmpfangen) UartState = 1; // Startzeichen und Daten schon verarbeitet |
||
310 | buf_ptr = 0; |
||
311 | RxdBuffer[buf_ptr++] = SioTmp; |
||
312 | crc = SioTmp; |
||
313 | display_line1[2]='A'; |
||
314 | display_line1[1]='X'; |
||
315 | break; |
||
316 | case 1: // Adresse auswerten |
||
317 | UartState++; |
||
318 | RxdBuffer[buf_ptr++] = SioTmp; |
||
319 | crc += SioTmp; |
||
320 | display_line1[2]='B'; |
||
321 | break; |
||
322 | case 2: // Eingangsdaten sammeln |
||
323 | RxdBuffer[buf_ptr] = SioTmp; |
||
324 | if(buf_ptr < MAX_RX_BUF) buf_ptr++; |
||
325 | else UartState = 0; |
||
326 | crc += SioTmp; |
||
327 | display_line1[2]='C'; |
||
328 | break; |
||
329 | default: |
||
330 | UartState = 0; |
||
331 | display_line1[2]='D'; |
||
332 | break; |
||
333 | } |
||
334 | |||
335 | |||
336 | if(rxtx[8]==0x00) |
||
337 | rxtx[8]=0x01; |
||
338 | else |
||
339 | rxtx[8]=0x00; |
||
340 | } |
||
341 | |||
342 | //----------------------------------------------------------------------------- |
||
343 | // convert_uint16 |
||
344 | //----------------------------------------------------------------------------- |
||
345 | extern void convert_uint16(unsigned char * c,int len, unsigned int value) |
||
346 | { |
||
347 | int tempvalue, i; |
||
348 | char c1[7]; |
||
349 | |||
350 | if(len<1) return; |
||
351 | for(i=0;i<len;i++) { |
||
352 | c1[i]='0'; |
||
353 | } |
||
354 | |||
355 | i=len-1; |
||
356 | while(value>0) { |
||
357 | tempvalue=value; |
||
358 | value=value/10; |
||
359 | c1[i]=(tempvalue-(value*10))+'0'; |
||
360 | i--; |
||
361 | } |
||
362 | for(i=0;i<len;i++) { |
||
363 | *c=c1[i]; |
||
364 | c++; |
||
365 | |||
366 | } |
||
367 | } |
||
368 | |||
369 | |||
370 | //----------------------------------------------------------------------------- |
||
371 | //main |
||
372 | //main execution loop |
||
373 | //----------------------------------------------------------------------------- |
||
374 | extern int main(void) |
||
375 | { |
||
376 | unsigned char c; |
||
377 | unsigned int i; |
||
378 | int i1; |
||
379 | |||
380 | HIDEGRAPHIC; |
||
381 | HIDEGRAPHICBACK; |
||
382 | |||
383 | CLKPR=0x80; |
||
384 | CLKPR=0x00; |
||
385 | |||
386 | // PORT D - unused right now |
||
387 | PORTD = 0x10; |
||
388 | DDRD = 0x00; |
||
389 | |||
390 | // USART initialization |
||
391 | // Communication Parameters: 8 Data, 1 Stop, No Parity |
||
392 | // USART Receiver: On |
||
393 | // USART Transmitter: On |
||
394 | // USART Mode: Asynchronous |
||
395 | // USART Baud rate: 57600 |
||
396 | UCSR0A=0x00; |
||
397 | UCSR0B=0x18; |
||
398 | UCSR0C=0x86; |
||
399 | #ifdef CPUSPEED_20 //20.000MHz |
||
400 | UBRR0H=0x00; |
||
401 | UBRR0L=0x15; |
||
402 | #endif |
||
403 | |||
404 | #ifdef CPUSPEED_16 //16.000MHz |
||
405 | UBRR0H=0x00; |
||
406 | UBRR0L=0x10; |
||
407 | #endif |
||
408 | |||
409 | #ifdef CPUSPEED_11059 //11.059MHz |
||
410 | UBRR0H=0x00; |
||
411 | UBRR0L=0x0B; |
||
412 | #endif |
||
413 | |||
414 | // Initialize the 8-bit Timer0 to clock at 20/8 MHz */ |
||
415 | TCCR0A=0x00; |
||
416 | TCCR0B=0x01; |
||
417 | |||
418 | // Initialize the SPI Interface |
||
419 | PORTB = 0x00; |
||
420 | DDRB = 0x3E; //0x3E |
||
421 | //DDRB = 0x3A; |
||
422 | |||
423 | SPCR = (1<<SPE) | (1<<MSTR) | (1<<CPHA); |
||
424 | SPSR = 1; |
||
425 | |||
426 | // External Interrupt(s) initialization |
||
427 | // INT0: On |
||
428 | // INT0 Mode: Falling Edge |
||
429 | // INT1: On |
||
430 | // INT1 Mode: Falling Edge |
||
431 | // Interrupt on any change on pins PCINT0-7: Off |
||
432 | // Interrupt on any change on pins PCINT8-14: Off |
||
433 | // Interrupt on any change on pins PCINT16-23: Off |
||
434 | EICRA=0x0A; |
||
435 | EIMSK=0x03; |
||
436 | EIFR=0x03; |
||
437 | PCICR=0x00; |
||
438 | |||
439 | // Enable interrupts |
||
440 | sei(); |
||
441 | |||
442 | // MAIN lOOP |
||
443 | display_line1[0]='X'; |
||
444 | display_line1[1]='X'; |
||
445 | display_line1[2]='X'; |
||
446 | display_line1[3]='X'; |
||
447 | display_line1[4]='X'; |
||
448 | display_line1[5]='X'; |
||
449 | |||
450 | NeuerDatensatzEmpfangen = 0; |
||
451 | |||
452 | framecounter = 0; |
||
453 | |||
454 | GR_Clear(); |
||
455 | GR_Copy(&grlevel[0],(GR_Lines/2)*7,21); |
||
456 | SHOWGRAPHIC; |
||
457 | |||
458 | while (1) |
||
459 | { |
||
460 | |||
461 | if (UCSR0A & (1<<RXC0)) { |
||
462 | c=UDR0; |
||
463 | UDR0=c; |
||
464 | process_rxdata(c); |
||
465 | } |
||
466 | |||
467 | if (framecounter<25) showmessage1=1; else showmessage1=0; |
||
468 | if (framecounter>50) framecounter = 0; |
||
469 | |||
470 | if(NeuerDatensatzEmpfangen) { |
||
471 | switch(RxdBuffer[2]) |
||
472 | { |
||
473 | case 'D': |
||
474 | //decode the Messagee |
||
475 | Decode64((unsigned char *)&DebugOut,sizeof(DebugOut),3,AnzahlEmpfangsBytes); |
||
476 | |||
477 | // Heading information |
||
478 | convert_uint16((unsigned char *)&heading[1],3,(unsigned int)DebugOut.Analog[8]); |
||
479 | |||
480 | // Altitute Information |
||
481 | if(DebugOut.Analog[5]>old_alt) { |
||
482 | alt_inc=1; |
||
483 | alt_dec=0; |
||
484 | alt_delta=DebugOut.Analog[5]-old_alt; |
||
485 | } |
||
486 | else { |
||
487 | if(DebugOut.Analog[5]<old_alt) { |
||
488 | alt_inc=0; |
||
489 | alt_dec=1; |
||
490 | alt_delta=old_alt-DebugOut.Analog[5]; |
||
491 | } |
||
492 | else { |
||
493 | alt_inc=0; |
||
494 | alt_dec=0; |
||
495 | alt_delta=0; |
||
496 | } |
||
497 | } |
||
498 | if(alt_delta>60) alt_delta=60; |
||
499 | if(alt_delta<0) alt_delta=0; |
||
500 | |||
501 | old_alt=DebugOut.Analog[5]; |
||
502 | if(DebugOut.Analog[5]<0) { |
||
503 | altv[0]='-'; |
||
504 | DebugOut.Analog[5]=(0xffff-(unsigned int)DebugOut.Analog[5]); |
||
505 | } |
||
506 | else { |
||
507 | altv[0]='+'; |
||
508 | } |
||
509 | convert_uint16((unsigned char *)&altv[1],5,(unsigned int)DebugOut.Analog[5]); |
||
510 | |||
511 | //Voltage value |
||
512 | convert_uint16((unsigned char *)&templine[0],5,(unsigned int)DebugOut.Analog[9]); |
||
513 | ubat[3]=templine[2]; |
||
514 | ubat[4]=templine[3]; |
||
515 | ubat[6]=templine[4]; |
||
516 | |||
517 | if(DebugOut.Analog[9]>90) bat[0]=0x08; else bat[0]=0x04; |
||
518 | if(DebugOut.Analog[9]>95) bat[1]=0x08; else bat[1]=0x04; |
||
519 | if(DebugOut.Analog[9]>100) bat[2]=0x08; else bat[2]=0x04; |
||
520 | if(DebugOut.Analog[9]>105) bat[3]=0x08; else bat[3]=0x04; |
||
521 | if(DebugOut.Analog[9]>110) bat[4]=0x08; else bat[4]=0x04; |
||
522 | if(DebugOut.Analog[9]>115) bat[5]=0x08; else bat[5]=0x04; |
||
523 | if(DebugOut.Analog[9]>120) bat[6]=0x08; else bat[6]=0x04; |
||
524 | if(DebugOut.Analog[9]>125) bat[7]=0x08; else bat[7]=0x04; |
||
525 | |||
526 | if(DebugOut.Analog[9]<94) lowbat=1; else lowbat = 0; |
||
527 | |||
528 | //RX level |
||
529 | i=((unsigned int)DebugOut.Analog[10]*100)/255; |
||
530 | |||
531 | convert_uint16((unsigned char *)&templine[0],5,(unsigned int)i); |
||
532 | urx[4]=templine[2]; |
||
533 | urx[5]=templine[3]; |
||
534 | urx[6]=templine[4]; |
||
535 | |||
536 | if(i>10) rx[0]=0x08; else rx[0]=0x04; |
||
537 | if(i>20) rx[1]=0x08; else rx[1]=0x04; |
||
538 | if(i>30) rx[2]=0x08; else rx[2]=0x04; |
||
539 | if(i>40) rx[3]=0x08; else rx[3]=0x04; |
||
540 | if(i>50) rx[4]=0x08; else rx[4]=0x04; |
||
541 | if(i>60) rx[5]=0x08; else rx[5]=0x04; |
||
542 | if(i>70) rx[6]=0x08; else rx[6]=0x04; |
||
543 | if(i>80) rx[7]=0x08; else rx[7]=0x04; |
||
544 | |||
545 | // nick |
||
546 | i1=DebugOut.Analog[0]/50; |
||
547 | i1=((GR_Lines/2)-i1); |
||
548 | if(i1<0) i1=0; |
||
549 | if(i1>37) i1=37; |
||
550 | GR_Clear(); |
||
551 | GR_Copy(&grlevel[0],i1*7,21); |
||
552 | if(i1!=20) GR_Copy(&grlevel0[0],20*7,7); |
||
553 | break; |
||
554 | |||
555 | |||
556 | |||
557 | default: |
||
558 | break; |
||
559 | |||
560 | } |
||
561 | NeuerDatensatzEmpfangen=0; |
||
562 | } |
||
563 | } |
||
564 | return(1); |
||
565 | } /* main */ |
||
566 | |||
567 | |||
568 | |||
569 | //----------------------------------------------------------------------------- |
||
570 | // draw line() |
||
571 | // will be executed in interrupt context and will display the overlay content |
||
572 | //-----------------------------------------------------------------------------*/ |
||
573 | extern void draw_line() |
||
574 | { |
||
575 | unsigned char *ltr_p; |
||
576 | unsigned char *num_p; |
||
577 | unsigned char *info_p; |
||
578 | short ltemp; |
||
579 | short ntemp; |
||
580 | short itemp; |
||
581 | unsigned int i1; |
||
582 | unsigned char i=0; |
||
583 | unsigned char c1; |
||
584 | unsigned char c2; |
||
585 | unsigned char c3; |
||
586 | unsigned char c4; |
||
587 | unsigned char c5; |
||
588 | unsigned char c6; |
||
589 | unsigned char c7; |
||
590 | |||
591 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
592 | // Bat and Heading output |
||
593 | if ((line > 35) && (line < 43)) |
||
594 | { |
||
595 | ltemp = (line - 36) * 27 - 64; |
||
596 | ntemp = (line - 36) * 16 - 43; |
||
597 | itemp = (line - 36) * 9; |
||
598 | ltr_p = ltrs+ltemp; |
||
599 | num_p = nums+ntemp; |
||
600 | info_p = infos+itemp; |
||
601 | // +++ Bat |
||
602 | while(TCNT0<LINESTART); |
||
603 | TCNT0=0; |
||
604 | SPSR=1; |
||
605 | |||
606 | DDRB|=1; //sink thru PB0 |
||
607 | SPDR = info_p[bat[0]]; Wait(); |
||
608 | SPDR = info_p[bat[1]]; Wait(); |
||
609 | SPDR = info_p[bat[2]]; Wait(); |
||
610 | SPDR = info_p[bat[3]]; Wait(); |
||
611 | SPDR = info_p[bat[4]]; Wait(); |
||
612 | SPDR = info_p[bat[5]]; Wait(); |
||
613 | SPDR = info_p[bat[6]]; Wait(); |
||
614 | SPDR = info_p[bat[7]]; Wait(); |
||
615 | DDRB&=0xFE; //PB0 Hi-Z again, and load a blank so spacing is right |
||
616 | |||
617 | // +++ Heading |
||
618 | TCNT0=0; |
||
619 | while(TCNT0<80); |
||
620 | TCNT0=0; |
||
621 | SPSR=0; |
||
622 | DDRB|=1; |
||
623 | SPDR = info_p[heading[0]]; Wait(); |
||
624 | SPDR = num_p[heading[1]]; Wait(); |
||
625 | SPDR = num_p[heading[2]]; Wait(); |
||
626 | SPDR = num_p[heading[3]]; Wait(); |
||
627 | SPDR = info_p[heading[4]]; Wait(); |
||
628 | DDRB&=0xFE; //PB0 Hi-Z again, and load a blank so spacing is right |
||
629 | |||
630 | // +++ RX Level |
||
631 | while(TCNT0<250); |
||
632 | TCNT0=0; |
||
633 | while(TCNT0<70); |
||
634 | SPSR=1; |
||
635 | DDRB|=1; |
||
636 | SPDR = info_p[rx[0]]; Wait(); |
||
637 | SPDR = info_p[rx[1]]; Wait(); |
||
638 | SPDR = info_p[rx[2]]; Wait(); |
||
639 | SPDR = info_p[rx[3]]; Wait(); |
||
640 | SPDR = info_p[rx[4]]; Wait(); |
||
641 | SPDR = info_p[rx[5]]; Wait(); |
||
642 | SPDR = info_p[rx[6]]; Wait(); |
||
643 | SPDR = info_p[rx[7]]; Wait(); |
||
644 | DDRB&=0xFE; |
||
645 | } |
||
646 | |||
647 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
648 | // UBat |
||
649 | if ((line > 44) && (line < 52)) |
||
650 | { |
||
651 | ltemp = (line - 45) * 27 - 64; |
||
652 | ntemp = (line - 45) * 16 - 43; |
||
653 | itemp = (line - 45) * 9; |
||
654 | ltr_p = ltrs+ltemp; |
||
655 | num_p = nums+ntemp; |
||
656 | info_p = infos+itemp; |
||
657 | // +++ UBat |
||
658 | while(TCNT0<LINESTART); |
||
659 | TCNT0=0; |
||
660 | SPSR=1; |
||
661 | DDRB|=1; |
||
662 | SPDR = ltr_p[ubat[0]]; Wait(); |
||
663 | SPDR = num_p[ubat[1]]; Wait(); |
||
664 | SPDR = ltr_p[ubat[2]]; Wait(); |
||
665 | SPDR = num_p[ubat[3]]; Wait(); |
||
666 | SPDR = num_p[ubat[4]]; Wait(); |
||
667 | SPDR = num_p[ubat[5]]; Wait(); |
||
668 | SPDR = num_p[ubat[6]]; Wait(); |
||
669 | SPDR = ltr_p[ubat[7]]; Wait(); |
||
670 | DDRB&=0xFE; |
||
671 | TCNT0=0; |
||
672 | while(TCNT0<80); |
||
673 | TCNT0=0; |
||
674 | while(TCNT0<250); |
||
675 | TCNT0=0; |
||
676 | while(TCNT0<70); |
||
677 | TCNT0=0; |
||
678 | SPSR=1; |
||
679 | DDRB|=1; |
||
680 | SPDR = ltr_p[urx[0]]; Wait(); |
||
681 | SPDR = ltr_p[urx[1]]; Wait(); |
||
682 | SPDR = num_p[urx[2]]; Wait(); |
||
683 | SPDR = ltr_p[urx[3]]; Wait(); |
||
684 | SPDR = num_p[urx[4]]; Wait(); |
||
685 | SPDR = num_p[urx[5]]; Wait(); |
||
686 | SPDR = num_p[urx[6]]; Wait(); |
||
687 | SPDR = num_p[urx[7]]; Wait(); |
||
688 | DDRB&=0xFE; |
||
689 | |||
690 | } |
||
691 | |||
692 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
693 | // Message |
||
694 | if ((line > 60) && (line < 68) && (showmessage1) && (lowbat)) |
||
695 | { |
||
696 | ltemp = (line - 61) * 27 - 64; |
||
697 | ntemp = (line - 61) * 16 - 43; |
||
698 | itemp = (line - 61) * 9; |
||
699 | ltr_p = ltrs+ltemp; |
||
700 | num_p = nums+ntemp; |
||
701 | info_p = infos+itemp; |
||
702 | // +++ UBat |
||
703 | while(TCNT0<LINESTART); |
||
704 | TCNT0=0; |
||
705 | while(TCNT0<250); |
||
706 | SPSR=1; |
||
707 | SPDR = ltr_p[Message_LowBat[0]]; Wait(); |
||
708 | SPDR = ltr_p[Message_LowBat[1]]; Wait(); |
||
709 | SPDR = ltr_p[Message_LowBat[2]]; Wait(); |
||
710 | SPDR = ltr_p[Message_LowBat[3]]; Wait(); |
||
711 | SPDR = ltr_p[Message_LowBat[4]]; Wait(); |
||
712 | SPDR = ltr_p[Message_LowBat[5]]; Wait(); |
||
713 | SPDR = ltr_p[Message_LowBat[6]]; Wait(); |
||
714 | SPDR = ltr_p[Message_LowBat[7]]; Wait(); |
||
715 | SPDR = ltr_p[Message_LowBat[8]]; Wait(); |
||
716 | SPDR = ltr_p[Message_LowBat[9]]; Wait(); |
||
717 | SPDR = ltr_p[Message_LowBat[10]]; Wait(); |
||
718 | SPDR = ltr_p[Message_LowBat[11]]; Wait(); |
||
719 | SPDR = ltr_p[Message_LowBat[12]]; Wait(); |
||
720 | SPDR = ltr_p[Message_LowBat[13]]; Wait(); |
||
721 | SPDR = ltr_p[Message_LowBat[14]]; Wait(); |
||
722 | } |
||
723 | |||
724 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
725 | // alt value |
||
726 | |||
727 | if((line > 80) && (line <250)) |
||
728 | { |
||
729 | while(TCNT0<LINESTART); |
||
730 | TCNT0=0; |
||
731 | } |
||
732 | |||
733 | if ((line > 170) && (line < 178)) |
||
734 | { |
||
735 | ltemp = (line - 171) * 27 - 64; |
||
736 | ntemp = (line - 171) * 16 - 43; |
||
737 | itemp = (line - 171) * 9; |
||
738 | ltr_p = ltrs+ltemp; |
||
739 | num_p = nums+ntemp; |
||
740 | info_p = infos+itemp; |
||
741 | while(TCNT0<10); |
||
742 | SPSR=1; |
||
743 | DDRB|=1; |
||
744 | SPDR = num_p[altv[0]]; Wait(); |
||
745 | SPDR = num_p[altv[1]]; Wait(); |
||
746 | SPDR = num_p[altv[2]]; Wait(); |
||
747 | SPDR = num_p[altv[3]]; Wait(); |
||
748 | SPDR = num_p[altv[4]]; Wait(); |
||
749 | SPDR = num_p[altv[5]]; Wait(); |
||
750 | DDRB&=0xFE; |
||
751 | } |
||
752 | |||
753 | if ((line > 179) && (line < (179 + alt_delta)) && alt_dec) |
||
754 | { |
||
755 | while(TCNT0<50); |
||
756 | SPDR = bar1; Wait(); |
||
757 | } |
||
758 | |||
759 | if ((line > (169 - alt_delta)) && (line < 169) && alt_inc) |
||
760 | { |
||
761 | while(TCNT0<50); |
||
762 | SPDR = bar1; Wait(); |
||
763 | } |
||
764 | asm("nop"); |
||
765 | |||
766 | // +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
||
767 | // grafic array |
||
768 | if ((line > 90) && (line < 250) && (showgraphic==1)) |
||
769 | { |
||
770 | |||
771 | while(TCNT0<250); |
||
772 | TCNT0=0; |
||
773 | |||
774 | i1=7*((line-90)>>2); |
||
775 | i=0; |
||
776 | c1=dmem[i1++]; |
||
777 | c2=dmem[i1++]; |
||
778 | c3=dmem[i1++]; |
||
779 | c4=dmem[i1++]; |
||
780 | c5=dmem[i1++]; |
||
781 | c6=dmem[i1++]; |
||
782 | c7=dmem[i1++]; |
||
783 | while(TCNT0<20); |
||
784 | if (showgraphicb) DDRB|=1; |
||
785 | do { |
||
786 | PORTB=((c1<<2)&0x04); |
||
787 | c1=c1>>1; |
||
788 | i++; |
||
789 | } while(i<8); |
||
790 | do { |
||
791 | PORTB=((c2<<2)&0x04); |
||
792 | c2=c2>>1; |
||
793 | i++; |
||
794 | } while(i<16); |
||
795 | do { |
||
796 | PORTB=((c3<<2)&0x04); |
||
797 | c3=c3>>1; |
||
798 | i++; |
||
799 | } while(i<24); |
||
800 | do { |
||
801 | PORTB=((c4<<2)&0x04); |
||
802 | c4=c4>>1; |
||
803 | i++; |
||
804 | } while(i<32); |
||
805 | do { |
||
806 | PORTB=((c5<<2)&0x04); |
||
807 | c5=c5>>1; |
||
808 | i++; |
||
809 | } while(i<40); |
||
810 | do { |
||
811 | PORTB=((c6<<2)&0x04); |
||
812 | c6=c6>>1; |
||
813 | i++; |
||
814 | } while(i<48); |
||
815 | do { |
||
816 | PORTB=((c7<<2)&0x04); |
||
817 | c7=c7>>1; |
||
818 | i++; |
||
819 | } while(i<56); |
||
820 | PORTB=0x00; |
||
821 | DDRB&=0xFE; |
||
822 | } |
||
823 | |||
824 | |||
825 | // Debug - remove for release |
||
826 | // if ((line > 270) && (line < 278)) |
||
827 | // { |
||
828 | // SPSR=1; |
||
829 | // ltemp = (line - 271) * 27 - 64; |
||
830 | // ntemp = (line - 271) * 16 - 43; |
||
831 | // itemp = (line - 271) * 8; |
||
832 | // ltr_p = ltrs+ltemp; |
||
833 | // num_p = nums+ntemp; |
||
834 | // info_p = infos+itemp; |
||
835 | // while(TCNT0<LINESTART); |
||
836 | // DDRB|=1; //sink thru PB0 |
||
837 | // SPDR = ltr_p[rxtx[0]]; Wait(); |
||
838 | // SPDR = ltr_p[rxtx[1]]; Wait(); |
||
839 | // SPDR = ltr_p[rxtx[2]]; Wait(); |
||
840 | // SPDR = info_p[rxtx[3]]; Wait(); |
||
841 | // SPDR = ltr_p[rxtx[4]]; Wait(); |
||
842 | // SPDR = ltr_p[rxtx[5]]; Wait(); |
||
843 | // SPDR = ltr_p[rxtx[6]]; Wait(); |
||
844 | // SPDR = ltr_p[rxtx[7]]; Wait(); |
||
845 | // SPDR = info_p[rxtx[8]]; Wait(); |
||
846 | // TCNT0=0; |
||
847 | // while(TCNT0<3); // 3 wait a little bit before turning off dimmer so that the |
||
848 | // // length of black box on the right matches the one on the left |
||
849 | // DDRB&=0xFE; //PB0 Hi-Z again, and load a blank so spacing is right |
||
850 | // } |
||
851 | |||
852 | |||
853 | // if ((line > 280) && (line < 288)) |
||
854 | // { |
||
855 | // SPSR=1; |
||
856 | // ltemp = (line - 281) * 27 - 64; |
||
857 | // ntemp = (line - 281) * 16 - 43; |
||
858 | // ltr_p = ltrs+ltemp; //by calculating this pointer you only have to |
||
859 | // num_p = nums+ntemp; //add ltemp/ntemp once per line, instead of for |
||
860 | //every char. This tightens up printing a bit |
||
861 | //saves about 3 assembly instructions per char |
||
862 | |||
863 | // SPDR = ltr_p['@']; Wait(); //goofy hack to make SPSR=0 work, write an empty char at SPSR=1 first |
||
864 | // SPSR=1; |
||
865 | // while(TCNT0<LINESTART); |
||
866 | // DDRB|=1; //sink thru PB0 |
||
867 | // //;display_line1[0]='A'; |
||
868 | // SPDR = ltr_p[display_line1[0]]; Wait(); |
||
869 | // SPDR = ltr_p[display_line1[1]]; Wait(); |
||
870 | // SPDR = ltr_p[display_line1[2]]; Wait(); |
||
871 | // SPDR = ltr_p[display_line1[3]]; Wait(); |
||
872 | // SPDR = ltr_p[display_line1[4]]; Wait(); |
||
873 | // SPDR = ltr_p[display_line1[5]]; Wait(); |
||
874 | // TCNT0=0; |
||
875 | // while(TCNT0<3); // 3 wait a little bit before turning off dimmer so that the |
||
876 | // // length of black box on the right matches the one on the left |
||
877 | // DDRB&=0xFE; //PB0 Hi-Z again, and load a blank so spacing is right |
||
878 | // } |
||
879 | |||
880 | if ((line > 300) && (line < 308)) |
||
881 | { |
||
882 | SPSR=1; |
||
883 | ltemp = (line - 301) * 27 - 64; |
||
884 | ntemp = (line - 301) * 16 - 43; |
||
885 | ltr_p = ltrs+ltemp; |
||
886 | num_p = nums+ntemp; |
||
887 | while(TCNT0<LINESTART+COPYRIGHTSTART); |
||
888 | SPDR = ltr_p[head[0]]; Wait(); |
||
889 | SPDR = ltr_p[head[1]]; Wait(); |
||
890 | SPDR = ltr_p[head[2]]; Wait(); |
||
891 | SPDR = ltr_p[head[3]]; Wait(); |
||
892 | SPDR = ltr_p[head[4]]; Wait(); |
||
893 | SPDR = ltr_p[head[5]]; Wait(); |
||
894 | SPDR = ltr_p[head[6]]; Wait(); |
||
895 | SPDR = ltr_p[head[7]]; Wait(); |
||
896 | SPDR = ltr_p[head[8]]; Wait(); |
||
897 | SPDR = ltr_p[head[9]]; Wait(); |
||
898 | SPDR = ltr_p[head[10]]; Wait(); |
||
899 | SPDR = ltr_p[head[11]]; Wait(); |
||
900 | SPDR = ltr_p[head[12]]; Wait(); |
||
901 | SPDR = ltr_p[head[13]]; Wait(); |
||
902 | SPDR = ltr_p[head[14]]; Wait(); |
||
903 | SPDR = ltr_p[head[15]]; Wait(); |
||
904 | SPDR = ltr_p[head[16]]; Wait(); |
||
905 | TCNT0=0; |
||
906 | while(TCNT0<2); |
||
907 | } |
||
908 | } // end draw_line() |
||
909 | |||
910 | |||
911 | //----------------------------------------------------------------------------- |
||
912 | // H-Sync Interrupt |
||
913 | //-----------------------------------------------------------------------------*/ |
||
914 | SIGNAL(SIG_INTERRUPT0) |
||
915 | { |
||
916 | TCNT0=0; // reset timer |
||
917 | line++; // increment line counter |
||
918 | draw_line(); // output the line |
||
919 | } |
||
920 | |||
921 | |||
922 | //----------------------------------------------------------------------------- |
||
923 | // V-Sync Interrupt |
||
924 | //-----------------------------------------------------------------------------*/ |
||
925 | SIGNAL(SIG_INTERRUPT1) |
||
926 | { |
||
927 | line = 0; |
||
928 | framecounter++; |
||
929 | } |