⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 crc_check.cpp

📁 该CRC校验仿真完全符合国际标签卡协议ISO/IEC 14443所规定的CRC_A。是一种按字节进行运算的CRC校验法
💻 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+2); i++)
		scanf("%02X", &BuffCRC_A[i]);
	
	ComputeCrc(BuffCRC_A, Byte_sum, &First, &Second);
	if((First!=BuffCRC_A[Byte_sum]) || (Second!=BuffCRC_A[Byte_sum+1]))
	{
		printf("Error occurs!");
		scanf("%d", &i);
		return 1;
	}
	printf("Check done!");

	scanf("%d", &i);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -