亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? m500auc.c

?? PHLILPS RC500 讀寫函數原代碼
?? C
?? 第 1 頁 / 共 5 頁
字號:
///////////////////////////////////////////////////////////////////////////////
//    Copyright (c), Philips Semiconductors Gratkorn
//
//                  (C)PHILIPS Electronics N.V.2000
//       All rights are reserved. Reproduction in whole or in part is 
//      prohibited without the written consent of the copyright owner.
//  Philips reserves the right to make changes without notice at any time.
// Philips makes no warranty, expressed, implied or statutory, including but
// not limited to any implied warranty of merchantibility or fitness for any
//particular purpose, or that the use will not infringe any third party patent,
// copyright or trademark. Philips must not be liable for any loss or damage
//                          arising from its use.
///////////////////////////////////////////////////////////////////////////////
#define DLL_EXPORT      // library source module definition
#include <p89c51rx.h>
#include <Mfreg500.h>
#include <M500A.h>
#include <RdIo.h>

#include <string.h>
#include <stdio.h>
#include <main.h>

////////////////////////////////////////////////////////////////////////////////
//                M O D U L E   D E F I N I T I O N
////////////////////////////////////////////////////////////////////////////////
// COMMENT: This library module is modified from the original source code for a
//	    microcontroller C164 CI, to suit the general purpose 8051 mcu.
//          The source can be ported to other platforms very easily. 
//          The communication channel to the RC500 reader IC is assumed to be 
//          unknown. All data is written with the generic IO functions 
//          of the module ReaderIO.h. In our case the reader module is 
//          connected via memory mapped io at base address 0x7f00.
//          The interrupt pin of the reader IC is assumed to be connected to 
//          the fast external interrupt pin INT0# (active low) and the reset
//          pin of the reader IC should be connected to a dedicated port pin
//          (Port3: Pin: 3).
//          In this configuration, a reset of the reader module is independend
//          from the reset of the microcontroller.
//          In order to generate communication timeouts, 
//          general purpose timer 2 of the microcontroller is used. This 
//          timer need not to be initialised in advance. Before every usage 
//          the timer is completely initialised in each function. 
//          Non of the timers is essential for the functionality of the reader
//          module, but are helpful furing software development. All protocoll 
//          relevant timing constraints are generated
//          by the internal timer of the reader module.
//
//          Some explanations to the programming method of this library.
//          There are three kind of functions coded in this module.
//            a) internal functions, which have no prototypes in a header
//               file and are not intended to be used outside of this file
//            b) commands, which are intended for the reader module itself
//            c) commands, which are intended for any tag in the rf field.
//               These commands are send to the reader and the reader module
//               transmitts the data to the rf interface.
//          Commands for the reader and for the tag have the appropriate 
//          prefix (PCD for proximity coupled device or reader module
//                  PICC for proximity integrated circuit card or tag)
//          and their protypes are defined in the header file.
//          Each command for a PICC consists of a PCD command. Therefore
//          the function M500PcdCmd is very important for the understanding
//          of the communication.
//
//          The basic functionality is provided by the interrupt service
//          routine (ISR), which closely works together with the function
//          M500PcdCmd. All kinds of interrupts are serviced by the 
//          same ISR. 


// inline structure in order to reset the communication channel between 
// function and ISR
#define ResetInfo(info)    \
            info.cmd            = 0; \
            info.status         = MI_OK;\
            info.irqSource      = 0;   \
            info.nBytesSent     = 0;   \
            info.nBytesToSend   = 0;  \
            info.nBytesReceived = 0;  \
            info.nBitsReceived  = 0;   \
            info.collPos        = 0;

// struct definition for a communication channel between function and ISR
typedef struct 
         {
            unsigned char  cmd;           //!< command code 
            char           status;        // communication status
            unsigned char  nBytesSent;    // how many bytes already sent
            unsigned char  nBytesToSend;  // how many bytes to send
            unsigned char  nBytesReceived;// how many bytes received
            unsigned short nBitsReceived; // how many bits received
            unsigned char  irqSource;     // which interrupts have occured
            unsigned char  collPos;       // at which position occured a
                                          // collision
         } MfCmdInfo;

// modul variables 
extern	 unsigned char xdata *GpBase;

