📄 smbus.h
字号:
//SMBUS.H
//------------------------------------------------------//
// YnKing 原创,转载请注明出处
// http://www.21mcu.com/
// ynpsps@sina.com
//------------------------------------------------------//
#ifndef __SMBUS_H__
// <<< Use Configuration Wizard in Context Menu >>>
// <e> SMBUS Enable
#define SMBUS_Enable 1
#if SMBUS_Enable == 1
#define SYSCLK 22118400
//--------------------------------------------------------------------//
// 全 局 常 量 //
//--------------------------------------------------------------------//
#define SMB_BUS_ERROR 0x00 // (对所有方式)总线错误
#define SMB_START 0x08 // (MT & MR)起始条件已发送
#define SMB_RP_START 0x10 // (MT & MR)重复起始条件
#define SMB_MTADDACK 0x18 // (MT) 从地址+ W 已发送;收到ACK
#define SMB_MTADDNACK 0x20 // (MT) 从地址+ W 已发送;收到NACK
#define SMB_MTDBACK 0x28 // (MT) 数据字节已发送;收到ACK
#define SMB_MTDBNACK 0x30 // (MT) 数据字节已发送;收到NACK
#define SMB_MTARBLOST 0x38 // (MT) 竞争失败
#define SMB_MRADDACK 0x40 // (MR) 从地址+ R 已发送;收到ACK
#define SMB_MRADDNACK 0x48 // (MR) 从地址+ W 已发送;收到NACK
#define SMB_MRDBACK 0x50 // (MR) 收到数据字节;ACK 已发送
#define SMB_MRDBNACK 0x58 // (MR) 收到数据字节;NACK 已发送
extern void SMBUS_INIT(void);
//-----------------------------//
// <q> ROM24 Enable
//-----------------------------//
#define SMBUS_ROM24_Enable 1
#if SMBUS_ROM24_Enable == 1
typedef struct
{
unsigned char IsOpen; // 是否打开
unsigned char Chip_Addr; // 从器件设备地址
unsigned char AddrWidth; // 地址宽度 1,2
unsigned char PageSize; // 写页面大小
}SMBUS_ROM24_Device;
extern void SMBUS_ROM24_Device_Init(SMBUS_ROM24_Device *device , unsigned char chip_addr , unsigned char addrwidth , unsigned char pagesize);
extern void SMBUS_ROM24_WBS(SMBUS_ROM24_Device *device , unsigned int byte_address , char *dout , unsigned char len);
extern void SMBUS_ROM24_RBS(SMBUS_ROM24_Device *device , unsigned int byte_address , char *din , unsigned char len);
extern SMBUS_ROM24_Device ROM24CXX;
#define r24(rom,ram,len) SMBUS_ROM24_RBS(&ROM24CXX , rom , ram , len)
#define w24(rom,ram,len) SMBUS_ROM24_WBS(&ROM24CXX , rom , ram , len)
#endif
//--------------------------------------------------------------------//
//--------------------------------------------------------------------//
//--------------------------------------------------------------------//
// <q> RFID HY502 Enable
//--------------------------------------------------------------------//
#define HY502_Enable 0
#if HY502_Enable == 1
#define HY502_Addr 1
// Define the commands
#define PCD_PN 0x01 // 设备型号
#define PCD_SN 0x02 // 设备序列号
#define PWR_DOWN 0x03 //设备掉电,需重新加电复位
#define BAUD_SET 0x04 //波特率设置
#define FW_REL 0x10 //PCD固件版本号
#define SOFTDOWN 0x11 //HY502模块软掉电
#define HALT_CARD 0x12 //中止卡操作
#define AUTOSEARCH 0x13 //自动寻卡
#define BEEP 0x14 //蜂鸣器开关
#define BEEP_TIME 0x15 //鸣响时间
#define CARD_TYPE 0x19 //读取卡类型
#define CARD_SN 0x20 //读卡序列号
#define READ_BLOCK 0x21 //读块数据
#define WRITE_BLOCK 0x22 //写块数据
#define INIT_PURSE 0x23 //初始化钱包
#define READ_PURSE 0x24 //读钱包
#define ADD_PURSE 0x25 //钱包充值
#define DEC_PURSE 0x26 //钱包扣款
#define READ_SECTOR 0x2a // 读扇区
#define WRITE_SECTOR 0x2b // 写扇区
#define READ_E2 0x30 // 读E2
#define WRITE_E2 0x31 // 写E2
// Define the error commands return from HY502 chip
#define ERR_HALT 0xed //中止卡操作错误
#define ERR_AUTO 0xec //自动寻卡错误
#define ERR_TYPE 0xe6 //读取卡类型错误
#define ERR_SN 0xdf //读卡序列号错误
#define ERR_READ_BLOCK 0xde //读块数据错误
#define ERR_WRITE_BLOCK 0xdd //写块数据错误
#define ERR_INIT_PURSE 0xdc //初始化钱包错误
#define ERR_READ_PURSE 0xdb //读钱包错误
#define ERR_ADD_PURSE 0xda //钱包充值错误
#define ERR_DEC_PURSE 0xd9 //钱包扣款错误
//----------------------//
// 函 数 定 义 //
//----------------------//
//--- 初始化 ---//
//--- 读数据包 ---//
extern bit HY502_RP(unsigned char *p);
//--- 写数据包 ---//
extern bit HY502_WP(unsigned char *p);
//--- 读卡类型 ---//
extern unsigned int HY502_RCardType(void);
//--- 读卡ID号 ---//
extern unsigned long HY502_RCardID(void);
//--- 卡休眠 ---//
extern bit HY502_CardIdle(void);
#endif
//--------------------------------------------------------------------//
#else // 没有定义 SMBUS
#define ROM24_Enable 0
#endif
// </e>
// <<< end of configuration section >>>
#define __SMBUS_H__
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -