User's Manual

Table Of Contents
Document : WCAMODHEL.sxw
CRC principle coding in C language :
#include <iostream.h>
#include <stdio.h>
#include <string.h>
void main ( )
{
int Poly = 0x8408;
int lg = 9;
unsigned int Frame [] = { 0x0B, 0x20, 0x43, 0x06, 0x01, 0x00, 0x00, 0x02, 0X01};
unsigned int Crc;
int j, i_bits, carry;
Crc = 0;
for ( j=0 ; j < lg ; j++ )
{
Crc = Crc ^ Frame[j] ;
for ( i_bits=0 ; i_bits < 8 ; i_bits++ )
{
carry = Crc & 1 ;
Crc = Crc / 2 ;
if ( carry )
{
Crc = Crc ^ Poly;
}
}
}
printf ( “CRC = %x “, Crc);
}
The computed CRC is the following : 41D2 hexadecimal
Then LSB byte and MSB byte must be inverted before storage in the frame.
This example allows to compute a CRC on a fix frame length equal to 9.
WCAMODHEL Handbook page 9 of 74