在用RFID读卡的时候,向串口发送卡片信息,但是每次在串口上看到的都是循环读卡片的信息,我只想让下位机通过串口只发送一次卡片信息;求各位大神代码怎么写;
主函数代码如下:
void main( )
{
unsigned char status,i;
unsigned int temp;
lcd_init();
InitializeSystem( );
PcdReset();
PcdAntennaOff();
PcdAntennaOn();
display_welcome2();
while ( 1 )
{
status = PcdRequest(PICC_REQALL, g_ucTempbuf);//寻卡
if (status != MI_OK)
{
continue;
}
display_type();//寻到卡后显示出该卡的类型
printf("卡的类型:");
for(i=0;i<2;i++)
{
temp=g_ucTempbuf[i];
printf("%X",temp);
}
status = PcdAnticoll(g_ucTempbuf);//防冲撞
if (status != MI_OK)
{ continue; }
display_cardnum();//显示寻到的卡的序列号
////////以下为超级终端打印出的内容////////////////////////
printf("卡序列号:"); //超级终端显示,
for(i=0;i<4;i++)
{
temp=g_ucTempbuf[i];
printf("%X",temp);
}
status = PcdAnticoll(g_ucTempbuf);//防冲撞
//temp=m1erea;
//printf("%X\n",temp);
///////////////////////////////////////////////////////////
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_REQIDL, g_ucTempbuf);//寻卡
if (status != MI_OK)
{
continue;
}
status = PcdAnticoll(g_ucTempbuf);//防冲撞
if (status != MI_OK)
{ continue; }
display_cardnum();//显示寻到的卡的序列号
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; }
display_xiaofeicarddat();//消费
/* status = PcdValue(PICC_INCREMENT,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");
display_carddat();//显示数据
//memcpy(data1,g_ucTempbuf,16);
LED_GREEN = 0;
FM_QI= 0;
delay1(100);
LED_GREEN = 1;
FM_QI= 1;
delay1(100);
LED_GREEN = 0;
FM_QI= 0;
delay1(200);
LED_GREEN = 1;
FM_QI= 1;
delay1(600);
PcdHalt();
//PcdAntennaOff();
printf("test1:");
}
}
|