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

📄 nembtgpsa.txt

📁 Bluetooth to display GPS data with PIC16F
💻 TXT
📖 第 1 页 / 共 3 页
字号:
  high TxD
  serout TxD, "AT+ZV BOND 00081b0ca81b 0000", CR
  return    
  
SPPConnectBTM:
  'Send Command to BTM to perform SPPConnect
  'After Bonded, this sets up serial data flow, bi-directional
  'Skip sending SERVICE, as BT GPS has none
  '+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  '+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*  
  '+*+*+*  NOTE: Replace the 12 character UNIQUE BT address for 
  '+*+*+*  your own BT GPS Receiver in the following command.
  '+*+*+*  NOTE: Must change ID Code in the above subroutine, also!
  '+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  '+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*+*
  high TxD
  serout TxD, "AT+ZV SPPConnect 00081b0ca81b", CR
  return    

GetBTM2:
  'Parse serial input from BTM looking for its response
  'Response is always AT-ZV_XYZ...  (_ = SPACE)
  'Space character after the V, before the true response
  'This leaves trash in the buffer, the rest of long responses
  'Flash LED when find BTM Responses

  gosub GetChar
  if RdChar <> 'A' then 
    goto GetBTM2
  endif
  gosub GetChar
  if RdChar <> 'T' then
    goto GetBTM2
  endif
  for DZ = 1 to 4       'AT-ZV_   Skip Checking Each Char for now
    gosub GetChar
  next DZ

  high 6                'LED On, found a command response header
  
  for x = 0 to 14       'Read in variable length response
    gosub GetChar
    if RdChar = 13 then            'CRLF End Of Response
      goto GetDone
    endif
    arrayset DA, x, RdChar         'Store in DA, DB, DC, DD... DO
  next x
GetDone:
  low 6                 'LED Off
  return

DispResp:
  'Display the BTM Response on the LCD
    lcdcontrol 1    'Cls, Home, First line, First Char position
    pause 2
    for x = 0 to 14      'Length of LCD Line...
      arrayget DA, x, DZ 'Store in DA, DB...
      lcdwrite DZ
    next x
    return

Speed:
  'Convert Speed in variable length ASCII values to numeric, then to MPH
  'On Entry Have: Spd1, Spd2...5, with a decimal point SOMEWHERE, and each is 
  'an ASCII Character.  MY GPS: Minimum reported is 0.00 (Knots) --> eg 123.35 MPH...
  'This program, Max of 5 characters allowcated to Speed in Knots Data.
  'First Char in speed is Spd1, etc.
  'Not worried about Rounding Errors for now...
  'Conversion Error is 0 - +1 MPH for 0-100 Kts, 0 - +2 MPH at 150 Kts
  'On Exit DC = Speed in MPH, decimal, numberic

  DD = Spd1
  DD = DD - 48        'ASCII to Numeric Conversion  eg 4 ASCII -> 4 dec
 
  if Spd2 = '.' then
    'Have 0.00x format, ie single units, 0 - 9 Knots speed.
    'Algorithm: If speed is >= 4 knots, just add 1 for rounded MPH
    gosub ConvOnes          'Convert Knots to MPH
  endif
  
  if Spd3 = '.' then
    'Have 37.25 Knots format, ie 2 ASCII Chars represent Spd in Knots, round up tenths of Knots
    'Speed is 10 - 99 Knots.
    'Algorithm: Divide Spd(Kts) by 6, integer is how much to add to get approx MPH
    'Error is 0 to +1 in MPH value, up to 100 Kts
    'First convert 2 Char spd to numeric
    DD = Spd2          'ASCII Ones Digit  (Kts)
    DD = DD - 48       'ASCII to numeric  (Kts)
    DE = Spd1          'ASCII Tens Digit  (Kts)
    DE = DE - 48       'ASCII to numeric  (Kts)
    DE = DE * 10       'Integer multiply  (Kts)
    DC = DD + DE       'Add 10s Kts and 1s (Kts), DC is now numeric speed in Kts
    DG = Spd4          'ASCII Tenths      (Kts)
    DG = DG - 48       'ASCII to numeric  (Kts)
    if DG > 4 then
      'Round up 0.5 and higher fractional Kts
      DC = DC + 1
    endif
    DF = DC / 6        'Integer divide, ignore any remainder
    DC = DC + DF       'Add conversion offset, DC = Speed in MPH, numeric
  endif

  if Spd4 = '.' then
    '--->  If you are driving, you are speeding... <---
    'Have 123.57 Knots format, ie 3 ASCII Chars respresent Spd in Kts, round up tenths of Kts
    'Speed is 100 - And Up Kts
    'Use same algorithm as 10 - 99 Kts, at 150 Kts error is +2 MPH (175 instead of 173 MPH)
    'Algorithm works for Speed up to 255 MPH, limited by 8 bit integers for now.
    'For cars, and my driving, this is not a problem...
    DD = Spd3          'ASCII Ones Digit  (Kts)
    DD = DD - 48       'ASCII to numeric  (Kts)
    DH = Spd5          'ASCII Tenths      (Kts)
    DH = DH - 48       'ASCII to numeric  (Kts)
    if DH > 4 then
      'Round up 0.5 and higher fractional Kts
      DD = DD + 1
    endif 
    DE = Spd2          'ASCII Tens Digit  (Kts)
    DE = DE - 48       'ASCII to numeric  (Kts)
    DE = DE * 10       'Integer multiply  (Kts)
    DF = Spd1          'ASCII 100s digit  (Kts)
    DF = DF - 48       'ASCII to numeric  (Kts)
    DF = DF * 100      'Integer multiply  (Kts)  (Works for 100 and 200 Kts, not 300 or greater...)
    DC = DD + DE       'Add 10s Kts and 1s (Kts), DC is now numeric speed in Kts
    DC = DC + DF       'Add 100s to it
    DG = DC / 6        'Integer divide, ignore any remainder
    DC = DC + DG       'Add conversion offset, DC = Speed in MPH, numeric    
  endif     
  return

