非常全和详细的24C02(I2C)驱动程序
/*---------------------------------------24C02.h-----------------------------------*/ #ifndef _24C02_H #define _24C02_H
/* Includes ----------------------------------------------------------------*/ #include "STC15F2K60S2.h" #include "stdbool.h"
/* Define ------------------------------------------------------------------*/ #define WC24C02 0xa0 //器件地址 写 #define RC24C02 0xa1 //器件地址 读
#define MAXSIZE24C02 256 //AT24C02最多256个字节 2K bits 32页 #define I2C_PAGESIZE 8 //AT24C02每页有8个字节
#define delayNOP() _nop_();_nop_();_nop_();_nop_() //延时
sbit SDA = P2^5; //定义数据线 sbit SCL = P2^6; //定义时钟线
/* Private ------------------------------------------------------------------*/ /* Public -------------------------------------------------------------------*/ uint idata ucSendBuffer[8]={0x01,0x02,0x04,0x08, 0x10,0x20,0x40,0x80}; uint idata ucReceData;
uint idata ucReceiveBuffer[8]; //从器件中读出的多字节数据暂存区
/* Function Declaration -----------------------------------------------------*/ bool I2CStart(void); //启动I2C void I2CStop(void); //停止I2C void I2CAck(void); //应答信号 void I2CNoAck(void); //发送非应答信号 bool I2CWaitAck(void); //检测应答位 void I2CSendByte(u8 demand);
热门文档