/Designs/skrysohledac1/SW/gps.PJT
32,8 → 32,8
 
[Opened Files]
1=C:\Users\locadmin\Documents\MLAB\Designs\skrysohledac1\SW\gps.c
2=
3=C:\Users\locadmin\Documents\MLAB\Designs\skrysohledac1\SW\gps.h
2=C:\Users\locadmin\Documents\MLAB\Designs\skrysohledac1\SW\gps.h
3=C:\Program Files\PICC\devices\16F876A.h
4=C:\Program Files\PICC\drivers\math.h
5=C:\Program Files\PICC\drivers\stdlib.h
6=C:\Program Files\PICC\drivers\stddef.h
41,8 → 41,24
8=C:\Program Files\PICC\drivers\ctype.h
9=C:\Program Files\PICC\drivers\stdlibm.h
10=C:\Program Files\PICC\drivers\memmgmt.c
11=
12=
11=C:\Users\locadmin\Documents\MLAB\Designs\skrysohledac1\SW\MYLCD.C
12=C:\Users\locadmin\Documents\MLAB\Designs\skrysohledac1\SW\gps.err
13=
[debugperif]
selected=Analog/Digital Conv
[debugram]
autoread=1
[debugeedata]
autoread=1
[debugbreak]
count=0
[pcwdebug]
watchcol0=75
[debugwatch]
count=0
[debugexpr]
expr=
sideeffects=0
[Units]
Count=1
1=C:\Users\locadmin\Documents\MLAB\Designs\skrysohledac1\SW\gps.c (main)
/Designs/skrysohledac1/SW/gps.c
8,35 → 8,55
#include <stdlibm.h>
 
#define LCD_RS PIN_B1 // LCD control
#define LCD_E PIN_B0 // LCD enable
#define LCD_E PIN_B2 // LCD enable
#define LCD_DATA_LSB PIN_B4 // LSB data bit LCD
#include "MYLCD.C"
 
// NMEA
#define TIME 6 // For NMEA parsing
#define TIME_LEN 10
#define LATDEG 19
#define LATMIN 21
#define LONDEG 32
#define LONMIN 34
#define DEG_LEN 2
#define MIN_LEN 7
#define AZIMUTH 46
#define TIME 6 // For NMEA parsing
#define TIME_LEN 10
#define LATDEG 19
#define LATMIN 21
#define LONDEG 32
#define LONMIN 34
#define DEG_LEN 2
#define MIN_LEN 7
#define AZIMUTH 46
#define NMEA_LINESIZE 60
 
#define MAXGC 4
 
struct geocache
{
float lat;
float lon;
char name[8];
};
 
struct geocache const gc[MAXGC] =
{
{49*60+15.5740,14*60+42.3310,"GCCISTI"}, // Testovaci souradnice: cisticka
{49*60+12.4452,14*60+18.9079,"GCKOMET"}, // Testovaci souradnice: kometa
{49*60+12.4452,14*60+18.9079,"GCXXX3"},
{49*60+12.4452,14*60+18.9079,"GCXXX4"}
};
 
float lat,lon; // Latitude, Longitude, Azimuth
int16 az;
int8 gcnum; // Selection of the GC point
 
#define NMEA_LINESIZE 72
 
//$GPRMC,105815.503,V,4915.5877,N,01442.3896,E,0.0,0.00,060108,,,N*44
inline void read_NMEA() // NMEA parsing
{
auto char line[NMEA_LINESIZE];
auto char item[16];
char *ptr,*line;
auto char *ptr;
// auto char *line;
auto int8 n;
auto char c;
 
line=malloc(NMEA_LINESIZE); // Space for one line
if (line==NULL) {printf(lcd_putc,"Error"); sleep();};
// line=malloc(NMEA_LINESIZE); // Space for one line
// if (line==NULL) {printf(lcd_putc,"Error"); sleep();};
line[NMEA_LINESIZE-1]=0;
 
while(fgetc(NMEA)!='$'); // Waiting for start character
51,16 → 71,16
line[n]=c;
};
 
lcd_gotoxy(12,4);
lcd_gotoxy(12,4);
printf(lcd_putc,"%c %06.0g ",line[17],strtod(&line[TIME],&ptr));
 
