Rev Author Line No. Line
1103 kakl 1 /**** GPS skrysohledac ****/
2 #define ID "$Id: gps.c 984 2008-01-06 23:41:31Z kakl $"
3  
4 #include "gpsrl.h"
5  
6 #include <math.h>
7 #include <stdlib.h>
8 #include <stdlibm.h>
9  
1104 kaklik 10 #define SCINTILAK 1 //kanal adc pro scintilacni detektor NB3201
11 #define RANGE PIN_A4 // vystup detektoru urcujici rozsah mereni.
12  
13  
1103 kakl 14 #define LCD_RS PIN_B1 // LCD control
15 #define LCD_E PIN_B2 // LCD enable
16 #define LCD_DATA_LSB PIN_B4 // LSB data bit LCD
17 #include "MYLCD.C"
18  
1104 kaklik 19 #define TL1 PIN_C0
20 #define TL2 PIN_C1
21 #define TL3 PIN_C2
22  
1103 kakl 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
1104 kaklik 30 #define SAT 36
1103 kakl 31 #define DEG_LEN 2
32 #define MIN_LEN 7
33 #define AZIMUTH 46
1104 kaklik 34 #define NMEA_LINESIZE 79
1103 kakl 35  
1104 kaklik 36 //$GPRMC,105815.503,V,4915.5877,N,01442.3896,E,0.0,0.00,060108,,,N*44
1103 kakl 37  
1104 kaklik 38 void main()
1103 kakl 39 {
40  
1104 kaklik 41 setup_adc_ports(AN0);
42 setup_adc(ADC_CLOCK_INTERNAL);
43 setup_spi(FALSE);
44 setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1);
45 setup_timer_1(T1_DISABLED);
46 setup_timer_2(T2_DISABLED,0,1);
47 setup_comparator(NC_NC_NC_NC);
48 setup_vref(VREF_LOW|-2);
49 lcd_init();
1103 kakl 50  
1104 kaklik 51 delay_ms(100);
52 lcd_gotoxy(5,1);
53 printf(lcd_putc,"GPSRL01B \n");
54 printf(lcd_putc,"(c) Kaklik 2008");
55 delay_ms(300);
56 printf(lcd_putc,"\f");
57  
58 set_adc_channel(SCINTILAK);
1103 kakl 59  
1104 kaklik 60 while(TRUE)
61 {
62  
63 auto char line[NMEA_LINESIZE];
64 char item[16];
65 char *ptr;
66 int8 n;
67 char c;
68  
69  
1103 kakl 70 // line=malloc(NMEA_LINESIZE); // Space for one line
71 // if (line==NULL) {printf(lcd_putc,"Error"); sleep();};
72 line[NMEA_LINESIZE-1]=0;
73  
74 while(fgetc(NMEA)!='$'); // Waiting for start character
75 for(n=0;n<(NMEA_LINESIZE-1);n++) // Read line up to checksum
76 {
77 c=fgetc(NMEA);
78 if(c=='*')
79 {
80 line[n]=0;
81 break;
82 };
83 line[n]=c;
84 };
85  
1104 kaklik 86 printf(lcd_putc,"\f");
1103 kakl 87  
1104 kaklik 88 if(!input(TL1))
89 {
90 lcd_gotoxy(1,1);
1103 kakl 91 strncpy(item,&line[LATDEG],DEG_LEN+MIN_LEN); item[DEG_LEN+MIN_LEN]=0;
1104 kaklik 92 printf(lcd_putc,"%s \n",item);
93  
1103 kakl 94 strncpy(item,&line[LONDEG],DEG_LEN+MIN_LEN); item[DEG_LEN+MIN_LEN]=0;
1104 kaklik 95 printf(lcd_putc,"%s",item);
1103 kakl 96  
97 }
1104 kaklik 98 else
1103 kakl 99 {
1104 kaklik 100 lcd_gotoxy(1,1);
101 printf(lcd_putc,"Time %06.0g \n",strtod(&line[TIME],&ptr));
102 printf(lcd_putc,"sats %06.0g ",strtod(&line[SAT],&ptr));
103 }
1103 kakl 104  
1104 kaklik 105 puts(line,PC);
1103 kakl 106  
1104 kaklik 107 // free(line);
1103 kakl 108 }
109 }
110