⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fm1715.lst

📁 内容有FM1702对非接触IC卡的读写程序
💻 LST
📖 第 1 页 / 共 4 页
字号:
 264   1      }
 265          
 266          //********************************************************************
 267          //name:Clear_FIFO
 268          //function: Clear the data in FIFO
 269          //input:N/A
 270          //output: TRUE, FIFO has been cleared
 271          //       FALSE, FIFO hasn't beend cleared
 272          //********************************************************************
 273          uchar Clear_FIFO(void)
 274          {
 275   1              uchar temp;
 276   1              uint i;
 277   1              
 278   1              temp=Control;                   //Clear FIFO
 279   1              temp=(temp|0x01);
 280   1              Control=temp;
 281   1              for(i=0;i<RF_TimeOut;i++)       //检查FIFO是否为空
 282   1              {
 283   2                      temp=FIFO_Length;
 284   2                      if(temp==0)
 285   2                      {
 286   3                              return TRUE;
 287   3                      }
 288   2              }
 289   1              return FALSE;
 290   1      }
 291          
 292          //******************************************************************
 293          //name: Write_FIFO
 294          //function: write n bytes to FM1715's FIFO
 295          //input: count , the data's length
 296          //       buff, point to the data that to be writen
 297          //output: N/A
 298          //******************************************************************
 299          void Write_FIFO(uchar count,uchar idata *buff)
 300          {
 301   1              uchar i;
 302   1              for(i=0;i<count;i++)
 303   1              {
C51 COMPILER V7.09   FM1715                                                                07/26/2005 17:00:30 PAGE 6   

 304   2                      FIFO=*(buff+i);
 305   2              }
 306   1      }
 307          
 308          //*****************************************************************
 309          //name: Read_FIFO
 310          //function: read data from FM1715's FIFO
 311          //input: buff, 指向读出数据的指针
 312          //output: N/A
 313          //*****************************************************************
 314          uchar Read_FIFO(uchar idata *buff)
 315          {
 316   1              uchar temp;
 317   1              uchar i;
 318   1              
 319   1              temp=FIFO_Length;
 320   1              if(temp==0)
 321   1              {
 322   2                      return 0;
 323   2              }
 324   1              if(temp>=24)                    //temp=255,会进入死循环,因此增加FIFO_length越界判断
 325   1              {
 326   2                      temp=24;
 327   2              }
 328   1              for(i=0;i<temp;i++)
 329   1              {
 330   2                      *(buff+i)=FIFO;
 331   2              }
 332   1              return temp;
 333   1      }
 334          
 335          
 336          //******************************************************************
 337          //name: Command_Send
 338          //function: send command to FM1715
 339          //input: count, the length of command
 340          //       buff, point to the data that ready to send
 341          //       Comm_Set, command code
 342          //output: TRUE ,  running command succeed
 343          //        FALSE,  running command error
 344          //******************************************************************
 345          uchar Command_Send(uchar count,uchar idata *buff,uchar Comm_Set)
 346          {
 347   1              uint j;
 348   1              uchar idata temp,temp1;
 349   1              Command=0x00;
 350   1              Clear_FIFO();
 351   1              Write_FIFO(count,buff);
 352   1      //      temp=MFOUTSelect;
 353   1              Command=Comm_Set;               //running command
 354   1              for(j=0;j<RF_TimeOut;j++)
 355   1              {
 356   2      //              temp=MFOUTSelect;
 357   2                      temp=Command;
 358   2                      temp1=Int_Req&0x80;
 359   2                      if((temp==0x00)||(temp1==0x80))
 360   2                      {
 361   3                              Green=!Green;
 362   3                              return TRUE;
 363   3                      }
 364   2              }
 365   1              return FALSE;
C51 COMPILER V7.09   FM1715                                                                07/26/2005 17:00:30 PAGE 7   

 366   1      }
 367          
 368          
 369          //*****************************************************************
 370          //name: MIF_Halt
 371          //function: halt the mifare card
 372          //input: N/A
 373          //output: FM1715_OK : ack succeed
 374          //       FM1715_PARITYERR: parity verify error
 375          //       FM1715_CRCERR: CRC verify error
 376          //       FM1715_NOTAGERR: na card
 377          //*****************************************************************
 378          uchar MIF_Halt(void)
 379          {
 380   1              uchar temp;
 381   1              CRCPresetLSB=0x63;
 382   1              CWConductance=0x3f;
 383   1              ChannelRedundancy=0x03;
 384   1              *buffer=RF_CMD_HALT;
 385   1              *(buffer+1)=0x00;
 386   1              temp=Command_Send(2,buffer,Transceive);
 387   1              if(temp == FALSE)
 388   1              {
 389   2                      return FM1715_OK;
 390   2              }
 391   1              else
 392   1              {
 393   2                      temp = ErrorFlag;
 394   2                      if((temp&0x02)==0x02)
 395   2                      {
 396   3                              return(FM1715_PARITYERR);
 397   3                      }
 398   2                      if((temp&0x04)==0x04)
 399   2                      {
 400   3                              return(FM1715_FRAMINGERR);
 401   3                      }
 402   2                      return(FM1715_NOTAGERR);
 403   2              }
 404   1      }
 405          
 406          //********************************************************************
 407          //name: Load_key_CPY
 408          //function: save E2's password to FM1715's keybuffer
 409          //input: keybuffer: save key to this buffer
 410          //output: TRUE: load key succeed
 411          //       FLASE: load key fail
 412          //********************************************************************
 413          uchar Load_key_CPY(void)
 414          {
 415   1              uchar temp,i;
 416   1              uchar ln=0;
 417   1              uchar hn=0;
 418   1              
 419   1              for(i=0;i<6;i++)                //change the key to RC531 format
 420   1              {
 421   2                      ln=keybuffer[i]&0x0f;   //low four bit
 422   2                      hn=keybuffer[i]>>4;     //high four bit
 423   2                      buffer[i*2+1]=(~ln<<4)|ln;
 424   2                      buffer[i*2]=(~hn<<4)|hn;
 425   2              }
 426   1              temp=Command_Send(12,buffer,LoadKey);
 427   1              temp=ErrorFlag&0x40;
C51 COMPILER V7.09   FM1715                                                                07/26/2005 17:00:30 PAGE 8   

 428   1              if(temp==0x40)
 429   1              {
 430   2                      return FALSE;
 431   2              }
 432   1              return TRUE;
 433   1      }
 434          
 435          
 436          //***********************************************************************
 437          //name: delay
 438          //function: 
 439          void delay(uchar i)
 440          {
 441   1              int j;
 442   1              while(i)
 443   1              {
 444   2                      for(j=0x00;j<0x1000;j++);
 445   2                      i--;
 446   2              }
 447   1      }
 448          
 449          //***********************************************************************
 450          //name: Request
 451          //function: response the card's request in FM1715's control range
 452          //input: mode: ALL(monitor card in FM1715 control range)
 453          //       STD:(monitor the halt card in FM1715's control range)
 454          //output: FM1715_NOTAGERR: no card
 455          //        FM1715_OK: ack succeed 
 456          //        FM1715_REQERR: ack error
 457          //************************************************************************
 458          uchar Request(uchar mode)
 459          {
 460   1              uchar temp;
 461   1              TxControl=0x58;
 462   1              delay(1);
 463   1              TxControl=0x5b;
 464   1              CRCPresetLSB=0x63;
 465   1              CWConductance=0x3f;
 466   1              buffer[0]=mode;         //select Request mode
 467   1              Bit_Frame=0x07;         //send 7 bit
 468   1              ChannelRedundancy=0x03; //closed CRC
 469   1              TxControl=0x5b;
 470   1              Control=0x01;           //mask CRYPT01 bit
 471   1      
 472   1              temp=Command_Send(1,buffer,Transceive);
 473   1      
 474   1              if(temp==FALSE)
 475   1              {
 476   2                      return FM1715_NOTAGERR;
 477   2              }
 478   1      
 479   1              Read_FIFO(buffer);      //read ack information from FIFO
 480   1              tagtype[0]=buffer[0];
 481   1              tagtype[1]=buffer[1];
 482   1              
 483   1              return FM1715_OK;
 484   1      }
 485          
 486          //**************************************************************************
 487          //name: AntiColl(void)
 488          //function: anticollision for the card in FM1715's control range
 489          //input: N/A
