📄 main.h
字号:
/****************************************************************************
* *
* File: MAIN.H *
* *
* Version: 1.0 *
* *
* Created: 21.03.2006 *
* Last Change: 16.05.2006 *
* *
* Author: ZUZI *
* *
* Compiler: KEIL C51 uVision3.3 *
* *
* Description: STC89C52-Firmware for HY502 Demo *
* *
****************************************************************************/
//#include "reg52.h"
#include "at89s52.h"
//#include "stc89c51.h"
#include "intrins.h"
#include "string.h"
#define SUCCESS 0
#define FAILURE 1
#define READ_HY502 0xA3
#define WRITE_HY502 0xA2
#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;
// 定义IIC端口
sbit SDA = P1^6;
sbit SCL = P1^7;
sbit sig = P3^2; // INT0
// Defing iic address
// 定义IIC地址线
sbit a0 =P1^5;
sbit a1 =P1^4;
sbit a2 =P1^3;
#define TRUE 1
#define FALSE 0
/*******************************************************************************
* pin declare
*******************************************************************************/
// Port define
sbit LED_GREEN =P1^0; // LED定义
sbit BUZ =P1^1; // 蜂鸣器,1=beep,0=silence
sbit RST_HY =P1^2; // 复位管脚,低电平有效
//sbit M1 =P1^3; // 复用管脚选择
sbit LED_YELLOW =P3^7; // LED定义
unsigned char code ComReadBlock7[] = {0x0a, 0x21, 0x60, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
// --------------------
// CL: command length 长度
// CC: command code 命令字
// CD: command data 数据
// --------------------
// shut antenna CL CC CD
unsigned char AntOff[] = {0x03, 0x11, 0x00};
// open antenna
unsigned char AntOn[] = {0x03, 0x11, 0x01};
// halt the selected card 卡休眠
unsigned char CardHalt[] = {0x02, 0x12};
// auto search card 设置自动寻卡
unsigned char AutoCard[] = {0x03, 0x13,0x01};
// auto search card 关闭自动寻卡
unsigned char AutoOff[] = {0x03, 0x13,0x00};
// card type 读卡类型
unsigned char code ComCardType[] = {0x02, 0x19};
// search card and get card serial number 读卡序列号
unsigned char code ComSearchCard[] = {0x02, 0x20};
// read block No.4 读块4(扇区1块0)
unsigned char code ComReadBlock4[] = {0x0a, 0x21, 0x60, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
// read block No.5 读块5(扇区1块1)
unsigned char code ComReadBlock5[] = {0x0a, 0x21, 0x60, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
// read block No.6 读块6(扇区1块2)
unsigned char code ComReadBlock6[] = {0x0a, 0x21, 0x60, 0x06, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
// write block No.4 with 0x00 to 0x0f 写16个字节数据0x00-0x0f到块4
unsigned char code ComWriteBlock4[] = {0x1a, 0x22, 0x60, 0x04, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
// write block No.5 with 0x00 to 0x0f 写16个字节数据0x00-0x0f到块5
/*
unsigned char code ComWriteBlock5[] = {0x1a, 0x22, 0x60, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
*/
// write block No.5 with 0x00 to 0x0f 写16个字节数据0x00-0x09到块5
unsigned char code ComWriteBlock5[] = {0x1a, 0x22, 0x60, 0x05, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
// initialize block No.8 as a purse with value: 0x12345678 初始化钱包块8(扇区2块0)为12345678
unsigned char code ComIntiPurse8[] = {0x0e, 0x23, 0x60, 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x78, 0x56, 0x34, 0x12};
// read purse value of block No.8 读钱包块8
unsigned char code ComReadPurse8[] = {0x0a, 0x24, 0x60, 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
// purse in block No.8 increase with value "2" 给钱包块8充值2
unsigned char code ComIncrPurse8[] = {0x0e, 0x25, 0x60, 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x02, 0x00, 0x00, 0x00};
// purse in block No.8 decrease with value "2" 给钱包块8扣款2
unsigned char code ComDecrPurse8[] = {0x0e, 0x26, 0x60, 0x08, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0x02, 0x00, 0x00, 0x00};
//-----------------------------------------------------------------------------------------SendBuffer
unsigned char data cp[30]; // HY502 buffer
unsigned char data g_cReceBuf[30]; //uart Receive buffer
unsigned char data SendBuffer[33]; // send 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]; //卡序列号
void InitializeSystem(); //initialize the MCU system
/*
void UartSendHY502(unsigned char *g_cCommand); //send a command to HY502 over UART
*/
//extern void Delay100uS(unsigned int); //delay function, in "Delay.asm"
void I2CStart(void);
void I2CStop(void);
bit I2CWaitAck(void);
void I2CSendAck(void);
void I2CSendNotAck(void);
void I2CSendByte(unsigned char cSendByte);
unsigned char I2CReceiveByte(void);
unsigned char IicReadHY502(unsigned char *cP); // Receive COMMAND from HY502 over IIC bus
unsigned char IicSendHY502(unsigned char *cP); // Send COMMAND to HY502 over IIC bus
//------------------File end--------------------------
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -