描述
24C02读写汇编程序,24C02 read / write process
关键字:24C02读写汇编程序
24C02读写汇编程序
;简洁的24C02读写汇编程序
;--------------------------------------------
I2C_SDA EQU P1.6 ; PIN 5
I2C_SCL EQU P1.7 ; PIN 6
;=============================================
I2C_WRITE: ; WRITE 8 BYTES TO EEROM ; INPUT: A - A*8 = EEROM START ADDR
; R0 - RAN START ADDR
; USE: C, A, R0, R6, R7
ACALL I2C_START
ACALL OUT
MOV R6, #8
WR_LP:MOV A, @R0
ACALL OUT
INC R0
DJNZ R6, WR_LP
AJMP I2C_STOP
;==========================================
I2C_READ: ; READ 8 BYTES FROM EEROM ; INPUT: A - A*8 = EEROM START ADDR
; R0 - RAN START ADDR
; USE: C, A, R0, R6, R7
ACALL I2C_START
ACALL OUT
MOV R6, #8
MOV A, #0A1H; #RDCMD
ACALL OUTS
BRDLP:
MOV R7, #8
SETB I2C_SDA
INLP: CLR I2C_SCL
ACALL DELAY6
SETB I2C_SCL
NOP
MOV C, I2C_SDA
RLC A
DJNZ R7, INLP
CLR I2C_SCL
MOV @R0, A
INC R0
DJNZ R6, ACKLP
;;;;----------------------------
I2C_STOP:
CLR I2C_SDA
ACALL DELAY5
SETB I2C_SCL
ACALL DELAY5
SETB I2C_SDA
DELAY6:
NOP
DELAY5:
NOP
RET
;;-----------------------------
I2C_START:
SWAP A
RR A
MOV R6, A
MOV A, #0A0H; #WTCMD
ACALL OUTS
MOV A, R6
RET
;-------------------------------
ACKLP:
CLR I2C_SDA
SETB I2C_SCL
ACALL DELAY5
CLR I2C_SCL
AJMP BRDLP
;=======================
OUTS:
SETB I2C_SDA
SETB I2C_SCL
ACALL DELAY5
CLR I2C_SDA
ACALL DELAY5
CLR I2C_SCL
;========================
OUT:
SETB C
MOV R7, #9
OTLP: RLC A
NOP
MOV I2C_SDA, C
NOP
NOP
SETB I2C_SCL
ACALL DELAY5
CLR I2C_SCL
DJNZ R7, OTLP
RET
;========================
END
打开APP阅读更多精彩内容