C51 COMPILER V7.09   FM1715                                                                07/26/2005 17:00:30 PAGE 9   

 490          //output: FM1715_NOTAGERR: no card
 491          //        FM1715_BYTECOUNTERR: receive byte error
 492          //        FM1715_SERNRERR: card's serial ack error
 493          //        FM1715_OK: card ack succeed
 494          //**************************************************************************
 495          uchar AntiColl(void)
 496          {
 497   1              uchar temp;
 498   1              uchar i;
 499   1              uchar row,col;
 500   1              uchar pre_row;
 501   1              
 502   1              row=0;
 503   1              col=0;
 504   1              pre_row=0;
 505   1      
 506   1              CRCPresetLSB=0x63;
 507   1              CWConductance=0x3f;
 508   1              ModConductance=0x3f;
 509   1      //      ChannelRedundancy=0x03;                         //closed CRC,start parity
 510   1      
 511   1              buffer[0]=RF_CMD_ANTICOL;
 512   1              buffer[1]=0x20;
 513   1              ChannelRedundancy=0x03;                         //closed CRC,start parity
 514   1              temp=Command_Send(2,buffer,Transceive);
 515   1      
 516   1              while(1)
 517   1              {
 518   2                      if(temp==FALSE)
 519   2                      {
 520   3                              return(FM1715_NOTAGERR);
 521   3                      }
 522   2                      temp = ErrorFlag;
 523   2                      if((temp & 0x02)==0x02)
 524   2                              return(FM1715_PARITYERR);
 525   2                      if((temp & 0x04)==0x04)
 526   2                              return(FM1715_FRAMINGERR);
 527   2                      temp=FIFO_Length;
 528   2                      if (temp==0)
 529   2                      {
 530   3                              return FM1715_BYTECOUNTERR;
 531   3                      }
 532   2                      Read_FIFO(buffer);
 533   2                      Save_UID(row, col, temp); //将收到的UID 放入UID 数组中
 534   2      //              Show_UID(); //显示UID
 535   2                      temp=ErrorFlag;                 //

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -