單片機匯編實驗六:I2C串行總線存儲器讀寫實驗
MOV R3,A //讀出的字節(jié)傳給R3
RET
STAR:SETB SDA //起始條件子程序
SETB SCL
NOP
NOP
NOP
NOP
CLR SDA
NOP
NOP
NOP
NOP
RET
SDATA:MOV R0,#08H //向24C02傳輸數(shù)據(jù)子程序
LOOP0:CLR SCL
RLC A
MOV SDA,C
NOP
NOP
SETB SCL
NOP
NOP
NOP
NOP
DJNZ R0,LOOP0
CLR SCL
NOP
SETB SDA
NOP
NOP
SETB SCL
REP:MOV C,SDA
JC REP
NOP
NOP
NOP
CLR SCL
NOP
NOP
RET
RDATA:MOV R0,#08H //從24C02讀取數(shù)據(jù)子程序(讀取一個字節(jié)以后不做應答)
LOOP1:SETB SCL
NOP
NOP
NOP
NOP
MOV C,SDA
RLC A
CLR SCL
NOP
NOP
NOP
NOP
DJNZ R0,LOOP1
SETB SCL
NOP
NOP
NOP
NOP
CLR SCL
RET
STOP:CLR SDA ;結束條件
NOP
NOP
NOP
NOP
SETB SCL
NOP
NOP
NOP
NOP
SETB SDA
NOP
NOP
NOP
NOP
RET
CHULI: //1999uS ;這里是用于寫完數(shù)據(jù)以后留給24C02的內部數(shù)據(jù)處理時間,2ms是一個非常保險的時間,最短需要1ms
MOV R6,#04H
WR0:
MOV R5,#0F8H
DJNZ R5,$
DJNZ R6,WR0
RET
END本文引用地址:http://m.butianyuan.cn/article/201612/324146.htm
評論