完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
扫一扫,分享给好友
我在调试RC-522时,寻卡都寻不到,请高手帮忙指点一下以下是程序
#include "output.h" #include "delay.h" #include "sys.h" #include "rc522.h" #include "lcd.h" //ÏÔʾģ¿é #include "usart.h" #include "string.h" ////////////////////////////////////////////////////////// //M1¿¨·Öžé16‚€ÉÈ…^£¬Ã¿‚€ÉÈ…^ÓÉ4‰K£¨‰K0¡¢‰K1¡¢‰K2¡¢‰K3£©½M³É //ÎÒ‚ƒÒ²Œ¢16‚€ÉÈ…^µÄ64‚€‰K°´½^Œ¦µØÖ·¾ŽÌ–0~63 //µÚ0ÉÈ…^µÄ‰K0£¨¼´½^Œ¦µØÖ·0‰K£©£¬ËûÓÃ춴æ·ÅSÉÌ´ú´a£¬Òѽ›¹Ì»¯£¬²»¿É¸ü¸Ä //ÿ‚€ÉÈ…^µÄ‰K0¡¢‰K1¡¢‰K2žé”µ“þ‰K£¬¿ÉÓÃ춴æ·Å”µ“þ //ÿ‚€ÉÈ…^µÄ‰K3žé¿ØÖƉK£¨½^Œ¦µØÖ·‰K3¡¢7¡¢11....£©£¬°üÀ¨ÁËÃÜ´aA£¬´æÈ¡¿ØÖÆ¡¢ÃÜ´aB¡£ /******************************* *Á¬Ïß˵Ã÷£º *1--SS <----->PC6 *2--SCK <----->PB13 *3--MOSI<----->PB15 *4--MISO<----->PB14 *5--Ðü¿Õ *6--GND <----->GND *7--RST <----->PC8 *8--VCC <----->VCC ************************************/ /*È«¾Ö±äÁ¿*/ unsigned char CT[4];//¿¨ÀàÐÍ unsigned char SN[4]; //¿¨ºÅ unsigned char RFID[16]; //´æ·ÅRFID unsigned char lxl_bit=0; unsigned char card1_bit=0; unsigned char card2_bit=0; unsigned char card3_bit=0; unsigned char card4_bit=0; unsigned char total=0; unsigned char lxl[4]={6,109,250,186}; unsigned char card_1[4]={66,193,88,0}; unsigned char card_2[4]={66,191,104,0}; unsigned char card_3[4]={62,84,28,11}; unsigned char card_4[4]={126,252,248,12}; u8 KEY[6]={0xff,0xff,0xff,0xff,0xff,0xff}; unsigned char RFID1[16]={0x00,0x00,0x00,0x00,0x00,0x00,0xff,0x07,0x80,0x29,0xff,0xff,0xff,0xff,0xff,0xff}; /*º¯ÊýÉùÃ÷*/ void ShowID(u16 x,u16 y, u8 *p, u16 charColor, u16 bkColor); //ÏÔʾ¿¨µÄ¿¨ºÅ£¬ÒÔÊ®Áù½øÖÆÏÔʾ void PutNum(u16 x,u16 y, u32 n1,u8 n0, u16 charColor, u16 bkColor); //ÏÔʾÓà¶îº¯Êý void Store(u8 *p,u8 store,u8 cash);//×îÖØÒªµÄÒ»¸öº¯Êý int main(void) { unsigned char status; unsigned char s=0x08; delay_init(); //ÑÓʱº¯Êý³õʼ»¯ NVIC_Configuration(); //ÉèÖÃNVICÖжϷÖ×é2:2λÇÀÕ¼ÓÅÏȼ¶£¬2λÏìÓ¦ÓÅÏȼ¶ OUTPUT_Init(); //Êä³öÄ£¿é³õʼ»¯ //uart_init(9600); LCD_Init(); LCD_Clear(RED); LCD_ShowString(50,100,"Hallo everyone"); InitRc522(); //³õʼ»¯ÉäƵ¿¨Ä£¿é while(1) { u16 i,j; status = PcdRequest(0x52,CT);/*Œ¤¿¨*/ if(status==MI_OK)//Œ¤¿¨³É¹¦ { // if(CT[0]==0x04&&CT[1]==0x00) // LCD_ShowString(50,150,"S50");//??????MFOne-S50 ?????????? // // //USART_SendData(USART1, "S50");//Ïò´®¿Ú1·¢ËÍÊý¾Ý // else if(CT[0]==0x02&&CT[1]==0x00) // LCD_ShowString(50,150,"S70"); // else if(CT[0]==0x44&&CT[1]==0x00) // LCD_ShowString(50,150,"UltraLight"); // else if(CT[0]==0x08&&CT[1]==0x00) // LCD_ShowString(50,150,"Pro"); // else if(CT[0]==0x44&&CT[1]==0x03) // LCD_ShowString(50,150,"Desire"); // else // LCD_ShowString(50,50,"default"); status=MI_ERR; status = PcdAnticoll(SN); } else { // LCD_ShowString(50,80,"error"); LED1=~LED1; } /*·À³åײ*/ if ( PcdAnticoll(SN)==MI_OK)//·ÀÐnײ³É¹¦ { LCD_ShowString(30,30,"PcdAnticoll_MI_OK"); ShowID(0,200,SN,BLUE,WHITE); //ÔÚÒº¾§ÆÁÉÏÏÔʾ¿¨µÄIDºÅ LCD_ShowString(0,100,"The Card ID is:"); for(j=0;j<4;j++) { LCD_ShowNum(0,116+j*16,SN[j],16); } // if((SN[0]==lxl[0])&&(SN[1]==lxl[1])&&(SN[2]==lxl[2])&&(SN[3]==lxl[3])) // { // lxl_bit=1; // LCD_ShowString(0,0,"The User is:lxl"); // } // if((SN[0]==card_1[0])&&(SN[1]==card_1[1])&&(SN[2]==card_1[2])&&(SN[3]==card_1[3])) // { // card1_bit=1; // LCD_ShowString(0,0,"The User is:card_1"); // } // if((SN[0]==card_2[0])&&(SN[1]==card_2[1])&&(SN[2]==card_2[2])&&(SN[3]==card_2[3])) // { // card2_bit=1; // LCD_ShowString(0,0,"The User is:card_2"); // } // // if((SN[0]==card_3[0])&&(SN[1]==card_3[1])&&(SN[2]==card_3[2])&&(SN[3]==card_3[3])) // { // card3_bit=1; // LCD_ShowString(0,0,"The User is:card_3"); // } // if((SN[0]==card_4[0])&&(SN[1]==card_4[1])&&(SN[2]==card_4[2])&&(SN[3]==card_4[3])) // { // card4_bit=1; // LCD_ShowString(0,0,"The User is:card_4"); // } // total=card1_bit+card2_bit+card3_bit+card4_bit+lxl_bit; // LCD_ShowString(0,16,"total:"); // LCD_ShowNum(46,16,total,16); status =PcdSelect(SN); // Reset_RC522(); } else { LED2=~LED2; delay_ms(500); } if(status==MI_OK)//ßx¿¨³É¹¦ { //LCD_ShowString(0,50,200,16,16,"PcdAnticoll_MI_OK"); // // LCD_ShowString(0,48,"PcdSelect_MI_OK "); status=MI_ERR; status =PcdAuthState(0x60,0x09,KEY,SN); } if(status==MI_OK)//òž×C³É¹¦ { LCD_ShowString(0,64,"PcdAuthState_MI_OK "); status=MI_ERR; status=PcdRead(s,RFID); //status=PcdWrite(s,RFID1); } if(status==MI_OK)//×x¿¨³É¹¦ { LCD_ShowString(0,80,"READ_MI_OK"); status=MI_ERR; delay_ms(100); } } } /************************************* *º¯Êý¹¦ÄÜ£ºÏÔʾ¿¨µÄ¿¨ºÅ£¬ÒÔÊ®Áù½øÖÆÏÔʾ *²ÎÊý£ºx£¬y ×ø±ê * p ¿¨ºÅµÄµØÖ· * charcolor ×Ö·ûµÄÑÕÉ« * bkcolor ±³¾°µÄÑÕÉ« ***************************************/ void ShowID(u16 x,u16 y, u8 *p, u16 charColor, u16 bkColor) //ÏÔʾ¿¨µÄ¿¨ºÅ£¬ÒÔÊ®Áù½øÖÆÏÔʾ { u8 num[9]; u8 i; for(i=0;i<4;i++) { num[i*2]=p[i]/16; num[i*2]>9?(num[i*2]+='7'):(num[i*2]+='0'); num[i*2+1]=p[i]%16; num[i*2+1]>9?(num[i*2+1]+='7'):(num[i*2+1]+='0'); } num[8]=0; POINT_COLOR=RED; LCD_ShowString(x,y,"The Card ID is:"); //DisplayString(x,y+16,num,charColor,bkColor); for(i=0;i<8;i++) { LCD_ShowNum(x+16*i,y+16,num[i],16); //LCD_ShowNum(x,y+32,num[1],2,16); // LCD_ShowNum(x,y+48,num[2],2,16); // LCD_ShowNum(x,y+64,num[3],2,16); // LCD_ShowNum(x,y+80,num[4],2,16); // LCD_ShowNum(x,y+96,num[5],2,16); // LCD_ShowNum(x,y+16*7,num[6],2,16); // LCD_ShowNum(x,y+16*8,num[7],2,16); // LCD_ShowNum(x,y+16*9,num[8],2,16); // LCD_ShowNum(x,y+16*10,num[9],2,16); } } /******************************** *º¯Êý¹¦ÄÜ£ºÇópµÄn´ÎÃÝ */ int power(u8 p,u8 n) { int pow=1; u8 i; for(i=0;i pow*=p; } return pow; } u8 ReadData(u8 addr,u8 *pKey,u8 *pSnr,u8 *dataout) { u8 status,k; status=0x02;// k=5; do { status=PcdAuthState(PICC_AUTHENT1A,addr,pKey,pSnr); k--; //printf("AuthState is wrongn"); }while(status!=MI_OK && k>0); status=0x02;// k=5; do { status=PcdRead(addr,dataout); k--; //printf("ReadData is wrongn"); }while(status!=MI_OK && k>0); return status; } u8 WriteData(u8 addr,u8 *pKey,u8 *pSnr,u8 *datain) { u8 status,k; status=0x02;// k=5; do { status=PcdAuthState(PICC_AUTHENT1A,addr,pKey,pSnr); k--; //printf("AuthState is wrongn"); }while(status!=MI_OK && k>0); status=0x02;// k=5; do { status=PcdWrite(addr,datain); k--; //printf("ReadData is wrongn"); }while(status!=MI_OK && k>0); return status; } void PutNum(u16 x,u16 y, u32 n1,u8 n0, u16 charColor, u16 bkColor) { // u8 tmp[13]; // u8 i; //LCD_SetRegion(0,0,239,319,FALSE); // tmp[0]=n1/1000000000+'0'; // for(i=1;i<10;i++) // { /// tmp[i]=n1/(1000000000/power(10,i))%10+'0'; // } // tmp[10]='.'; // tmp[11]=n0+'0'; // tmp[12]=0; //DisplayString(x,y,tmp,charColor,bkColor); //LCD_ShowString(x,y,) } void Store(u8 *p,u8 store,u8 cash) { } |
|
相关推荐
1个回答
|
|
om!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
你正在撰写答案
如果你是对答案或其他答案精选点评或询问,请使用“评论”功能。
1848 浏览 0 评论
如何解决MPU-9250与STM32通讯时,出现HAL_ERROR = 0x01U
979 浏览 1 评论
hal库中i2c卡死在HAL_I2C_Master_Transmit
1381 浏览 1 评论
LL库F030进行3个串口收发,2个串口为232,一个为485,长时间后,会出现串口1停止运行,另外两个正常,只有重启复原
1829 浏览 1 评论
564 浏览 0 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-16 15:31 , Processed in 0.557007 second(s), Total 73, Slave 56 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号