7,19 → 7,11 |
#include <stdlib.h> |
#include <stdlibm.h> |
|
#define SCINTILAK 1 //kanal adc pro scintilacni detektor NB3201 |
#define RANGE PIN_A4 // vystup detektoru urcujici rozsah mereni. |
|
|
#define LCD_RS PIN_B1 // LCD control |
#define LCD_E PIN_B2 // LCD enable |
#define LCD_DATA_LSB PIN_B4 // LSB data bit LCD |
#include "MYLCD.C" |
|
#define TL1 PIN_C0 |
#define TL2 PIN_C1 |
#define TL3 PIN_C2 |
|
// NMEA |
#define TIME 6 // For NMEA parsing |
#define TIME_LEN 10 |
27,46 → 19,41 |
#define LATMIN 21 |
#define LONDEG 32 |
#define LONMIN 34 |
#define SAT 36 |
#define DEG_LEN 2 |
#define MIN_LEN 7 |
#define AZIMUTH 46 |
#define NMEA_LINESIZE 79 |
#define NMEA_LINESIZE 60 |
|
//$GPRMC,105815.503,V,4915.5877,N,01442.3896,E,0.0,0.00,060108,,,N*44 |
#define MAXGC 4 |
struct geocache |
{ |
float lat; |
float lon; |
char name[8]; |
}; |
|
void main() |
struct geocache const gc[MAXGC] = |
{ |
{49*60+15.5740,14*60+42.3310,"DOMA"}, // Testovaci souradnice: cisticka |
{48*60+57.966,14*60+28.655,"GC16JMH"}, |
{48*60+57.837,14*60+28.599,"GC16F8Y"}, |
{49*60+9.542,14*60+56.417,"GC-----"} |
}; |
|
setup_adc_ports(AN0); |
setup_adc(ADC_CLOCK_INTERNAL); |
setup_spi(FALSE); |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
setup_timer_1(T1_DISABLED); |
setup_timer_2(T2_DISABLED,0,1); |
setup_comparator(NC_NC_NC_NC); |
setup_vref(VREF_LOW|-2); |
lcd_init(); |
float lat,lon; // Latitude, Longitude, Azimuth |
int16 az; |
int8 gcnum; // Selection of the GC point |
|
delay_ms(100); |
lcd_gotoxy(5,1); |
printf(lcd_putc,"GPSRL01B \n"); |
printf(lcd_putc,"(c) Kaklik 2008"); |
delay_ms(300); |
printf(lcd_putc,"\f"); |
|
set_adc_channel(SCINTILAK); |
//$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]; |
auto char *ptr; |
// auto char *line; |
auto int8 n; |
auto char c; |
|
while(TRUE) |
{ |
|
auto char line[NMEA_LINESIZE]; |
char item[16]; |
char *ptr; |
int8 n; |
char c; |
|
|
// line=malloc(NMEA_LINESIZE); // Space for one line |
// if (line==NULL) {printf(lcd_putc,"Error"); sleep();}; |
line[NMEA_LINESIZE-1]=0; |
83,28 → 70,68 |
line[n]=c; |
}; |
|
printf(lcd_putc,"\f"); |
lcd_gotoxy(12,4); |
printf(lcd_putc,"%c %06.0g ",line[17],strtod(&line[TIME],&ptr)); |
|
if(!input(TL1)) |
{ |
lcd_gotoxy(1,1); |
lcd_gotoxy(1,3); |
strncpy(item,&line[LATDEG],DEG_LEN+MIN_LEN); item[DEG_LEN+MIN_LEN]=0; |
printf(lcd_putc,"%s \n",item); |
|
printf(lcd_putc,"%s*",item); |
strncpy(item,&line[LONDEG],DEG_LEN+MIN_LEN); item[DEG_LEN+MIN_LEN]=0; |
printf(lcd_putc,"%s",item); |
printf(lcd_putc,"%s*",item); |
|
// lcd_gotoxy(1,2); |
lat=strtod(&line[LATMIN],&ptr); |
line[LATMIN]=0; |
lat+=60*strtod(&line[LATDEG],&ptr); |
lon=strtod(&line[LONMIN],&ptr); |
line[LONMIN]=0; |
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); |
} |
else |
|
void main() |
{ |
lcd_gotoxy(1,1); |
printf(lcd_putc,"Time %06.0g \n",strtod(&line[TIME],&ptr)); |
printf(lcd_putc,"sats %06.0g ",strtod(&line[SAT],&ptr)); |
} |
|
puts(line,PC); |
setup_adc_ports(NO_ANALOGS); |
setup_adc(ADC_OFF); |
setup_spi(FALSE); |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
setup_timer_1(T1_DISABLED); |
setup_timer_2(T2_DISABLED,0,1); |
setup_comparator(NC_NC_NC_NC); |
setup_vref(VREF_LOW|-2); |
lcd_init(); |
|
// free(line); |
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) |
{ |
read_NMEA(); // Read one NMEA line and parse |
|
lon=(gc[gcnum].lon-lon)*1214; // Kakona's projection :) |
lat=(gc[gcnum].lat-lat)*1854; |
|
lcd_gotoxy(1,4); |
printf(lcd_putc,"%.0gm ",sqrt((lon*lon) + (lat*lat))); // Distance |
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.0gh*",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.0gh*AZ%2.0gh*",lon,lat); |
} |
} |
|