⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nembtgpsa.txt

📁 Bluetooth to display GPS data with PIC16F
💻 TXT
📖 第 1 页 / 共 3 页
字号:
  'On Exit: Buff = 0 : No char in buffer; Buff = 1 : Have a char in RdChar
  'This version awaits input in the buffer before returning
  startasm
    checkbuff Buff, RdChar   'read input buffer
    while Buff = 0
      checkbuff, Buff, RdChar
    wend
  endasm
  return

EmptyBuf:
  'Read in UART Input Buffer, Empty it
  'This version uses Assem Lang, is faster
  'Buff = 0 = Empty flag
  startasm
    checkbuff, Buff, RdChar  'Read input buffer
    while Buff = 1
      checkbuff, Buff, RdChar
    wend
  endasm
  return

InitLink:
  'Reset the BTM, and initialize (set up) a BT link to the BT GPS
  'Do a BTM HARDWARE Reset
    low Rst           'HARDWARE RESET BTM This is necessary, PwrUp
    pause 10          'Min 5 mSec
    high Rst
 
  'Issue Discovery Command, see what BT Devices are out there
    'Wait 10 to 10 Sec for Discovery, plus a bit
    gosub DiscoveryBTM    'Send Discovery Command
    longpause 250, 82   'Wait up to 10 Sec...
    
    'Now Empty the buffer of the Name and ID for all 
    'of the answering devices
    gosub EmptyBuf 

  'Now Issue Bond to BT GPS Unit, already knowing its ID code
    gosub BondBTM

IL1:
    gosub GetBTM2          'First get BondPending, then BondOk
    if DF <> 'k' then      'Looking for BondOk
      goto IL1             'Init Loop 1, still Bonding (Can lock up)   
    endif
     'gosub DispResp
  'Now Issue Connect using SPP Protocol
     'lcdcontrol 1        'Cls, Home
     'pause 2
     'lcdwrite "SP"
     'longpause 250, 2
     gosub SPPConnectBTM    'Connects, (Can lock up)
IL2:
    gosub GetBTM2
    if DA <> 'C' then      'Looking for ConnectUp
       'Have an error, did not connect, can try again...
       'lcdcontrol 1        'Cls, Home
       'lcdwrite "ERR"
       'longpause 250, 12
       goto InitLink     
    endif
  return

GetDataRMC:
  'This is the Recommended Minimum Navigation Information data string
  'Format: $GPRMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,xxxx,a,m,*hh<CR><LF>
  'UTC Time, V/A (A=Valid Data, V=Warning), Latitude, N/S, Longitude, E/W
  'Speed over grnd in Knots, Track made good in Degrees True, Date ddmmyy
  'Mag variation in degrees, E/W, FAA Mode Indicatior, Checksum
  '$GPRMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,xxxx,a,m,*hh<CR><LF>
  'Put in DA, DB, ...
  'SKIP ERROR HANDLING for now... 

  gosub NextField      'Skip over "MC,"

  'Parse UTC Time Info:
  'Read in UTC Time
  for x = 0 to 5      'Read in TIME HHMMSS, skip tenths of Sec
    gosub GetChar
    arrayset Time1, x, RdChar 'Read into sequential variables
  next x  

  gosub NextField          'Skip  .xxx,V,    (Tenths of Sec time)
  gosub NextField 

  if Mode = 3 then
    'Parse in the Lat & Long data, otherwise use their variables elsewhere
    'Parse Latitude Info:
    for x = 0 to 8      'Read in Latitude  XXXX.XXXX,N/S
      gosub GetChar
      arrayset Lat1, x, RdChar 'Read into serial variables
    next x 
    gosub GetChar
    gosub GetChar
    LatNS = RdChar
    gosub GetChar

    'Parse Longitude Info:
    for x = 0 to 9      'Read in Longitude  XXXXX.XXXX,E/W
      gosub GetChar
      arrayset Lon1, x, RdChar 'Read into serial variables
    next x 
    gosub GetChar
    gosub GetChar
    LonEW = RdChar
    gosub GetChar
  else
    'Skip over it
    for x = 1 to 4
      gosub NextField
    next x
  endif

  'Now SUBPARSE SPEED and TRAK Data... bummer
  'Speed: My BT GPS reports 0.00 for stationary, 4 characters
  'Im allowing 5 char for speed in this program.
  'If going 125 mph, then would get 125.70  5 of 6 characters
  'If going  34 mph, then would get  34.30  5 of 5 characters
  'I don't care about decimal speed...
  'If the 5th character is a comma, then overwrite it to space, for display.

  'Parse Speed Info:
  for x = 0 to 4      'Read in Speed, up to 5 characters for this program
    gosub GetChar
    arrayset Spd1, x, RdChar 'Read into sequential variables
  next x 
  if RdChar <> ',' then
    'If did not yet hit end of speed info, then find it
    gosub NextField
  endif
  if Spd5 = ',' then
    Spd5 =  ' '      'Overwrite trailing comma delimiter if speed = 0.00,
  endif

  'Parse Track (Heading, Bearing, ...) Info:
  'Already trashed the comma on entry
  for x = 0 to 4      'Read in Track, up to 5 characters for this program
    gosub GetChar
    arrayset Trk1, x, RdChar 'Read into sequential variables
  next x 
  if RdChar <> ',' then
    'If did not yet hit end of speed info, then find it
    gosub NextField
  endif
  if Trk5 = ',' then
    Trk5 =  ' '      'Overwrite trailing comma delimiter if Trk = 0.XX,
  endif 

  'Parse Date Info:
  'Already trashed the comma on entry
  for x = 0 to 5      'Read in Date, 6 characters 
    gosub GetChar
    arrayset Date1, x, RdChar 'Read into sequential variables
  next x 

  return

