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

📄 mfrc500uc.lst

📁 包括读卡器源代码
💻 LST
📖 第 1 页 / 共 4 页
字号:
 452                         if ( nbits != 0 )           // last byte was not complete
 453                         {
 454                            snr_in[nbytes - 1] = snr_in[nbytes - 1] | MRcvBuffer[0];
 455                            byteOffset = 1;
 456                         }
 457                         for ( i =0; i < (4 - nbytes); i++)     
 458                         {
 459                            snr_in[nbytes + i] = MRcvBuffer[i + byteOffset];
 460                         }
 461               
 462                         if (status != MI_COLLERR ) // no error and no collision
 463                         {
 464                            // SerCh check
 465                            snr_crc = snr_in[0] ^ snr_in[1] ^ snr_in[2] ^ snr_in[3];
 466                            snr_check = MRcvBuffer[MInfo.nBytesReceived - 1];
 467                            if (snr_crc != snr_check)
 468                            {
 469                               status = MI_SERNRERR;
 470                            } 
 471                            else   
 472                            {
 473                               complete = 1;
 474                            }
 475                         }
 476                         else                   // collision occured
 477                         {
 478                            bcnt = bcnt + MInfo.collPos - nbits;
 479                            status = MI_OK;
 480                         }
 481                      }
 482                  }
 483                }
 484             }
 485             if (status == MI_OK)
 486             {
 487                // transfer snr_in to snr
C51 COMPILER V8.02   MFRC500UC                                                             04/12/2009 10:36:17 PAGE 9   

 488                memcpy(snr,snr_in,4);
 489             }
 490             else
 491             {
 492                memcpy(snr,"0000",4);
 493             }
 494          
 495             //----------------------Einstellungen aus Initialisierung ruecksetzen 
 496             ClearBitMask(RegDecoderControl,0x20); // ZeroAfterColl disable
 497             
 498             return status;  
 499          }
 500          
 501          ///////////////////////////////////////////////////////////////////////
 502          //          M I F A R E    S E L E C T 
 503          // for std. select
 504          ///////////////////////////////////////////////////////////////////////
 505          char Mf500PiccSelect(unsigned char *snr, 
 506                            unsigned char *sak)
 507          {
 508             return Mf500PiccCascSelect(0x93,snr,sak); // first cascade level
 509          }
 510          
 511          ///////////////////////////////////////////////////////////////////////
 512          //          M I F A R E    C A S C A D E D   S E L E C T 
 513          //  for extended serial number
 514          ///////////////////////////////////////////////////////////////////////
 515          char Mf500PiccCascSelect(unsigned char select_code, 
 516                                  unsigned char *snr,
 517                                  unsigned char *sak)
 518          {
 519             char   status = MI_OK; 
 520          
 521             if ((status = Mf500PcdSetDefaultAttrib()) == MI_OK)
 522             {
 523                PcdSetTmo(106);
 524              
 525                WriteRC(RegChannelRedundancy,0x0F); // RxCRC,TxCRC, Parity enable
 526                ClearBitMask(RegControl,0x08);    // disable crypto 1 unit
 527             
 528                //************* Cmd Sequence ********************************** 
 529                ResetInfo(MInfo);   
 530                MSndBuffer[0] = select_code;
 531                MSndBuffer[1] = 0x70;         // number of bytes send
 532                
 533                memcpy(MSndBuffer + 2,snr,4);
 534                MSndBuffer[6] = MSndBuffer[2] 
 535                                ^ MSndBuffer[3] 
 536                                ^ MSndBuffer[4] 
 537                                ^ MSndBuffer[5];
 538                MInfo.nBytesToSend   = 7;
 539                status = PcdSingleResponseCmd(PCD_TRANSCEIVE,
 540                                    MSndBuffer,
 541                                    MRcvBuffer,
 542                                    &MInfo);
 543             
 544                *sak = 0;   
 545                if (status == MI_OK)    // no timeout occured
 546                {
 547                   if (MInfo.nBitsReceived != 8)    // last byte is not complete
 548                   {
 549                      status = MI_BITCOUNTERR;
C51 COMPILER V8.02   MFRC500UC                                                             04/12/2009 10:36:17 PAGE 10  

 550                   }
 551                   else
 552                   {
 553                      *sak = MRcvBuffer[0];
 554                      memcpy(MLastSelectedSnr,snr,4);            
 555                   }
 556                }
 557             }
 558             return status;
 559          }
 560          
 561          ///////////////////////////////////////////////////////////////////////
 562          //       M I F A R E   P I C C   A C T I V A T I O N    S E Q E N C E
 563          ///////////////////////////////////////////////////////////////////////
 564          char Mf500PiccActivateIdle(unsigned char br,
 565                                     unsigned char *atq, 
 566                                     unsigned char *sak, 
 567                                     unsigned char *uid, 
 568                                     unsigned char *uid_len)
 569          {
 570            unsigned char cascade_level;
 571            unsigned char sel_code;
 572            unsigned char uid_index;
 573            signed char status;
 574            unsigned char cmdASEL;
 575          
 576            *uid_len      = 0;
 577          
 578            //call activation with def. divs
 579            status = Mf500PcdSetDefaultAttrib();
 580            if (status == MI_OK)
 581            {
 582               status = Mf500PiccCommonRequest(PICC_REQIDL,atq);
 583            }
 584            if (status == MI_OK)
 585            {
 586               if((atq[0] & 0x1F) == 0x00) // check lower 5 bits, for tag-type
 587                                           // all tags within this 5 bits have to
 588                                           // provide a bitwise anticollision
 589               {
 590                  status = MI_NOBITWISEANTICOLL;
 591               }
 592            }
 593            if (status == MI_OK)
 594            {
 595                //Get UID in 1 - 3 levels (standard, [double], [triple] )
 596                //-------
 597                switch(br)
 598                {
 599                   case 0: cmdASEL = PICC_ANTICOLL1; break;
 600                   default:
 601                        status = MI_BAUDRATE_NOT_SUPPORTED; break;
 602                }
 603            }
 604            if (status == MI_OK)
 605            {
 606                cascade_level = 0;
 607                uid_index     = 0;
 608                do
 609                {
 610                  //Select code depends on cascade level
 611                  sel_code   = cmdASEL + (2 * cascade_level);
C51 COMPILER V8.02   MFRC500UC                                                             04/12/2009 10:36:17 PAGE 11  

 612                  cmdASEL = PICC_ANTICOLL1; // reset anticollistion level for calculation
 613                  //ANTICOLLISION
 614                  status = Mf500PiccCascAnticoll(sel_code, 0, &uid[uid_index]);
 615                  //SELECT
 616                  if (status == MI_OK)
 617                  {
 618                     status = Mf500PiccCascSelect(sel_code, &uid[uid_index], sak);
 619                     if (status == MI_OK)
 620                     {
 621                        cascade_level++;
 622          
 623                        //we differ cascaded and uncascaded UIDs
 624                        if (*sak & 0x04) // if cascaded, bit 2 is set in answer to select
 625                        {
 626                           //this UID is cascaded, remove the cascaded tag that is
 627                           //0x88 as first of the 4 byte received
 628                           memmove(&uid[uid_index], &uid[uid_index + 1], 3);
 629                           uid_index += 3;
 630                           *uid_len += 3;
 631                        }
 632                        else
 633                        {
 634                           //this UID is not cascaded -> the length is 4 bytes
 635                           uid_index += 4;
 636                           *uid_len += 4;
 637                        }
 638                     }
 639                  }
 640                }
 641                while((status == MI_OK)        // error status
 642                      && (*sak & 0x04)         // no further cascade level
 643                      && (cascade_level < 3)); // highest cascade level is reached
 644             }
 645             if (status == MI_OK)
 646             {
 647                //Exit function, if cascade level is triple and sak indicates another
 648                //cascase level.
 649                if ((cascade_level == 3) && (*sak & 0x04))
 650                {
 651                   *uid_len = 0;
 652                   status = MI_SERNRERR;
 653                }
 654             }
 655             return (status);
 656          }
 657          
 658          ///////////////////////////////////////////////////////////////////////
 659          //       M I F A R E   P I C C   A C T I V A T I O N    S E Q E N C E
 660          ///////////////////////////////////////////////////////////////////////
 661          char Mf500PiccActivateWakeup(unsigned char br,
 662                                       unsigned char *atq, 
 663                                       unsigned char *sak,
 664                                       unsigned char *uid, 
 665                                       unsigned char uid_len)
 666          {
 667             unsigned char cascade_level;
 668             unsigned char uid_index;
 669             unsigned char tmpuid[4];
 670             unsigned char sel_code;
 671             unsigned char cmdASEL;
 672             signed char   status;
 673          
C51 COMPILER V8.02   MFRC500UC                                                             04/12/2009 10:36:17 PAGE 12  

 674             //call activation with def. divs
 675             status = Mf500PcdSetDefaultAttrib();
 676             if (status == MI_OK)
 677             {
 678                status = Mf500PiccCommonRequest(PICC_REQIDL,atq);
 679             }
 680             if (status == MI_OK)
 681             {

⌨️ 快捷键说明

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