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

📄 mfrc500uc.lst

📁 C++ 非接触读写程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
 242          
 243          #define WriteRawRC(addr,value) *(gpcRCBaseAddress + addr) = value;
 244          
 245          //! Read one byte from the reader IC address space
 246          /*!
 247          * -o  address  (IN) reader ic register address
 248          * -o  value    (IN) 8 bit value
 249          * return: none
 250          *
 251          * Function for reading one char from the reader module
 252          *
 253          * The reader module is connected to a 16 bit demultiplexed bus,
 254          * therefore the address pin of the reader module is mapped as
 255          * follows: \n
 256          * uC             Reader \n
 257          * A1               A0   \n
 258          * A2               A1   \n
 259          * A3               A2   \n
 260          *
 261          * In order to get the correct address, the original address need to 
 262          * be multiplied by 2.
 263          */
 264          #define ReadRawRC(addr) (*(gpcRCBaseAddress + addr))
 265          
 266          
 267          //! Open Reader IC Connection
 268          /*!
 269          * -o  none
 270          * return: MI_OK
 271          *         other    error opening reader ic channel
 272          *
 273          * Open and initialize communication channel to the reader module
 274          */
 275          char OpenRC(void);
 276          
 277          //! Write one byte to the reader IC address space
 278          /*!
 279          * -o  address  (IN) reader ic register address
 280          * -o  value    (IN) 8 bit value
 281          * return: none
 282          *
 283          * This function determines the necessary page address of the 
 284          * reader module and writes the page number to the page 
 285          * register and the value to the specified address.
 286          */
 287          void WriteRC(unsigned char Address, unsigned char value);
 288          
 289          //! Write one byte to the reader IC address space
 290          /*
 291          * -o  address   (IN) reader IC register address
 292          * return: value    8 bit data, read from the reader ic address space
 293          *
 294          * This function determines the necessary page address of the 
 295          * reader module and writes the page number to the page 
 296          * register and reads the value from the specified address.
 297          */
 298          unsigned char ReadRC(unsigned char Address);
 299          
 300          //! Close reader IC communication channel
 301          /*!
 302          * -o  none
 303          * return: none
C51 COMPILER V7.00  MFRC500UC                                                              03/05/2004 15:25:52 PAGE 6   

 304          *
 305          * Closing the communication channel to the reader module
 306          */
 307          void CloseRC(void);
 308          
 309          // In case of a parallel connection, the address space of the reader module
 310          // needs to be mapped to the address space of the microcontroller. Therefore
 311          // a base address is reserved.
 312          //unsigned char * const gpcRCBaseAddress = (unsigned char * const)(MEMORY_BASE_ADDRESS);
 313          unsigned char * const gpcRCBaseAddress = (unsigned char * const)(10);
 314          ///////////////////////////////////////////////////////////////////////////////
 315          //                 Open Reader Communication
 316          ///////////////////////////////////////////////////////////////////////////////
 317          char OpenRC(void)
 318          {
 319   1         signed char status = MI_OK;
 320   1      
 321   1         READER_INIT_RESET;
 322   1      
 323   1         return status;
 324   1      }
 325          
 326          ///////////////////////////////////////////////////////////////////////////////
 327          //                 Close Reader Communication
 328          ///////////////////////////////////////////////////////////////////////////////
 329          void CloseRC(void)
 330          {
 331   1      }
 332          
 333          ///////////////////////////////////////////////////////////////////////////////
 334          //          G E N E R I C    W R I T E
 335          ///////////////////////////////////////////////////////////////////////////////
 336          void WriteRC(unsigned char Address, unsigned char value)
 337          {
 338   1         WriteRawRC(0x00,GetRegPage(Address));   // select appropriate page
 339   1         WriteRawRC(Address,value);              // write value at the specified 
 340   1                                                 // address
 341   1      }
 342          
 343          ///////////////////////////////////////////////////////////////////////////////
 344          //          G E N E R I C    R E A D
 345          ///////////////////////////////////////////////////////////////////////////////
 346          unsigned char ReadRC(unsigned char Address)
 347          {
 348   1         WriteRawRC(0x00,GetRegPage(Address));   // select appropriate page
 349   1         return ReadRawRC(Address);              // read value at the specified 
 350   1      }  
 351          
 352          ///////////////////////////////////////////////////////////////////////////////
 353          //             Prototypes for local functions 
 354          ///////////////////////////////////////////////////////////////////////////////
 355          
 356          ///  Internal Authentication State Switch
 357          /*!
 358          * -o  auth_mode (IN) 
 359          *                  enum: selects master key A or master key B 
 360          *                   - PICC_AUTHENT1A
 361          *                   - PICC_AUTHENT1B 
 362          *                  
 363          * -o  *snr      (IN) 
 364          *                  4 byte serial number of the card, which should be 
 365          *                  authenticated
C51 COMPILER V7.00  MFRC500UC                                                              03/05/2004 15:25:52 PAGE 7   

 366          * -o  sector (IN) Range [0..15] 
 367          *               specifies the key RAM address 
 368          *               from which the keys should be taken
 369          * return: enum:
 370          *          - MI_OK
 371          *          - CCE
 372          *          - MI_BITCOUNTERR  wrong number of bits received
 373          *          - MI_AUTHERR      wrong keys for selected card
 374          *          - MI_KEYERR       error while loading keys
 375          *         
 376          * 
 377          * Internal authentication state function.
 378          */
 379          char Mf500PiccAuthState(unsigned char auth_mode,// PICC_AUTHENT1A, PICC_AUTHENT1B
 380                                 unsigned char *snr,    // 4 byte serial number
 381                                 unsigned char sector); // 0 <= sector <= 15  
 382                                                      // sector address for authentication
 383          
 384          /// Write Baudrate Divider
 385          /*!
 386          * -o     none
 387          * return:   MI_OK
 388          *
 389          * Write function for baudrate divider and PCD properties
 390          */
 391          char  Mf500PcdWriteAttrib(void);
 392          
 393          /* ISR Communication Structure
 394          * Data, which have to be passed between ISR and other functions are
 395          * colleted within one structure. 
 396          */ 
 397          //{
 398          // ISR for Single Response Commands 
 399          /*
 400          * -o  none
 401          * return: none
 402          *
 403          * This function is a central routine in the communication chain between
 404          * PCD and PICC. 
 405          */ 
 406          //interrupt (READER_INT) 
 407          void SingleResponseIsr(void);
 408          
 409          // Command issuer for Single Response Commands 
 410          /*
 411          * -o  cmd  (IN)
 412          *             Command type
 413          *             enum:
 414          *              - PCD_IDLE
 415          *              - PCD_WRITEE2
 416          *              - PCD_READE2
 417          *              - PCD_LOADCONFIG
 418          *              - PCD_LOADKEYE2
 419          *              - PCD_AUTHENT1
 420          *              - PCD_CALCCRC
 421          *              - PCD_AUTHENT2
 422          *              - PCD_RECEIVE
 423          *              - PCD_LOADKEY
 424          *              - PCD_TRANSMIT
 425          *              - PCD_TRANSCEIVE
 426          *             
 427          *       send  (IN)
C51 COMPILER V7.00  MFRC500UC                                                              03/05/2004 15:25:52 PAGE 8   

 428          *             byte stream of variable length, which should be send to
 429          *             the PICC, the length of stream has to be specified
 430          *             in the info - structure
 431          *       rcv   (OUT) 
 432          *             byte stream of variable length, which was received 
 433          *             from the PICC. The length can be obtained from the
 434          *             info - structure
 435          *       info  (OUT)
 436          *             communication and status structure
 437          * return: enum:
 438          *          - MI_OK               operation without error
 439          *          - MI_NOTAGERR         no tag in rf field
 440          *          - MI_ACCESSTIMEOUT    RIC is not responding in time
 441          *          - MI_COLLERR          collision in during rf data transfer
 442          *          - MI_PARITYERR        parity error while receiving data
 443          *          - MI_FRAMINGERR       framing error - start bit not valid
 444          *          - MI_OVFLERR          FIFO overflow - to many data bytes
 445          *          - MI_CRCERR           CRC error of received data
 446          *          - MI_NY_IMPLEMENTED   internal error - source not identified
 447          *         
 448          *
 449          * This function provides the central interface to the reader module.
 450          * Depending on the "cmd"-value, all necessary interrupts are enabled
 451          * and the communication is started. While the processing is done by
 452          * the reader module, this function waits for its completion.
 453          *
 454          * It's notable, that the data in the send byte stream is written 
 455          * to the FIFO of the reader module by the ISR itself. Immediate after 
 456          * enabling the interrupts, the LoAlert interrupt is activated.
 457          *
 458          * The ISR writes the data to the FIFO. This function is not directly involved
 459          * in writing or fetching data from FIFO, all work is done by the 
 460          * corresponding ISR.After command completion, the error status is evaluated and 
 461          * returned to the calling function.
 462          */ 
 463          char PcdSingleResponseCmd(unsigned char cmd,
 464                          volatile unsigned char* send, 
 465                          volatile unsigned char* rcv,
 466                          volatile MfCmdInfo *info);
 467          
 468          /// Basic Register definitions
 469          /*!
 470          * return: none
 471          */
 472          char PcdBasicRegisterConfiguration(void);
 473          
 474          /// Set Reader IC Register Bit
 475          /*!
 476          * -o  reg  (IN)
 477          *             register address
 478          * -o  mask (IN)
 479          *             Bit mask to set
 480          * return:     none
 481          *              
 482          * This function performs a read - modify - write sequence
 483          * on the specified register. All bits with a 1 in the mask
 484          * are set - all other bits keep their original value.
 485          */
 486          void SetBitMask(unsigned char reg,unsigned char mask);
 487          
 488          /// Clear Reader IC Register Bit
 489          /*!
C51 COMPILER V7.00  MFRC500UC                                                              03/05/2004 15:25:52 PAGE 9   

 490          * -o  reg  (IN)
 491          *             register address

⌨️ 快捷键说明

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