高级会员 
  
	- 积分
 - 798
 
        - 金钱
 - 798 
 
       - 注册时间
 - 2016-9-17
 
      - 在线时间
 - 241 小时
 
 
 
 | 
 
///////////////////////////////////////////////////////////////////// 
//功    能:通过RC522和ISO14443卡通讯 
//参数说明:Command[IN]:RC522命令字 
//          pInData[IN]:通过RC522发送到卡片的数据 
//          InLenByte[IN]:发送数据的字节长度 
//          pOutData[OUT]:接收到的卡片返回数据 
//          *pOutLenBit[OUT]:返回数据的位长度 
///////////////////////////////////////////////////////////////////// 
char PcdComMF522(unsigned char Command,  
                 unsigned char *pInData,  
                 unsigned char InLenByte, 
                 unsigned char *pOutData,  
                 unsigned int *pOutLenBit) 
{ 
    char status = MI_ERR; 
    unsigned char irqEn   = 0x00; 
    unsigned char waitFor = 0x00; 
    unsigned char lastBits; 
    unsigned char n; 
    unsigned int i; 
    switch (Command) 
    { 
        case PCD_AUTHENT: 
                        irqEn   = 0x12; 
                        waitFor = 0x10; 
                        break; 
                case PCD_TRANSCEIVE: 
                        irqEn   = 0x77; 
                        waitFor = 0x30; 
                        break; 
                default: 
                        break; 
    } 
 
    WriteRawRC(ComIEnReg,irqEn|0x80); 
    ClearBitMask(ComIrqReg,0x80); 
    WriteRawRC(CommandReg,PCD_IDLE); 
    SetBitMask(FIFOLevelReg,0x80); 
 
    for (i=0; i<InLenByte; i++) 
    {    
                WriteRawRC(FIFODataReg, pInData[i]);     
        } 
    WriteRawRC(CommandReg, Command); 
 
    if (Command == PCD_TRANSCEIVE) 
    {     
                SetBitMask(BitFramingReg,0x80);   
        } 
 
    //i = 600;//根据时钟频率调整,操作M1卡最大等待时间25ms 
        i = 2000; 
    do  
    { 
        n = ReadRawRC(ComIrqReg); 
        i--; 
    } 
    while ((i!=0) && !(n&0x01) && !(n&waitFor)); 
    ClearBitMask(BitFramingReg,0x80); 
 
    if (i!=0) 
    {     
        if(!(ReadRawRC(ErrorReg)&0x1B)) 
        { 
            status = MI_OK; 
            if (n & irqEn & 0x01) 
            {   status = MI_NOTAGERR;   } 
            if (Command == PCD_TRANSCEIVE) 
            { 
                       n = ReadRawRC(FIFOLevelReg); 
                      lastBits = ReadRawRC(ControlReg) & 0x07; 
                if (lastBits) 
                {    
                                        *pOutLenBit = (n-1)*8 + lastBits;    
                                } 
                else 
                {    
                                        *pOutLenBit = n*8;    
                                } 
                if (n == 0) 
                {    
                                        n = 1;     
                                } 
                if (n > MAXRLEN) 
                {    
                                        n = MAXRLEN;    
                                } 
                for (i=0; i<n; i++) 
                {    
                                        pOutData[i] = ReadRawRC(FIFODataReg);     
                                } 
            } 
        } 
        else 
        {    
                        status = MI_ERR;    
                } 
 
    } 
 
    SetBitMask(ControlReg,0x80);           // stop timer now 
    WriteRawRC(CommandReg,PCD_IDLE);  
    return status; 
} 
 
///////////////////////////////////////////////////////////////////// 
//功    能:寻卡 
//参数说明: 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; 
} 
 
 |   
 
 
 
 |