主函数
int main(void)
{
unsigned char status,i;
unsigned int temp;
delay_init();
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
led_init();
TFT_Init();
lcd_display();
RC522_Init();
PcdReset();
PcdAntennaOff();
delay_ms(10);
PcdAntennaOn();
delay_ms(10);
tim3_init(1000,7199);
uart_init(9600); //波特率使用9600
printf("Start \r\n");
while ( 1 )
{
status = PcdRequest(PICC_REQALL, g_ucTempbuf);//寻卡
if (status != MI_OK)
{
PcdReset();
PcdAntennaOff();
PcdAntennaOn();
continue;
}
printf("卡的类型:");
for(i=0;i<2;i++)
{
temp=g_ucTempbuf[i];
printf("%X",temp);
}
status = PcdAnticoll(g_ucTempbuf);//防冲撞
if(status != MI_OK)
{ continue; }
////////以下为超级终端打印出的内容////////////////////////
printf("卡序列号:"); //超级终端显示,
for(i=0;i<4;i++)
{
temp=g_ucTempbuf[i];
printf("%X",temp);
}
if(g_ucTempbuf[0]==0xd4&&g_ucTempbuf[1]==0xd5&&g_ucTempbuf[2]==0x34&&g_ucTempbuf[3]==0x00)
{
led1=0;
GUI_Show12ASCII(10,110,"Open Door... ",RED,BLACK); //开门
}
else
{
led1=1;
GUI_Show12ASCII(10,110," ",RED,BLACK);
}
///////////////////////////////////////////////////////////
status = PcdSelect(g_ucTempbuf);//选定卡片
if (status != MI_OK)
{ continue; }
status = PcdAuthState(PICC_AUTHENT1A, 1, DefaultKey, g_ucTempbuf);//验证卡片密码
if (status != MI_OK)
{ continue; }
status = PcdWrite(1, data1);//写块
if (status != MI_OK)
{ continue; }
while(1)
{
status = PcdRequest(PICC_REQALL, g_ucTempbuf);//寻卡
if (status != MI_OK)
{
PcdReset();
PcdAntennaOff();
PcdAntennaOn();
continue;
}
status = PcdAnticoll(g_ucTempbuf);//防冲撞
if (status != MI_OK)
{ continue; }
status = PcdSelect(g_ucTempbuf);//选定卡片
if (status != MI_OK)
{ continue; }
status = PcdAuthState(PICC_AUTHENT1A, 1, DefaultKey, g_ucTempbuf);//验证卡片密码
if (status != MI_OK)
{ continue; }
status = PcdValue(PICC_DECREMENT,1,data2);//扣款
if (status != MI_OK)
{ continue; }
status = PcdBakValue(1, 2);//块备份
if (status != MI_OK)
{ continue; }
status = PcdRead(2, g_ucTempbuf);//读块
if (status != MI_OK)
{ continue; }
printf("卡读块:"); //超级终端显示,
for(i=0;i<16;i++)
{
temp=g_ucTempbuf[i];
printf("%X",temp);
}
printf("\n");
PcdHalt();
}
}
} |