📄 nembtgpsa.txt
字号:
Nemesis
'File: NemBTGPSa.txt
'Nemesis PIC with Bluetooth Module connects to BT GPS.
'Displays GPS data on LCD.
'This is the operational program for the Circuit Cellar project.
'Prior version: NemBTGPS.txt Nemesis Bluetooth GPS Interface
'AKA NemBTGPS10.txt
'JEC 8/05 11/05 12/05
'Rev. 12/22/05 Added Number of Satellites in View,
'(ie above the horizon), as well as the actual number
'being used for the present GPS calculations.
'++++++++++++++++++++++++++++++++++++++++++++++++++++++
' This program is for demonstration purposes only
' Use at your own risk
'++++++++++++++++++++++++++++++++++++++++++++++++++++++
'This program is distributed freely, for non-commercial use only.
'Contact the project creator for all other uses and inquiries.
'Jay Carter, MSEE, MD, FACEP
'e-mail: Carter@DocJC.US
'www.DocJC.US
'This program runs the Nemesis PIC / Wintec Bluetooth Module
'GPS project. The PIC instructs the BTM to connect to a BT GPS
'receiver. It then parses the data stream, process the data, and
'displays it on a 2 line LCD.
'Date & Time, Speed & Heading, and Lat & Long are all available,
'as well as the number of active satellites currently being used
'for GPS calculations, and the total number of satellites in view,
'ie above the horizon.
'A setup mode allows one to enter a Local Time Zone offset from
'the GPS reported UTC Time. (+/- 0 to 12 hrs).
'Speed is convert from Knots to MPH, and displayed as MPH.
'Direction / Heading / Bearing / Track are used interchangeably
'here, and the value is reported in degrees, as well as an
'approximate N, NE, E... alpha character display.
'The Nemesis is programmed in Athena, a PIC version of BASIC
'by Kronos Robotics.
'+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
'NOTE: The UNIQUE Bluetooth address of the BT GPS receiver that this
'project connects to MUST be changed in the code, in TWO subroutines,
'below. The address is hard coded to the particular GPS unit it
'connects to.
'The subroutines are marked with delimiters as is this notice.
'+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
'This verison performs Discovery, Bond, and SPPConnect to a
'Bluetooth GPS receiver.
'It will display Date & Time, Speed & Heading, and Lat & Long data.
'A front panel push button switch selects the display mode.
'The switch is NOT interrupt driven, you may have to push and hold it
'until the CPU gets around to reading it.
'The number of active satellites being used by the GPS is also
'displayed on both the D&T, and S&H display modes.
'
'The GPS reports time in UTC (GMT) format. By pushing the display
'mode push button on power up one enters a set up mode to set the
'local time zone offset from GMT. eg EST = GMT - 5 (hrs),
'then +/- daylight savings time, also.
'Pushing the switch cycles through minus 0 - 12, and plus 0 - 12
'hours of offset, which is then stored in eeprom.
'Just shut off the power to EXIT set up mode.
'Note: The User instructions on the LCD have been removed to add
'other features to the program.
'The BT connection process also does not provide much in the way of
'User feedback, in order to save memory. It takes about 20 - 30 Sec
'to Discovery, Bond, and SPPConnect to a BT GPS, at which time the
'LCD comes alive with the current Date & Time.
'A Separate program is available to study the BT connection in more
'detail, with LCD step-by-step feedback. It is NemBTConnect.txt.
'It includes some primate error checking on the connection process,
'which is, by and large, not included in this version.
'This program receives speed in knots, and converts it to MPH.
'This program calculates a N/NE/E alpha heading character.
'This program displays the number of active satellites being used
'by the GPS receiver to make it's calculations. This number is
'displayed on the D&T and S&H display modes. The individual
'satellite ID codes, and signal strengths are available, but not
'presently used.
'PIC PWM LCD Backlight dimmer was removed for more program space.
'With tighter coding, or more memory, one could display a list
'of Discovered BT devices, and the User could scroll through them,
'and select the device (GPS) to connect to.
'Board Set Up:
'There are three, 3 position headers on the project circuit board.
'TWO are for setting the mode, and should BOTH be in position A, B, or C.
'
'Step 1: Mode A, BTM is tied to PC via RS-232 serial link.
'Ues Windows Hyperterminal to test the BTM, and to reset it's
'default baud rate for 115,200 N81 to 9600.
'Step 2: Mode B, Nemesis is tied to PC via RS-232 serial link.
'Use Kronosis Robotic's Nemesis's development platform, free from
'their web site, to edit and program the Nemesis.
'Can load either of the two available programs, and modify as desired.
'Step 3: Mode C, Nemesis is tied to the BTM, the operational mode for
'this project. Nemesis does BT GPS connection, and parses, processes,
'and displays the GPS data.
'NMEA: Note that the 2 digits before the decimal point
'are whole minutes. Before this is degrees.
'After the decimal point is decimal minutes.
'Note: Date is read in DDMMYY format.
'Note: $GPRMC is Recommended Minimum Navigation Info Data Packet
'Note: $GPSVG is Satellites in View, their Signal Strength, etc.
'Note: RMC reported Speed is in KNOTS, Not in MPH.
'Multiply knots by 1.15 to get MPH.
'NOTE: Reading UART Buffer via Assem works well,
'using getpacket and serin is challenging.
'Note: Nemesis eeprom, location 1 and 2 are used for setting up the
'Local Time Zone offset from UTC (GMC) Time, reported by the GPS.
'Location 1 = 0 - 12, number of hours difference from UTC (GMT) Time
'Location 2 = 0 for Minus offset, 1 for + offset.
'Eastern Stad Time = UTC - 5, Loc 1 = 5, Loc 2 = 0 (minus offset)
'Note: In this version the GPS data is stored as ASCII characters.
'For data logging, and telemetry, without a local display, it makes
'more sense to convert it to numeric data.
'With a local display, trade off is converting it back from bin to
'(decimal) ASCII Char strings.
'Bug List:
' * This version has some added features, such as the number of active
' satellites, at the expense of error checking the BT connection process.
' * There is presently no detection for loss of the BT connection.
' * User feedback during the BT connection process, and prompts for
' the Local Time Zone set up have been REMOVED to make memory for other
' features.
' * A separate program: NemBTConnect.txt provides more robust BT connecting
' and LCD user feedback, but does not format the GPS data.
' * This reads the Front Panel Push Button Switches within the Main processing
' loop, not via interrupts, which, therefore, sometimes gives a sluggish
' response.
' * The UTC Time can be offset for the Local Time Zone, +/- 0 to 12 integer hours.
' The Date is always UTC Date, it isn't converted in this demo program.
' UTC Date rolls over to the next day 5 hours before EST Zone reaches
' midnight, and the date changes locally.
' Rolling back the date is easy, just takes too much memory for now to code
' rolling from the 1st, back to the preceeding last day of the month...
'Hardware Definition:
'Nemesis Port: Function:
' Port 0 LCD
' 1 LCD
' 2 LCD
' 3 LCD
' 4 TxData Nem to PC for Programming, Debug
' 5 LCD
' 6 Org LED, 1 = On
' 7 Nem to BTM Serial Comm, 9600 (N81)
' 8 PBS2 Push Button Switch, Floats High, Pushed = Low
' 9 BTM Hardware Reset, Active LOW for 5 mSec
' 10 LCD RS
' 11 Blue LED, 1 = ON
' 12 Nem RxData from PC for Programming, or BTM for GPS data
' 13 N/C, available, pad on circuit board
' 14 N/C, available, pad on circuit board
Begin:
'Set up some variables to read in serial data sent from the BTM:
'DA - DO form a pseudo 1-dimensional array for sequential data access.
dim DA, DB, DC, DD, DE, DF, DG, DH, DI, DJ, DK, DL, DM, DN, DO, DZ
dim Lat1, Lat2, Lat3, Lat4, Lat5, Lat6, Lat7, Lat8, Lat9, LatNS
dim Lon1, Lon2, Lon3, Lon4, Lon5, Lon6, Lon7, Lon8, Lon9, Lon10, LonEW
dim Time1, Time2, Time3, Time4, Time5, Time6
dim Date1, Date2, Date3, Date4, Date5, Date6
dim Spd1, Spd2, Spd3, Spd4, Spd5
dim Trk1, Trk2, Trk3, Trk4, Trk5 'Track / Heading / Direction of Travel
dim Buff, RdChar 'Buffer and Read In Char from Buffer
dim LCDLoc 'LCD Location
dim Mode 'Display Mode, 1-3, Date&Time, Spd&Dir, Lat/Long
dim x
'Init LCD
const LCDD4 0
const LCDD5 1
const LCDD6 2
const LCDD7 3
const LCDRS 10
const LCDE 5
const TxD 7 'TxData Port Nemesis to BTM
const RxD 12 'TxData Port BTM to Nemesis, with UART, 80 char buffer
const CR 13 'CR for serial commands to BTM, 0D h, 13 dec
const LF 10 'LF, 0Ah, 10 dec
const Rst 9 'BTM Reset, Active LOW for 5 mSec
const PBS 8 'Nem Port 8 is Frt Panel Push Button switch, Pushed = LOW
configio 4, 6, 7, 9, 11 'Define Output Ports, all others are Input by Default
lcdinit LCDRS,LCDE,LCDD4,LCDD5,LCDD6,LCDD7 'LCD Setup
high Rst 'BTM Hardware Reset to Active Mode
setbaud SBAUD9600 'Set Baud rate PIC to BTM
Mode = 1 'Init LCD Display Data Mode
Main:
gosub LCDMSG 'Start up message on LCD
gosub UTCSetup 'See if Usr is entering UTC Time Zone setup mode
eeread 1, DA '0-12, Time Zone Offset for Local Time wrt GMT
eeread 2, DB '0 = Minus offsets, 1 = + offsets
gosub InitLink 'Initialize / Set Up the Bluetooth Link to GPS Rx
high 11 'LED, Blue, ON for BT Link established
gosub EmptyBuf
Lp:
gosub ChkMode 'Chk Usr Pushing Frt Panel Sw, Change LCD Display Mode
gosub FindSOP 'Find Start of Packet in incoming data stream
gosub DispInfo 'Display GPS Information on LCD
goto Lp 'Process forever.
FindSOP:
'Find the Start of a Data Packet within the incoming data stream
'then process that packet, if desired.
'SOP = "$"
'On Exit point somewhere withing the $GPxyz packet header
gosub GetChar
if RdChar <> '$' then
goto FindSOP 'Keep looking
endif
gosub GetChar 'Read and trash G
gosub GetChar 'Read and trash P
'IDPacket:
'Parse the incoming packets to identify what we have next in the data stream.
'If it is RMC, GGA, or GSV, then go process them.
'If it is GLL, GSA, or VTG, then ignore them.
'Ignore other packets, based on GPS being used.
'Algoritm: If first char = R then have RMC, then
' If second char = G then have GGA, then
' If third char = V then have GSV, else skip them.
gosub GetChar 'State Machine, Parse Header Char by Char
if RdChar = 'R' then 'Found $GPRMC
gosub GetDataRMC
gosub Speed 'Convert Speed in Kts to MPH
gosub ConvUTC 'Convert Time, UTC, to Local
gosub AlphaDir 'Convert Heading to Alpha Display (N/NE/E...)
return
endif
if Mode <> 3 then
'Mode 3 = Display Lat & Long, don't need this data
'If NOT Mode 3, then use Long variables to hold this data, for display
gosub GetChar 'State Machine, Parse Header Char by Char
if RdChar = 'G' then 'Found $GPGGA
gosub GetDataGGA
return
endif
gosub GetChar 'State Machine, Parse Header Char by Char
if RdChar = 'V' then 'Found $GPGSV
gosub GetDataGSV
return
endif
endif
return 'Keep for any other packets not processed
UTCSetup:
'See if Usr pushed and held the Frt Panel Switch on system Power up.
'If so, enter Set Up mode, for user to set the offset from UTC time
'for their local time zone.
'Pushing button cycles through 0 to -12 and 0 to +12 hours offset from UTC.
'Eastern Standard Time is UTC - 5 hrs, +/- Daylight Savings....
'Value is store for subsequent usage until re-programmed.
'Note Well: >>>>> EXIT Setup by Turning Unit OFF. <<<<<<
'Originally displayed Set Up on LCD, removed for memory space.
'Read Port 8, Frt Panel Switch, Non-Interrupt Driven...
x = 1 'Clr high bits, set bit 0 to 1
portbitget x, 0, 8 'Var X, Bit 0, Port 8 (Switch)
if x = 0 then
'Usr is pushing Frt Panel Switch, (Active Low)
'Enter Set Up Mode
' lcdcontrol 1 'Cls, Home Erase current display, Usr Feedback
' pause 2
' lcdwrite "Set"
UTCLp:
onportgoto 8, UTCLp, -
'Wait for Usr to release the Frt Panel Switch
'Cycle through 0 to - 12 Hours Offset
eewrite 2, 0 'Store 0 for minus offsets, 1 for + offsets
for DA = 0 to 12
lcdcontrol 192 'Start on Second Line, First Char Position
lcdwrite "-", dec DA , " " 'Trailing Space for overwrites
eewrite 1, DA 'Write the currently displayed value to memory
gosub Await 'Await Frt Panel Push, or Pwr Down by Usr
next
'Cycle through 0 to +12 Hours Offset
eewrite 2, 1 'Store 0 for minus offsets, 1 for + offsets
for DA = 0 to 12
lcdcontrol 192 'Start on Second Line, First Char Position
lcdwrite "+", dec DA, " "
eewrite 1, DA 'Write the currently displayed value to memory
gosub Await 'Await Frt Panel Push, or Pwr Down by Usr
next
goto UTCLp 'Loop again, EXIT by Pwr OFF !!!
endif
'Otherwise dont do Setup, Run Main program
return
Await:
'Awaiting a Frt Panel Push, Active Low when pushed. ---|____|----
'First Await push, then await release.
onportgoto 8, -, Await 'Wait for a push, if any
'If fall through, Usr pushed switch to select next UTC offset value
Release:
onportgoto 8, Release, - 'Wait for release of Switch, then fall through
return
GetChar:
'Read in a single character from the input buffer in Nemesis
'Reading in with Assem Lang on input buffer works well.
'Alternative: Serin is challenging to use.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -