CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

CRC_XMODEM

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
aldinlapinig



Joined: 16 Dec 2005
Posts: 22

View user's profile Send private message

CRC_XMODEM
PostPosted: Tue Mar 21, 2006 8:30 pm     Reply with quote

hi all,

anybody have any idea on how to generate the CRC-XMODEM checksum using CCS C? I'm trying to interface an RFID reader module (TI product) with 18f877a. They'r using CRC-XMODEM algorithm (poly = 0x8408) for their data CRC. I tried to use CRC.C (of CCSC) but the pattern available for generating 16-bit CRC is only 0x1021 (CRC-CCITT). Any idea on how I cud modify the driver to fit my needs or write another driver? Any help will be highly appreciated. Thanx everyone!

hopefully I could get something for CCS C.

-=alDin=-
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Tue Mar 21, 2006 11:51 pm     Reply with quote

Here's a VB routine that you might find useful (I use it for file transfers)

Code:

Const CRC_TABLE_SIZE = 256

Public Sub createcrctab()
  'Added by ErrHandler parser
  On Error GoTo ErrHandler

  Dim b As Long
  Dim v As Long
  Dim i As Long

  'this the number of bits per char: don't change it.
  Const BITS_PER_CHAR = 8
  'number of bits in CRC: don't change it.
  Const CRC_BITS = 16
  'CCITT polynomial
  Const P = &H1021

  'CITT reverse polynomial
  'Const P = &H8408
 
  'CRC16 polynomial
  'Const P = &H8005
 
  'CRC16 reverse polynomial
  'Const P = &HA001
 
  For b = 0 To CRC_TABLE_SIZE - 1
    v = b * (2 ^ (CRC_BITS - BITS_PER_CHAR))
    For i = 1 To 8
      If (v And &H8000) Then
        v = v And &H7FFF
        v = (v * 2) Xor P
      Else
        v = v * 2
      End If
    Next i
    crctab(b) = v
  Next b

  'Added by ErrHandler parser
  Exit Sub

'Added by ErrHandler parser
ErrHandler:
  Dim myerror As String

  myerror = "The following error has occurred:" + vbCr + _
            "Error: " + Format$(Err, "0") + vbCr + Error$(Err) + vbCr + _
            vbCr + "This error occurred in Public Sub createcrctab()."
  MsgBox myerror, vbExclamation, "Error"
  Resume Next

End Sub
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group