Syntax, Example, Crc8( ) function – Echelon Neuron C User Manual
Page 96: Crc16( ) function
76
Functions
Syntax
#include
void clr_bit (void *
array
, unsigned
bitnum
);
Example
#include
unsigned short a[4];
void f(void)
{
memset(a, 0xFF, 4); // Sets all bits
clr_bit(a, 4); // Clears a[0] to 0xF7 (5th bit)
}
crc8( )
Function
The crc8( ) function iteratively calculates an 8-bit cyclic redundancy check (CRC)
over an array of data using the following polynomial:
1
4
5
8
+
+
+
x
x
x
This function is useful in conjunction with the support for the Touch I/O model,
but can also be used whenever a CRC is needed.
Syntax
#include
unsigned crc8 (unsigned
crc
, unsigned
new-data
);
Example
#include
unsigned data[SIZE];
void f(void)
{
unsigned i; // Or 'unsigned long' depending on SIZE
unsigned
crc;
crc = 0;
for (i = 0; i < SIZE; ++i) {
// Combine partial CRC with next data byte
crc = crc8(crc, data[i]);
}
}
crc16( )
Function
The crc16( ) function iteratively calculates a 16-bit cyclic redundancy check (CRC)
over an array of data bytes using the following polynomial: