📄 crc_gen.cpp
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define BYTE unsigned char
#define WORD unsigned short
WORD UpdataCrc(BYTE ch, WORD *lpwCrc) //以字节为单位进行计算
{
ch = (ch ^ (BYTE)((*lpwCrc) & 0x00ff));
ch = (ch ^ (ch<<4));
*lpwCrc = (*lpwCrc>>8) ^ ((WORD)ch<<8)
^ ((WORD)ch<<3) ^ ((WORD)ch>>4);
return(*lpwCrc);
}
void ComputeCrc(BYTE *Data, int Sum, BYTE *TransmitFirst, BYTE *TransmitSecond)
{
BYTE chBlock;
WORD wCrc = 0x6363; //寄存器初始化
do{
chBlock = *Data++;
UpdataCrc(chBlock, &wCrc);
}while(--Sum);
*TransmitFirst = (BYTE)(wCrc & 0xff);
*TransmitSecond=(BYTE)((wCrc>>8) & 0xff);
return;
}
BYTE BuffCRC_A[10];
BYTE First, Second;
int Byte_sum;
int i;
int main()
{
printf("CRC_16 reference results ISO/IEC 14443-3\n");
printf("Crc-16 G(x)=x^16+x^12+x^5+1\n\n");
printf("Please input the number and the content of raw data:\n");
scanf("%d", &Byte_sum);
for(i=0; i<Byte_sum; i++)
scanf("%02X", &BuffCRC_A[i]);
printf("CRC_A of [");
for(i=0; i<Byte_sum; i++)
printf("%02X", BuffCRC_A[i]);
ComputeCrc(BuffCRC_A, Byte_sum, &First, &Second);
printf("] Transmitted:%02X then %02X.\n", First, Second);
scanf("%d", &i);
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -