Creating Checksum in PBP


Results 1 to 9 of 9

Threaded View

  1. #5
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Your VB program is calculating the checksum using every single
    ASCII digit. If you want to do this with your PIC, then you'll need
    to work with single ASCII digits also. At least when calculating the
    checksum.
    Code:
    X        VAR BYTE
    SUM      VAR byte
    Dec_lat1 VAR BYTE
    Dec_lat2 VAR BYTE
    C        VAR BYTE [35]
    
    ' Load array string with "$GPWPL,119.98,W,47.3456,N,TOMHOME,*"
    
    ' Note: Dec_Lat1 & Dec_Lat2 ASCII values are computed in Num_To_ASCII
    ' sub-routine. This converts individual DIGits from each byte into ASCII.
    ' Array elements to be converted to ASCII are marked with an x.
    
    C[0]="$"  :C[1]="G"  :C[2]="P"  :C[3]="W"  :C[4]="P"  :C[5]="L"
    C[6]=","  :C[7]="x"  :C[8]="x"  :C[9]="x"  :C[10]="." :C[11]="x"
    C[12]="x" :C[13]="," :C[14]="W" :C[15]="," :C[16]="4" :C[17]="7"
    C[18]="." :C[19]="3" :C[20]="4" :C[21]="5" :C[22]="6" :C[23]=","
    C[24]="N" :C[25]="," :C[26]="T" :C[27]="O" :C[28]="M" :C[29]="H"
    C[30]="O" :C[31]="M" :C[32]="E" :C[33]="," :C[34]="*"
    
    MAIN:
        SUM = 0         ' Clear SUM on entry
        GOSUB Num_To_ASCII ' Convert Lat1 & Lat2 to ASCII for calculation
        GOSUB CheckSum  ' Calculate checksum of array
        HSEROUT [STR C\35,HEX SUM,13,10] ' Now show retult
        PAUSE 2000
        GOTO Main
    
    CheckSum:
        ' 33 bytes from "G" to "," chopping off "$" & "*"
        FOR X = 1 TO 33
          SUM = (SUM ^ C[X])
        NEXT X
        RETURN
        
    Num_To_ASCII:
        Dec_lat1 = 119
        C[7] = Dec_lat1 DIG 2+"0" ' element c[7] = ASCII 1
        C[8] = Dec_lat1 DIG 1+"0" ' element c[8] = ASCII 1
        C[9] = Dec_lat1 DIG 0+"0" ' element c[9] = ASCII 9
        Dec_lat2 = 98
        C[11] = Dec_lat2 DIG 0+"0"
        C[12] = Dec_lat2 DIG 1+"0"    
        RETURN
                
        END
    This returns the same checksum values as your VB program.

    Just modify the Num_To_ASCII routine to work on whatever byte
    (or word) variables you have your longitude/latitude data in. Convert
    each digit to ASCII, and stuff them into the appropriate array element
    spaces.

    The output captured in a terminal program from the above is
    $GPWPL,119.89,W,47.3456,N,TOMHOME,*23

    A slightly modified version of your VB program outputs the same.
    Code:
    Private Sub Command1_Click()
    Dim sText As String
    Dim NMEAChecksum As String
    Dim i&, sum&
    
    sText = "$GPWPL,119.98,W,47.3456,N,TOMHOME,*"
    
    For i = 2 To Len(sText) - 1
        sum = sum Xor Asc(Mid$(sText, i, 1))
    Next i
    
    NMEAChecksum = Right$("0" & Hex$(sum), 2)
    
    Debug.Print sText & NMEAChecksum
    
    End Sub
    Last edited by Bruce; - 14th March 2005 at 01:03.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 12:55
  2. Checksum
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th October 2009, 04:09
  3. Calculate Byte Value Checksum in PBP Pro
    By Pedro Pinto in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 8th July 2009, 22:50
  4. Replies: 1
    Last Post: - 10th May 2006, 15:17
  5. Checksum problem!
    By atomski in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd November 2004, 07:21

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts