微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > 单片机读写24C02的汇编程序

单片机读写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

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top