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

📄 mf_rc500.h

📁 Mifare RC500 非接觸式讀卡機驅動程式碼 (Keil C/8051)
💻 H
字号:
#include <stdio.h>
#include <string.h>
#include <absacc.h>
#include <intrins.h>
#include <at89x52.h>
#include "MF_RC500Reg.h"
#include "MF_ErrNo.h"

#define TRUE 			1
#define FALSE 			0     
#define true                    1
#define false                   0
#define OSC_FREQ              11059200L
#define BAUD_9600             0xFD                   //256 - (OSC_FREQ/192L)/9600L     // 244
#define TH0_20ms              0xB8               //osc=11.0592M
#define TL0_20ms              0x00


#define uchar 			unsigned char
#define uint  				unsigned int

//card type defined
#define nocard			0
#define mifare1			1
#define mifarepro		2
#define mifarelight		3
#define unknowncard		4

#define tmod_1ms		1
#define tmod_1_5ms		2
#define tmod_6ms		3
#define tmod_9_6ms		4

#define ALL	               	0x52
#define IDLE	        		0x26
#define KEYA	        		0x60
#define KEYB	        		0x61
#define BLOCK_NUM_SET  	                0x01           //the read block number

#define OPEN_TIME                       0x02        //open door delay time (second)
     
#define CMD_READ_SN                     0x01
#define CMD_READ_BLOCK                  0x02
#define CMD_WRITE_BLOCK                 0x03
#define CMD_WRITE_PASSWD                0x04

//EEPROM
#define   UNIT_KEY_ADDR         0x00
#define   USER_CARD_SIGN        0x02
#define   MANAGE_CARD_SIGN      0x03
#define   LOST_CARD_SIGN        0x04
#define   BUILD_ENTRY_NUM       0x05
#define   LOST_LIST_AREA        0x07
#define   SYSTEM_CARD_SIGN      0x04

#define   LOAD_KEYB_ERR           0xee
#define   LOAD_KEYA_ERR           0xdd


//hardware defined
/*
sbit    RC500CS         	= P2^0;
sbit    RC500RST        	= P1^3;// hk
sbit    LED	                = P3^5 ;
sbit    SPK                     =P3^5;
sbit    LED1                = P1^4;
sbit    WDG                 = P1^7;
*/
sbit   RC500CS           =P2^0;
sbit   RC500RST         =P1^3;

sbit   SDA                   =P1^0;
sbit   SCL                    =P1^1;
sbit   WP                     =P1^2;

sbit   RLED                  =P3^3;
sbit   LED                    =P3^3;
sbit   GLED                  =P3^4;
sbit   LED1                   =P3^4;

sbit   WDG                   =P1^7;
sbit   SPK                    =P3^5;

sbit   TX_RX                 =P1^5;
sbit   OPEN                   =P1^6;

sbit   LOCK                    =P1^4;

#define GetRegPage(addr) (0x80 | (addr>>3))

//unsigned char idata MLastSelectedSnr[4];
//unsigned char data RevBuffer[10];
unsigned char data SerBuffer[20];          //origin=20

typedef struct 
         {
            unsigned char  cmd;           
            char           status;        
            unsigned char  nBytesSent;   
            unsigned char  nBytesToSend; 
            unsigned char  nBytesReceived;
            unsigned short nBitsReceived; 
            unsigned char  irqSource;     
            unsigned char  collPos;       
                                          
         } MfCmdInfo;
#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;


static   volatile MfCmdInfo 		idata   MInfo; 
static   volatile MfCmdInfo    		*MpIsrInfo = 0; 
static   volatile unsigned char  	*MpIsrOut  = 0; 



 uchar  tt[2];
// uchar code Nkey_a[6]    = {0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5};
 uchar code Nkeya[6]    = {0xc5,0xc4,0xc3,0xc2,0xc1,0xc0};
 uchar code Nkeyb[6]    = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
 uchar idata card_snr[4];
 uchar idata size;
 uchar block_num,sec_num;
 uchar idata datas[34];    
 volatile uchar cmd_code=0;    
 volatile uchar rcv_start=false;
 uchar rcv_counter=0;  
 uchar sum;   
 uchar idata com_t_index,com_t_length,com_tmr_rx,com_r_index;
 bit	com_r_busy;

⌨️ 快捷键说明

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