static   unsigned char idata MFIFOLength = DEF_FIFO_LENGTH; // actual FIFO length

static   unsigned char xdata MKeys[16][12]; // storage for authentication keys
                                      // in order to provide a calling 
                                      // compatible interface to old libraries
                             // Other reader modules keep several sets
                             // of keys in an E2PROM. In this case,
                             // these keys are stored in the uC and
                             // transfered to the reader module 
                             // before authentication

// Infomation concerning data processing
         // send buffer for general use
static   volatile unsigned char xdata MSndBuffer[SND_BUF_LEN];
         // receive buffer for general use
static   volatile unsigned char xdata MRcvBuffer[RCV_BUF_LEN];
         // info struct for general use
static   volatile MfCmdInfo     MInfo;                  

// Interrupt service routine
// Variable in order to exchange data between function and ISR
static   volatile MfCmdInfo     *MpIsrInfo = 0; 
        // ISR send buffer
static   volatile unsigned char *MpIsrOut  = 0; 
         // ISR receive buffer
static   volatile unsigned char *MpIsrIn   = 0;     

// storage of the last selected serial number including check byte.
//For multi level serial numbers, only the first 4 bytes are stored.
unsigned char MLastSelectedSnr[5];

// Timer 2
bit		T2IR	 	= 0;	// Timer2 timeout flag
unsigned int 	CountDown	= 0;	// Timeout counter with 50us resolution

sbit    RC500RST        	= P3^3;
sbit    LED	        	= P3^5;

///////////////////////////////////////////////////////////////////////////////
//             Prototypes for local functions 
///////////////////////////////////////////////////////////////////////////////

void start_timeout(unsigned int _50us);
void stop_timeout(void);

// _____________________________________________________________________________
//
//  FUNCTION: M500PcdSetTmo
//        IN: tmoLength   1  ... 1.0 ms timeout periode
//                        2  ... 1.5 ms timeout periode
//                        3  ... 6.0 ms timeout periode
//        		  4  ... 9.6 ms timeout period
//                        5  ... 38.5 ms timeout period
//                        6  ... 154 ms timeout period
//                        7  ... 616.2 ms timeout period
//       OUT: -
//    RETURN: 
//   COMMENT: Set timeout length of the reader internal timer.
//               
void M500PcdSetTmo(unsigned char tmoLength);

// _____________________________________________________________________________
//
//  FUNCTION: M500PcdCmd
//        IN: cmd  PCD_IDLE
//                   PCD_WRITEE2
//                   PCD_READE2
//                   PCD_LOADCONFIG
//                   PCD_LOADKEYE2
//                   PCD_AUTHENT1
//                   PCD_CALCCRC
//                   PCD_AUTHENT2
//                   PCD_RECEIVE
//                   PCD_LOADKEY
//                   PCD_TRANSMIT
//                   PCD_TRANSCEIVE
//                   PCD_RESETPHASE
//                   for a detailed description of the parameter values, please
//                   have a look on the header file of the reader register
//                   definitions.
//            send      byte stream of variable length, which should be send to
//                      the PICC, the length of stream has to be specified
//                      in the info - structure
//       OUT: rcv    byte stream of variable length, which was received 
//                      from the PICC or PCD
//            info      communication and status structure
//    RETURN: 
//   COMMENT: This function provides the central interface to the reader module.
//            Depending on the "cmd"-value, all necessary interrupts are enabled
//            and the communication is started. While the processing is done by
//            the reader module, this function waits for its completion.
//            It's notable, that the data in the "send byte stream" is written 
//            to the FIFO of the reader module by the ISR. Immediate after 
//            enabling the interrupts, the LoAlert interrupt is activated.
//            The ISR writes the data to the FIFO. This function is not involved
//            in writing or fetching data from FIFO, all work is done by the 
//            ISR.After command completion, the error status is evaluated and 
//            returned to the calling function.
//
char M500PcdCmd(unsigned char cmd,
                volatile unsigned char* send, 
                volatile unsigned char* rcv,
                volatile MfCmdInfo *info);

// _____________________________________________________________________________
//
//  FUNCTION: SetBitMask
//        IN: reg      register address
//            mask     bit mask to set
//       OUT: -
//    RETURN: 
//   COMMENT:  This function performs a read - modify - write sequence
//             on the specified register. All bits with a 1 in the mask
//             are set - all other bits keep their original value.
//
char SetBitMask(unsigned char reg,unsigned char mask);

