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

📄 m500auc.c

📁 奥尔斯公司pxa270试验箱射频卡读写器相关资料
💻 C
📖 第 1 页 / 共 4 页
字号:
        status = M500PiccAuthState(auth_mode,snr,block);

    }

    return status;

}



*/

///////////////////////////////////////////////////////////////////////

//

///////////////////////////////////////////////////////////////////////

char M500PiccAuthState( unsigned char auth_mode,unsigned char *snr,unsigned char block)

{

    char idata status = MI_OK;

    unsigned char idata i = 0;



    status = ReadIO(RegErrorFlag);

    if (status != MI_OK)

    {

        if (status & 0x40)

        {

            status = MI_KEYERR;

        }

        else

        {

            status = MI_AUTHERR;

        }

    }

    else

    {

        SerBuffer[0] = auth_mode;



        SerBuffer[1] = block;

        memcpy(SerBuffer + 2,snr,4);

        ResetInfo(MInfo);

        MInfo.nBytesToSend = 6;

        if ((status = M500PcdCmd(PCD_AUTHENT1,SerBuffer,&MInfo)) == MI_OK)

        {

            if (ReadIO(RegSecondaryStatus) & 0x07)

            {

                status = MI_BITCOUNTERR;

            }

            else

            {

                ResetInfo(MInfo);

                MInfo.nBytesToSend = 0;

                if ((status = M500PcdCmd(PCD_AUTHENT2,

                                     SerBuffer,

                                     &MInfo)) == MI_OK)

                {

                    if ( ReadIO(RegControl) & 0x08 )

                    {

                        status = MI_OK;

                    }

                    else

                    {

                        status = MI_AUTHERR;

                    }

                }

            }

        }

    }

    return status;

}



////////////////////////////////////////////////////////////////

// Read the mifare card

// 读卡

// addr: 所读目标数据的地址

// data: 读出数据所存放的地址

////////////////////////////////////////////////////////////////

char M500PiccRead(unsigned char addr,unsigned char *_data)

{

    char idata status = MI_OK;

    char idata tmp    = 0;



    FlushFIFO();



    M500PcdSetTmo(3);

    WriteIO(RegChannelRedundancy,0x0F);

    ResetInfo(MInfo);

    SerBuffer[0] = PICC_READ;

    SerBuffer[1] = addr;

    MInfo.nBytesToSend   = 2;

    status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);



    if (status != MI_OK)

    {

        if (status != MI_NOTAGERR )

        {

            if (MInfo.nBitsReceived == 4)

            {

                SerBuffer[0] &= 0x0f;

                if ((SerBuffer[0] & 0x0a) == 0)

                {

                    status = MI_NOTAUTHERR;

                }

                else

                {

                    status = MI_CODEERR;

                }

            }

        }

        memcpy(_data,"0000000000000000",16);

    }

    else                // Response Processing

    {

        if (MInfo.nBytesReceived != 16)

        {

            status = MI_BYTECOUNTERR;

            memcpy(_data,"0000000000000000",16);

        }

        else

        {

            memcpy(_data,SerBuffer,16);

        }

    }

    M500PcdSetTmo(1);

    return status;

}



////////////////////////////////////////////////////////////////

// Write the mifare card

// 写卡  下载密码

// addr: 所写的 卡的地址

// data: 所写数据的地址

////////////////////////////////////////////////////////////////

/*

char M500PiccWrite( unsigned char addr,unsigned char *_data)

{

    char idata status = MI_OK;



    ResetInfo(MInfo);

    SerBuffer[0] = PICC_WRITE;

    SerBuffer[1] = addr;

    MInfo.nBytesToSend   = 2;

    status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);



    if (status != MI_NOTAGERR)

    {

        if (MInfo.nBitsReceived != 4)

        {

            status = MI_BITCOUNTERR;

        }

        else

        {

            SerBuffer[0] &= 0x0f;

            if ((SerBuffer[0] & 0x0a) == 0)

            {

                status = MI_NOTAUTHERR;

            }

            else

            {

                if (SerBuffer[0] == 0x0a)

                {

                    status = MI_OK;

                }

                else

                {

                    status = MI_CODEERR;

                }

            }

        }

    }



    if ( status == MI_OK)

    {

        M500PcdSetTmo(3);



        ResetInfo(MInfo);

        memcpy(SerBuffer,_data,16);

        MInfo.nBytesToSend   = 16;

        status = M500PcdCmd(PCD_TRANSCEIVE,SerBuffer,&MInfo);



        if (status & 0x80)

        {

            status = MI_NOTAGERR;

        }

        else

        {

            if (MInfo.nBitsReceived != 4)

            {

                status = MI_BITCOUNTERR;

            }

            else

            {

                SerBuffer[0] &= 0x0f;

                if ((SerBuffer[0] & 0x0a) == 0)

                {

                    status = MI_WRITEERR;

                }

                else

                {

                    if (SerBuffer[0] == 0x0a)

                    {

                        status = MI_OK;

                    }

                    else

                    {

                        status = MI_CODEERR;

                    }

                }

            }

        }

        M500PcdSetTmo(1);

    }

    return status;

}

*/

///////////////////////////////////////////////////////////////////////

// Reset Rf Card

// ms: RF电路重启的时间

///////////////////////////////////////////////////////////////////////



char M500PcdRfReset(unsigned char ms)

{

    char idata status = MI_OK;



    if(ms)

    {

        ClearBitMask(RegTxControl,0x03);

        delay_1ms(2);

        SetBitMask(RegTxControl,0x03);

    }

    else

    {

        ClearBitMask(RegTxControl,0x03);

    }

    return status;

}



