是这样的,小弟在玩rc522 ,现在想读出卡的序列号,然而发现在1602上读出来是一对乱码,认为是没有进行进制转换,请求各位大佬指点一二。
主函数:
#include "reg52.h" //51头文件
#include "main.h"
#include "1602.h" //液晶1602头文件
#include "mfrc522.h"
#include <stdio.h>
//char ON;
//char variable; //中间变量
unsigned char code DefaultKey[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
unsigned char writeData[16]={1, 2, 3, 4, 0};
unsigned char Temp[4],UID[4],variable[4],re[4];
uchar code table[]={'0','1','2','3','4','5','6','7','8','9'};
//void delayms(uint xms) //延时程序
//{
// uint a,b; //
// for(a=xms;a>0;a--) //
// for(b=110;b>0;b--); //
//}
void led()
{
write_charstr(1,1," ");
write_charstr(0,1,"ID:");
// write_charstr(6,1,"OFF"); //显示状态
// write_charstr(0,2,"key");
// write_charstr(1,3,":");
}
void main()
{
unsigned char status;
lcd_init(); //初始化lcd1602
led();
M500PcdConfigISOType( 'A' );
PcdReset();//复位RC522
PcdAntennaOff();
PcdAntennaOn();//开启天线发射
while(1)
{
status=PcdRequest(0x52,Temp);////寻卡,输出为卡类型
if(status==MI_OK)
status = PcdAnticoll(UID); //防冲撞处理,输出卡片序列号,4字节
if(status==MI_OK)
{
write_char(4,1,UID[0]);
write_char(5,1,UID[1]);
write_char(6,1,UID[2]);
write_char(7,1,UID[3]);
write_charstr(7,2,"2");
}
}
}
此帖出自
小平头技术问答
不谢,同是新人,哈哈
一周热门 更多>