ConvOnes:
  'Convert Ones Digit Knots to MPH
  'On Entry have: DD = Numeric Ones Spd in Knots
  'On Exit DC = Ones Spd in MPH
    'Have 0.00x format, ie single units, 0 - 9 Knots speed.
    'Algorithm: If speed is >= 4 knots, just add 1 for rounded MPH
    if DD > 3 then
      DC = DD + 1    'Speed in MPH = numeric Knots + 1
    else
      DC = DD        'Speed in MPH, numeric
    endif
    DG = Spd3          'ASCII Tenths      (Kts)
    DG = DG - 48       'ASCII to numeric  (Kts)
    if DG > 4 then
      'Round up 0.5 and higher fractional Kts
      DC = DC + 1
    endif
  return

AlphaDir:
  'Convert Track (Heading/Bearing/Direction) in ASCII String, degrees, 
  'to N/E/S/W
  'On Entry have Trk1, 2, 3, 4, 5
  'On Exit have Index into array for  N NE E SE S SW W NW 
  'On Exit DN & DO have N NE E etc, 2 characters of alpha data
  'Note: For this item, divide Track by 2, so range is 0 - 180 Degrees
  'This Range fits in single byte, (0-255). Resolution is 2 Degrees.
  'i.e. Can not do 359 degress in single byte integer math

  DI = Trk1                  'Can change to parse into these
  DJ = Trk2                  'Get the Tracking ASCII String Data
  DK = Trk3
  DL = Trk4
  DM = Trk5
  gosub Alpha3Conv          'Convert ASCII String Track to numeric, 0-180 Full circle
  DI = DI + 12              'Offset into Arc
  DI = DI / 22              'Arc Sector 0, 1, 2..., 8 = N NE E...
  'Arc Sector:    0    1    2    3    4    5    6    7    8
  lookup DN, DI, 'N', 'N', 'E', 'S', 'S', 'S', 'W', 'N', 'N'  
  lookup DO, DI, ' ', 'E', ' ', 'E', ' ', 'W', ' ', 'W', ' '
  return

