?? twi.h
字號:
#define pinSCL 5 //PC5 SCL
#define pinSDA 4 //PC4 SDA
#define fSCL 100000 //TWI時鐘為100KHz
#define fosc 7372800
#define baud 115200
//預分頻系數=1(TWPS=0)
#if fosc < fSCL*36
#define TWBR_SET 10; //TWBR必須大于等于10
#else
#define TWBR_SET (fosc/fSCL-16)/2; //計算TWBR值
//(F_CPU/fSCL-16)/2; //計算TWBR值
#endif
#define TW_ACT (1<<TWINT)|(1<<TWEN)|(1<<TWIE)
//TWCR只能IN/OUT,直接賦值比邏輯運算(|= &=)更節省空間
#define SLA_24CXX 0xA0 //24Cxx系列的廠商器件地址(高四位)
#define ADDR_24C64 0x00
// AT24C64的地址線A2/1/0全部接地,SLAW=0xA0+0x00<<1+0x00,SLAR=0xA0+0x00<<1+0x01
//TWI_操作狀態
#define TW_BUSY 0
#define TW_OK 1
#define TW_FAIL 2
//TWI_讀寫命令狀態
#define OP_BUSY 0
#define OP_RUN 1
//TWI讀寫操作公共步驟
#define ST_FAIL 0 //出錯狀態
#define ST_START 1 //START狀態檢查
#define ST_SLAW 2 //SLAW狀態檢查
#define ST_ADDR 3
#define ST_WADDR 4 //ADDR狀態檢查
//TWI讀操作步驟
#define ST_RESTART 5 //RESTART狀態檢查
#define ST_SLAR 6 //SLAR狀態檢查
#define ST_RDATA 7 //讀取數據狀態檢查,循環n字節
//TWI寫操作步驟
#define ST_WDATA 8 //寫數據狀態檢查,循環n字節
#define FAIL_MAX 20 //重試次數最大值
#define KEY 0X04
#define FREQ 4
#define TWI_ADDRESS 0X32
#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
/* R/~W bit in SLA+R/W address field. */
#define TW_READ 1
#define TW_WRITE 0
//#define LCD_EN_PORT PORTD
//#define LCD_RW_PORT PORTD
//#define LCD_RS_PORT PORTD
//#define CONTROL_PORT DDRD
//#define LCD_DATA_PORT PORTB
//#define LCD_DATA_DDR DDRB
//#define LCD_DATA_PIN PINB
//定義全局變量
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -