933 |
kakl |
1 |
#include "gps.h" |
|
|
2 |
|
|
|
3 |
#include <math.h> |
|
|
4 |
#include <stdlib.h> |
|
|
5 |
#include <stdlibm.h> |
|
|
6 |
//#include <string.h> |
|
|
7 |
|
|
|
8 |
#define LCD_RS PIN_B1 // rizeni registru LCD displeje |
|
|
9 |
#define LCD_E PIN_B0 // enable LCD displeje |
|
|
10 |
#define LCD_DATA_LSB PIN_B4 // pripojeni LSB bitu datoveho portu LCD displeje |
|
|
11 |
#include "MYLCD.C" |
|
|
12 |
|
|
|
13 |
// NMEA |
|
|
14 |
#define TIME 6 |
|
|
15 |
#define TIME_LEN 10 |
|
|
16 |
#define LATDEG 19 |
|
|
17 |
#define LATMIN 21 |
|
|
18 |
#define LONDEG 32 |
|
|
19 |
#define LONMIN 34 |
|
|
20 |
#define DEG_LEN 2 |
|
|
21 |
#define MIN_LEN 7 |
|
|
22 |
#define AZIMUTH 46 |
|
|
23 |
|
|
|
24 |
float lat,lon; |
|
|
25 |
int16 az; |
|
|
26 |
|
|
|
27 |
inline void read_NMEA() |
|
|
28 |
{ |
|
|
29 |
// auto char line[70]; |
|
|
30 |
auto char item[16]; |
|
|
31 |
char *ptr,*line; |
|
|
32 |
auto int8 n; |
|
|
33 |
auto char c; |
|
|
34 |
|
|
|
35 |
line=malloc(72); |
|
|
36 |
if (line==NULL) {printf(lcd_putc,"Error"); sleep();}; |
|
|
37 |
line[71]=0; |
|
|
38 |
|
|
|
39 |
while(fgetc(NMEA)!='$'); |
|
|
40 |
for(n=0;n<71;n++) |
|
|
41 |
{ |
|
|
42 |
c=fgetc(NMEA); |
|
|
43 |
if(c=='*') |
|
|
44 |
{ |
|
|
45 |
line[n]=0; |
|
|
46 |
break; |
|
|
47 |
}; |
|
|
48 |
line[n]=c; |
|
|
49 |
}; |
|
|
50 |
|
|
|
51 |
lcd_gotoxy(12,4); |
|
|
52 |
printf(lcd_putc,"%c %06.0g ",line[17],strtod(&line[TIME],&ptr)); |
|
|
53 |
|
|
|
54 |
lcd_gotoxy(1,3); |
|
|
55 |
strncpy(item,&line[LATDEG],DEG_LEN+MIN_LEN); item[DEG_LEN+MIN_LEN]=0; |
|
|
56 |
printf(lcd_putc,"%s*",item); |
|
|
57 |
strncpy(item,&line[LONDEG],DEG_LEN+MIN_LEN); item[DEG_LEN+MIN_LEN]=0; |
|
|
58 |
printf(lcd_putc,"%s*",item); |
|
|
59 |
lcd_gotoxy(1,4); |
|
|
60 |
// strncpy(item,&line[AZIMUTH],6); item[6]=0; |
|
|
61 |
// printf(lcd_putc,"%s*",item); |
|
|
62 |
|
|
|
63 |
lcd_gotoxy(1,2); |
|
|
64 |
lat=strtod(&line[LATMIN],&ptr); |
|
|
65 |
line[LATMIN]=0; |
|
|
66 |
lat+=60*strtod(&line[LATDEG],&ptr); |
|
|
67 |
lon=strtod(&line[LONMIN],&ptr); |
|
|
68 |
line[LONMIN]=0; |
|
|
69 |
lon+=60*strtod(&line[LONDEG],&ptr); |
|
|
70 |
strtod(&line[AZIMUTH],&ptr); |
|
|
71 |
az=strtoul(ptr+1,&ptr,10); |
|
|
72 |
printf(lcd_putc,"%.3g*%.3g*%03Lu",lat,lon,az); |
|
|
73 |
free(line); |
|
|
74 |
} |
|
|
75 |
|
|
|
76 |
void main() |
|
|
77 |
{ |
|
|
78 |
|
|
|
79 |
setup_adc_ports(NO_ANALOGS); |
|
|
80 |
setup_adc(ADC_OFF); |
|
|
81 |
setup_spi(FALSE); |
|
|
82 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
83 |
setup_timer_1(T1_DISABLED); |
|
|
84 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
85 |
setup_comparator(NC_NC_NC_NC); |
|
|
86 |
setup_vref(VREF_LOW|-2); |
|
|
87 |
lcd_init(); |
|
|
88 |
|
|
|
89 |
// gets(line,NMEA); // Dummy read form the GPS |
|
|
90 |
|
|
|
91 |
|
|
|
92 |
while(TRUE) |
|
|
93 |
{ |
|
|
94 |
const float gc_lat=49*60+15.574,gc_lon=14*60+42.331; // Cisticka |
|
|
95 |
|
|
|
96 |
read_NMEA(); |
|
|
97 |
|
|
|
98 |
lon=(gc_lon-lon)*1214; |
|
|
99 |
lat=(gc_lat-lat)*1854; |
|
|
100 |
|
|
|
101 |
lcd_gotoxy(1,4); |
|
|
102 |
printf(lcd_putc,"%.0g* ",sqrt((lon*lon) + (lat*lat))); |
|
|
103 |
lcd_gotoxy(1,1); |
|
|
104 |
if (lat==0) lat=0.001; |
|
|
105 |
lon=3-(6/PI*atan2(lat,lon)); |
|
|
106 |
if (lon<0) lon+=12; |
|
|
107 |
if (lon>12) lon-=12; |
|
|
108 |
printf(lcd_putc,"BE%2.0g*",lon); |
|
|
109 |
lat=12.0/360*az; |
|
|
110 |
lon=lon-lat; |
|
|
111 |
if (lon<0) lon+=12; |
|
|
112 |
if (lon>12) lon-=12; |
|
|
113 |
printf(lcd_putc,"HE%2.0g*AZ%2.0g* ",lon,lat); |
|
|
114 |
} |
|
|
115 |
|
|
|
116 |
} |