#pragma noaregs



///////////////////////////////////////////////////////////////////////

// Delay 50us

///////////////////////////////////////////////////////////////////////

void delay_50us(unsigned char _50us)

{

    while(_50us--)

	{

	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

	    _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();_nop_();

    }

}



///////////////////////////////////////////////////////////////////////

// Delay 1ms

///////////////////////////////////////////////////////////////////////

void delay_1ms(unsigned char _1ms)

{

#ifndef NO_TIMER2

    RCAP2LH = RCAP2_1ms;

    T2LH    = RCAP2_1ms;



    TR2 = TRUE;

    while (_1ms--)

    {

	    while (!TF2);

	    TF2 = FALSE;

    }

    TR2 = FALSE;

#else

    while (_1ms--)

    {

	    delay_50us(20);

    }

#endif

}



///////////////////////////////////////////////////////////////////////

// Delay 10ms

///////////////////////////////////////////////////////////////////////

void delay_10ms(unsigned int _10ms)

{

#ifndef NO_TIMER2

    RCAP2LH = RCAP2_10ms;

    T2LH    = RCAP2_10ms;



    TR2 = TRUE;

    while (_10ms--)

    {

	    while (!TF2);

	    TF2 = FALSE;

    }

    TR2 = FALSE;

#else

    while (_10ms--)

    {

	    delay_50us(19);

	    if (CmdValid)

	        return;

	    delay_50us(20);

	    if (CmdValid)

	        return;

	    delay_50us(20);

	    if (CmdValid)

	        return;

	    delay_50us(20);

	    if (CmdValid)

	        return;

	    delay_50us(20);

	    if (CmdValid )

	        return;

	    delay_50us(20);

	    if (CmdValid)

	        return;

	    delay_50us(20);

	    if (CmdValid)

	        return;

	    delay_50us(20);

	    if (CmdValid)

	        return;

	    delay_50us(20);

	    if (CmdValid)

	        return;

	    delay_50us(19);

	    if (CmdValid)

	        return;

    }

#endif

}

///////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////

void RC500ISR (void) interrupt 0 using 1

{

    static unsigned char idata irqBits;

    static unsigned char idata irqMask;

    static unsigned char idata nbytes;

    static unsigned char idata cnt;



    IE0 = 0;

    WriteRawIO(0,0x80);

    if (MpIsrInfo && MpIsrOut)

    {

        while( ReadRawIO(RegPrimaryStatus) & 0x08)

        {

            irqMask = ReadRawIO(RegInterruptEn);

            irqBits = ReadRawIO(RegInterruptRq) & irqMask;

            MpIsrInfo->irqSource |= irqBits;

            if (irqBits & 0x01)

            {

                nbytes = 64 - ReadRawIO(RegFIFOLength);

                if ((MpIsrInfo->nBytesToSend - MpIsrInfo->nBytesSent) <= nbytes)

                {

                    nbytes = MpIsrInfo->nBytesToSend - MpIsrInfo->nBytesSent;

                    WriteRawIO(RegInterruptEn,0x01);

                }

                for ( cnt = 0;cnt < nbytes;cnt++)

                {

                    WriteRawIO(RegFIFOData,MpIsrOut[MpIsrInfo->nBytesSent]);

                    MpIsrInfo->nBytesSent++;

                }

                WriteRawIO(RegInterruptRq,0x01);

            }

            if (irqBits & 0x10)

            {

                WriteRawIO(RegInterruptRq,0x10);

                WriteRawIO(RegInterruptEn,0x82);

                if (MpIsrInfo->cmd == PICC_ANTICOLL1)

	            {

                    WriteIO(RegChannelRedundancy,0x02);

                    WriteRawIO(0,0x80);

	            }

            }

            if (irqBits & 0x0E)

            {

                nbytes = ReadRawIO(RegFIFOLength);

                for ( cnt = 0; cnt < nbytes; cnt++)

                {

                    MpIsrOut[MpIsrInfo->nBytesReceived] = ReadRawIO(RegFIFOData);

                    MpIsrInfo->nBytesReceived++;

                }

                WriteRawIO(RegInterruptRq,0x0A & irqBits);

            }

            if (irqBits & 0x04)

            {

                WriteRawIO(RegInterruptEn,0x20);

                WriteRawIO(RegInterruptRq,0x20);

                irqBits &= ~0x20;

                MpIsrInfo->irqSource &= ~0x20;

                WriteRawIO(RegInterruptRq,0x04);

            }

            if (irqBits & 0x20)

            {

                WriteRawIO(RegInterruptRq,0x20);

                MpIsrInfo->status = MI_NOTAGERR;

            }

        }

    }

}

///////////////////////////////////////////////////////////////////////

// MF RC500 Config

///////////////////////////////////////////////////////////////////////

char MfConfig(void)

{

	char status=MI_OK;



	M500PcdConfig();

	M500PcdMfOutSelect(2);

	return status;

}



///////////////////////////////////////////////////////////////////////

// 系统初始化

///////////////////////////////////////////////////////////////////////

void init(void)

{

	RC500RST=0;

	ET2 = 0;

	T2CON = 0x04;

    //PCON = 0x80;

	PCON = 0x80;                                   //SMOD = 0,不加速串口

        IP   = 0x10;                                   //定义串口为最高优先级

        SCON = 0x50;                                   //多机模式,串口模式3

        TMOD = 0x21;                                   //TMOD = 0x22;



	TH1   = 0xFD;

⌨️ 快捷键说明

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