main.h
资源名称:RFID.rar [点击查看]
上传用户:njxy551199
上传日期:2022-04-06
资源大小:1990k
文件大小:6k
源码类别:
RFID编程
开发平台:
C/C++
- /****************************************************************************
- * *
- * File: MAIN.H *
- * *
- *
- * *
- * Author: ZUZI *
- * *
- * Compiler: KEIL C51 uVision3.3 *
- * *
- * Description: STC89C52-Firmware for HY502 Demo *
- * *
- ****************************************************************************/
- #ifndef __MAIN_H__
- #define __MAIN_H__
- //#include "reg52.h"
- #include "REG52x2.h"
- //#include "at89s52.h
- //#include "stc89c51.h"
- #include "intrins.h"
- #include "string.h"
- #define uchar unsigned char
- #define uint unsigned int
- #define SUCCESS 0
- #define FAILURE 1
- //#define TIMER2 TRUE
- #define MF1_S50 0
- #define MF1_S70 1
- #define MF0_ULIGHT 2
- #define MF1_LIGHT 3
- //设置波特率
- #define OSC_FREQ 11059200L
- #define BAUD_115200 256 - (OSC_FREQ/192L)/115200L // 255
- #define BAUD_57600 256 - (OSC_FREQ/192L)/57600L // 254
- #define BAUD_38400 256 - (OSC_FREQ/192L)/38400L // 253
- #define BAUD_28800 256 - (OSC_FREQ/192L)/28800L // 252
- #define BAUD_19200 256 - (OSC_FREQ/192L)/19200L // 250
- #define BAUD_14400 256 - (OSC_FREQ/192L)/14400L // 248
- #define BAUD_9600 256 - (OSC_FREQ/192L)/9600L // 244
- // Timer2
- #define RCAP2_50us 65536L - OSC_FREQ/240417L
- #define RCAP2_1ms 65536L - OSC_FREQ/12021L
- #define RCAP2_10ms 65536L - OSC_FREQ/1200L
- #define RCAP2_1s 65536L - OSC_FREQ/12L
- sfr16 RCAP2LH = 0xCA;
- sfr16 T2LH = 0xCC;
- #define TRUE 1
- #define FALSE 0
- /*******************************************************************************
- * pin declare
- *******************************************************************************/
- sbit RST_HY =P1^2; // 复位管脚,低电平有效
- sbit NSS =P1^3; //接HY502 NSS
- sbit MOSI =P1^5; //接HY502 MOSI
- sbit MISO =P1^6; //接HY502 MISO
- sbit sig =P1^4; // INT0 low level active
- sbit SCL =P1^7;
- //-----------------------------------------------------------------------------------------SendBuffer
- unsigned char idata cp[30]; // HY502 buffer
- unsigned char idata g_cReceBuf[30]; //uart Receive buffer
- unsigned char g_cReceNum; //bytes of received, used in interrupt
- bit g_bReceCommandOk; //flag of command receive OK
- bit g_bReceAA; //flag of last received byte is "0xaa", used in interrupt
- bit g_bCard; //flag of card in
- unsigned char idata SelectedSnr[4]; //卡序列号
- //command list in both UART & IIC, with out command header "0xAA, 0xBB" of UART
- // CL: command length
- // CC: command code
- // CD: command data
- // CL CC CD
- // Set the module Power Down mode
- unsigned char ComPWRdwn[] = {0x02, 0x03};
- // Write E2 data
- unsigned char ComWriteE2[] = {0x09, 0x31, 0x00, 0x00, 0x04,
- 0x11, 0x00, 0x11, 0x00};
- // Read E2 data
- unsigned char ComReadE2[] ={0x05, 0x30, 0x00, 0x00, 0x04};
- // search card and get card serial number
- unsigned char code ComSearchCard[] = {0x03, 0x13, 0x01};
- // read block No.4
- unsigned char code ComReadBlock4[] = {0x0a, 0x21, 0x00, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
- // read block No.6
- unsigned char code ComReadBlock6[] = {0x0a, 0x21, 0x00, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
- // write block No.4 with 0x01 to 0x0f
- unsigned char idata ComWriteBlock4[] = {0x1a, 0x22, 0x00, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
- 0x00, 0x00, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05};
- // initialize block No.5 as a purse with value: 0x12345678
- unsigned char code ComIntiPurse5[] = {0x0e, 0x23, 0x00, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x52, 0x30, 0x20, 0x10};
- // read purse value of block No.5
- unsigned char code ComReadPurse5[] = {0x0a, 0x24, 0x00, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
- // purse in block No.5 increase with value "2"
- unsigned char code ComIncrPurse5[] = {0x0e, 0x25, 0x00, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x02, 0x00, 0x00, 0x00};
- // purse in block No.5 decrease with value "1"
- unsigned char code ComDecrPurse5[] = {0x0e, 0x26, 0x00, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
- 0x02, 0x00, 0x00, 0x00};
- // halt the card selected
- unsigned char code ComHaltCard[] = {0x02, 0x12};
- void InitializeSystem(); //initialize the MCU system
- void AlarmErr(); //beep, indicate a error occured
- void ShowError(unsigned char cTimes); //flash LED2, the flash time indicate where is the error
- unsigned char SPITesting(); //SPITESTING PROGRAM
- #endif
- //------------------File end--------------------------