Code:
'****************************************************************
'* Name : UNTITLED.BAS *
'* Author : [select VIEW...EDITOR OPTIONS] *
'* Notice : Copyright (c) 2010 [select VIEW...EDITOR OPTIONS] *
'* : All Rights Reserved *
'* Date : 2/28/2010 *
'* Version : 1.0 *
'* Notes : *
'* : *
'****************************************************************
DEFINE ADC_BITS 8 ' Number of bits in ADCIN result
define ADC_CLOCK 3 'SET CLOCK SOURCE TO RC = 3
DEFINE ADC_SAMPLEUS 50
' -----[ Initialization ]------------------------------------------------
Reset:
CMCON0 = %00000111 ' Comparators off
TRISIO = %101100
ADCON0 = %00001100 ' LeftJust,VDD,x,x,AN3,x,ADCdisabled
ANSEL = %0010000 ' -001xxxx Fosc/8, -xxx0000 all pins digital not analog
IOC = %001000 'enable gpio.3 interrupt on change
'NOTE: you must also clear the CONFIG.5 fuse bit to change gpio.3 to
'an I/O instead of MCLR (its under the configuration link on the
'pickit2 programing app. This bit must be done each time before you
'program the chip.
OPTION_REG = %10111111 'b7=pullups disabled
'b6=int on falling edge
' -----[ Timer setup ]----------------------------------------------------
' T1CON = %00110001 'Enable Timer1 with 1:8 prescaler
' PIE1 = %00000001 'Enable Timer1 overflow interrupt
' 'PIR1 = %0000000
' TMR1h = 0 'reset timer1 to zero
' TMR1l = 0 'reset timer1 to zero
Xpwr var gpio.0 'Output to turn on XBee
XBrx var gpio.1 'Output serial data to XBee
XBtx var gpio.2 'Input
rst var gpio.3 'Input
Gpwr var gpio.4 'Output to turn on GPS
GPS var gpio.5 'Input serial data from GPS
symbol I = 254 'LCD prefix for Instruction
symbol clr = 1 'LCD CLEAR SCREEN
SYMBOL LINE2 = 192 'LCD ADDR FOR 1ST CHAR ON 2ND LINE
SYMBOL H = 2 'LCD HOME COMMAND
GPRMC VAR BYTE[64]
hh VAR BYTE 'hours
mm VAR BYTE 'minutes
ss VAR BYTE 'seconds
sss var word 'milliseconds
fix VAR WORD 'GPS fix
latdeg VAR BYTE 'degrees latitude
latmin VAR BYTE 'minutes latitude
latminn var word 'fractional minutes latitude
NS VAR BYTE 'north or south
londeg VAR BYTE 'degrees longitude
lonmin VAR BYTE 'minutes longitude
lonminn var word 'fractional minutes longitude
EW VAR BYTE 'east or west
Knots VAR byte 'speed in knots (units)
Knotss var byte 'speed in fractional knots
course var word 'heading
dy VAR BYTE 'day
mt VAR BYTE 'month
yr VAR BYTE 'year
speed var byte[4] 'array to hold knots & knotss
mph var word 'units of mph
mphh var byte 'fractional mph
KK var word 'this var will contain knots(12) & knotss(34) = 1234
Value VAR WORD 'AD value, Must be a WORD even though AD is 8bit
' -----[ Program Code ]----------------------------------------------------
'low lcd
'pause 1000 'allow lcd to initialize
'serout2 lcd,16780,[i,clr]
high gpwr
high xpwr
Main:
'high gpwr
serin2 gps,188,3000,tmout,[WAIT("$GPRMC,"),STR GPRMC\63\"$"] 'Data IN from GPS
arrayread gprmc,[DEC2 hh,DEC2 mm,dec2 ss,_
wait(","),fix,wait(","),DEC2 latdeg,DEC2 latmin,wait("."),dec4 latminn,_
wait(","),NS,wait(","),DEC3 londeg,DEC2 lonmin,wait("."),dec4 lonminn,_
wait(","),EW,wait(","),dec knots,dec Knotss,dec course,_
wait(","),DEC2 dy,DEC2 mt,DEC2 yr] 'parse the GPS array into parts
'high xpwr
pause 500
if fix = "V" then nofix 'jump to "waiting for fix" display
SEROUT2 xbtx,188,[$0D,$0A,"$GPRMC,",STR GPRMC\63] 'Data OUT to XBEE
'low xpwr
pause 5000
goto main
'gosub calcmph 'convert knots.knotss to mph.h
'serout2 lcd,16780,[i,h," ",dec2 latdeg,$DF,dec2 latmin,".",dec4 latminn,"'",ns,dec2 mph,dec1 mphh]
'serout2 lcd,16780,[i,line2,dec3 londeg,$DF,dec2 lonmin,".",dec4 lonminn,"'",ew,dec3 course]
'-----------subroutines-------------------------
'CalcMPH:
' arraywrite speed,[dec2 knots,dec2 knotss] 'combine knots and knotss into 4 byte array
' arrayread speed,[dec4 kk] 'now get the 4 digit dec value of the array
' mph = kk * 9881
' mph = R0 + R2.15 + kk 'mph now contains 4 digit value of mph/tenths/hundredths
' mphh = mph//100 'isolate tenths and hundredths
' mphh = mphh/10 'eliminate the hundreths and keep tenths
' mph = mph/100 'now keep integer mph, first two digits of 4 digit value
'return
NoFix:
serout2 xbtx,188,["waiting for fix"]
goto main
tmout: 'end up here if no data from gps within 3 seconds
serout2 xbtx,188,["timeout"]
GOTO MAIN
Bookmarks