附件是RC522的驱动文件。。
读取一个 扇区的数据并打印- void ReadSector(unsigned char Sector)
- {
- unsigned char i;
- status = PcdAuthState(PICC_AUTHENT1A,Sector*4,Card_KEY,Card_ID);
- if(status == MI_OK)
- {
- status = PcdRead(Sector*4,Card_Data1); //再一次把它读取出来16字节的卡片数据
- if(status == MI_OK)
- {
- printf("Sector %u of 1 Read OK.The Data Is:0x",Sector);
- myDelay(50);
- for(i=0;i<16;i++)
- {
- printf("%x",Card_Data1);
- myDelay(1);
- }
- printf(" OK\r\n");
- myDelay(5);
- }
- status = PcdRead(Sector*4+1,Card_Data2); //再一次把它读取出来16字节的卡片数据
- if(status == MI_OK)
- {
- printf("Sector %u of 2 Read OK.The Data Is:0x",Sector);
- myDelay(50);
- for(i=0;i<16;i++)
- {
- printf("%x",Card_Data2);
- myDelay(1);
- }
- printf(" OK\r\n");
- myDelay(5);
- }
- status = PcdRead(Sector*4+2,Card_Data3); //再一次把它读取出来16字节的卡片数据
- if(status == MI_OK)
- {
- printf("Sector %u of 3 Read OK.The Data Is:0x",Sector);
- myDelay(50);
- for(i=0;i<16;i++)
- {
- printf("%x",Card_Data3);
- myDelay(1);
- }
- printf(" OK\r\n");
- myDelay(5);
- }
- }
- }
- 读取整个卡片并打印
- void ScanCard(void)
- {
- unsigned char i;
- PcdAntennaOn();
- myDelay(50);
- status = 0;
- status = PcdRequest(PICC_REQALL,Card_Type1);
- if(status == MI_OK)
- {
- printf("Card type = 0x%x%x\r\n",Card_Type1[0],Card_Type1[1]);
- status = PcdAnticoll(Card_ID);//防冲撞
- if(status == MI_OK)
- {
- printf("Card ID = 0x%x%x%x%x\r\n",Card_ID[0],Card_ID[1],Card_ID[2],Card_ID[3]);
- status = PcdSelect(Card_ID); //选卡
- if(status == MI_OK)
- {
- for(i=0;i<16;i++)
- {
- ReadSector(i);
- }
- }
- }
- }
- PcdAntennaOff();
- myDelay(3000);
- }
|