Alpha3Conv:
  'Convert a variable length ASCII number to numeric output.
  'Data Packet parses 5 chars into DI, DJ, DK, DL, DM
  'Could have 1, 2, or 3 places before the decimal point.
  'eg: 0.00 Knots, 37.45 Knots, 359.9 Degrees, etc.
  'On Exit: DI has the Integer Numeric Value for this data.
  'Degrees is Divided  by 2, so range is 0 - 180 for Full Circle.
  'This fits in 1 byte integer math, resolution is 2 Degrees.
  '(359 Degrees doesnt fit in 1 byte)
  
  if DJ = '.' then
    'Case 1: 1 place before decimal point
    DI = DI - 48        'ASCII to Numeric Conversion, Ones
    DK = DK - 48        'ASCII to Numeric Conv, Tenths
    if DK > 4 then
      DI = DI + 1       'Round it up
    endif
    DI = DI / 2         'Scale it, Divide by 2
  endif

  if DK = '.' then
    'Case 2: 2 places before decimal point  
    DI = DI - 48      'ASCII to Numeric Conv, Tens
    DI = DI * 10      'Conv to 10s
    DJ = DJ - 48      'ASCII to Numeric Conv, Ones
    DI = DI + DJ      'Sum of Tens and Ones
    DL = DL - 48      'ASCII to Numeric Conv, Tenths
    if DL > 4 then
      DI = DI + 1     'Round it up
    endif    
    DI = DI / 2       'Scale it, Divide by 2
  endif

  if DL = '.' then
    'Case 3: 3 places before decimal point   EXCEEDS 1 BYTE INTEGERS 
    'Use DJ for High Byte (bit), and DI for Low Byte
    DI = DI - 48      'ASCII to Numeric Conv, 100s, (0, 1, 2, 0r 3, eg 359.9 Deg)
      if DI = 3 then  'Scale 100s by 1/2, input is in 300s range
        DI = 150
      endif
      if DI = 2 then  'Input is in 200s range
        DI = 100
      endif
      if DI = 1 then  'Input is in 100s range
        DI = 50
      endif
    DJ = DJ - 48      'ASCII to Numeric Conv, 10s
    DJ = DJ * 10      'Conv to 10s
    DK = DK - 48      'ASCII to Numeric Conv, 1s
    DJ = DJ + DK      'Sum 10s & 1s
    DM = DM - 48      'ASCII to Numeric Conv, Tenths
    if DM > 4 then
      DJ = DJ + 1     'Round it up
    endif    
    DJ = DJ / 2       'Scale by 1/2
    DI = DI + DJ      'Sum 100s & (10S & 1s), all scaled by 1/2
  endif
  return

LCDMSG:
  'LCD Start Up Message    (Out of Memory for Longer Message...)
    lcdcontrol 1    'Cls, Home, First line, First Char position
    pause 2
    lcdwrite "GPS"
 '   lcdcontrol 192   'Start on Second Line, First Char Position
 '   lcdwrite "JEC  V 1.0"
 '   longpause 250,3
 '   lcdcontrol 1    'Cls, Home, First line, First Char position
 '   pause 2
  return  

'DisconnectBTM:
   'Send Command to BTM to perform SPPDisconnect      
'  high TxD
'  serout TxD, "AT+ZV SPPDisconnect", CR
'  return 

'VersionBTM:                                
   'Query for BTM Version #                  
'  high TxD
'  serout TxD, "AT+ZV Version", CR
'  return   


'Vers:
    'Query BTM Version, get single packet response
'   lcdcontrol 1        'Cls, Home, First line, First Char position
'   pause 2
'   lcdwrite "Get Version"
'   longpause 250, 1
'   gosub VersionBTM
'   longpause 250, 1
'   gosub GetBTM2       'Get Response:  "AT-ZV ZerialVer 6.1"
'   gosub DispResp
'   gosub CRTResp       '+++
'   longpause 250, 1
'   if DA <> 'Z' then
'     goto Vers         'Keep trying until get exected result
'   else
'     longpause 250,2   'Read Version #
'   endif

'SoftReset:   
    'Reset BTM  (Optional, but good to watch, and to read Wintec Modules own ID) 
'   gosub EmptyBuf          'Clr Nem UART Buffer      +++++++++==
'   lcdcontrol 1            'Cls, Home
'   pause 2
'   lcdwrite "Soft Reset"
'   longpause 250, 2
'   gosub ResetBTM           'Send Software RESET BTM Command
'   longpause 250, 4         ' Tweak later
'   gosub GetBTM2            '"AT-ZV ResetPending" 
'   gosub DispResp
'   longpause 250, 1
'   gosub GetBTM2            '"AT-ZV -CommandMode-"
'   gosub DispResp
'   longpause 250, 1
'   gosub GetBTM2            ' Addr of this BT Module
'   gosub DispResp           '"AT-ZV BDAddress 000f70...   "
'   longpause 250, 1

'FlashLEDs:
'  for x = 1 to 5
'    high 11
'    low 6
'    pause 100
'    low 11
'    high 6
'    pause 100
'  next
'  low 6
'  return

'TestLCD:
     'LCD Test
'    lcdcontrol 2    'Home, line 1, non-destructive
'    pause 2
     lcdcontrol 1    'Cls, Home, First line, First Char position
'    pause 2
'    lcdwrite "12345.....*"
'    lcdcontrol 192   'Start on Second Line, First Char Position
'    for x = 65 to 80
'     lcdchar x
'    next


⌨️ 快捷键说明

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