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

📄 zlg500s_test.c

📁 嵌入式系统开发 MRC 522 S50 S70
💻 C
字号:
#define PcdTest_globals
#include "config.h"
#include "zlg500S_comm.h"
#include "zlg500S.h"
#include "zlg500S_test.h"

#define LED1	(1<<10)
#define LED2	(1<<11)
#define LED3	(1<<12)
#define LED4	(1<<13)
//INT8U Key[6] = {0xff,0xff,0xff,0xff,0xff,0xff};
INT8U Status;

INT8U DataBfr[16];
INT8U Card_Snr[4];
INT8U TxMode;
INT8U Atq[2];
INT8U Sak;

void PcdTest(void)
{
	INT8U temp;	
	
	ZLG500S_COMM_Init();
	
	IODIR |= LED1 | LED2 | LED3 | LED4;
	IOSET = LED1 | LED2 | LED3 | LED4;
	
	GetDvcInfo(DataBfr);
	DataBfr[0] = 0xff;
	DataBfr[1] = 0xff;
	DataBfr[2] = 0xff;
	DataBfr[3] = 0xff;
	DataBfr[4] = 0xff;
	DataBfr[5] = 0xff;
	PCDLoadKey(KEYA,0,DataBfr);

	while(1)
	{
		if(PiccRequest(REQSTD,DataBfr) != OK)	continue;
		if(PiccAnticoll(SELCODE1,0,Card_Snr)!=OK)	continue;
		if(PiccSelect(SELCODE1,Card_Snr,DataBfr)!=OK)	continue;
		if(PiccAuthE2(KEYA,Card_Snr,0,4)!=OK)	continue;
		if(PiccRead(4,DataBfr)!=OK)	continue;
		DataBfr[0] = 0x10;	DataBfr[4] = 0xef;	DataBfr[8] = 0x10;
		DataBfr[1] = 0x0;	DataBfr[5] = 0xff;	DataBfr[9] = 0x0;
		DataBfr[2] = 0x0;	DataBfr[6] = 0xff;	DataBfr[10] = 0x0;
		DataBfr[3] = 0x0;	DataBfr[7] = 0xff;	DataBfr[11] = 0x0;
		DataBfr[12] = 0x04;	DataBfr[13] = 0xfb;	DataBfr[14] = 0x04;	DataBfr[15] = 0xfb;
		if(PiccWrite(4,DataBfr)!=OK)	continue;
		DataBfr[0] = 0x0;
		if(PiccRead(4,DataBfr)!=OK)		continue;
		DataBfr[0] = 0x01;
		DataBfr[1] = 0x0;
		DataBfr[2] = 0x0;
		DataBfr[3] = 0x0;
		if(PiccValue(DECREMENT,4,DataBfr,5)!=OK)	continue;
		if(PiccValue(INCREMENT,4,DataBfr,6)!=OK)	continue;
		if(PiccRead(5,DataBfr)!=OK)		continue;
		if(PiccRead(6,DataBfr)!=OK)		continue;
		PiccHalt();
		
		IOCLR = LED1;
		LedDly = 20;
		while(LedDly);
		IOSET = LED1;

		//测试卡自动检测----不连续检测,卡不挂起,TX交替,E2密码验证,密钥A,读4块
		DataBfr[0] = 0;
		while(PiccAutoDetect(0, ADTXALERT, REQSTD, 'E', KEYA, DataBfr, 4) != 0);
		while(PiccADRcv(&TxMode,Atq,&Sak,Card_Snr,DataBfr) != 0);	
		DataBfr[0] = 0x10;	DataBfr[4] = 0xef;	DataBfr[8] = 0x10;
		DataBfr[1] = 0x0;	DataBfr[5] = 0xff;	DataBfr[9] = 0x0;
		DataBfr[2] = 0x0;	DataBfr[6] = 0xff;	DataBfr[10] = 0x0;
		DataBfr[3] = 0x0;	DataBfr[7] = 0xff;	DataBfr[11] = 0x0;
		DataBfr[12] = 0x04;	DataBfr[13] = 0xfb;	DataBfr[14] = 0x04;	DataBfr[15] = 0xfb;
		if(PiccWrite(4,DataBfr)!=OK)	continue;
		DataBfr[0] = 0x0;
		if(PiccRead(4,DataBfr)!=OK)		continue;
		DataBfr[0] = 0x01;
		DataBfr[1] = 0x0;
		DataBfr[2] = 0x0;
		DataBfr[3] = 0x0;
		if(PiccValue(DECREMENT,4,DataBfr,5)!=OK)	continue;
		if(PiccValue(INCREMENT,4,DataBfr,6)!=OK)	continue;
		if(PiccRead(5,DataBfr)!=OK)		continue;
		if(PiccRead(6,DataBfr)!=OK)		continue;
		PiccHalt();
		
		IOCLR = LED2;
		LedDly = 20;
		while(LedDly);
		IOSET = LED2;
				

		//测试卡自动检测----发回后继续检测,检测后将卡挂起,TX全发送,直接密码验证,密钥A,读4块
		DataBfr[0] = 0xff;	DataBfr[1] = 0xff;	DataBfr[2] = 0xff;
		DataBfr[3] = 0xff;	DataBfr[4] = 0xff;	DataBfr[5] = 0xff;
 		while(PiccAutoDetect(ADCONTINUE | ADHALT, ADALLTX, REQSTD, 'F', KEYA, DataBfr, 4) != 0);
		temp = 3;
		while(temp)
		{	
			if(PiccADRcv(&TxMode,Atq,&Sak,Card_Snr,DataBfr) == 0)
			{
				temp--;
				IOCLR = LED3;
				LedDly = 20;
				while(LedDly);
				IOSET = LED3;
			}
		}
		PiccReadADDT(ADRFU,&TxMode,Atq,&Sak,Card_Snr,DataBfr);

		//测试卡自动检测----不连续检测,检测后将卡挂起,TX全发送,直接密码验证,密钥A,读4块
		DataBfr[0] = 0xff;	DataBfr[1] = 0xff;	DataBfr[2] = 0xff;
		DataBfr[3] = 0xff;	DataBfr[4] = 0xff;	DataBfr[5] = 0xff;
 		while(PiccAutoDetect(ADHALT, ADALLTX, REQSTD, 'F', KEYA, DataBfr, 4) != 0);
		temp = 3;
		while(temp)
		{
			if(!zlg500S_Int)
			{					//读回数据,继续检测
				if(PiccReadADDT(ADRFU | ADREENABLE,&TxMode,Atq,&Sak,Card_Snr,DataBfr) == 0)
				{
					temp--;
					IOCLR = LED4;
					LedDly = 20;
					while(LedDly);
					IOSET = LED4;
				}
			}
		}
		PiccReadADDT(ADRFU,&TxMode,Atq,&Sak,Card_Snr,DataBfr);	//读回数据,停止检测

	}
}

⌨️ 快捷键说明

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