#include<intrins.h>
#include<reg52.h>
#include"RC632.h"
#include"slrc632.h"
#include"iso14443a.h"
void Delay_50us(unsigned int t);
void DelayMs(unsigned int t);
extern void UART0_init(void);
extern void SendData(unsigned char SendByte);
extern void SendString(char *s);
unsigned char Nkey_a[6] = {0xff,0xff,0xff,0xff,0xff,0xff}; //定义密钥A
unsigned char Nkey_c[12];
unsigned char Nkey_c3[12]={0xcf,0xdf,0xdf,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xdf,0xd9,0xda};
unsigned char Nkey_c1[12]={0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0,0xf0};//定义用来转换后12字节的密钥
unsigned char Nkey_c2[12]={0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff};//定义用来转换后12字节的密钥
unsigned char KuaiN=0;
unsigned char xdata Read_data[16];
void main()
{
unsigned char i=0;
unsigned char status;
unsigned char atq[2];
unsigned char UID[4];
UART0_init();
RF_RST=0;
led=1 ;
Rc500Ready();
// SendData(0xaa);SendData(0xaa); DelayMs(100);
led=1;
status=M500PcdConfigISOType('A');
led=0 ;
// status=ChangeCodeKey(Nkey_a,Nkey_c); //将密钥转换为RC500接收格式,
// if(status==MI_OK)
// {
// for(i=0;i<12;i++)
//{
//
// SendData(Nkey_c[i]);
//}
while(1)
{
led=1 ;
status = PcdRequest(0x52, atq);
if (status != MI_OK)
{
status = PcdRequest(0x52, atq);
if (status != MI_OK)
{
// SendData(0xa1);
continue;
}
}
status=PcdAnticoll(&UID);
if(status==MI_OK)
{
//SendData(0xa1);
for(i=0;i<4;i++)
{
led=0 ;
//SendData(UID[i]);
}
status = PcdSelect(&UID);
}
if(status==MI_OK) //开始验证该卡
{//SendString("选卡");
ChangeCodeKey(Nkey_a,Nkey_c);
//SendString("密钥转换");
status=PcdAuthKey(Nkey_c); //将已转换格式后的密钥送到RC500的FIFO中
if(status==MI_OK)
{//SendString("密钥送到RC500的FIFO");
/* 用存放RC500的FIFO中的密钥和卡上的密钥进行验证 ,0x60:验证A密钥,0x61:验证B密钥
*/
status=PcdAuthState(0x60,0x35,UID);
if(status==MI_OK)
{//SendString("验证后读卡");
status=PcdRead(0x35,Read_data); //读取一个块号中16个字节的数据 //读卡上一块(block)数据(16字节
for(i=0;i<16;i++)
{
SendData(Read_data[i]);
}
if(status==MI_OK)
{
PcdHalt(); //命令卡进入休眠状态
}
DelayMs(50);
led=0 ;
DelayMs(50);
led=1 ;
}
}
}}}//}
这句是验证密码status=PcdAuthState(0x60,0x35,UID);总是验证不过去请有经验的高手帮看下密码什么地方不对
此帖出自
小平头技术问答
一周热门 更多>