1 |
/**** GPS skrysohledac ****/ |
1 |
/**** GPS skrysohledac ****/ |
2 |
#define ID "$Id: gps.c 984 2008-01-06 23:41:31Z kakl $" |
2 |
#define ID "$Id: gps.c 984 2008-01-06 23:41:31Z kakl $" |
3 |
|
3 |
|
4 |
#include "gpsrl.h" |
4 |
#include "gpsrl.h" |
5 |
|
5 |
|
6 |
#include <math.h> |
6 |
#include <math.h> |
7 |
#include <stdlib.h> |
7 |
#include <stdlib.h> |
8 |
#include <stdlibm.h> |
8 |
#include <stdlibm.h> |
9 |
|
9 |
|
10 |
#define SCINTILAK 1 //kanal adc pro scintilacni detektor NB3201 |
10 |
#define SCINTILAK 1 //kanal adc pro scintilacni detektor NB3201 |
11 |
#define RANGE PIN_A4 // vystup detektoru urcujici rozsah mereni. |
11 |
#define RANGE PIN_A4 // vystup detektoru urcujici rozsah mereni. |
12 |
|
12 |
|
13 |
|
13 |
|
14 |
#define LCD_RS PIN_B1 // LCD control |
14 |
#define LCD_RS PIN_B1 // LCD control |
15 |
#define LCD_E PIN_B2 // LCD enable |
15 |
#define LCD_E PIN_B2 // LCD enable |
16 |
#define LCD_DATA_LSB PIN_B4 // LSB data bit LCD |
16 |
#define LCD_DATA_LSB PIN_B4 // LSB data bit LCD |
17 |
#include "MYLCD.C" |
17 |
#include "MYLCD.C" |
18 |
|
18 |
|
19 |
#define TL1 PIN_C0 |
19 |
#define TL1 PIN_C0 |
20 |
#define TL2 PIN_C1 |
20 |
#define TL2 PIN_C1 |
21 |
#define TL3 PIN_C2 |
21 |
#define TL3 PIN_C2 |
22 |
|
22 |
|
23 |
// NMEA |
- |
|
24 |
#define TIME 6 // For NMEA parsing |
- |
|
25 |
#define TIME_LEN 10 |
- |
|
26 |
#define LATDEG 19 |
- |
|
27 |
#define LATMIN 21 |
- |
|
28 |
#define LONDEG 32 |
- |
|
29 |
#define LONMIN 34 |
- |
|
30 |
#define SAT 36 |
- |
|
31 |
#define DEG_LEN 2 |
- |
|
32 |
#define MIN_LEN 7 |
- |
|
33 |
#define AZIMUTH 46 |
- |
|
34 |
#define NMEA_LINESIZE 79 |
- |
|
35 |
|
- |
|
36 |
//$GPRMC,105815.503,V,4915.5877,N,01442.3896,E,0.0,0.00,060108,,,N*44 |
23 |
//$GPRMC,105815.503,V,4915.5877,N,01442.3896,E,0.0,0.00,060108,,,N*44 |
37 |
|
- |
|
- |
|
24 |
//$GPGGA,000415.000,4915.6225,N,01442.3608,E,1,03,50.0,409.6,M,45.2,M,0.0,0000*48 |
38 |
void main() |
25 |
void main() |
39 |
{ |
26 |
{ |
40 |
|
27 |
|
41 |
setup_adc_ports(AN0); |
28 |
setup_adc_ports(AN0); |
42 |
setup_adc(ADC_CLOCK_INTERNAL); |
29 |
setup_adc(ADC_CLOCK_INTERNAL); |
43 |
setup_spi(FALSE); |
30 |
setup_spi(FALSE); |
44 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
31 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
45 |
setup_timer_1(T1_DISABLED); |
32 |
setup_timer_1(T1_DISABLED); |
46 |
setup_timer_2(T2_DISABLED,0,1); |
33 |
setup_timer_2(T2_DISABLED,0,1); |
47 |
setup_comparator(NC_NC_NC_NC); |
34 |
setup_comparator(NC_NC_NC_NC); |
48 |
setup_vref(VREF_LOW|-2); |
35 |
setup_vref(VREF_LOW|-2); |
49 |
lcd_init(); |
36 |
lcd_init(); |
50 |
|
37 |
|
51 |
delay_ms(100); |
38 |
delay_ms(100); |
52 |
lcd_gotoxy(5,1); |
39 |
lcd_gotoxy(5,1); |
53 |
printf(lcd_putc,"GPSRL01B \n"); |
40 |
printf(lcd_putc,"GPSRL01B \n"); |
54 |
printf(lcd_putc,"(c) Kaklik 2008"); |
41 |
printf(lcd_putc,"(c) Kaklik 2008"); |
55 |
delay_ms(300); |
42 |
delay_ms(300); |
56 |
printf(lcd_putc,"\f"); |
43 |
printf(lcd_putc,"\f"); |
57 |
|
44 |
|
58 |
set_adc_channel(SCINTILAK); |
45 |
set_adc_channel(SCINTILAK); |
59 |
|
46 |
|
60 |
while(TRUE) |
47 |
while(TRUE) |
61 |
{ |
48 |
{ |
62 |
|
49 |
|
- |
|
50 |
|
63 |
auto char line[NMEA_LINESIZE]; |
51 |
char tab1[20]; |
64 |
char item[16]; |
52 |
char tab2[20]; |
- |
|
53 |
char tab3[20]; |
- |
|
54 |
char tab4[20]; |
65 |
char *ptr; |
55 |
char tab5[20]; |
- |
|
56 |
|
66 |
int8 n; |
57 |
int8 n; |
- |
|
58 |
int16 intensity; |
67 |
char c; |
59 |
char c; |
68 |
|
60 |
|
69 |
|
- |
|
- |
|
61 |
tab1[19]=0; |
70 |
// line=malloc(NMEA_LINESIZE); // Space for one line |
62 |
tab2[19]=0; |
71 |
// if (line==NULL) {printf(lcd_putc,"Error"); sleep();}; |
63 |
tab3[19]=0; |
72 |
line[NMEA_LINESIZE-1]=0; |
64 |
tab4[19]=0; |
- |
|
65 |
tab5[19]=0; |
73 |
|
66 |
|
74 |
while(fgetc(NMEA)!='$'); // Waiting for start character |
67 |
while(fgetc(NMEA)!='$'); // Waiting for start character |
- |
|
68 |
|
- |
|
69 |
intensity=read_adc(); |
- |
|
70 |
tab1[0]='$'; |
- |
|
71 |
|
- |
|
72 |
for(n=1;n<(19);n++) |
- |
|
73 |
{ |
- |
|
74 |
tab1[n]=fgetc(NMEA); |
- |
|
75 |
}; |
- |
|
76 |
|
75 |
for(n=0;n<(NMEA_LINESIZE-1);n++) // Read line up to checksum |
77 |
for(n=0;n<(19);n++) |
- |
|
78 |
{ |
- |
|
79 |
tab2[n]=fgetc(NMEA); |
- |
|
80 |
}; |
- |
|
81 |
|
- |
|
82 |
for(n=0;n<(19);n++) |
- |
|
83 |
{ |
- |
|
84 |
tab3[n]=fgetc(NMEA); |
- |
|
85 |
}; |
- |
|
86 |
|
- |
|
87 |
for(n=0;n<(19);n++) |
76 |
{ |
88 |
{ |
77 |
c=fgetc(NMEA); |
89 |
c=fgetc(NMEA); |
78 |
if(c=='*') |
90 |
if(c=='*') |
79 |
{ |
91 |
{ |
80 |
line[n]=0; |
92 |
tab4[n]=0; |
- |
|
93 |
tab5[0]=c; |
- |
|
94 |
tab5[1]=fgetc(NMEA); |
- |
|
95 |
tab5[2]=fgetc(NMEA); |
- |
|
96 |
tab5[3]=0; |
- |
|
97 |
goto tisk; |
- |
|
98 |
}; |
- |
|
99 |
tab4[n]=c; |
- |
|
100 |
}; |
- |
|
101 |
|
- |
|
102 |
for(n=0;n<(19);n++) // Read line up to checksum |
- |
|
103 |
{ |
- |
|
104 |
c=fgetc(NMEA); |
- |
|
105 |
if(c=='*') |
- |
|
106 |
{ |
- |
|
107 |
tab5[n]=c; |
- |
|
108 |
tab5[n+1]=fgetc(NMEA); |
- |
|
109 |
tab5[n+2]=fgetc(NMEA); |
- |
|
110 |
tab5[n+3]=0; |
81 |
break; |
111 |
break; |
82 |
}; |
112 |
}; |
83 |
line[n]=c; |
113 |
tab5[n]=c; |
84 |
}; |
114 |
}; |
85 |
|
115 |
|
- |
|
116 |
tisk: |
- |
|
117 |
|
86 |
printf(lcd_putc,"\f"); |
118 |
printf(lcd_putc,"\f"); |
87 |
|
119 |
|
88 |
if(!input(TL1)) |
120 |
if(!input(TL1)) |
89 |
{ |
121 |
{ |
90 |
lcd_gotoxy(1,1); |
122 |
lcd_gotoxy(1,1); |
91 |
strncpy(item,&line[LATDEG],DEG_LEN+MIN_LEN); item[DEG_LEN+MIN_LEN]=0; |
- |
|
92 |
printf(lcd_putc,"%s \n",item); |
123 |
printf(lcd_putc,"%s\n",tab1); |
93 |
|
- |
|
94 |
strncpy(item,&line[LONDEG],DEG_LEN+MIN_LEN); item[DEG_LEN+MIN_LEN]=0; |
- |
|
95 |
printf(lcd_putc,"%s",item); |
124 |
printf(lcd_putc,"%s",tab2); |
96 |
|
- |
|
97 |
} |
125 |
} |
98 |
else |
126 |
else |
99 |
{ |
127 |
{ |
100 |
lcd_gotoxy(1,1); |
128 |
lcd_gotoxy(1,1); |
101 |
printf(lcd_putc,"Time %06.0g \n",strtod(&line[TIME],&ptr)); |
129 |
printf(lcd_putc,"%s\n",tab3); |
102 |
printf(lcd_putc,"sats %06.0g ",strtod(&line[SAT],&ptr)); |
130 |
printf(lcd_putc,"%s",tab4); |
103 |
} |
131 |
} |
104 |
|
132 |
|
- |
|
133 |
puts(strcat(tab1,strcat(tab2,tab3)),PC); |
105 |
puts(line,PC); |
134 |
puts(strcat(tab4,tab5),PC); |
- |
|
135 |
printf(" /%u/%Lu\n\r",input(RANGE), intensity); |
106 |
|
136 |
|
107 |
// free(line); |
- |
|
108 |
} |
137 |
} |
109 |
} |
138 |
} |
110 |
|
139 |
|