at24c02跨页写
自己定义一个变量,表示当前写入24c02的位置(24c02存储地址为0-255),每写一个数据地址+1,当地址是8的倍数时(即低3位为0)表示跨页了,这时发送一个结束信息(24c02会在这时写一页数据)然后轮询24c02是否空闲,空闲则继续
I2CWriteNBytes:
STZ R_I2CIndex
?LoopLen
LDA R_I2CLength //要写入数据的长度
BEQ ?End
?Loop
JSR I2CStart
LDA #A0H
STA R_I2C8Bit
JSR I2CWrite8Bit
JSR I2CTestAck
LDA R_I2CAck
BEQ ?Ready
JSR I2CStop
JMP ?Loop
?Ready //轮询是否空闲
LDA R_I2CByteAddr //要写入24c02的地址
STA R_I2C8Bit
JSR I2CWrite8Bit
JSR I2CTestAck
?InLoop
LDA R_I2CLength
BEQ ?InEnd
LDX R_I2CIndex
LDA R_I2CByte,X
STA R_I2C8Bit
JSR I2CWrite8Bit
JSR I2CTestAck
INC R_I2CIndex
DEC R_I2CLength
INC R_I2CByteAddr
LDA R_I2CByteAddr
AND #00000111B
BEQ ?InEnd
JMP ?InLoop //循环发送数据,地址是8的倍数时退出循环,24c02执行页写操作
?InEnd //然后继续轮询,把剩余数据写完
JSR I2CStop
JMP ?LoopLen
?End
RTS
谢谢,我已经明白了