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
Posted: Tue Mar 21, 2006 11:51 pm
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
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