/*---------------------------------------------------------------------------
Copyright (c), Philips Semiconductors Gratkorn
mfrc500或fm1702基本函数库
------------------------------------------------------------------------------*/
#define DLL_EXPORT // library source module definition
#include <main.h>
#include <Mfreg500.h>
#include <M500A.h>
#include <RdIo.h>
#include <string.h>
//#include <stdio.h>
#include "PORT.h"
#include "DELAY.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
{
tByte cmd; //!< command code
char status; // communication status
tByte nBytesSent; // how many bytes already sent
tByte nBytesToSend; // how many bytes to send
tByte nBytesReceived;// how many bytes received
unsigned short nBitsReceived; // how many bits received
tByte irqSource; // which interrupts have occured
tByte collPos; // at which position occured a
// collision
} MfCmdInfo;
// modul variables
extern tByte xdata *GpBase;
static tByte idata MFIFOLength = DEF_FIFO_LENGTH; // actual FIFO length
static tByte 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 tByte xdata MSndBuffer[SND_BUF_LEN];
// receive buffer for general use
static volatile tByte 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 tByte *MpIsrOut = 0;
// ISR receive buffer
static volatile tByte *MpIsrIn = 0;
// storage of the last selected serial number including check byte.
//For multi level serial numbers, only the first 4 bytes are stored.
tByte MLastSelectedSnr[5];
// Timer 2
bit T2IR = 0; // Timer2 timeout flag
unsigned int CountDown = 0; // Timeout counter with 50us resolution
///////////////////////////////////////////////////////////////////////////////
// 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(tByte 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 l
fanka.rar_500wk3. com_mfrc500
版权申诉
199 浏览量
2022-09-24
18:16:18
上传
评论
收藏 249KB RAR 举报
朱moyimi
- 粉丝: 63
- 资源: 1万+
最新资源
- CocosDashboard-v2.1.3-win-042311.exe
- 基于yolov5和deepsort算法的车辆检测项目源码+数据集(高分项目).zip
- 基于YOLOv5+Deepsort实现车辆行人追踪和计数(完整源码+说明文档+数据).zip
- 150360364459673Pex10_9.py
- 74ls138译码器Multisim仿真设计
- 深度学习在图像分类任务中的应用
- 华为OD资源整理-包含华为OD概述,招聘流程等
- 基于BP神经网络的供热管道压力和温度预测(代码完整,数据齐全)
- 架空电力线弧垂计算公式
- 基于BP神经网络的四分类预测,基于RBF的四分类预测,基于GRNN的四分类预测,基于PNN的四分类预测
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0