lcd_gotoxy(1,3);
lcd_gotoxy(1,3);
strncpy(item,&line[LATDEG],DEG_LEN+MIN_LEN); item[DEG_LEN+MIN_LEN]=0;
printf(lcd_putc,"%s*",item);
strncpy(item,&line[LONDEG],DEG_LEN+MIN_LEN); item[DEG_LEN+MIN_LEN]=0;
printf(lcd_putc,"%s*",item);
 
lcd_gotoxy(1,2);
// lcd_gotoxy(1,2);
lat=strtod(&line[LATMIN],&ptr);
line[LATMIN]=0;
lat+=60*strtod(&line[LATDEG],&ptr);
69,8 → 89,8
lon+=60*strtod(&line[LONDEG],&ptr);
strtod(&line[AZIMUTH],&ptr);
az=strtoul(ptr+1,&ptr,10);
printf(lcd_putc,"%.3g*%.3g*%03Lu",lat,lon,az);
free(line);
// printf(lcd_putc,"%.3g*%.3g*%03Lu",lat,lon,az);
// free(line);
}
 
void main()
86,29 → 106,33
setup_vref(VREF_LOW|-2);
lcd_init();
 
gcnum++; // Next GC
if (gcnum>(MAXGC-1)) gcnum=0;
 
delay_ms(200);
lcd_gotoxy(1,2);
printf(lcd_putc,"%s",gc[gcnum].name); // Print GC name
 
while(TRUE)
{
const float gc_lat=49*60+12.4452,gc_lon=14*60+18.9079; // Testovaci souradnice: Cisticka
 
float bearing, heading, azim;
 
read_NMEA(); // Read one NMEA line and parse
 
lon=(gc_lon-lon)*1214; // Kakona's projection :)
lat=(gc_lat-lat)*1854;
lon=(gc[gcnum].lon-lon)*1214; // Kakona's projection :)
lat=(gc[gcnum].lat-lat)*1854;
 
lcd_gotoxy(1,4);
lcd_gotoxy(1,4);
printf(lcd_putc,"%.0g* ",sqrt((lon*lon) + (lat*lat))); // Distance
lcd_gotoxy(1,1);
if (lon==0) lon=0.001; // Divided by zero cure
bearing=3-(6/PI*atan2(lat,lon)); // Bearing
if (bearing<0) bearing+=12; // overflow cure
if (bearing>12) bearing-=12;
printf(lcd_putc,"BE%2.0g*",bearing);
azim=12.0/360*az; // Azimuth of the movement
heading=bearing-lat; // Heading
if (heading<0) heading+=12; // overflow cure
if (heading>12) heading-=12;
printf(lcd_putc,"HE%2.0g*AZ%2.0g* ",heading,azim);
lcd_gotoxy(1,1);
if (lon==0) lon=0.001; // Divided by zero cure
lon=3-(6/PI*atan2(lat,lon)); // Bearing
if (lon<0) lon+=12; // overflow cure
if (lon>12) lon-=12;
printf(lcd_putc,"BE%2.0g*",lon);
lat=12.0/360*az; // Azimuth of the movement
lon=lon-lat; // Heading
if (lon<0) lon+=12; // overflow cure
if (lon>12) lon-=12;
printf(lcd_putc,"HE%2.0g*AZ%2.0g* ",lon,lat);
}
}
/Designs/skrysohledac1/SW/gps.h
1,4 → 1,5
#include <16F876A.h>
#device *=8
#device adc=8
 
#FUSES NOWDT //No Watch Dog Timer
12,5 → 13,5
#FUSES NOWRT //Program memory not write protected
 
#use delay(clock=4000000)
#use rs232(stream=NMEA,baud=4800,parity=N,rcv=PIN_C7,bits=8)
//#use rs232(stream=PC,baud=9600,parity=N,rcv=PIN_C4,bits=8)
#use rs232(stream=NMEA,baud=4800,parity=N,rcv=PIN_C6,bits=8)
#use rs232(stream=PC,baud=9600,parity=N,rcv=PIN_C7,bits=8)