我用的是stm32l053的单片机读写ic卡,读取错误计数器和读取操作返回值都是正确的,但是遇到的问题就是密码校验不过。
下面是密码校验的函数 ReadPsw读出来的值是计数器的值,我读出来是0x7 但是在校验之后在46行的ReadPsw函数读出来就变成了0x3
不知道在哪里出了问题 卡了我两天了。
- uint8_t Check_Pass(uint8_t *password)
- {
- int i=0;
- uint8_t ReadBuf[4]={0};
- ReadPsw(ReadBuf);
-
-
- for(i=0;i<10;i++)
- {
- if(IC_Reset())
- {
- break;
- }
- }
- if(i==10)
- {
- return -1;
- }
- if(ReadBuf[0]==0x07)
- {
- Send_Comand(WRITE_SAFE_MEM,0,0x03); //½«ECдΪ0x03
- IC_Wait(); //·¢ËͲÙ×÷Âö³å
- }
- else if(ReadBuf[0]==0x06 || ReadBuf[0]==0x05 || ReadBuf[0]==0x03)
- {
- Send_Comand(WRITE_SAFE_MEM,0,0x01); //½«ECдΪ0x01
- IC_Wait(); //·¢ËͲÙ×÷Âö³å
- }
- else if(ReadBuf[0]==0x01 || ReadBuf[0]==0x02 || ReadBuf[0]==0x04)
- {
- Send_Comand(WRITE_SAFE_MEM,0,0x00); //½«ECдΪ0x00
- IC_Wait(); //·¢ËͲÙ×÷Âö³å
- }
-
- Send_Comand(SLE_PSC_CHK,1,password[0]);//УÑéÃÜÂëµÄµÚÒ»¸ö×Ö½Ú
- IC_Wait(); //·¢ËͲÙ×÷Âö³å
- Send_Comand(SLE_PSC_CHK,2,password[1]);//УÑéÃÜÂëµÄµÚ¶þ¸ö×Ö½Ú
- IC_Wait(); //·¢ËͲÙ×÷Âö³å
- Send_Comand(SLE_PSC_CHK,3,password[2]);//УÑéÃÜÂëµÄµÚÈý¸ö×Ö½Ú
- IC_Wait(); //·¢ËͲÙ×÷Âö³å
- Send_Comand(WRITE_SAFE_MEM,0,0xff); //²Á³ý´íÎó¼ÆÊýÆ÷
- IC_Wait(); //·¢ËͲÙ×÷Âö³å
- ReadPsw([ReadBuf]);
-
- if(ReadBuf[0] == 0x07)
- {
- return 3; //Ê£ÏÂ3´ÎУÑé»ú»á,УÑéÃÜÂë³É¹
- }
- else if(ReadBuf[0] == 0x06 || ReadBuf[0] == 0x05 || ReadBuf[0] == 0x03)
- {
- return 2;//Ê£ÏÂ2´ÎУÑé»ú»á,УÑéÃÜÂëʧ°
- }
- else if(ReadBuf[0] == 0x04 || ReadBuf[0] == 0x02 || ReadBuf[0] == 0x01)
- {
- return 1;//Ê£ÏÂ1´ÎУÑé»ú»á,УÑéÃÜÂëʧ°Ü
- }
- else return 0; //Ê£ÏÂ0´ÎУÑé»ú»á,¿¨±¨·Ï
- }
复制代码
调用过程
- uint8_t test(uint8_t *password)
- {
- uint8_t ReadBuf[8]={0};
- int i=0;
- for(i=0;i<10;i++)
- {
- if(IC_Reset())
- {
- break;
- }
- }
- if(i==10)
- {
- return -1;
- }
- i=Check_Pass(password);
- if(i!=3)
- {
- return -1;
- }
- // Send_Comand(WRITE_SAFE_MEM,0x10,0x11); //½«ECдΪ0x01
- ////Read(READ_PSCR,20,0x11);
- }
复制代码
|