标签:电子小制作,http://www.5idzw.com
24C02的简单操作(汇编),http://www.5idzw.com
org 0
mov sp,#sp_begain
acall delay
acall delay
acall delay
mov 30h,#0
mov 31h,#1
mov 32h,#2
mov 33h,#3
mov 34h,#4
mov 35h,#5
mov 36h,#6
mov 37h,#7
write: clr a ;address
mov r0,#30h ;point
mov r1,#8 ;sum
acall wrs_2402
cjne r1,#0ffh,next0
sjmp err_2402
next0: acall delay
read: clr a ;address
mov r0,#38h ;point
mov r1,#8 ;sum
acall rds_2402
cjne r1,#0ffh,next1
sjmp err_2402
next1: acall delay
write0: mov a,#8 ;address
mov r0,#38h ;point
mov r1,#8 ;sum
acall wrs_2402
cjne r1,#0ffh,next2
sjmp err_2402
next2: acall delay
sjmp $
err_2402:sjmp $
delay: mov r6,#20 ;24M--5ms----24c02的写入时间间隔
delay_0:djnz r7,$
djnz r6,delay_0
ret
;---------------------------------------------
wI2c equ 0a0h ;器件地址及写操作
rI2c equ 0a1h ;器件地址及读操作
sta_2402: ;启始
setb sda_2402
setb scl_2402
sjmp $+2 ;24M至少间隔周期
sjmp $+2
clr sda_2402
sjmp $+2
sjmp $+2
clr scl_2402
sjmp $+2
sjmp $+2
ret
stp_2402: ;结束
clr sda_2402
setb scl_2402
sjmp $+2
sjmp $+2
setb sda_2402
sjmp $+2
sjmp $+2
ret
wr_2402: ;写单个字节
mov b,#8
wr_2402_0: rlc a
jc wr_2402_1
clr sda_2402
sjmp wr_2402_2
wr_2402_1: setb sda_2402
wr_2402_2: setb scl_2402
sjmp $+2
sjmp $+2
clr scl_2402
sjmp $+2
sjmp $+2
djnz b,wr_2402_0
nmack_2402: setb sda_2402
nmack_2402_0:setb scl_2402
sjmp $+2
sjmp $+2
mov c,sda_2402
clr scl_2402
sjmp $+2
sjmp $+2
ret
mack_2402: clr sda_2402
sjmp nmack_2402_0
rd_2402: ;读单个字节
mov b,#8
setb sda_2402
rd_2402_0: setb scl_2402
,24C02的简单操作(汇编)
; 24c02的简单操作
;www.808cn.com
scl_2402 bit p3.5
sda_2402 bit p3.7
sp_begain equ 60h
org 0
mov sp,#sp_begain
acall delay
acall delay
acall delay
mov 30h,#0
mov 31h,#1
mov 32h,#2
mov 33h,#3
mov 34h,#4
mov 35h,#5
mov 36h,#6
mov 37h,#7
write: clr a ;address
mov r0,#30h ;point
mov r1,#8 ;sum
acall wrs_2402
cjne r1,#0ffh,next0
sjmp err_2402
next0: acall delay
read: clr a ;address
mov r0,#38h ;point
mov r1,#8 ;sum
acall rds_2402
cjne r1,#0ffh,next1
sjmp err_2402
next1: acall delay
write0: mov a,#8 ;address
mov r0,#38h ;point
mov r1,#8 ;sum
acall wrs_2402
cjne r1,#0ffh,next2
sjmp err_2402
next2: acall delay
sjmp $
err_2402:sjmp $
delay: mov r6,#20 ;24M--5ms----24c02的写入时间间隔
delay_0:djnz r7,$
djnz r6,delay_0
ret
;---------------------------------------------
wI2c equ 0a0h ;器件地址及写操作
rI2c equ 0a1h ;器件地址及读操作
sta_2402: ;启始
setb sda_2402
setb scl_2402
sjmp $+2 ;24M至少间隔周期
sjmp $+2
clr sda_2402
sjmp $+2
sjmp $+2
clr scl_2402
sjmp $+2
sjmp $+2
ret
stp_2402: ;结束
clr sda_2402
setb scl_2402
sjmp $+2
sjmp $+2
setb sda_2402
sjmp $+2
sjmp $+2
ret
wr_2402: ;写单个字节
mov b,#8
wr_2402_0: rlc a
jc wr_2402_1
clr sda_2402
sjmp wr_2402_2
wr_2402_1: setb sda_2402
wr_2402_2: setb scl_2402
sjmp $+2
sjmp $+2
clr scl_2402
sjmp $+2
sjmp $+2
djnz b,wr_2402_0
nmack_2402: setb sda_2402
nmack_2402_0:setb scl_2402
sjmp $+2
sjmp $+2
mov c,sda_2402
clr scl_2402
sjmp $+2
sjmp $+2
ret
mack_2402: clr sda_2402
sjmp nmack_2402_0
rd_2402: ;读单个字节
mov b,#8
setb sda_2402
rd_2402_0: setb scl_2402
,24C02的简单操作(汇编)