Sei sulla pagina 1di 8

' {$STAMP BS2}

' {$PBASIC 2.5}


'By Charles Beener 09/17/2008
'------------------------------------------------------'
I/O Definitions
'------------------------------------------------------SOUT
PIN
15
'Send command and data to JP Module
StatePin
PIN
14
ResetPin
PIN
13
GPS_In
PIN
12
'GPS Data in
RecIndicator
PIN
11
'GPS Data record Indicate
'------------------------------------------------------DegSym
CON
176 ' degrees symbol for report
MinSym
CON
39
' minutes symbol
SecSym
CON
34
' seconds symbol
'------------------------------------------------------'
Variables
'------------------------------------------------------'Program to read in GPS coordinates from the NMEA 0183 GPRMC statement
x
gpstime
GPSData
workVal

VAR
Byte
VAR
Byte(2)
VAR
Byte(10)
VAR
Word(2)
char VAR Byte
char2 VAR Byte
index VAR Byte
counter VAR Byte
Y VAR Byte
j VAR Byte

'GPS Data from module


'
'
'
'
'

character sent to LCD


Duplicate character store
loop counter
2nd counter
Y position

' -----[ Constants ]------------------------------------------------------' Ports used


RS CON 4 ' Register Select (1 = char)
E CON 5 ' LCD Enable pin (1 = enabled)
' LCD control characters
'
ClrLCD CON $01 ' clear the LCD
CrsrHm CON $02 ' move cursor to home position
CRSRLF1 CON $10 ' move cursor left
CRSRRT1 CON $14 ' move cursor right
DispLf CON $18 ' shift displayed chars left
DispRt CON $1C ' shift displayed chars right
DDRam CON $80 ' Display Data RAM control
n9600 CON 84
'16468
n4800 CON 16572 ' inverted 4800 baud 188 for noninverted
' Data
DATA " Latitude Longitude Speed Deg UTC Meters #Sat "
main:
'
Init: DIRL = %00111111 ' set pins 0-5 as outputs
OUTS = $0000
' clear the pins
IF x=0 THEN
GOSUB LCDinit
ENDIF
'GOSUB LCD_ClearHome

'----------------------------------------------------DisplayData:
GOSUB LCD_GPS_Time
' DEBUG STR gpstime\6 ,CR
' DEBUG gpstime(0),gpstime(1),":", gpstime(2), gpstime(3),":", gpstime(4), gpst
ime(5),CR
workVal= (gpstime(0)-48)*10 + ( gpstime(1)-48)
IF workVal<5 THEN
workVal=workVal+24
ENDIF
workVal=workVal-4
IF workVal>24 THEN
workVal=workVal-24
ENDIF
Y=1
x=1
FOR j=1 TO 6
IF j=3 THEN
x=x+1
char=":"
GOSUB LCDPos
ENDIF
IF j=5 THEN
x=x+1
char=":"
GOSUB LCDPos
ENDIF
x=x+1
char=gpstime(j-1)
GOSUB LCDPos
NEXT
FOR j = 30 TO 32
x=x+1
READ j, char
GOSUB LCDwr
NEXT
IF workVal>12 THEN
workVal=workVal-12
ENDIF
' DEBUG DEC2 workVal ,":", gpstime(2), gpstime(3),":", gpstime(4), gpstime(5),
CR
x=x+2
char= ((workVal-5)/10)+48
GOSUB LCDPos
x=x+1
char=(workVal-(((workVal-5)/10)*10))+48
GOSUB LCDPos
FOR j=3 TO 6
IF j=3 THEN
x=x+1
char=":"
GOSUB LCDPos
ENDIF
IF j=5 THEN
x=x+1
char=":"
GOSUB LCDPos