GetDataGGA:
  'Packet includes Number of Active Satellites, those used for calculations.
  'Also includes Altitude, Meters, currently not used.
  for x = 1 to 7
    gosub NextField
  next x
  gosub GetChar
  Lon3 = RdChar
  gosub GetChar
  Lon4 = RdChar
  return

GetDataGSV:
  'This is the Satellites in View Data Packet.
  'It includes their signal strength.
  'Format: $GPGSV,x,x,x,x,x,x,x,...*hh<CR><LF>
  'Field 1: Total number of GSV Messages, data is dispersed in several...
  '      2: This Messages number, 1 - n
  '      3: Number of Satellites in View
  '      4...  Sat #, Elevation, Azimuth, SNR; repeat for more satellites, ChkSum
  for x = 1 to 3
    gosub NextField
  next x
  gosub GetChar
  Lon1 = RdChar
  gosub GetChar
  Lon2 = RdChar
  return

NextField:
  'Parse and Trash GPS data packet up to and through the next comma
  gosub GetChar
  if RdChar <> ',' then    'Single Quotes, Note Athena Language Syntax!
    goto NextField
  endif
  return

DispInfo:
  'Disp the GPS Data on a 2 line x 16 Char / line LCD
  'Added Mode Selected Display Options
  'Display Mode 3 = Lat & Long, if not in this mode, then use
  'Longitude variables for other data.

  lcdcontrol 1    'Cls, Home, First line, First Char position
  pause 2
  
  if Mode = 1 then
    'Disp Date & Time
    'Disp Number of Active Satellites, and Number of Sats in View
    'Time is UTC Converted to Local Time
    'NOTE: Date is UTC, it is not converted to local date, (memory).
    lcdwrite dec Time1, ":", Time3, Time4, ":", Time5, Time6  'HH:MM:SS  
    lcdwrite "  ", Lon3, Lon4, "/", Lon1, Lon2  'Active and in View Sats                 
    lcdcontrol 192      'Line 2
    pause 2 
    lcdwrite Date3, Date4, "/", Date1, Date2, "/", Date5, Date6 ' MM/DD/YY 
  endif

  if Mode = 2 then
    'Display Speed (MPH), Heading (degrees), and Alpha Direction (N NE E ...)
    'Display the Number of Active Satellites, and Total Number in View 
    'Spd in MPH, in DC
    'DK is numeric number of Satellites used to calculate the current position.
    'Ignore 10ths of Degree Track, but have the info if desired.
    'Ignore Spd in Knots, but have it if desired.
    'Note: Data for this Mode changes number of characters used as speed and direction
    'change, therefore format appropriately.
    lcdwrite "S ", dec DC, "  ", "D ", Trk1, Trk2, Trk3, 223, " ", DN,DO 
    lcdcontrol 192    'Start on Second Line, first char position
    lcdwrite Lon3, Lon4, "/", Lon1, Lon2  'Active and in View Sats  
  endif
 
  if Mode = 3 then
    'Display Position Info, Lat & Long Only      (223 dec displays degree sign on LCD)
    lcdwrite "Lt  ", Lat1, Lat2, 223, Lat3, Lat4, Lat5, Lat6, Lat7, Lat8, Lat9, " ", LatNS
    lcdcontrol 192    'Start on Second LIne, first char position
    lcdwrite "Lg ", Lon1, Lon2, Lon3, 223, Lon4, Lon5, Lon6, Lon7, Lon8, Lon9, Lon10, " ", LonEW
  endif
  
  'Out of Nemesis Memory, otherwise:
  'Mode 4  Display Streaming NMEA GPS data on LCD
  'Mode 5 Display Software file Name, Version Number, Rev. Date
  return
 
