MPASM Help


Closed Thread
Results 1 to 8 of 8

Thread: MPASM Help

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Posts
    74


    Did you find this post helpful? Yes | No

    Default

    No, Modbus ASCII LRC Calculation

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


    Did you find this post helpful? Yes | No

    Default

    Assume LRC = 10.

    LRC = 256 - LRC. Which works out to LRC = 246, but returns a warning message.

    Now try this approach with LRC still = 10;

    LRC = $FF - LRC ' LRC = 255 - 10. Now LRC = 245
    LRC = LRC - 1. Now we have 245 - 1 which = 244. Oops! Not what we expected, although it
    looked darn good at 1st glance.

    Now try this, and see if you can figure out why it works & doesn't return the warning
    message;

    LRC = !256-LRC ' LRC = NOT 256 - LRC

    Here's a short test to verify it;
    Code:
    LRC VAR BYTE
    X VAR BYTE
    
    Main:
        FOR X = 0 TO 255
        LRC = X ' We'll work with LRC = 0 to 255 to prove it works
        HSEROUT ["256-",DEC X,"="]
        LRC = !256-LRC
        HSEROUT [DEC LRC,13,10]
        NEXT X
    Here:
        GOTO Here ' done    
        END
    Food for thought ehh....;o}

    A more efficient approach would be to just promote LRC to a word variable,
    and use the lower byte for your result, but this is pretty cool.
    Last edited by Bruce; - 19th February 2008 at 22:51. Reason: A better way
    Regards,

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

  3. #3
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Bruce View Post
    .....Now try this, and see if you can figure out why it works & doesn't return the warning message;
    That's pretty slick...
    I almost missed it and was about to reply back that you were wrong in this instance. Good thing I didn't. My foot goes in my mouth enough as it is...

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


    Did you find this post helpful? Yes | No

    Default

    It certainly wouldn't be the 1st time I was wrong, but it does work..;o}
    Regards,

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

Similar Threads

  1. 16F914 and MPASM
    By jderson in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 7th February 2009, 04:21
  2. 12F675 MCLR directive MPASM
    By OLDSCHOOL in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 4th May 2008, 02:29
  3. MPASM 18F4550 getting started
    By BrianT in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th September 2007, 00:59
  4. 18F8722 and MPASM confusion!
    By Jackson in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 2nd April 2006, 02:24
  5. Converting to MPASM
    By btaylor in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 4th November 2005, 02:35

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