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