mifare_crc.c

来自「mifarea卡程序mifarea卡程序mifarea卡程序」· C语言 代码 · 共 45 行

C
45
字号
/*

File nmae: Mifare_CRC.c
Function :UpdateCrc() and ComputerCrc().This function is 
		  original source code in ISO/IEC14443-3 Annex B
Comment  :This file include all of the commputering ISO/IEC
		  14443-3 Annex B type card's CRC function.
Note!!    This files should implemented by the Mifare Pro 
          function and computer the CRC for receive data from 
		  ISO/IEC 14443-4 type A  IC card. 		   

*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "Mifarepro.h"

//unsigned char First, Second;

unsigned short UpdateCrc(unsigned char ch, unsigned short *lpwCrc)
{
    ch = (ch^(unsigned char)((*lpwCrc) & 0x00FF));
    ch = (ch^(ch<<4));
    *lpwCrc = (*lpwCrc >> 8)^((unsigned short)ch << 8)^((unsigned short)ch<<3)^((unsigned short)ch>>4);
    return(*lpwCrc);
}
void ComputeCrc(char *Data, int Length,unsigned char *TransmitFirst, unsigned char *TransmitSecond)
{
    unsigned char chBlock;
    unsigned short wCrc;
   
    wCrc = 0x6363;   /* ITU-V.41 */
    do 
    {
        chBlock = *Data++;
        UpdateCrc(chBlock, &wCrc);
    } while (--Length);
        
    *TransmitFirst = (unsigned char) (wCrc & 0xFF);
    *TransmitSecond = (unsigned char) ((wCrc >> 8) & 0xFF);
}

//ComputeCrc(BuffCRC_A, length, &First, &Second);

⌨️ 快捷键说明

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