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

📄 i2c.h

📁 MCU控制程序
💻 H
字号:
//i2c.h 

#define TWPS0 0 
#define TWPS1 1 
#define TWEN  2 
#define TWIE  0 
#define TWEA  6 
#define TWINT 7 
#define TWSTA 5 
#define TWSTO 4 

// TWSR values (not bits) 
// Master 
#define TW_START               0x08 
#define TW_REP_START            0x10 
// Master Transmitter 
#define TW_MT_SLA_ACK            0x18 
#define TW_MT_SLA_NACK            0x20 
#define TW_MT_DATA_ACK            0x28 
#define TW_MT_DATA_NACK            0x30 
#define TW_MT_ARB_LOST            0x38 
// Master Receiver 
#define TW_MR_ARB_LOST            0x38 
#define TW_MR_SLA_ACK            0x40 
#define TW_MR_SLA_NACK            0x48 
#define TW_MR_DATA_ACK            0x50 
#define TW_MR_DATA_NACK            0x58 
// Slave Transmitter 
#define TW_ST_SLA_ACK            0xA8 
#define TW_ST_ARB_LOST_SLA_ACK                 0xB0 
#define TW_ST_DATA_ACK            0xB8 
#define TW_ST_DATA_NACK            0xC0 
#define TW_ST_LAST_DATA            0xC8 
// Slave Receiver 
#define TW_SR_SLA_ACK            0x60 
#define TW_SR_ARB_LOST_SLA_ACK                0x68 
#define TW_SR_GCALL_ACK            0x70 
#define TW_SR_ARB_LOST_GCALL_ACK                       0x78 
#define TW_SR_DATA_ACK            0x80 
#define TW_SR_DATA_NACK            0x88 
#define TW_SR_GCALL_DATA_ACK                          0x90 
#define TW_SR_GCALL_DATA_NACK                          0x98 
#define TW_SR_STOP               0xA0 
// Misc 
#define TW_NO_INFO               0xF8 
#define TW_BUS_ERROR            0x00 

// defines and constants 
#define TWCR_CMD_MASK                             0x0F 
#define TWSR_STATUS_MASK                             0xF8 

// return values 
#define I2C_OK                            0x00 
#define I2C_ERROR_NODEV                              0x01 

#define I2C_SEND_DATA_BUFFER_SIZE                0x10 
#define I2C_RECEIVE_DATA_BUFFER_SIZE                 0x10 

#define F_CPU 7372800 
#define TRUE  1 
#define FALSE 0    

#define   I2C_ADDR             0x48  //本机i2c从地址

// types 
typedef enum 
{ 
   I2C_IDLE = 0, I2C_BUSY = 1, 
   I2C_MASTER_TX = 2, I2C_MASTER_RX = 3, 
   I2C_SLAVE_TX = 4, I2C_SLAVE_RX = 5 
} eI2cStateType; 

// I2C 状态和地址变量 
static volatile eI2cStateType I2cState; 
static unsigned char I2cDeviceAddrRW; 
//static unsigned char i2creceive_b;  //接收到命令
//static unsigned char i2creadtime_b; //
// 发送缓冲区 
/*
static unsigned char I2cSendData[I2C_SEND_DATA_BUFFER_SIZE]; 
static unsigned char I2cSendDataIndex; 
static unsigned char I2cSendDataLength;
*/ 
// 接收缓冲区 
/*
static unsigned char I2cReceiveData[I2C_RECEIVE_DATA_BUFFER_SIZE]; 
static unsigned char I2cReceiveDataIndex; 
static unsigned char I2cReceiveDataLength;
*/ 
void i2cSetBitrate(void);
void i2cSetLocalDeviceAddr(unsigned char deviceAddr);

//unsigned char I2cData[3]; 
//unsigned char I2cSendDataIndex1; 

⌨️ 快捷键说明

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