|
24C512:
sda bit p3.6
scl bit p3.7
mov Sp,#50h
;*********************************************************
type equ 0
;TYPE =0 用EE24C01-EE24C16
;TYPE =1 用EE24C32-EE24C512
;*********************************************************
;测试程序
;*********************************************************
tEST:
mov a,#0eh
call INput
mov a,#type
mov r0,#21h
mov r1,#4
call Wree
call Delay
call Delay
mov a,#0h
call INput
mov a,#type
mov r0,#21h
mov r1,#8
call Rdee
nop
sjmp TEST
InPut:
mov r7,#8
mov r0,#21h
lok1:
mov @r0,a
inc r0
djnz r7,lok1
ret
Delay:
mov R7,#20
de11:
djnz b,$
djnz R7,De11
ret
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
;子程序
;入口程序条件:
;A=0 用EE24C01-EE24C16
;A=1 用EE24C32-EE24C512
;DPTR =EE24XX的地址
;R0=MCU内部RAM的地址
;R1=读出(写入)数据的长度BYTE
;C=1操作失败
;>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
Nop_:
nop
nop
nop
nop
ret
StarEe:
setb sda
call Nop_
setb scl
call Nop_
clr sda
call Nop_
clr scl
ret
StopEe:
clr sda
call Nop_
setb Scl
call Nop_
setb sda
call Nop_
clr scl
ret
Ack:
Call Nop_
setb scl
call Nop_
mov c,sda
call Nop_
clr scl
ret
McuAck:
clr sda
call Ack
setb Sda
ret
McuNAck:
setb sda
setb Scl
call NOp_
clr Scl
clr Sda
ret
WrByte:
mov b,#8
Wr11:
rlc a
mov sda,c
call Ack
djnz b,Wr11
setb Sda
call Ack
ret
RdByte:
mov b,#08
Rd11:
call Ack
rlc a
djnz b,Rd11
ret
MakeAdr:
mov a,dph
rl a
orl a,#0a0h
ret
;*********************************
;a=0 =>24c16;=>24c32...
;r1=Long;R0=Adr;Dptr=EeAdr
;*********************************
EeAll:
call StarEe
jz Ee24c16
;*************
;Ee24c32
mov a,#0a0h
call WrByte
jc EeErr
mov a,dph
call WrByte
jc EeErr
sjmp EeDo
Ee24c16:
mov a,#dph
call MakeAdr
call WrByte
EeDo:
mov a,Dpl
call WrByte
jc EeErr
ret
EeErr:
nop
ret
;)))))))))))))))))))))))))))))))))
WrEe: ;写子程序
call EeAll
jc eeerr
;***** Ok
we1:
mov a,@r0
call WrByte
jc EeErr
;********** Delay
inc r0
djnz r1,We1
call StopEe
clr c
ret
RdEe:;读子程序
call EeAll
jc EeErr
;********* Ok
call StarEe
mov a,#0a1H
call WrByte
jc Eeerr
;********** Ok
DEC R1
mov a,r1
jz Red11
Red1:
call RdByte
call McuAck
mov @r0,a
inc r0
djnz r1,Red1
Red11:
call RdByte
MOV @R0,A
call McuNAck
call StopEe
clr c
ret
|
|