Creating Checksum in PBP


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Feb 2004
    Location
    Germany
    Posts
    762


    Did you find this post helpful? Yes | No

    Default

    Tom,

    I have dealt with NMEA a few times in the past.

    The checksum is optional, and you do not really need it
    (as long as your wires aren't too long and the environment isn't too "noisy")

    What the example does is pretty simple:

    -----
    Num_To_ASCII:
    Dec_lat1 = 119
    C[7] = Dec_lat1 DIG 2+"0" ' element c[7] = ASCII 1
    -----

    DIG2 of Dec_lat1 in this example is decimal 1 (or $01)
    the ASCII value for the character "1" is 31, so you need to add 30
    (which equals the the decimal value of the ASCII character "0")
    to get the ASCII value for this character

    You could also use this:
    -----
    C[7] = Dec_lat1 DIG 2+30 ' element c[7] = ASCII 1
    -----

    (hope it is not too confusing)
    Last edited by NavMicroSystems; - 14th March 2005 at 17:10.
    regards

    Ralph

    _______________________________________________
    There are only 10 types of people:
    Those who understand binary, and those who don't ...
    _______________________________________________



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


    Did you find this post helpful? Yes | No

    Default

    Just look at any ASCII chart to understand what's happening.

    With PBP most people assume sending serial data goes something like this;
    Code:
    X VAR BYTE
    X = 123
    
    Main
        SEROUT2 0,16468,[DEC X]
        PAUSEUS 200
        GOTO Main
    You would assume you're sending a single byte, but PBP is first converting your three decimal digits in X into three separate ASCII characters, and sending a total of three bytes. "1" then "2" then "3". That's what the DEC modifier does.

    So your PC isn't receiving a single byte value of 123. It's receiving three separate bytes. ASCII characters 1 then 2 then 3. This is what it's using to calculate the checksum.

    Since your PC checksum program runs a cumulative checksum calculated from each separate ASCII digit, you just need to do the same with your PIC-based cheksum program before sending the final checksum result to the PC.

    Try running this with a PIC connected to your PC serial port, and see what displays in a terminal window.
    Code:
    X = 123
    
    Main
        HSEROUT [DEC X,13,10]
        HSEROUT [X,13,10]    
        PAUSEUS 2000
        GOTO Main
    Regards,

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

  3. #3


    Did you find this post helpful? Yes | No

    Post

    Hi,

    The attached file may be of some help.

    Cheers.
    Attached Images Attached Images
    ---> picnaut

Similar Threads

  1. PBP Book
    By Bruce in forum Off Topic
    Replies: 83
    Last Post: - 4th October 2021, 13:55
  2. Checksum
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th October 2009, 05: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, 23:50
  4. Replies: 1
    Last Post: - 10th May 2006, 16:17
  5. Checksum problem!
    By atomski in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 3rd November 2004, 08: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