// _____________________________________________________________________________
//
//  FUNCTION: ClearBitMask
//        IN: reg      register address
//            mask     bit mask to clear
//       OUT: -
//    RETURN: 
//   COMMENT:  This function performs a read - modify - write sequence
//             on the specified register. All bits with a 1 in the mask
//             are cleared - all other bits keep their original value.
//
char ClearBitMask(unsigned char reg,unsigned char mask);

// _____________________________________________________________________________
//
//  FUNCTION: FlushFIFO
//        IN: -
//       OUT: -
//    RETURN: 
//   COMMENT: All remaining date in the FIFO of the reader module is 
//            erased by this function. Before wrinting new data or
//            starting a new command, all remaining data from former 
//            commands should be deleted. Please note, that in 
//            normal operation, never data should be left, that means
//            that a call to this function should not be necessary.
//
void FlushFIFO(void);

// _____________________________________________________________________________
//
//  FUNCTION: M500PiccAuthState
//        IN: auth_mode
//            snr
//            sector
//       OUT: -
//    RETURN: 
//   COMMENT: 
//
char M500PiccAuthState(unsigned char auth_mode,// PICC_AUTHENT1A, PICC_AUTHENT1B
                       unsigned char *snr,    // 4 byte serial number
                       unsigned char sector); // 0 <= sector <= 15  
                                            // sector address for authentication

//////////////////////////////////////////////////////////////////////
//           E X C H A N G E   B Y T E   S T R E A M
///////////////////////////////////////////////////////////////////////
char ExchangeByteStream(unsigned char Cmd,
                        unsigned char *send_data,
                        unsigned char send_bytelen,
                        unsigned char *rec_data,  
                        unsigned char *rec_bytelen);

