CRC Calculation - Need a little help


Closed Thread
Results 1 to 9 of 9

Hybrid View

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


    Did you find this post helpful? Yes | No

    Default

    Here ya go..!
    Code:
    Poly    con $8408   ' CRC polynomial
    I       VAR BYTE
    pData   VAR BYTE
    X       VAR BYTE
    CRC     VAR WORD
    C_Data  VAR WORD
    VAL     VAR BYTE[3] ' Holds 3 values passed to CRC routiine
    
    VAL[0] = $AA
    VAL[1] = $05
    VAL[2] = $01
    
    Begin:
        CRC = $FFFF
        for X = 0 TO 2
          pData = VAL[X]
          gosub Calc_CRC
        next X
        CRC = ~CRC
        hserout [IHEX CRC.LowByte,IHEX CRC.HighByte,13,10]
        pause 1000
        goto Begin
        
    Calc_CRC:
        C_Data = $00FF & pData
        CRC = CRC ^ C_Data
        for I = 0 to 7
            if CRC.Bit0 = 1 then
             CRC = (CRC >> 1) ^ Poly
            else
             CRC = CRC >> 1
            endif
        next I
        return
    I'll let you figure out how to send your original data with the final result, but there's your C-to-BASIC
    conversion. Much easier than the assembly routine, but still easier in C....;o]
    Regards,

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

  2. #2
    Steve43's Avatar
    Steve43 Guest


    Did you find this post helpful? Yes | No

    Default

    Works perfectly! Thanks Bruce, I once again find myself in your debt. Your solution is simple and elegant and is actually a better option for me than what I started out with (although I did learn something by playing with the assembly integration examples.)

    Again, this forum is a great resource and thanks to you and the others who help the rest of us over the rough spots...

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


    Did you find this post helpful? Yes | No

    Default

    You're very welcome. Glad I could help...;o]

    I learn a lot here myself. Great resource.
    Regards,

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

Similar Threads

  1. Dallas CRC8 Routines
    By Tom Estes in forum Code Examples
    Replies: 23
    Last Post: - 8th May 2018, 18:07
  2. Calculating CRC for Modbus RTU
    By tekart in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 20th January 2010, 22:42
  3. CRC Calculations
    By timmers in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 16th June 2009, 17:10
  4. Sensirion CRC
    By Tom Estes in forum Code Examples
    Replies: 3
    Last Post: - 9th November 2007, 15:09
  5. Dallas 1-Wire CRC Calculation
    By CocaColaKid in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 15th August 2005, 09:43

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