Home > Software engineering >  CRC check
CRC check

Time:09-23

CRC check, generate polynomial:
X7 + + X5 X6 + X2 + 1, how to write CRC checking algorithm, data B0 99 41 81 02 00 02 generated check code

CodePudding user response:

Fyi:
/* * * * * crc16. C * * * * */
#include

# define CRC16_DNP 0 x3d65u//DNP, IEC 870, M - BUS, wM - BUS,...
# define CRC16_CCITT 0 x1021u//x. 25, v. 41, in HDLC FCS, Bluetooth,...

//Other polynoms not *
# define CRC16_IBM 0 x8005u//ModBus, USB, Bisync, CRC - 16, CRC - 16 - ANSI,...
# define CRC16_T10_DIF 0 x8bb7u//SCSI DIF
# define CRC16_DECT 0 x0589u//Cordeless Telephones
# define CRC16_ARINC 0 xa02bu//ACARS Aplications

# define POLYNOM CRC16_DNP//define the informs the POLYNOM from one of the aboves

//Calculates the new crc16 have the newByte. Variable crcValue is the actual or initial value (0).
Unsigned short crc16 (unsigned short crcValue, unsigned char newByte) {
int i;

for (i=0; i <8; I++) {
If (((crcValue & amp; 0 x8000u) & gt;> 8) ^ (newByte & amp; {0 x80u))
CrcValue=https://bbs.csdn.net/topics/(crcValue <1) ^ POLYNOM;
} else {
CrcValue=https://bbs.csdn.net/topics/(crcValue <1);
}
NewByte & lt; <=1;
}
Return crcValue;
}

Unsigned short exampleOfUseCRC16 (unsigned char * Data, int len) {

Unsigned short CRC;
Int aux=0;

CRC=0 x0000u;//Initialization of CRC to 0 x0000 for DNP
//CRC=0 xffffu;//Initialization of CRC to 0 XFFFF for CCITT

While (aux & lt; Len) {
CRC=crc16 (CRC, Data/aux);
Aux++;
}

Return (CRC) ~;//The CRC value for DNP it is obtained by The NOT operation

//return CRC;//The CRC value for CCITT
}

Int main () {
Unsigned char d [10]=,1,2,3,4,5,6,7,8,9 {0};

Printf (" % 0 x 04 hx \ n ", exampleOfUseCRC16 (d, 10));//0 x1078
return 0;
}

CodePudding user response:

https://wenku.baidu.com/view/4dde6302cc1755270722082d.html

CodePudding user response:

Void CKysoftver2App: : ToCRC (BYTE szBuffer [8])
{

BYTE d;
UINT uj, UK, CRC;

CRC=0 x0000ffff;
For (uj=0; Uj<6; Uj++)
{
CRC=CRC ^ szBuffer [uj];
For (UK=0; Uk<8; Uk++)
{
D=CRC & amp; 0 x00000001;
CRC=CRC> 1;
If (d! CRC==0) CRC ^ 0 x0000a001;
}
}
D=CRC & amp; 0 x000000ff; SzBuffer [6]=d;
D=(CRC> 8) & amp; 0 x000000ff; SzBuffer [7]=d;//to generate CRC check
}

CodePudding user response:

 
//CRC8 polynomial by 8 + + X1 X2 00000111 + 1=1=0 x07; Use "& lt; & lt;" Rev=11100000=0 xe0-0xfc use & gt; "" & gt;"
//or by 8 + x 5 + X4 + 1=1 00110001=0 x31 rev=10001100=0 x8c
Unsigned char CRC8 (unsigned char * PTR, unsigned char len)
{
Unsigned char CRC;
unsigned char i;
CRC=0;
While (len -)
{
CRC ^=* ptr++;
for(i=0; i <8; I++)
{
If (CRC & amp; 0 x80) CRC=(CRC & lt; <1) ^ 0 x07;
The else CRC & lt; <=1;
}
}
return crc;
}
# if 0
X55 BYTE STR []={0, 0 x55, 0 x01, 0 x04, 0 x00 to 0 x04, 0 x14};//0 xb5
X55 BYTE str1 []={0, 0 x55, 0 x01, 0 x04, 0 x01, 0 x04, 0 x32};//0 xc2
BYTE CRC;
CRC=CRC8 (STR, 7);
AfxDump. HexDump) (" 0 x ", & amp; CRC, 1, 1);
CRC=CRC8 (str1, 7);
AfxDump. HexDump) (" 0 x ", & amp; CRC, 1, 1);
//afxDump & lt; # endif

//data for the pointer to the calibration data, length of length, return a byte checksum
BYTE CRC8Rev (unsigned char * PTR, unsigned char len)
{
Unsigned char CRC=0;//or 0 XFF;
int i;
PTR +=len - 1;
While (len -)
{
CRC ^=* PTR -;
For (I=8; I & gt; 0; I -)
{
If (CRC & amp; 1) CRC=(CRC & gt;> 1) ^ 0 xe0-0xfc;
The else CRC & gt;>=1;
}
}
return crc;
}

CodePudding user response:

Climb a ready-made online?

CodePudding user response:

The CSDN advertising is really drunk
  • Related