單片機(jī)匯編實(shí)驗(yàn)六:I2C串行總線存儲(chǔ)器讀寫實(shí)驗(yàn)
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ù)子程序(讀取一個(gè)字節(jié)以后不做應(yīng)答)
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 ;結(jié)束條件
NOP
NOP
NOP
NOP
SETB SCL
NOP
NOP
NOP
NOP
SETB SDA
NOP
NOP
NOP
NOP
RET
CHULI: //1999uS ;這里是用于寫完數(shù)據(jù)以后留給24C02的內(nèi)部數(shù)據(jù)處理時(shí)間,2ms是一個(gè)非常保險(xiǎn)的時(shí)間,最短需要1ms
MOV R6,#04H
WR0:
MOV R5,#0F8H
DJNZ R5,$
DJNZ R6,WR0
RET
END本文引用地址:http://m.butianyuan.cn/article/201612/324146.htm
評(píng)論