EasyManua.ls Logo

Coronis Wavenis Wavecard - Sample CRC Code (C Language)

Default Icon
70 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Wavecard-Waveport User Manual Coronis Systems
2.2.3 Sample CRC code (C language)
This example shows how to compute CRC on a fixed frame length equal to 9.
#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);
}
Notes:
The computed CRC is: 41D2 hexadecimal
The LSB and MSB bytes must then be inverted before storing them in the frame.
CS-SUP-MUTI-WPORTAPP-E04 11

Table of Contents