单片机读写24C02的汇编程序
时间:10-12
来源:互联网
点击:
;简洁的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
;--------------------------------------------
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
- FPGA的DSP性能揭秘(06-16)
- 基于单片机通用引脚的软件UART设计(10-16)
- 分时操作系统思想在单片机中的具体应用 (10-30)
- 基于AT89C51+DSP的双CPU伺服运动控制器的研究(05-26)
- 关于RTX51 TINY的分析与探讨(05-30)
- 基于MC9S12DGl28单片机的智能寻迹车设计(04-03)