ENDIF
x=x+1
char=gpstime(j-1)
GOSUB LCDPos
NEXT
'DEBUG STR GPSData," Time" ,CR
GOSUB LAT_GPS_Data
' DEBUG STR GPSData,CR
'DEBUG DEC workVal,CR
workVal=((GPSData(5)-48)*1000) + ((GPSData(6)-48)*100)+((GPSData(7)-48)*10) +
(GPSData(8)-48)
' convert decimal minutes to tenths of seconds
workVal = (workVal) ** $0F5C 'Dec minutes * 0.06
'DEBUG DEC workVal,CR
DEBUG "Lat=",GPSData(0),GPSData(1),".",GPSData(2),GPSData(3),".",DEC2 (workVal
/ 10), ".", DEC1 (workVal // 10),CR
Y=2
x=1
GPSData(5)=(workVal/100)+48
GPSData(6)=(workVal-((workVal/100)*100)/10)+48
gpstime=workVal-((workVal/100)*100)
GPSData(7)=gpstime-((gpstime/10)*10)+48
GPSData(8)=0'(workVal)+48
FOR j=1 TO 8
IF j=3 THEN
x=x+1
char=223'"."
GOSUB LCDPos
ENDIF
IF j=5 THEN
x=x+1
char=MinSym'"'"
GOSUB LCDPos
GOTO skip1
ENDIF
IF j=8 THEN
x=x+1
char="."
GOSUB LCDPos
ENDIF
x=x+1
char=GPSData(j-1)
GOSUB LCDPos
skip1:
NEXT
x=x+2
FOR j = 0 TO 9
x=x+1
READ j, char
GOSUB LCDwr
NEXT
GOSUB Lon_GPS_data
workVal=((GPSData(6)-48)*1000) + ((GPSData(7)-48)*100)+((GPSData(8)-48)*10)
+ (GPSData(9)-48)
' convert decimal minutes to tenths of seconds
workVal = workVal ** $0F5C ' minutesD * 0.06
' DEBUG STR GPSData,CR
DEBUG "Lon=",GPSData(0),GPSData(1),GPSData(2),".",GPSData(3),GPSData(4),".",DEC
2 (workVal / 10), ".", DEC1 (workVal // 10),CR

Y=3
x=1
GPSData(6)=(workVal/100)+48
GPSData(7)=(workVal-((workVal/100)*100)/10)+48
gpstime=workVal-((workVal/100)*100)
GPSData(8)=gpstime-((gpstime/10)*10)+48
GPSData(9)=0'(workVal)+48
FOR j=1 TO 9
IF j=4 THEN
x=x+1
char=223'"."
GOSUB LCDPos
ENDIF
IF j=6 THEN
x=x+1
char=MinSym'"'"
GOSUB LCDPos
GOTO skip2
ENDIF
IF j=9 THEN
x=x+1
char="."
GOSUB LCDPos
ENDIF
x=x+1
char=GPSData(j-1)
GOSUB LCDPos
skip2:
NEXT
x=x+2
FOR j = 9 TO 17
x=x+1
READ j, char
GOSUB LCDwr
NEXT
GOSUB Speed_GPS_data
'DEBUG GPSData(0),GPSData(1),GPSData(2),".",GPSData(4)," Speed",CR
Y=4
x=1
FOR j=1 TO 5
IF j=24 THEN
x=x+1
char=223'"."
GOSUB LCDPos
ENDIF
x=x+1
char=GPSData(j-1)
GOSUB LCDPos
NEXT
x=x+2
FOR j = 20 TO 24
x=x+1
READ j, char
GOSUB LCDwr
NEXT
GOSUB Direction_GPS_data
'DEBUG GPSData(0),GPSData(1),GPSData(2),".",GPSData(4)," Degrees to",CR
Y=4
FOR j=1 TO 3

x=x+1
char=GPSData(j-1)
GOSUB LCDPos
NEXT
x=x+1
FOR j = 25 TO 28
x=x+1
READ j, char
GOSUB LCDwr
NEXT
GOSUB Altitude_GPS_data
workVal= ((GPSData(0)-48)*100) + ((GPSData(1)-48)*10) + (GPSData(2)-48)
'workVal=workVal*3
' workVal = workVal / 10 ' remove tenths from altitude
' convert altitude from meters to feet
workVal = (workVal * 3) + (workVal ** $47E5) ' 1 meter = 3.2808399 feet
DEBUG "Feet=", DEC workVal,CR
Y=4
x=x-20
'GOSUB LCDPos
FOR j=1 TO 3
x=x+1
char=GPSData(j-1)
GOSUB LCDPos
NEXT
x=x+1
FOR j = 33 TO 40
x=x+1
READ j, char
GOSUB LCDwr
NEXT
GOSUB Satulites_GPS_data
DEBUG "Satulites=", STR GPSData,CR
FOR j=1 TO 2
x=x+1
char=GPSData(j-1)
GOSUB LCDPos
NEXT
x=x+1
FOR j = 40 TO 45
x=x+1
READ j, char
GOSUB LCDwr
NEXT
'GOSUB Altitude2_GPS_data
' DEBUG STR GPSData,CR
DEBUG CR
GOTO main
' convert to decimal format, too
' workVal = (minutes * 1000 / 6) + (minutesD / 60)
' DEBUG " (", " " + (dir * 13), DEC degrees, ".", DEC4 workVal, " ) "
' RETURN
' ---------------------------------------------------' convert speed from knots to MPH
' workVal = speed + (speed ** $2699) ' 1 knot = 1.1507771555 MPH
' DEBUG " ( ", DEC (workVal / 10), ".", DEC1 (workVal // 10), " MPH )
"
'------------------------------------------------------GPS_RMC:

GPSData(56) = 0
SERIN GPS_In, n4800, [WAIT ("$GPRMC"), SKIP 1, STR GPSData\55]
RETURN
'------------------------------------------------------LCD_GPS_Time:
gpstime(6) = 0
SERIN GPS_In, n4800, [WAIT ("$GPRMC"), SKIP 1, STR gpstime\6]
RETURN
'------------------------------------------------------LAT_GPS_data:
GPSData(21) = 0
SERIN GPS_In, n4800, [WAIT ("$GPRMC"), SKIP 14, STR GPSData\21]'SERIN GPS_In, n
4800, [WAIT ("$GPRMC"), SKIP 14, STR GPSData\11]
RETURN
'------------------------------------------------------Lon_GPS_data:
GPSData(38) = 0
'38
SERIN GPS_In, n4800, [WAIT ("$GPRMC"), SKIP 26, STR GPSData\12] 'SERIN GPS_In,
n4800, [WAIT ("$GPRMC"), SKIP 26, STR GPSData\12]
RETURN
'------------------------------------------------------Speed_GPS_data:
GPSData(45) = 0
SERIN GPS_In, n4800, [WAIT ("$GPRMC"), SKIP 39, STR GPSData\5]
RETURN
'------------------------------------------------------Direction_GPS_data:
GPSData(49) = 0
SERIN GPS_In, n4800, [WAIT ("$GPRMC"), SKIP 44, STR GPSData\5]
RETURN
'------------------------------------------------------'Altitude2_GPS_data:
' GPSData(48) = 0
' SERIN GPS_In, n4800, [WAIT ("$GPGGA"),SKIP 5, STR GPSData\19]
'RETURN
'------------------------------------------------------Altitude_GPS_data:
GPSData(35) = 0
SERIN GPS_In, n4800, [WAIT ("$GPGGA"),SKIP 46, STR GPSData\3]
RETURN
'------------------------------------------------------Satulites_GPS_data:
GPSData(34) = 0
SERIN GPS_In, n4800, [WAIT ("$GPGGA"),SKIP 39, STR GPSData\2]
RETURN
'------------------------------------------------------'-----[ Initialization ]--------------------------------------------------

LCDinit:

'=================================
' STANDARD HITACHI 44780 4-BIT INIT
' =================================
PAUSE 500
' Wait for LCD init
char=%00000011 ' Set 8-bit mode (1)
GOSUB LCDcmd
char=%00000011 ' Set 8-bit mode (2)
GOSUB LCDcmd
char=%00000011 ' Set 8-bit mode (3)
GOSUB LCDcmd
char=%00000010 ' Set 4-bit mode

GOSUB LCDcmd
char=%00101111
GOSUB LCDcmd
char=%00000000
GOSUB LCDcmd
char=%00001000
GOSUB LCDcmd
char=%00000000
GOSUB LCDcmd
char=%00001100
GOSUB LCDcmd
char=%00000000
GOSUB LCDcmd
char=%00000110
GOSUB LCDcmd

' Set duty cycle 11xx = 5x11 matrix


' 10xx = 5x8 matric
' Display control mode
' Set display OFF, cursor OFF, blink OFF
' Display control mode
' Set display ON, cursor ON, blink ON
' 11CB -> C=1 cursor on, B=1 blink on
' Entry control mode
' Set cursor right, no display shift
' 01IS -> I=1 cursor right, S=1 shift display

char = ClrLCD ' Clear LCD


GOSUB LCDcmd
PAUSE 500
RETURN
'-----[ Subroutines ]----------------------------------------------------' ============================
' Write char at position (X,Y)
' ============================
' Usage:
' X=10 ' horizontal position or column (X)
' Y=2 ' vertikal position or line (Y)
' char="A" ' character to write
' GOSUB LCDpos ' position cursor and write char
' (note: this is the SLOW version! look at the next example for a better way!)
LCDpos:
char2=char ' Save char
char=CrsrHm ' Set cursor to home location
GOSUB LCDcmd
counter=0 ' Reset counter
IF
IF
IF
IF
pos_row2:
pos_row3:
pos_row4:
position:

Y=1 THEN position


Y=2 THEN pos_row2
Y=3 THEN pos_row3
Y=4 THEN pos_row4
' 4x20: row2 starts at position 40
counter=40
GOTO position
' 4x20: row3 starts at position 20
counter=20
GOTO position
' 4x20: row4 starts at position 60
counter=60
GOTO position
' 4x20: row1 starts at position 0
counter=counter+X-2 ' Add X to Y position minus 1 (pos 1 = 0)
IF counter=0 THEN done ' work around the loop for pos (0,0)
FOR index=1 TO counter ' move cursor x steps to the right
char=CRSRRT1
GOSUB LCDcmd
NEXT

done:
char=char2 ' restore old char
GOSUB LCDwr ' and write it
RETURN
'=======================
' Send command to the LCD
' =======================
LCDcmd:
LOW RS ' enter command mode
'=======================
' Write ASCII char to LCD
' =======================
LCDwr:
OUTA = char.HIGHNIB ' output high nibble
PULSOUT E, 1 ' strobe the Enable line
OUTA = char.LOWNIB ' output low nibble
PULSOUT E, 1
HIGH RS ' return to character mode
RETURN
'*********************************** GPS NOT Detected Routine ******************
*********************
'(having the Debug statement here will cause the debug window to come automatica
lly but not interfere with data collection in HyperTerminal)
nogps1:
DEBUG "no gps",CR
GOTO MAIN

Potrebbero piacerti anche