///////////////////////////////////////////////////////////////////////////////
//                  Interrupt Handler RC500
///////////////////////////////////////////////////////////////////////////////
void RC500ISR (void) interrupt 0 using 1    //Ext0 interrupt
{
   static unsigned char idata irqBits;
   static unsigned char idata irqMask;            
   static unsigned char idata nbytes;
   static unsigned char idata cnt;

   IE0 = 0; 	// Clear interrupt request flag

   if (MpIsrInfo && MpIsrOut && MpIsrIn)  // transfer pointers have to be set
                                          // correctly
   {
      while( ReadRawIO(RegPrimaryStatus) & 0x08) // loop while IRQ pending
                                                // Attention: IRQ bit is 
                                                // inverted when used with
                                                // low activ IRQ
      {
         irqMask = ReadRawIO(RegInterruptEn); // read enabled interrupts
         // read pending interrupts
         irqBits = ReadRawIO(RegInterruptRq) & irqMask;
         MpIsrInfo->irqSource |= irqBits; // save pending interrupts
         //************ LoAlertIRQ ******************
         if (irqBits & 0x01)    // LoAlert
         {  
            nbytes = MFIFOLength - ReadRawIO(RegFIFOLength);
            // less bytes to send, than space in FIFO
            if ((MpIsrInfo->nBytesToSend - MpIsrInfo->nBytesSent) <= nbytes)
            {
               nbytes = MpIsrInfo->nBytesToSend - MpIsrInfo->nBytesSent;
               WriteRawIO(RegInterruptEn,0x01); // disable LoAlert IRQ
            }
            // write remaining data to the FIFO
            for ( cnt = 0;cnt < nbytes;cnt++)
            {
               WriteRawIO(RegFIFOData,MpIsrOut[MpIsrInfo->nBytesSent]);
               MpIsrInfo->nBytesSent++;
            }
            WriteRawIO(RegInterruptRq,0x01);  // reset IRQ bit
         }
      
         //************* TxIRQ Handling **************
         if (irqBits & 0x10)       // TxIRQ
         {
            WriteRawIO(RegInterruptRq,0x10);    // reset IRQ bit 
            WriteRawIO(RegInterruptEn,0x82);    // enable HiAlert Irq for
                                           // response
            
         if (((MpIsrInfo->cmd & 0xF0) == 0x90) // if cmd is anticollision
                && (MpIsrInfo->nBitsReceived == 7)) // and 7 bits are known
	    {                                           // switch off parity generation
               WriteRawIO(RegChannelRedundancy,0x02);	// RXCRC and TXCRC disable, parity disable
	    }	
         }

         //************* HiAlertIRQ or RxIRQ Handling ******************
         if (irqBits & 0x0E) // HiAlert, Idle or RxIRQ
         {
            // read some bytes ( length of FIFO queue)              
            // into the receive buffer
            nbytes = ReadRawIO(RegFIFOLength);
            // read date from the FIFO and store them in the receive buffer
            for ( cnt = 0; cnt < nbytes; cnt++)               
            {
               MpIsrIn[MpIsrInfo->nBytesReceived] = ReadRawIO(RegFIFOData);
               MpIsrInfo->nBytesReceived++;
            }
            WriteRawIO(RegInterruptRq,0x0A & irqBits);  
                                       // reset IRQ bit - idle irq will
                                       // be deleted in a seperate section
         }   
   
         //************** IdleIRQ Handling ***********
         if (irqBits & 0x04)     // Idle IRQ
         {
            WriteRawIO(RegInterruptEn,0x20); // disable Timer IRQ
            WriteRawIO(RegInterruptRq,0x20); // disable Timer IRQ request
            irqBits &= ~0x20;   // clear Timer IRQ in local var
            MpIsrInfo->irqSource &= ~0x20; // clear Timer IRQ in info var
                                        // when idle received, then cancel
                                        // timeout
            WriteRawIO(RegInterruptRq,0x04);  // reset IRQ bit 
            // status should still be MI_OK
            // no error - only used for wake up
         }
       
         //************* TimerIRQ Handling ***********
         if (irqBits & 0x20)       // timer IRQ
         {

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日韩影院在线观看| 国产精品色在线| av一区二区不卡| 免费看日韩a级影片| 国产精品久久久久久久岛一牛影视 | 天堂蜜桃一区二区三区| 日本一二三不卡| 日韩欧美视频在线| 色爱区综合激月婷婷| 懂色av一区二区三区免费观看 | 久久激情五月激情| 亚洲国产另类精品专区| ●精品国产综合乱码久久久久 | 丝袜国产日韩另类美女| 国产精品人成在线观看免费| 欧美videossexotv100| 欧美三电影在线| 色噜噜狠狠成人中文综合| 国产成人精品亚洲日本在线桃色 | 91在线观看美女| 国产成人综合网| 极品尤物av久久免费看| 免费精品视频在线| 日韩av电影天堂| 天堂影院一区二区| 婷婷亚洲久悠悠色悠在线播放 | 美女在线观看视频一区二区| 亚洲第一在线综合网站| 樱花草国产18久久久久| 最近中文字幕一区二区三区| 国产精品午夜在线| 亚洲国产精品国自产拍av| 2023国产精品自拍| 久久中文字幕电影| 久久婷婷成人综合色| 精品国产凹凸成av人导航| 日韩视频一区二区在线观看| 91麻豆精品国产自产在线| 在线播放国产精品二区一二区四区| 91在线观看成人| 久久久综合九色合综国产精品| 日韩欧美一区电影| 日韩无一区二区| 2021国产精品久久精品| 久久综合五月天婷婷伊人| 精品国产乱码久久久久久牛牛| 欧美一级视频精品观看| 精品久久久久久久久久久久包黑料| 欧美一区二区视频观看视频| 欧美va亚洲va| 久久久久免费观看| 欧美韩国日本综合| 亚洲桃色在线一区| 亚洲国产精品精华液网站| 日韩电影在线免费看| 久久99精品久久只有精品| 国产成人一区二区精品非洲| 成人国产亚洲欧美成人综合网 | 午夜视频在线观看一区二区 | 中文字幕高清不卡| 一区二区在线观看免费| 五月天精品一区二区三区| 久久国内精品自在自线400部| 国产一区二区在线看| 不卡区在线中文字幕| 欧美性感一区二区三区| 日韩色在线观看| 日本一区二区动态图| 亚洲一二三区视频在线观看| 另类小说综合欧美亚洲| 国产aⅴ综合色| 欧美亚洲国产一区二区三区| 欧美videossexotv100| 中文字幕一区不卡| 青青草国产成人99久久| 高清不卡一二三区| 欧美日韩不卡在线| 国产精品中文字幕一区二区三区| 日韩一区日韩二区| 美女视频黄 久久| 成人免费黄色在线| 91麻豆精品国产91久久久使用方法 | 久久久久国色av免费看影院| 亚洲免费大片在线观看| 麻豆成人在线观看| 色悠悠亚洲一区二区| 日韩精品一区二区三区在线观看 | 7878成人国产在线观看| 国产精品国产三级国产专播品爱网| 亚洲影院在线观看| 成人午夜精品在线| 日韩欧美一级特黄在线播放| 亚洲日本一区二区| 国产一区二区三区四区五区入口| 在线观看国产日韩| 国产三级三级三级精品8ⅰ区| 亚洲一区二区三区四区不卡| 风流少妇一区二区| 91精品国产综合久久香蕉麻豆 | 日韩无一区二区| 亚洲国产精品久久不卡毛片| 成人教育av在线| 久久先锋影音av鲁色资源| 午夜电影网一区| 一本色道久久加勒比精品| 国产日本欧洲亚洲| 精品一区二区三区影院在线午夜 | 国产精品一区二区三区四区| 欧美日韩国产天堂| 一区二区三区四区中文字幕| 成人99免费视频| 精品国产一区二区三区av性色| 亚洲电影欧美电影有声小说| 91在线无精精品入口| 久久九九影视网| 久久99精品久久久久久动态图 | 亚洲日本免费电影| 成人久久18免费网站麻豆| 久久先锋影音av鲁色资源| 免播放器亚洲一区| 91精品国产一区二区| 亚洲成av人片一区二区梦乃| 色妞www精品视频| 一区免费观看视频| 福利91精品一区二区三区| 国产性色一区二区| 国产精品资源在线| 国产三级精品三级在线专区| 精品午夜久久福利影院| 日韩精品最新网址| 久久激情五月婷婷| 精品精品国产高清a毛片牛牛| 色国产精品一区在线观看| 亚洲人午夜精品天堂一二香蕉| 99久久精品免费看国产| 亚洲天堂成人在线观看| 色综合中文字幕国产 | 色哟哟一区二区三区| 中文字幕制服丝袜一区二区三区| 粉嫩一区二区三区在线看| 国产欧美一区二区在线观看| 国产不卡在线一区| 国产精品电影院| 91美女蜜桃在线| 亚洲国产精品久久一线不卡| 91精品国产综合久久久蜜臀图片| 午夜精品久久久久久久久久 | 欧美亚洲一区二区在线观看| 一区二区免费视频| 91精品国产91久久综合桃花| 蜜桃一区二区三区四区| www激情久久| 不卡的av电影在线观看| 亚洲综合成人网| 欧美一二三四在线| 国产美女娇喘av呻吟久久| 国产精品乱码一区二区三区软件| 99re热这里只有精品视频| 伊人一区二区三区| 欧美日本一区二区在线观看| 狠狠色综合播放一区二区| 国产精品久久久久久久午夜片| 一本大道综合伊人精品热热 | 国内精品视频一区二区三区八戒| 国产欧美日韩视频一区二区| 色婷婷av一区| 麻豆精品新av中文字幕| 国产精品视频一二| 欧美精品久久一区| 国产99精品在线观看| 亚洲一区日韩精品中文字幕| 日韩免费看的电影| 不卡视频一二三四| 日本强好片久久久久久aaa| 欧美经典三级视频一区二区三区| 91黄视频在线观看| 精品一区二区三区在线观看| 亚洲欧美国产三级| 日韩欧美在线1卡| 91性感美女视频| 美日韩一级片在线观看| 亚洲欧洲精品天堂一级| 日韩欧美黄色影院| 色猫猫国产区一区二在线视频| 男男成人高潮片免费网站| 国产精品二三区| 欧美大片免费久久精品三p| 99久久777色| 精品影视av免费| 亚洲成人精品一区二区| 国产欧美日韩卡一| 欧美一区二区视频网站| 色综合色综合色综合| 国产剧情一区在线| 日本vs亚洲vs韩国一区三区| 亚洲精品美腿丝袜| 国产精品五月天| 欧美成人a∨高清免费观看| 91国偷自产一区二区开放时间 | 日韩激情视频在线观看|