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