新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > 單片機讀寫24C02的匯編程序

單片機讀寫24C02的匯編程序

作者: 時間:2012-10-12 來源:網絡 收藏
;簡潔的讀寫
;--------------------------------------------
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


評論


相關推薦

技術專區(qū)

關閉