Rev Author Line No. Line
1213 mija 1 /* mija 2008
2 demo for LCD NOKIA5110 and MCP9800 and GPS modul
3  
4 CPU ATMEGA644P
1361 mija 5 fcpu = 7372800
1213 mija 6  
7 !! define PIN,PORT,DDR for IOpin !!
8 */
9  
10  
11 //************************************************************************
12 // defines
13  
1361 mija 14 #define POINTNAME " DOMOV"
1220 mija 15 #define MY_LAT 48*60+57.7647
16 #define MY_LON 14*60+28.0836
17  
1361 mija 18 /*
19 // 50°7'38.768"N, 13°32'43.132"E
20 #define POINTNAME " ORACOV"
21 #define MY_LAT 50*60+7.64613
22 #define MY_LON 13*60+32.7189
23 */
24 /*
25 // 50°7'38.768"N, 13°32'43.132"E
26 #define POINTNAME " ZAMEK"
27 #define MY_LAT 50*60+6.191
28 #define MY_LON 13*60+32.118
29 */
30  
1213 mija 31 #define KEY_TIME_DEAD 5 //cca 50ms 8*5
32 //#define KEY_TIME_START_REPEAT 100 //cca 1s
33 //#define KEY_TIME_REPEAT 20 //cca 240ms
34 #define KEY_TIME_FIRST 50
35  
36 #define TEMP_TIME_REPEAT 100
37  
38 #define OFF_TIME 200
1220 mija 39 #define TIME_KEY_LONG 200
1213 mija 40  
41 #define REFRESH_TIME 100
42  
43 #define STATUS_REFRESH_TIME 100
44  
45 #define CLOCK1S 100
46 #define CLOCK2S 200
47 #define CLOCK5S 255;
48 #define CLOCK50MS 5
49  
1361 mija 50 //#define DEBUG
1213 mija 51  
52 //************************************************************************
53 //including
54  
55 #include <avr/io.h>
56 #include <stdlib.h>
57 #include <avr/pgmspace.h>
58 #include <avr/interrupt.h>
59 #include <avr/sleep.h>
60 #include <util/delay.h>
61 #include <stdio.h>
62 #include <math.h>
63 //#include "ascii_table.h"
64 #include "lcd.h" //define PINs LCD
65 #include "GPS.h" //define PINs GPS,TL,LED,REF,I2C
66 #include "nmea_scan.h"
67  
68 //************************************************************************
69 // pomocne
1217 mija 70  
1213 mija 71 #define WIDTH_CHAR_SIGNALL 8
72 prog_uint8_t CHAR_SIGNALL[WIDTH_CHAR_SIGNALL]={127,12,30,51,51,30,12,127};
73  
74 #define WIDTH_CHAR_SIGNALL_D 8
75 prog_uint8_t CHAR_SIGNALL_D[WIDTH_CHAR_SIGNALL_D]={127,12,30,63,63,30,12,127};
76  
77 #define WIDTH_CHAR_SIGNALL_2D 7
78 prog_uint8_t CHAR_SIGNALL_2D[WIDTH_CHAR_SIGNALL_2D]={1,2,4,127,4,2,1};
79  
80 #define WIDTH_CHAR_SIGNALL_3D 7
81 prog_uint8_t CHAR_SIGNALL_3D[WIDTH_CHAR_SIGNALL_3D]={124,68,71,69,125,17,31};
82  
83 #define WIDTH_CHAR_LIGHT 5
84 prog_uint8_t CHAR_LIGHT[WIDTH_CHAR_LIGHT]={127,65,95,95,127};
85  
86  
1217 mija 87 #define BOOT() (((void(*)(void))(char *)0x7C00)())
88 #define RESET() (((void(*)(void))(char *)0x0000)())
1213 mija 89 //***********************************************************************
90 // global variables
1217 mija 91  
1213 mija 92 extern uint8_t video_buf[504];
93 extern uint8_t *offset_text;
94  
95 uint8_t id_mod;
96 char scan_buf[MAX_NMEA_LOAD];
97 POINT_T now,max,min;
98 DATA_GPS gps;
99 DATA_GPS *pgps;
100  
101 enum {ID_TIME,ID_LOCATION,ID_COURSE,ID_ALL_POSITION,ID_ALL_SERVICE,ID_SERVICE,ID_TEMP,ID_SATELITES,ID_NORTH,ID_NAV};
102  
1217 mija 103 static FILE mystdout = FDEV_SETUP_STREAM(lcd_put, NULL,_FDEV_SETUP_WRITE); // in lcd.h
104 static FILE mystdout2 = FDEV_SETUP_STREAM(lcd_put2, NULL,_FDEV_SETUP_WRITE); // in lcd.h
1213 mija 105  
1217 mija 106 //************************************************************************
107 // prototypes
1213 mija 108  
1217 mija 109 //(*bootloader)(void) = 0x7C00;
110 void delay_ms(uint16_t time);
111 void null_variables(void);
112  
1213 mija 113 //************************************************************************
114 // general cpu init
115  
116 void general_cpu_init(void)
117 {
118 //*** IO_PIN ***
119 TL1_INIT;
120 TL1_PULLUP;
121 TL2_INIT;
122 TL2_PULLUP;
123 TL3_INIT;
124 TL3_PULLUP;
125  
1217 mija 126 USB_INIT;
127 //USB_PULLUP;
1213 mija 128  
129 GPS_INIT;
130 GPS_OFF;
131  
132 REF_INIT;
133 REF_OFF;
134  
135 nSCLK_INIT;
136 nSDIN_INIT;
137 nDC_INIT;
138 nCS_INIT;
139 nRESET_INIT;
140  
141 SCL_INIT;
142 SDA_FLOAT;
143  
144 LED_INIT;
145 LED_OFF;
146  
147 //*** EXTERNAL PIN INTERRUPTS
1217 mija 148 //EICRA = _BV(ISC21); //pin INT2 - TL2
149 //EIMSK = _BV(INT2); //pin INT2 - TL2
150  
1213 mija 151  
1217 mija 152 //*** PIN CHANGE INTERRUPTS PCINT29
153 PCICR = _BV(PCIE1);
154 PCMSK1 = _BV(PCINT10) | _BV(PCINT11) |_BV(PCINT12); //pin change TL1,TL2,TL3
155  
156 PCICR |= _BV(PCIE3);
157 PCMSK3 = _BV(PCINT29); // pin USB
158  
159 //*** TIMER1 *** tik for TL fosc/64 /1024(TCNT1) cca 8ms
1213 mija 160 TCNT1 = 0;
161 OCR1A = 1024;
162 TCCR1A = _BV(WGM11) | _BV(WGM10);
1217 mija 163 TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS11) | _BV(CS10) ; // TIMER1 fast PWM
1213 mija 164 TIMSK1 = _BV(TOIE1);
165  
166 //*** TIMER2 *** RTC
167 ASSR = _BV(AS2);
168 TCCR2B = _BV(CS22) | _BV(CS21) | _BV(CS20);
169 TIMSK2 = _BV(TOIE2);
170  
171 //*** SLEEP ***
172 SMCR = _BV(SM1) | _BV(SM0) | _BV(SE);
173  
174 //*** WDT ***
175 //WDTCSR = _BV(WDCE) | _BV(WDE);
176 //WDTCSR = _BV(WDIE) | _BV(WDP3) | _BV(WDP0);
177  
178 //*** USART0 *** RX PD0, TX PD1, GPS
1217 mija 179 UBRR0 = 95;
1213 mija 180 //UCSR0A =
181 UCSR0B = _BV(RXCIE0) | _BV(RXEN0) | _BV(TXEN0);
182  
183 //*** USART1 *** RX PD2, TX PD3 PC
1361 mija 184 DDRD |= _BV(PD3);
185 PORTD &= (~(_BV(PD3)));
186  
1217 mija 187 #ifndef DEBUG
188 UBRR1 = 95;
189 #else
190 UBRR1 = 3;
191 #endif
1213 mija 192 //UCSR0A =
1361 mija 193 UCSR1B = _BV(RXCIE1) | _BV(RXEN1) | _BV(TXEN1);
1213 mija 194  
195 //*** ADC ***
196 ADMUX = _BV(REFS1) | _BV(MUX0);
1217 mija 197 ADCSRA = _BV(ADPS1) | _BV(ADPS2);
1213 mija 198  
199 }
200  
201 //************************************************************************
202 // interrupts + RTC / clock 8s ... TIMER2 /
203  
204 volatile uint8_t RTC_flag;
205 volatile uint8_t sRTC,mRTC,hRTC,dRTC,mdRTC,yRTC;
206  
207 uint8_t modulo(uint8_t h,uint8_t m) //pomocna fce pro modulo x
208 {
209 if (h<m) return (h);
210 return(h-m);
211 }
212  
213 void set_date(void) //citac datumu
214 {
215 dRTC++;
216 switch (mdRTC)
217 {
218 case 1:
219 case 3:
220 case 5:
221 case 7:
222 case 8:
223 case 10:
224 case 12: if(dRTC>=32) {dRTC=1;mdRTC++;if(mdRTC==13) {mdRTC =1;yRTC=modulo(yRTC++,100);}} break;
225 case 4:
226 case 6:
227 case 9:
228 case 11: if(dRTC>=31) {dRTC=1;mdRTC++;} break;
229 case 2: if (dRTC >= 30) {dRTC=1;mdRTC++;break;}
230 if (dRTC ==29) {if (!(yRTC & 0x03)) break;dRTC=1;mdRTC++;}
231 }
232 }
233  
234  
235 volatile uint8_t timer1_ovf;
236  
237 ISR(TIMER1_OVF_vect)
238 {
239 timer1_ovf ++;
240 }
241  
242  
243 ISR(TIMER2_OVF_vect)
244 {
245 sRTC += 8;
246 if (sRTC >= 60)
247 {
248 sRTC=modulo(sRTC,60); //1min
249 if (++mRTC>=60)
250 {
251 mRTC=0; //1hod
252 if (++hRTC>=24)
253 {
254 hRTC=0;
255 set_date(); //1den
256 }
257 }
258 }
259 }
260  
261 char rx_buf[MAX_RX_BUF];
262 volatile uint8_t rx_shift;
263  
264 ISR(USART0_RX_vect)
265 {
266 if (++rx_shift >= MAX_RX_BUF) rx_shift =0;
267 rx_buf[rx_shift]=UDR0;
268 UDR1 = UDR0;
269 }
270  
1217 mija 271 uint8_t first_char_usart1 = 0;
272  
1213 mija 273 ISR(USART1_RX_vect)
274 {
1361 mija 275  
1217 mija 276 #ifndef DEBUG
1213 mija 277 UDR0 = UDR1;
1217 mija 278 #else
279 if (TL1_INPUT && TL3_INPUT) BOOT();
280 //bootloader();
281 #endif
1213 mija 282 }
283  
1217 mija 284 ISR(PCINT1_vect)
285 {
286 if ((!TL3_INPUT) && (!TL1_INPUT)) RESET();
287 }
288  
289 ISR(PCINT3_vect)
290 {
1361 mija 291 if (USB_PIN) USART_PC_ON;
292 else USART_PC_OFF;
1217 mija 293 if (!TL2_INPUT && USB_INPUT)
294 {
295 cli();
296 buffer_clr();
297 gotoxy(2,3);
1220 mija 298 fprintf(&mystdout2,"update");
299 gotoxy(2,5);
300 fprintf(&mystdout2,"firmware");
1217 mija 301 lcd_refresh();
302 delay_ms(1000);
303 BOOT();
304 }
305  
306 }
307  
1361 mija 308 //EMPTY_INTERRUPT(INT0_vect)
309 //EMPTY_INTERRUPT(INT2_vect)
310 //EMPTY_INTERRUPT(WDT_vect)
1213 mija 311  
312 //************************************************************************
313 // delay_ms functions /define fcpu /
314  
315 void delay_ms(uint16_t time)
316 {
317 while(time--) _delay_ms(1);
318 }
319 //************************************************************************
320 // static navigation
321  
322 void gps_put(char c)
323 {
324 while ( !( UCSR0A & _BV(UDRE0)) );
325 UDR0 = c;
326 }
327  
328 //************************************************************************
329 // key + timer1_ovf
330  
331  
332 volatile uint8_t key_press;
333 volatile uint8_t key_flag;
334 volatile uint8_t timer_key;
335 volatile uint8_t timer_temp;
336 volatile uint8_t timer_off;
337 volatile uint8_t timer_refresh;
338 volatile uint8_t timer_status;
1220 mija 339 volatile uint8_t timer_key_long;
1213 mija 340  
341 void timer1_tik(void)
342 {
343 uint8_t key_temp;
344  
1217 mija 345 while (timer1_ovf)
1213 mija 346 {
1217 mija 347 timer1_ovf--;
1213 mija 348 if (timer_status) timer_status--;
349 if (timer_refresh) timer_refresh--;
350 if (timer_off) timer_off--;
1220 mija 351 if (timer_key_long) timer_key_long--;
1213 mija 352 if (timer_temp) timer_temp--;
353 if (timer_key) timer_key--;
354 else
355 {
1217 mija 356 key_temp = 0;
357 if (!TL1_INPUT) key_temp = _BV(KEY1);
358 if (!TL2_INPUT) key_temp |= _BV(KEY2);
359 if (!TL3_INPUT) key_temp |= _BV(KEY3);
1220 mija 360 //if (key_temp != key_press)
1213 mija 361 {
1220 mija 362 if (key_temp != key_press)
363 {
364 timer_off= OFF_TIME;
365 timer_key_long=TIME_KEY_LONG;
366 }
1213 mija 367 timer_key = KEY_TIME_DEAD;
368 key_press = key_temp;
369 if (!key_flag) key_flag = key_press;
1220 mija 370  
1213 mija 371 }
372 }
373 }
374 }
375  
376 uint8_t key_read(void)
377 {
378 uint8_t key_send;
379  
380 key_send = key_flag;
381 key_flag = 0;
382 return key_send;
383 }
384  
385 //************************************************************************
386 // SW I2C /define SDA, SCL; tested for fosc 1Mhz/
387  
388 void I2C_start(void)
389 {
390 SDA_OUT;
391 SDA_L;
392 SCL_L;
393 }
394  
395 void I2C_stop(void)
396 {
397 SCL_H;
398 SDA_OUT;
399 SDA_H;
400 SDA_FLOAT;
401 }
402  
403 void I2C_write(uint8_t data)
404 {
405 uint8_t a;
406  
407 SDA_OUT;
408 for(a=0;a<8;a++)
409 {
410 SCL_L;
411 if (data & 0x80) SDA_H;
412 else SDA_L;
413 SCL_H;
414 data <<= 1;
415 }
416 SCL_L;
417 SDA_FLOAT;
418 SCL_H;
419 SCL_L;
420 }
421  
422 uint8_t I2C_read(uint8_t ack)
423 {
424 uint8_t a;
425 uint8_t data;
426  
427 SDA_IN;
428 data=0;
429 for(a=0;a<8;a++)
430 {
431 SCL_H;
432 if (SDA_INPUT) data |=1;
433 SCL_L;
434 if (a != 7)data <<= 1;
435 }
436  
437 if (ack) {SDA_OUT;SDA_L;}
438 else SDA_FLOAT;
439 SCL_H;
440 SCL_L;
441 SDA_FLOAT;
442 return data;
443 }
444  
445 //************************************************************************
446 // temperature sensor MCP9800 of MICROCHIP
447  
448 void start_MCP9800(void)
449 {
450 I2C_start();
451 I2C_write(0x90);
452 I2C_write(0x1); // configuration pointer MCP9800
453 //I2C_write(0xE1); // 12bit + only 1 convert and then sleep
454 I2C_write(0x81); // 9bit + only 1 convert and then sleep
455 I2C_stop();
456 I2C_start();
457 I2C_write(0x90);
458 I2C_write(0x0); // temperature pointer
459 I2C_stop();
460 }
461  
462 uint16_t read_temp(void)
463 {
464 uint16_t temp;
465  
466 I2C_start();
467 I2C_write(0x91);
468 temp = I2C_read(1) << 8;
469 temp |= I2C_read(0);
470 I2C_stop();
471 return temp;
472 }
473  
474 //************************************************************************
475 // templota
476  
477 void print_temp(int16_t teplota)
478 {
479 printf("%d.%01dC",((teplota>>8) & 0x807F) | (teplota & 0x8000),5*((teplota>>7)& 0x1));
480 }
481  
482 void print_time(TIME_T time)
483 {
484 uint8_t temp;
485  
486 temp = time.hour/10;
487 if (temp == 0) lcd_put(' ',0);
488 else lcd_put(temp + 0x30,0);
489 lcd_put(time.hour%10 + 0x30,0);
490 //put_lcd(':');
491 *(offset_text++) = 0x36;
492 offset_text++;
493 lcd_put(time.min/10 + 0x30,0);
494 lcd_put(time.min%10 + 0x30,0);
495 //put_lcd(':');
496 //put_lcd(sRTC/10 + 0x30);
497 //put_lcd(sRTC%10 + 0x30);
498 }
499  
500 void print_date(DATE_T date)
501 {
502 uint8_t temp;
503  
504 temp = date.day/10;
505 if (temp == 0) lcd_put(' ',0);
506 else lcd_put(temp + 0x30,0);
507 lcd_put(date.day%10 + 0x30,0);
508 //put_lcd('/');
509 *(offset_text++) = 0x60;
510 offset_text++;
511 temp = date.mon/10;
512 if (temp != 0) lcd_put(temp + 0x30,0);
513 lcd_put(date.mon%10 + 0x30,0);
514 if (temp == 0)
515 {
516 *(offset_text++) = 0x60;
517 offset_text++;
518 }
519 //put_lcd('/');
520 //put_lcd(yRTC/10 + 0x30);
521 //put_lcd(yRTC%10 + 0x30);
522 }
523  
524 TIME_T actual_time(void)
525 {
526 TIME_T time;
527  
528 time.sec=sRTC;
529 time.min=mRTC;
530 time.hour=hRTC;
531 return time;
532 }
533  
534 DATE_T actual_date(void)
535 {
536 DATE_T date;
537  
538 date.day=dRTC;
539 date.mon=mdRTC;
540 date.year=yRTC;
541 return date;
542 }
543  
544 //*********************************************************************
1220 mija 545 // key
546  
547 uint8_t test_key(void)
548 {
549 static uint8_t key_next = 0;
550  
551 if (key_press)
552 {
553 if (key_next)
554 {
555 key_read();
556 return 0;
557 }
558  
559 if(!timer_key_long)
560 {
561 key_next = 1;
562 timer_key = KEY_TIME_FIRST;
563 switch(key_read())
564 {
565 case _BV(KEY1): return KEY1_LONG;
566 case _BV(KEY2): return KEY2_LONG;
567 case _BV(KEY3): return KEY3_LONG;
568 }
569 }
570 return 0;
571 }
572 key_next=0;
573 switch(key_read())
574 {
575 case _BV(KEY1): return KEY1_SHORT;
576 case _BV(KEY2): return KEY2_SHORT;
577 case _BV(KEY3): return KEY3_SHORT;
578 }
579 return 0;
580 }
581  
582 //*********************************************************************
1213 mija 583 //status
584  
585 void status(void)
586 {
587 uint8_t a,b;
588 uint8_t *ptr;
589  
590 start_MCP9800();
591 REF_ON;
592 ADC_ON;
593 ADCSRA |= _BV(ADSC);
594 while (!(ADCSRA & _BV(ADIF)));
595  
596 gotoxy(1,1);
597 printf("%0.1fV %2d",1024.0*25/ADC/10,read_temp()>>8);
598 offset_text = video_buf + LCD_WIDTH - WIDTH_CHAR_LIGHT - 2*CHAR_WIDTH - WIDTH_CHAR_SIGNALL_3D - WIDTH_CHAR_SIGNALL - 2;
599 if (gps.fix_position)
600 {
1217 mija 601  
602 ptr= CHAR_SIGNALL_3D;b=WIDTH_CHAR_SIGNALL_3D;//offset_text++;
603 if (gps.mode2 == '3')
604 for (a=0;a<b;a++) *(offset_text++) =pgm_read_byte(ptr++);
605  
606 offset_text = video_buf + LCD_WIDTH - WIDTH_CHAR_LIGHT - 2*CHAR_WIDTH - WIDTH_CHAR_SIGNALL_3D - 2;
1213 mija 607 switch (gps.fix_position)
608 {
609 case 1: ptr= CHAR_SIGNALL;b=WIDTH_CHAR_SIGNALL;break;
610 case 2: ptr= CHAR_SIGNALL_D;b=WIDTH_CHAR_SIGNALL_D;break;
611 case 0:
612 default:ptr= CHAR_SIGNALL;b=0;
613 }
614 for (a=0;a<b;a++) *(offset_text++) =pgm_read_byte(ptr++);
615  
1217 mija 616  
1213 mija 617 }
618 offset_text = video_buf + LCD_WIDTH - WIDTH_CHAR_LIGHT-2*CHAR_WIDTH;
619 printf("%d",gps.satelites_used);
620 if (LED_INPUT)
621 {
622 ptr= CHAR_LIGHT;b=WIDTH_CHAR_LIGHT;
623 offset_text = video_buf + LCD_WIDTH - WIDTH_CHAR_LIGHT;
624 for (a=0;a<b;a++) *(offset_text++) =pgm_read_byte(ptr++);
625 }
626  
627 }
628  
629 //************************************************************************
630 // mod
631  
632 void displ_time(void)
633 {
634 GPS_ON;
1220 mija 635  
636 switch(test_key())
637 {
638 case KEY1_LONG: timer_refresh = 0;if (LED_INPUT) LED_OFF;else LED_ON;break;
639 case KEY2_LONG: id_mod=ID_OFF;return;
640 case KEY3_LONG: return;
641 case KEY1_SHORT:timer_refresh = 0;++id_mod;return;
642 case KEY2_SHORT:
643 case KEY3_SHORT:break;
644 }
645  
1213 mija 646 if (!timer_refresh)
647 {
648 timer_refresh = CLOCK1S;
649 buffer_clr();
650 status();
1217 mija 651 //gotoxy(1,2);
652 // printf("time & date");
1213 mija 653 gotoxy(1,3);
654 fprintf(&mystdout2," %2d:%02d:%02d",gps.hour+2,gps.minute,gps.second);
655 gotoxy(1,5);
656 fprintf(&mystdout2," %2d.%02d.20%02d",gps.day,gps.month,gps.year);
657 lcd_refresh();
658 }
659 }
660  
661 void displ_location(void)
662 {
1217 mija 663 uint8_t a,b;
664 uint8_t *ptr;
665  
1220 mija 666 switch(test_key())
667 {
668 case KEY1_LONG: timer_refresh = 0;if (LED_INPUT) LED_OFF;else LED_ON;break;
669 case KEY2_LONG: id_mod=ID_OFF;return;
670 case KEY3_LONG: return;
671 case KEY1_SHORT:timer_refresh = 0;++id_mod;return;
672 case KEY2_SHORT:
673 case KEY3_SHORT:break;
674 }
675  
1213 mija 676 if (!timer_refresh)
677 {
678 timer_refresh = CLOCK1S;
679 buffer_clr();
680 status();
1217 mija 681  
682 gotoxy(8,2);
683 offset_text -=2;
684 ptr= CHAR_SIGNALL_3D;b=WIDTH_CHAR_SIGNALL_3D;//offset_text++;
685 for (a=0;a<b;a++) *(offset_text++) =pgm_read_byte(ptr++);
686  
687 //gotoxy(9,2);
688 printf("%4.0fm",gps.altitude);
689  
1213 mija 690 gotoxy(1,3);
691 //gps.latitude = 14.5;
692 fprintf(&mystdout2,"%c %3d%.4f'",gps.ns_indicator,(uint8_t)gps.latitude,(gps.latitude - 1.0*(uint8_t)gps.latitude)*60);
693 gotoxy(1,5);
694 //gps.longitude = 48.25;
695 fprintf(&mystdout2,"%c %3d%.4f'",gps.we_indicator,(uint8_t)gps.longitude,(gps.longitude - 1.0*(uint8_t)gps.longitude)*60);
696 lcd_refresh();
697 }
698 }
699  
700 void displ_speed(void)
701 {
1220 mija 702 switch(test_key())
703 {
704 case KEY1_LONG: timer_refresh = 0;if (LED_INPUT) LED_OFF;else LED_ON;break;
705 case KEY2_LONG: id_mod=ID_OFF;return;
706 case KEY3_LONG: return;
707 case KEY1_SHORT:timer_refresh = 0;++id_mod;return;
708 case KEY2_SHORT:
709 case KEY3_SHORT:break;
710 }
711  
1213 mija 712 if (!timer_refresh)
713 {
714 timer_refresh = CLOCK1S;
715 buffer_clr();
716 status();
717 gotoxy(1,2);
718 printf("speed");
719 gotoxy(1,4);
720 fprintf(&mystdout2," %3.1f km/h",gps.speed);
721 lcd_refresh();
722 }
723 }
724  
725 void displ_course(void)
726 {
1220 mija 727 switch(test_key())
728 {
729 case KEY1_LONG: timer_refresh = 0;if (LED_INPUT) LED_OFF;else LED_ON;break;
730 case KEY2_LONG: id_mod=ID_OFF;return;
731 case KEY3_LONG: return;
732 case KEY1_SHORT:timer_refresh = 0;++id_mod;return;
733 case KEY2_SHORT:
734 case KEY3_SHORT:break;
735 }
736  
1213 mija 737 if (!timer_refresh)
738 {
739 timer_refresh = CLOCK1S;
740 buffer_clr();
741 status();
742 //gotoxy(1,2);
743 //printf("course");
744 gotoxy(1,3);
745 fprintf(&mystdout2," %3.1f km/h",gps.speed);
746 gotoxy(6,5);
747 fprintf(&mystdout2,"%3.0f",gps.course);
748 lcd_refresh();
749 }
750 }
751  
752 void displ_satelites(void)
753 {
754 #define WIDTH_REC 60
755  
756 uint8_t a,x,y,b;
757 static uint8_t d = 0;
758 static uint8_t c = 0;
759 double elevace,azimut;
760  
1220 mija 761 switch(test_key())
762 {
763 case KEY1_LONG:if (LED_INPUT) LED_OFF;else LED_ON;break;
764 case KEY2_LONG: c=0;id_mod=ID_OFF;return;
765 case KEY3_LONG: c=0;return;
766 case KEY1_SHORT:c=0;timer_refresh = 0;++id_mod;return;
767 case KEY2_SHORT:c=0;d++;timer_refresh = 0;break;
768 case KEY3_SHORT: break;
769 }
770  
1213 mija 771 if (!timer_refresh)
772 {
773 timer_refresh = CLOCK1S;
774 if (c--) return;
1220 mija 775 c=5;
1213 mija 776 buffer_clr();
777 //status();
778 #ifdef DEBUG
779 if(gps.gsv_satelites_view > 12)
780 {
781 printf("error view satelites");
782 lcd_refresh();
1220 mija 783 c=5;
1213 mija 784 return;
785 }
786 #endif
1220 mija 787 if (d >= gps.gsv_satelites_view) d = 0;
1213 mija 788 gotoxy(12,1);
789 printf("%d",gps.gsv_satelites_view);
790 gotoxy(12,2);
791 printf("%d",gps.satelit_detail[d].id);
792 gotoxy(12,3);
793 printf("%d",gps.satelit_detail[d].azimut);
794 gotoxy(12,4);
795 printf("%d",gps.satelit_detail[d].elevation);
796 gotoxy(12,5);
797 printf("%d",gps.satelit_detail[d].SNR);
798 gotoxy(12,6);
799  
800 for (a=0;a<gps.gsv_satelites_view;a++)
801 {
802 azimut = (double)gps.satelit_detail[a].azimut;
803 elevace = (double)gps.satelit_detail[a].elevation;
804  
805 x=(uint8_t)((WIDTH_REC-4)/2.0/90.0*(90.0-elevace)*sin(M_PI/180*azimut) + WIDTH_REC/2.0);
806 y=(uint8_t)((LCD_HEIGHT-4)/2.0/90.0*(90.0-elevace)*cos(M_PI/180*azimut) + LCD_HEIGHT/2.0);
807 if (gps.satelit_detail[a].SNR)
808 {
809 lcd_plot(x-1,y);lcd_plot(x+1,y);lcd_plot(x,y-1);lcd_plot(x,y+1);
810 for (b=0;b<gps.satelites_used;b++)
811 if (gps.satelit_detail[a].id == gps.satelite_id[b])
812 lcd_plot(x,y);
813 }
814 else lcd_plot(x,y);
815  
816 if (d == a)
817 {
818 lcd_line(x-2,y-2,x-2,y+2);
819 lcd_line(x+2,y+2,x+2,y-2);
820 lcd_line(x+2,y+2,x-2,y+2);
821 lcd_line(x-2,y-2,x+2,y-2);
822 }
823 }
824  
825 lcd_line(0,0,WIDTH_REC,0);
826 lcd_line(0,LCD_HEIGHT-1,WIDTH_REC,LCD_HEIGHT-1);
827 lcd_line(0,0,0,LCD_HEIGHT-1);
828 lcd_line(WIDTH_REC,0,WIDTH_REC,LCD_HEIGHT-1);
829  
830 lcd_refresh();
831 }
832 }
833  
834 void displ_all_position()
835 {
1220 mija 836  
837 switch(test_key())
838 {
839 case KEY1_LONG: timer_refresh = 0;if (LED_INPUT) LED_OFF;else LED_ON;break;
840 case KEY2_LONG: id_mod=ID_OFF;return;
841 case KEY3_LONG: return;
842 case KEY1_SHORT:timer_refresh = 0;++id_mod;return;
843 case KEY2_SHORT:
844 case KEY3_SHORT:break;
845 }
846  
1213 mija 847 if (!timer_refresh)
848 {
849 timer_refresh = CLOCK1S;
850 buffer_clr();
851 status();
852  
853 gotoxy(1,2);
854 printf("%c %3d%.4f'",gps.ns_indicator,(uint8_t)gps.latitude,(gps.latitude - 1.0*(uint8_t)gps.latitude)*60);
855 gotoxy(1,3);
856 printf("%c %3d%.4f'",gps.we_indicator,(uint8_t)gps.longitude,(gps.longitude - 1.0*(uint8_t)gps.longitude)*60);
857 gotoxy(1,4);
858 printf("alt%4.0fm V%2.1f",gps.altitude,gps.VDOP);
859 gotoxy(1,5);
1217 mija 860 printf("geo%4.1fm H%2.1f",gps.geoid,gps.HDOP);
1213 mija 861 gotoxy(1,6);
862 printf("%3.0fkm/h %3.0f",gps.speed,gps.course);
863 lcd_refresh();
864 }
865 }
866  
867 void displ_nav(void)
868 {
1217 mija 869  
1213 mija 870 double lon,lat,temp;
871 double course;
872 uint8_t x,y,xl,yl,xp,yp;
1217 mija 873 uint8_t a,b;
874 uint8_t *ptr;
1213 mija 875  
1220 mija 876 switch(test_key())
877 {
878 case KEY1_LONG: timer_refresh = 0;if (LED_INPUT) LED_OFF;else LED_ON;break;
879 case KEY2_LONG: id_mod=ID_OFF;return;
880 case KEY3_LONG: return;
881 case KEY1_SHORT:timer_refresh = 0;++id_mod;return;
882 case KEY2_SHORT:
883 case KEY3_SHORT:break;
884 }
885  
1213 mija 886 if (!timer_refresh)
887 {
888 timer_refresh = CLOCK1S;
889 buffer_clr();
890 status();
891  
1220 mija 892 const float gc_lat= MY_LAT,gc_lon=MY_LON; // DOMA
1213 mija 893  
894 lon=(gc_lon-gps.longitude*60)*1214;
895 lat=(gc_lat-gps.latitude*60)*1854;
896 temp = sqrt((lon*lon) + (lat*lat));
897  
898 gotoxy(9,3);
1217 mija 899 offset_text -=2;
900 ptr= CHAR_SIGNALL_3D;b=WIDTH_CHAR_SIGNALL_3D;
901 for (a=0;a<b;a++) *(offset_text++) =pgm_read_byte(ptr++);
902 //offset_text++;
903  
904 //gotoxy(10,3);
905 printf("%4.0fm",gps.altitude);
906  
907 gotoxy(7,2);
1361 mija 908 printf(POINTNAME);
1217 mija 909  
910 gotoxy(9,4);
1213 mija 911 if (temp < 10000)
912 {
913 if (temp<1000) fprintf(&mystdout2,"%.1f ",temp);
914 else
915 {
916 fprintf(&mystdout2,"%.3f ",temp/1000);
1217 mija 917 gotoxy(12,6);
1213 mija 918 printf("k");
919 }
1217 mija 920 gotoxy(13,6);
1213 mija 921 printf("m");
922 }
923 else
924 {
925 temp=temp/1000;
926 if (temp < 1000)
927 {
928 if (temp < 100)
929 {
930 fprintf(&mystdout2,"%.2f ",temp);
931 }
932 else
933 {
934 fprintf(&mystdout2,"%.1f ",temp);
935 }
936 }
937 else fprintf(&mystdout2,"%5.0f ",temp);
1217 mija 938 gotoxy(12,6);
1213 mija 939 printf("km");
940 }
941  
942 if (lat==0) lat=0.001;
943 lon=M_PI/2.0-(atan2(lat,lon));
944 if (lon<0) lon+=2*M_PI;
945 if (lon>(2*M_PI)) lon-=2*M_PI;
946 //printf(lcd_putc,"BE%2.0g*",lon);
947 lat=M_PI/180*gps.course;
948 lon=lon-lat;
949 if (lon<0) lon+=2*M_PI;
950 if (lon>2*M_PI) lon-=2*M_PI;
951 //printf(lcd_putc,"HE%2.0g*AZ%2.0g* ",lon,lat);
952  
953 #define WIDTH_REC_NAV 43
954 #define LCD_HEIGHT_NAV 35
955  
956 course = lon;
957 x=(uint8_t)(WIDTH_REC_NAV/2.0*sin(course) +WIDTH_REC_NAV/2);
958 y=(uint8_t)((LCD_HEIGHT_NAV)/2.0*cos(course) +(LCD_HEIGHT_NAV)/2);
959  
960 xl=(uint8_t)(WIDTH_REC_NAV/2.0*sin((course-2.62))+WIDTH_REC_NAV/2 );
961 yl=(uint8_t)((LCD_HEIGHT_NAV)/2.0*cos((course-2.62))+(LCD_HEIGHT_NAV)/2 );
962  
963 xp=(uint8_t)(WIDTH_REC_NAV/2.0*sin((course+2.62))+WIDTH_REC_NAV/2 );
964 yp=(uint8_t)((LCD_HEIGHT_NAV)/2.0*cos((course+2.62)) +(LCD_HEIGHT_NAV)/2);
965  
966 //xs=(uint8_t)((WIDTH_REC_NORTH-26)/2.0*sin(M_PI/180*(course+180.0))+WIDTH_REC_NORTH/2 );
967 //ys=(uint8_t)(((LCD_HEIGHT_NORTH-20))/2.0*cos(M_PI/180*(course+180.0)) +(LCD_HEIGHT_NORTH)/2);
968  
969 lcd_line( x,y,xl,yl);
970 lcd_line( x,y,xp,yp);
971 //lcd_line( xp,yp,xl,yl);
972 lcd_line(xl,yl,WIDTH_REC_NAV/2,(LCD_HEIGHT_NAV)/2);
973 lcd_line(xp,yp,WIDTH_REC_NAV/2,(LCD_HEIGHT_NAV)/2);
974  
975 //lcd_line(xl,yl,xs,ys);
976 //lcd_line(xp,yp,xs,ys);
977 lcd_refresh();
978 }
979 }
980  
981 void displ_service(char *buf)
982 {
983 uint8_t a;
1220 mija 984  
985 switch(test_key())
986 {
987 case KEY1_LONG: timer_refresh = 0;if (LED_INPUT) LED_OFF;else LED_ON;break;
988 case KEY2_LONG: id_mod=ID_OFF;return;
989 case KEY3_LONG: return;
990 case KEY1_SHORT:timer_refresh = 0;++id_mod;return;
991 case KEY2_SHORT:
992 case KEY3_SHORT:break;
993 }
994  
1213 mija 995 if (!timer_refresh)
996 {
997 timer_refresh = CLOCK1S;
998 buffer_clr();
999 for (a = 0; a<80; a++) putchar(*(buf++));
1000 lcd_refresh();
1001 }
1002 }
1003  
1004 void displ_north(void)
1005 {
1217 mija 1006 uint8_t a,b;
1007 uint8_t *ptr;
1213 mija 1008 uint8_t x,y;
1009 uint8_t xp,yp;
1010 uint8_t xl,yl;
1011 //uint8_t xs,ys;
1012 double course;
1013  
1220 mija 1014 switch(test_key())
1015 {
1016 case KEY1_LONG: timer_refresh = 0;if (LED_INPUT) LED_OFF;else LED_ON;break;
1017 case KEY2_LONG: id_mod=ID_OFF;return;
1018 case KEY3_LONG: return;
1019 case KEY1_SHORT:timer_refresh = 0;++id_mod;return;
1020 case KEY2_SHORT:
1021 case KEY3_SHORT:break;
1022 }
1023  
1213 mija 1024 if (!timer_refresh)
1025 {
1026 timer_refresh = CLOCK1S;
1027 buffer_clr();
1028 status();
1217 mija 1029  
1213 mija 1030 gotoxy(9,3);
1217 mija 1031 offset_text -=2;
1032 ptr= CHAR_SIGNALL_3D;b=WIDTH_CHAR_SIGNALL_3D;//offset_text++;
1033 for (a=0;a<b;a++) *(offset_text++) =pgm_read_byte(ptr++);
1034  
1035 //gotoxy(10,3);
1036 printf("%4.0fm",gps.altitude);
1037  
1038 gotoxy(9,2);
1039 printf("north");
1040  
1041 gotoxy(9,4);
1213 mija 1042 fprintf(&mystdout2,"%3.1f",gps.speed);
1217 mija 1043 gotoxy(10,6);
1213 mija 1044 printf("km/h");
1045  
1046 #define WIDTH_REC_NORTH 43
1047 #define LCD_HEIGHT_NORTH 35
1048  
1049 course = 360-gps.course;
1050 x=(uint8_t)(WIDTH_REC_NORTH/2.0*sin(M_PI/180*course) +WIDTH_REC_NORTH/2);
1051 y=(uint8_t)((LCD_HEIGHT_NORTH)/2.0*cos(M_PI/180*course) +(LCD_HEIGHT_NORTH)/2);
1052  
1053 xl=(uint8_t)(WIDTH_REC_NORTH/2.0*sin(M_PI/180*(course-150.0))+WIDTH_REC_NORTH/2 );
1054 yl=(uint8_t)((LCD_HEIGHT_NORTH)/2.0*cos(M_PI/180*(course-150.0))+(LCD_HEIGHT_NORTH)/2 );
1055  
1056 xp=(uint8_t)(WIDTH_REC_NORTH/2.0*sin(M_PI/180*(course+150.0))+WIDTH_REC_NORTH/2 );
1057 yp=(uint8_t)((LCD_HEIGHT_NORTH)/2.0*cos(M_PI/180*(course+150.0)) +(LCD_HEIGHT_NORTH)/2);
1058  
1059 //xs=(uint8_t)((WIDTH_REC_NORTH-26)/2.0*sin(M_PI/180*(course+180.0))+WIDTH_REC_NORTH/2 );
1060 //ys=(uint8_t)(((LCD_HEIGHT_NORTH-20))/2.0*cos(M_PI/180*(course+180.0)) +(LCD_HEIGHT_NORTH)/2);
1061  
1062 lcd_line( x,y,xl,yl);
1063 lcd_line( x,y,xp,yp);
1064 //lcd_line( xp,yp,xl,yl);
1065 lcd_line(xl,yl,WIDTH_REC_NORTH/2,(LCD_HEIGHT_NORTH)/2);
1066 lcd_line(xp,yp,WIDTH_REC_NORTH/2,(LCD_HEIGHT_NORTH)/2);
1067  
1068 //lcd_line(xl,yl,xs,ys);
1069 //lcd_line(xp,yp,xs,ys);
1070 lcd_refresh();
1071 }
1072 }
1073  
1074 void displ_all_service(void)
1075 {
1076 uint8_t a;
1077  
1220 mija 1078 switch(test_key())
1079 {
1080 case KEY1_LONG: timer_refresh = 0;if (LED_INPUT) LED_OFF;else LED_ON;break;
1081 case KEY2_LONG: id_mod=ID_OFF;return;
1082 case KEY3_LONG: return;
1083 case KEY1_SHORT:timer_refresh = 0;++id_mod;return;
1084 case KEY2_SHORT:
1085 case KEY3_SHORT:break;
1086 }
1087  
1213 mija 1088 if (!timer_refresh)
1089 {
1090 timer_refresh = CLOCK1S;
1091 buffer_clr();
1092 status();
1093  
1094 gotoxy(1,2);
1095 printf("d=%d %ds",gps.diff_id,gps.age_diff_corr);
1096 gotoxy(1,3);
1097 printf("%c st=%cD ",gps.mode1,gps.mode2);
1098 switch (gps.fix_position)
1099 {
1100 case 0: printf("nofix");break;
1101 case 1: printf("SPSfix");break;
1102 case 2: printf(" Dfix");break;
1103 default: printf("nopref");
1104 }
1105 gotoxy(1,4);
1106 printf("GSV %d %d %d",gps.gsv_num_msg,gps.gsv_msg,gps.gsv_satelites_view);
1107 gotoxy(1,5);
1108 for(a=0;a<6;a++)
1109 {
1110 printf("%2d",gps.satelite_id[a]);
1111 offset_text+=2;
1112 }
1113 gotoxy(1,6);
1114 for(a=6;a<12;a++)
1115 {
1116 printf("%2d",gps.satelite_id[a]);
1117 if (a != 11) offset_text+=2;
1118 }
1119 lcd_refresh();
1120 }
1121 }
1122  
1220 mija 1123 void temp(void)
1213 mija 1124 {
1220 mija 1125 timer_temp = TEMP_TIME_REPEAT;
1213 mija 1126 now.temperature=read_temp();
1127 now.time=actual_time();
1128 now.date=actual_date();
1129  
1130 buffer_clr();
1131 gotoxy(1,1);
1132 stdout = &mystdout2;
1133 print_temp(now.temperature);
1134 stdout = &mystdout;
1135 gotoxy(11,1);
1136 offset_text-= 2;
1137 print_time(now.time);
1138 gotoxy(11,2);
1139 offset_text-= 2;
1140 print_date(now.date);
1141 gotoxy(1,4);
1142 if (now.temperature > max.temperature) max=now;
1143 print_temp(max.temperature);
1144 gotoxy(11,4);
1145 offset_text-= 2;
1146 print_date(max.date);
1147 gotoxy(6,3);
1148 printf("max");
1149 gotoxy(11,3);
1150 offset_text-= 2;
1151 print_time(max.time);
1152 gotoxy(1,6);
1153 if (now.temperature < min.temperature) min=now;
1154 print_temp(min.temperature);
1155 gotoxy(11,6);
1156 offset_text-= 2;
1157 print_date(min.date);
1158 gotoxy(6,5);
1159 printf("min");
1160 gotoxy(11,5);
1161 offset_text-= 2;
1162 print_time(min.time);
1163 lcd_refresh();
1164 start_MCP9800();
1220 mija 1165 }
1166  
1167 void displ_temp()
1168 {
1169 //GPS_OFF;
1170 //ADC_OFF;
1171 //REF_OFF;
1172  
1173 switch(test_key())
1174 {
1175 case KEY1_LONG: timer_refresh = 0;if (LED_INPUT) LED_OFF;else LED_ON;break;
1176 case KEY2_LONG: id_mod=ID_OFF;return;
1177 case KEY3_LONG: return;
1178 case KEY1_SHORT:timer_refresh = 0;id_mod++;return;
1179 case KEY2_SHORT:timer_temp = 0; max.temperature=0x8000;min.temperature=0x7FFF;
1180 if (GPS_INPUT && (gps.status == 'A'))
1181 {
1182 sRTC=gps.second;
1183 mRTC=gps.minute;
1184 hRTC=gps.hour+2;
1185  
1186 dRTC=gps.day;
1187 mdRTC=gps.month;
1188 yRTC=gps.year;
1189 }break;
1190 case KEY3_SHORT: break;
1191 }
1192  
1193 if(!timer_temp)
1194 {
1195 temp();
1213 mija 1196 }
1197 }
1198  
1220 mija 1199  
1213 mija 1200 void displ_start(void)
1201 {
1202 buffer_clr();
1203 gotoxy(6,3);
1204 fprintf(&mystdout2,"GPS");
1205 lcd_refresh();
1206 delay_ms(1000);
1207 id_mod = ID_TEMP;
1208 }
1209  
1210 void all_off(void)
1211 {
1220 mija 1212 uint8_t temp_wiev;
1213  
1213 mija 1214 buffer_clr();
1215 gotoxy(6,3);
1216 fprintf(&mystdout2,"OFF");
1217 lcd_refresh();
1218 GPS_OFF;
1219 REF_OFF;
1220 mija 1220 ADC_OFF;
1361 mija 1221 USART_PC_OFF;
1217 mija 1222 delay_ms(1000);
1223 LED_OFF;
1213 mija 1224 N5110_send_command(POWER_DOWN);
1225  
1220 mija 1226 temp_wiev = 0;
1213 mija 1227 while (TL2_INPUT)
1217 mija 1228 {
1229 sleep_cpu();
1220 mija 1230 if (!TL1_INPUT)
1231 {
1232 if (!temp_wiev) N5110_send_command(ACTIVE_CHIP);
1233 temp_wiev = 1;
1234 timer1_ovf = 0;
1235 while ((!TL1_INPUT) && (timer1_ovf<200));
1236 if (timer1_ovf==200)
1237 {
1238 max.temperature=0x8000;
1239 min.temperature=0x7FFF;
1240 }
1241 }
1242 if (!TL3_INPUT) {N5110_send_command(POWER_DOWN);temp_wiev = 0;}
1243 if (temp_wiev) temp();
1213 mija 1244  
1217 mija 1245 }
1361 mija 1246  
1247 if (USB_PIN) USART_PC_ON;
1248 else USART_PC_OFF;
1249  
1217 mija 1250 null_variables();
1213 mija 1251 LCD_N5110_INIT();
1217 mija 1252 displ_start();
1213 mija 1253 }
1254  
1255 //************************************************************************
1256 // spol key
1257  
1258 uint8_t key(uint8_t mod)
1259 {
1260 if(key_press)
1261 {
1262 if (!timer_off)
1263 {
1264 if (key_read() == _BV(KEY2))
1265 {
1266 timer_refresh = 0;
1267 timer_key = CLOCK2S;
1268 key_read();
1269 return ID_OFF;
1270 }
1271 }
1272 }
1273 else
1274 {
1275 if (key_flag == _BV(KEY1))
1276 {
1277 timer_key = KEY_TIME_FIRST;
1278 key_read();
1279 timer_refresh = 0;
1280 ++mod;
1281 }
1282 if (key_flag == _BV(KEY2))
1283 {
1284 if (LED_INPUT) LED_OFF;
1285 else LED_ON;
1286 timer_key = KEY_TIME_FIRST;
1287 key_read();
1288 }
1289 if (key_flag == _BV(KEY3))
1290 {
1291 max.temperature=0x8000;
1292 min.temperature=0x7FFF;
1293 if (GPS_INPUT && (gps.status == 'A'))
1294 {
1295 sRTC=gps.second;
1296 mRTC=gps.minute;
1297 hRTC=gps.hour+2;
1298  
1299 dRTC=gps.day;
1300 mdRTC=gps.month;
1301 yRTC=gps.year;
1302 }
1303  
1304 timer_key = KEY_TIME_FIRST;
1305 key_read();
1306 }
1307 }
1308 return mod;
1309 }
1310  
1217 mija 1311 void null_variables(void)
1312 {
1313 key_press = 0;
1314 key_flag = 0;
1315  
1316 timer_key = 0;
1317 timer_temp = 0;
1318 timer_off = OFF_TIME;
1319 timer_refresh = 0;
1320 timer_status = 0;
1321 timer1_ovf =0;
1322  
1323 //max.temperature=0x8000;
1324 //min.temperature=0x7FFF;
1325  
1326 //sRTC=0;
1327 //mRTC=15;
1328 //hRTC=17;
1329  
1330 //dRTC=25;
1331 //mdRTC=7;
1332 //yRTC=8;
1333  
1334 id_mod = ID_START;
1335 }
1336  
1213 mija 1337 //************************************************************************
1338 // main
1339  
1340 int main(void)
1217 mija 1341 {
1213 mija 1342  
1343 pgps = &gps;
1344  
1217 mija 1345 null_variables();
1346  
1213 mija 1347 general_cpu_init();
1348 //GPS_ON;
1349 LCD_N5110_INIT();
1350  
1351 //set_static_navigation(0);
1361 mija 1352 if (USB_PIN) USART_PC_ON;
1353 else USART_PC_OFF;
1213 mija 1354 stdout = &mystdout;
1355 sei();
1356  
1357 for (;;)
1358 {
1359 switch(id_mod)
1360 {
1217 mija 1361 case ID_TIME: displ_time(); break;
1362 case ID_LOCATION: displ_location();break;
1213 mija 1363 //case ID_SPEED: displ_speed(); break;
1217 mija 1364 case ID_SATELITES: displ_satelites();break;
1365 case ID_COURSE: id_mod++;break;displ_course(); break;
1366 case ID_ALL_POSITION: displ_all_position(); break;
1367 case ID_ALL_SERVICE: id_mod++;break;displ_all_service();break;
1368 case ID_SERVICE: id_mod++;break;displ_service(scan_buf);break;
1369 case ID_TEMP: displ_temp(); break;
1370 case ID_OFF: all_off(); break;
1371 case ID_START: displ_start(); break;
1213 mija 1372 case ID_NAV: displ_nav();break;
1217 mija 1373 case ID_NORTH: displ_north();break;
1213 mija 1374 default : id_mod = 0;
1375 }
1376  
1377  
1378 switch (load_nmea(rx_shift,rx_buf,scan_buf))
1379 {
1380 case RETURN_GGA: nmea_gga(scan_buf,pgps);break;
1381 case RETURN_GSA: nmea_gsa(scan_buf,pgps);break;
1382 case RETURN_GSV: nmea_gsv(scan_buf,pgps);break;
1383 case RETURN_RMC: nmea_rmc(scan_buf,pgps);break;
1384 case RETURN_VTG: nmea_vtg(scan_buf,pgps);break;
1385 }
1217 mija 1386  
1387 timer1_tik();
1388  
1220 mija 1389 //id_mod = key(id_mod);
1217 mija 1390  
1213 mija 1391 }
1392 return 0;
1393 }
1394