1026 |
mija |
1 |
//***************************************************************************** |
|
|
2 |
//*** GPS CZ,no terminal,no time,no position,no math atan2,no save |
|
|
3 |
//*** yes - arrow, distanc, load GCPOINT from PC |
|
|
4 |
|
|
|
5 |
#include "GPS_LCD_876_A2.h" |
|
|
6 |
#include <math.h> |
|
|
7 |
#include <stdlib.h> |
|
|
8 |
|
|
|
9 |
//***************************************************************************** |
|
|
10 |
//*** defines *** |
|
|
11 |
|
|
|
12 |
#define LCD_CS PIN_B0 |
|
|
13 |
#define LCD_DATA PIN_B1 |
|
|
14 |
#define LCD_CLK PIN_B2 |
|
|
15 |
#define LCD_A0 PIN_B3 |
|
|
16 |
#define LCD_RESET PIN_B4 |
|
|
17 |
#include "LCD_ALCATEL.C" |
|
|
18 |
|
|
|
19 |
#define ARROW_UR 0x1 |
|
|
20 |
#define ARROW_UL 0x0 |
|
|
21 |
#define ARROWR "\xf\x3\x5\x9\x10\x10\x10" |
|
|
22 |
#define ARROWL "\x1e\x18\x14\x12\x1\x1\x1" |
|
|
23 |
|
|
|
24 |
#define TAN22 0.4142 |
|
|
25 |
#define TAN67 2.4241 |
|
|
26 |
|
|
|
27 |
#define MAX_GC_POINT 2 |
|
|
28 |
|
|
|
29 |
//***************************************************************************** |
|
|
30 |
//*** functions *** |
|
|
31 |
|
|
|
32 |
void NMEA_part_scan(int8 *point); |
|
|
33 |
void NMEA_GPRMC(void); |
|
|
34 |
void read_ee_gc(int8 numgc); |
|
|
35 |
int8 atan2_my(float x,float y); |
|
|
36 |
void calc_distanc_azimut(void); |
|
|
37 |
void PC_part_scan(int8 *point); |
|
|
38 |
void terminal(void); |
|
|
39 |
void main(void); |
|
|
40 |
|
|
|
41 |
//***************************************************************************** |
|
|
42 |
//*** global variables *** |
|
|
43 |
|
|
|
44 |
int8 sel; |
|
|
45 |
int8 azimut; |
|
|
46 |
float lon,lat; |
|
|
47 |
float gc_lon,gc_lat; |
|
|
48 |
int8 la[10]; |
|
|
49 |
int8 lo[11]; |
|
|
50 |
|
|
|
51 |
//***************************************************************************** |
|
|
52 |
|
|
|
53 |
void NMEA_part_scan(int8 *point) |
|
|
54 |
{ |
|
|
55 |
int8 a; |
|
|
56 |
a=0; |
|
|
57 |
while (a!=',') {a=fgetc(GPS);*(point++)=a;} |
|
|
58 |
*(--point)=0x00; |
|
|
59 |
} |
|
|
60 |
|
|
|
61 |
//$GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598,,*10 |
|
|
62 |
void NMEA_GPRMC(void) |
|
|
63 |
{ |
|
|
64 |
int8 status; |
|
|
65 |
int8 n_s; |
|
|
66 |
int8 e_w; |
|
|
67 |
int8 course[7]; |
|
|
68 |
|
|
|
69 |
while (fgetc(GPS)!='$'); //$ |
|
|
70 |
while (fgetc(GPS)!=','); //GPRMC, |
|
|
71 |
while (fgetc(GPS)!=',');//NMEA_part_scan(&time[0]); //UTC, |
|
|
72 |
status=fgetc(GPS);fgetc(GPS); //status, |
|
|
73 |
NMEA_part_scan(&la[0]); //latitude, |
|
|
74 |
n_s=fgetc(GPS);fgetc(GPS); //N/S, |
|
|
75 |
NMEA_part_scan(&lo[0]); //longtitude, |
|
|
76 |
e_w=fgetc(GPS);fgetc(GPS); //E/W, |
|
|
77 |
while (fgetc(GPS)!=','); //NMEA_part_scan(&speed[0]); //speed, |
|
|
78 |
NMEA_part_scan(&course[0]);//while (fgetc(GPS)!=','); //course, |
|
|
79 |
//NMEA_part_scan(&date[0]); //date, |
|
|
80 |
|
|
|
81 |
LCD_gotoxy(8,1); |
|
|
82 |
LCD_putc(status); |
|
|
83 |
|
|
|
84 |
lat=600.0*(la[0]-0x30)+60.0*(la[1]-0x30)+atof(&la[2]); |
|
|
85 |
lon=600.0+60.0*(lo[2]-0x30)+atof(&lo[3]); |
|
|
86 |
azimut=atol(course)/360*8; |
|
|
87 |
} |
|
|
88 |
|
|
|
89 |
void read_ee_gc(int8 numgc) |
|
|
90 |
{ |
|
|
91 |
int8 a,b; |
|
|
92 |
int8 *point; |
|
|
93 |
|
|
|
94 |
a=(13*numgc) + 1; //5*char + 4byte float LAT + 4byte float LON |
|
|
95 |
LCD_gotoxy(1,1); |
|
|
96 |
LCD_putc('G');LCD_putc('P'); |
|
|
97 |
for(b=0;b<5;b++)LCD_putc(read_eeprom(a++)); |
|
|
98 |
point=&gc_lat; |
|
|
99 |
for (b=0;b<4;b++) *(point++)=read_eeprom(a++); |
|
|
100 |
point=&gc_lon; |
|
|
101 |
for (b=0;b<4;b++) *(point++)=read_eeprom(a++); |
|
|
102 |
} |
|
|
103 |
|
|
|
104 |
int8 atan2_my(float x,float y) |
|
|
105 |
{ |
|
|
106 |
float z; |
|
|
107 |
int8 arg; |
|
|
108 |
if (y==0) z=abs(x)/0.0001; |
|
|
109 |
else z=abs(x)/abs(y); |
|
|
110 |
if (z < TAN22) arg=0; |
|
|
111 |
else |
|
|
112 |
{ |
|
|
113 |
if (z < TAN67) arg=2; |
|
|
114 |
else arg=3; |
|
|
115 |
} |
|
|
116 |
if (x>=0 && y<=0) return (4-arg); |
|
|
117 |
if (x<0 && y<=0) return (4+arg); |
|
|
118 |
if (x<0 && y>0) return (8-arg); |
|
|
119 |
return arg; |
|
|
120 |
} |
|
|
121 |
|
|
|
122 |
void calc_distanc_azimut(void) |
|
|
123 |
{ |
|
|
124 |
lon=(gc_lon-lon)*1214; // metry (uhly v minutach) |
|
|
125 |
lat=(gc_lat-lat)*1854; // metry (uhly v minutach) |
|
|
126 |
|
|
|
127 |
lcd_gotoxy(3,2); |
|
|
128 |
printf(LCD_putc,"%5Lum",(int32) sqrt((lon*lon) + (lat*lat))); |
|
|
129 |
|
|
|
130 |
azimut=atan2_my(lon,lat)-azimut; |
|
|
131 |
if (azimut<0) azimut+=8; |
|
|
132 |
if (azimut>8) azimut-=8; |
|
|
133 |
|
|
|
134 |
lcd_gotoxy(1,2); |
|
|
135 |
switch (azimut) |
|
|
136 |
{ |
|
|
137 |
case 0: LCD_send_data(ASCII_ARROW_UP);break; |
|
|
138 |
case 1: LCD_send_data(ARROW_UR);break; |
|
|
139 |
case 2: LCD_send_data(ASCII_ARROW_R);break; |
|
|
140 |
case 7: LCD_send_data(ARROW_UL);break; |
|
|
141 |
case 6: LCD_send_data(ASCII_ARROW_L);break; |
|
|
142 |
default :LCD_send_data(ASCII_ARROW_DOWN); |
|
|
143 |
} |
|
|
144 |
} |
|
|
145 |
|
|
|
146 |
void PC_part_scan(int8 *point) |
|
|
147 |
{ |
|
|
148 |
int8 a; |
|
|
149 |
a=0; |
|
|
150 |
while (a!=',') {a=fgetc(PC); *(point++)=a;} |
|
|
151 |
*(--point)=0x00; |
|
|
152 |
} |
|
|
153 |
|
|
|
154 |
// line format: name,float,float, |
|
|
155 |
#INT_RDA |
|
|
156 |
void terminal(void) |
|
|
157 |
{ |
|
|
158 |
int8 a,b; |
|
|
159 |
int8 *point; |
|
|
160 |
char name[6]; |
|
|
161 |
restart_wdt(); |
|
|
162 |
PC_part_scan(name); |
|
|
163 |
PC_part_scan(la); |
|
|
164 |
PC_part_scan(lo); |
|
|
165 |
lat=60*atof(la); |
|
|
166 |
lon=60*atof(lo); |
|
|
167 |
a=read_eeprom(0); |
|
|
168 |
if (a > MAX_GC_POINT) a=0; |
|
|
169 |
write_eeprom(0,a+1); |
|
|
170 |
sel=a-1; |
|
|
171 |
a=(13*a)+1; |
|
|
172 |
for (b=0;b<5;b++) write_eeprom(a++,name[b]); |
|
|
173 |
point=⪫ |
|
|
174 |
for (b=0;b<4;b++) write_eeprom(a++,*(point+b)); |
|
|
175 |
point=&lon; |
|
|
176 |
for (b=0;b<4;b++) write_eeprom(a++,*(point+b)); |
|
|
177 |
} |
|
|
178 |
|
|
|
179 |
void main(void) |
|
|
180 |
{ |
|
|
181 |
setup_adc_ports(NO_ANALOGS); |
|
|
182 |
setup_adc(ADC_OFF); |
|
|
183 |
setup_spi(SPI_MASTER|SPI_L_TO_H|SPI_CLK_DIV_4); |
|
|
184 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
185 |
setup_timer_1(T1_DISABLED); |
|
|
186 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
187 |
setup_comparator(NC_NC_NC_NC); |
|
|
188 |
setup_vref(FALSE); |
|
|
189 |
setup_wdt(WDT_2304MS); |
|
|
190 |
|
|
|
191 |
enable_interrupts(INT_RDA); |
|
|
192 |
enable_interrupts(GLOBAL); |
|
|
193 |
|
|
|
194 |
output_low(LCD_RESET); |
|
|
195 |
output_high(LCD_CS); |
|
|
196 |
delay_ms(5); |
|
|
197 |
output_high(LCD_RESET); |
|
|
198 |
delay_ms(5); |
|
|
199 |
LCD_send_command(0x80); |
|
|
200 |
printf(LCD_send_data,ARROWL); |
|
|
201 |
LCD_send_command(0x88); |
|
|
202 |
printf(LCD_send_data,ARROWR); |
|
|
203 |
|
|
|
204 |
LCD_init(); |
|
|
205 |
LCD_cursor_off(); |
|
|
206 |
|
|
|
207 |
sel++; |
|
|
208 |
if (sel > MAX_GC_POINT) sel=0; |
|
|
209 |
read_ee_gc(sel); |
|
|
210 |
|
|
|
211 |
while (TRUE) |
|
|
212 |
{ |
|
|
213 |
restart_wdt(); |
|
|
214 |
NMEA_GPRMC(); |
|
|
215 |
calc_distanc_azimut(); |
|
|
216 |
} |
|
|
217 |
} |
|
|
218 |
|