嵌入式
//******************************************************************/ //功 能:寻卡 / //参数说明: req_code[IN]:寻卡方式 / // 0x52 = 寻感应区内所有符合14443A标准的卡 / // 0x26 = 寻未进入休眠状态的卡 / // pTagType[OUT]:卡片类型代码 / // 0x4400 = Mifare_UltraLight / // 0x0400 = Mifare_One(S50) / // 0x0200 = Mifare_One(S70) / // 0x0800 = Mifare_Pro(X) / // 0x4403 = Mifare_DESFire / //返 回: 成功返回MI_OK / //******************************************************************/ char PcdRequest(unsigned char req_code,unsigned char *pTagType) { char status ; unsigned int unLen ; unsigned char ucComMF522Buf[MAXRLEN] ; ClearBitMask(Status2Reg,0x08) ; WriteRawRC(BitFramingReg,0x07) ; SetBitMask(TxControlReg,0x03) ; ucComMF522Buf[0] = req_code ; status = PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf, 1,ucComMF522Buf,&unLen ); if ((status == MI_OK) && (unLen == 0x10)) { *pTagType = ucComMF522Buf[0] ; *(pTagType+1) = ucComMF522Buf[1] ; } else status = MI_ERR ; return status ; } //******************************************************************/ //功 能:防冲撞 / //参数说明: pSnr[OUT]:卡片序列号,4字节 / //返 回: 成功返回MI_OK / //******************************************************************/ char PcdAnticoll(unsigned char *pSnr) { char status; unsigned char i,snr_check=0; unsigned int unLen; unsigned char ucComMF522Buf[MAXRLEN]; ClearBitMask(Status2Reg,0x08); WriteRawRC(BitFramingReg,0x00); ClearBitMask(CollReg,0x80); ucComMF522Buf[0] = PICC_ANTICOLL1; ucComMF522Buf[1] = 0x20; Status=PcdComMF522(PCD_TRANSCEIVE,ucComMF522Buf,2,ucComMF522Buf,&unLen); if (status == MI_OK) { for (i=0; i<4; i++) { *(pSnr+i) = ucComMF522Buf[i]; snr_check ^= ucComMF522Buf[i]; } if (snr_check != ucComMF522Buf[i]) { status = MI_ERR; } } SetBitMask(CollReg,0x80); return status; }