应广单片机读写24C02程序代码Word格式文档下载.docx
《应广单片机读写24C02程序代码Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《应广单片机读写24C02程序代码Word格式文档下载.docx(8页珍藏版)》请在冰豆网上搜索。
I2C_SCLequpb.0
I2C_SDA_DIRequpbc.2
I2C_SCL_DIRequpbc.0
I2C_L0NG_DLYequ50
I2C_SH0RT_DLYequ20
I2C_SDA_HIGHequsetlI2C.SDAI2C_SDA_L0WequsetOI2C.SDA
I2C_SCL_HIGHequsetlI2C.SCLI2C_SCL_L0WequsetOI2C.SCL
I2CSDAOUTPUTequsetlI2CSDADIRI2CSDAINPUTequsetOI2CSDADIR
I2CSCLOUTPUTequsetlI2CSCLDIRI2CSCLINPUTequsetOI2CSCLDIR//?
aA?
uchari2c_rw_addr;
//?
AD?
M0O?
uchari2c_rw_byte;
fiy?
Yuchari2c_rw_cmd;
MAJ£
t)M0O?
uchari2c_rw_temp;
y?
10D?
a?
uchari2c_rw_cnt;
tOD?
//
////?
u£
uSTARTDA°
A
i2c_start:
I2CSDAOUTPUT
I2C_SCL_0UTPUT
I2C_SDA_HIGH
delayI2C_L0NG_DLY
I2C_SCL_HIGH
I2C_SDA_L0W
I2C_SCL_L0W
delayI2C_L0NG_DLYret
//
ufiiiSTOPDA0A
i2c_stop:
1?
QSALVEACKDAoA//
i2c_slave_ack:
//don'
tcheckACK
I2C_SDA_INPUT
delayI2C_SH0RT_DLY
I2C_SCL_LOW
I2C_SDA_0UTPUT
ret
//餡?
6MASTERACKDA°
A//
i2c_master_ack:
//骼?
6MASTERNACKDAoA//
i2c_master_nack:
delayI2C_SH0RT_DLYret
//D?
oXO?
//Input:
i2c_rw_temp
//Used:
i2c__rw_cnt
i2c_write_8bit:
i2crwent=8;
i2c_write_8bit_loop:
sici2c_rw_temp
swapcI2C_SDA
delayI2C_SHORT_DLY
I2CSCLLOW
dzsni2c_rw_cnt
gotoi2c_write_8bit_loop
A0?
dxo?
//Output:
i2c_rw_temp//
i2c_read_8bit:
i2c_rw_temp=0;
i2c_read_8bit_loop:
gotoi2c_read_8bit_loop
i2c_rw_addr//i2c_rw_cmd
//i2c_rw_temp//Output:
i2c_rw_byte
i2c_read_byte:
//start
calli2c_start
//writedeviceaddress(write)i2c_rw_temp=i2c_rw_cmd;
calli2c_write_8bit
//slaveack
cal1i2c_slave_ack
//writeregisteraddressi2c_rw_temp=i2c_rw_addr;
calli2c_write_8bit
//startrepeat
//writedeviceaddress(read)i2c_rw_temp=i2c_rw_cmd;
i2c_rw_temp・0二1;
delayI2C_SHORT_DLY//OaAi?
10fia(;
6?
dI2C_SDA?
6Axa?
fia?
d
//readdata
calli2c_read_8bit
i2c_rw_byte=i2c_rw_temp;
//storedata
//masternack
calli2c_master_nack
//stop
calli2c_stop
//retune
delayI2C_LONG_DLY
wdreset
i2c_rw_addr//i2c_rw_byte//i2c_rw_cmd//Used:
i2c_rw_cnt
//i2c_rw_temp//
i2c_write_byte:
//writedeviceaddressi2c_rw_temp=i2c_rw_cmd;
calli2c_slave_ack
//writedata
i2c_rw_temp=i2c_rw_byte;
EEPRONLRW.CN©
equOxAO
////°
CyAu:
eeprom_read_byte//Input:
i2c_rw_addr
i2c._rw_cnt
//i2c_rw_temp
//eeprom_read_byte:
i2c_rw_cmd=EEPROM_RW_CMD;
gotoi2c_read_byte//X?
0a0aA16AmA£
(^10Xa
£
yAu:
eeprom_write_byte//Input:
//i2c_rw_byte
//X?
0a?
°
M?
6Ai§
6D^da^?
y0?
ifi?
a0O?
O?
D?
0X?
te?
fi
//eeprom_write_byte:
gotoi2c_write_byte//X?
0a0aAi6ApAfi(pl0Xa