ChkMode:
  'Read Port 8, Frt Panel Switch, Non-Interrupt Driven...
  'User Pushes to cycle through various LCD Data Display Options
  'Push and HOLD... until cpu gets around to reading it, Interrupts would be better!
  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)
    lcdcontrol 1          'Cls, Home    Erase current display, Usr Feedback
    pause 2
    Mode = Mode + 1  
    If Mode = 4 then      'Wrap around Mode, impliment Modes 1 -> 3, out of memory
      Mode = 1
    endif
  endif
  return

ConvUTC:
  'Convert UTC Time to local time for LCD display.
  'EST is UTC - 5 hours.  (Coordinated Universal Time)
  'Note: Are not adjusting the date.
  'Can adjust offset for various time zones, and daylight savings time
  'through SETUP Mode.  Done manually, not automatically.
  'Must convert ASCII String of HRS to numeric, add/sub the Offset.
  'Skip conversion back to ASCII, just display dec Hrs, ASCII Min, Sec.
  'ON Exit: Time Hours, numeric, is stored in Time1
  eeread 1, DK      'Read in stored OFFSET, 0 to 12
  eeread 2, DL      'Read in offset sign, 0 = -, 1 = +
  DH = Time1        'Tens of Hours, ASCII
  DH = DH - 48      'Tens of Hours, numeric
  DH = DH * 10      'Conv to 10s, numeric
  DI = Time2        'Ones of Hours, ASCII
  DI = DI - 48      'Ones of Hours, numeric
  DJ = DH + DI      'Add 10s and 1s hours, (0-24, numeric)
  if DL = 0 then
    'Subtract offset
    if DJ >= DK then
      DJ = DJ - DK    'Just subtract the offset
    else
      DM = DK - DJ    'the difference, ( 1,  2, ...)
      DJ = 24 - DM    'Roll Back
    endif
  else
    'Add offset
    DJ = DJ + DK
    if DJ > 24 then
      DJ = DJ - 24    'Roll Over
    endif
  endif
  Time1 = DJ
  return

ResetBTM:
  'Send a RESET Command to the BTM
  high TxD
  serout TxD, "AT+ZV Reset", CR
  return

DiscoveryBTM:
  'Send Command for BTM to Issue Discovery Command
  high TxD
  serout TxD, "AT+ZV Discovery", CR
  return 

BondBTM:
  'Send Command to BOND to BTGPS Unit
  'Need to knows its BT Address, and PIN code
  'Note: Can do Discovery to get it, or hard code for now...
  '+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  '+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*  
  '+*+*+*  NOTE: Replace the 12 character UNIQUE BT address for 
  '+*+*+*  your own BT GPS Receiver in the following command.
  '+*+*+*  Also use your own 4 character PIN code, supplied with the
  '+*+*+*  info with your BT GPS, often 0000 or the last 4 chars of
  '+*+*+*  the unique ID code.
  '+*+*+*  NOTE: Must change ID Code in the following subroutine, also!
  '+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  '+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -