;x25165初始化应用程序
org 0000h
start:mov sp,#60h
acall wren
acall delay
mov 30h,#30h;状态字1.4秒
acall wrsr;调写状态子程序
mov p0,#0feh;p1口送"1"
lcall delay;延时
mov p0,#0fch;p1口送"2"
;停
weep:mov 30h,#00
mov 31h,#01h
mov 32h,#0fh
acall writ
acall delay
weep1:mov 30h,#00
mov 31h,#02h
mov 32h,#0f0h
acall writ
acall delay
reep:mov 30h,#00
mov 31h,#01h
acall read
mov p0,a
acall delay
reep1:mov 30h,#00
mov 31h,#02h
acall read
mov p0,a
acall delay
cc:sjmp cc
;
; 写使能子程序
wren:clr p1.0
nop
mov a,#06h
lcall sed
clr p1.3
nop
setb p1.0
ret
; 写状态子程序
wrsr:clr p1.0
nop
mov a,#01h
lcall sed
mov a,30h
lcall sed
clr p1.3
nop
setb p1.0
ret
; 读状态
rdsr:clr p1.0
nop
mov a,#05h
lcall sed
lcall red
clr p1.3
mov b,a
nop
setb p1.0
ret
; 写存储器子程序
writ:nop
lcall wren
clr p1.0
nop
mov a,#02h
lcall sed
clr p1.3
mov a,30h
lcall sed
clr p1.3
nop
mov a,31h
lcall sed
clr p1.3
nop
mov a,32h
lcall sed
clr p1.3
nop
setb p1.0
ret
; 读存储器子程序
read:clr p1.0
nop
mov a,#03h
lcall sed
clr p1.3
mov a,30h
lcall sed
clr p1.3
nop
mov a,31h
lcall sed
lcall red
setb p1.0
ret
; 写入8位子程序
sed:mov r6,#08h
sed1:clr p1.3
nop
rlc a
mov p1.2,c
nop
setb p1.3
nop
djnz r6,sed1
ret
; 读出8位子程序
red:mov r6,#07h
red1:clr p1.3
nop
mov c,p1.1
rlc a
setb p1.3
nop
djnz r6,red1
clr p1.3
nop
mov c,p1.1
rlc a
ret
delay:mov r7,#0ffh
d1:mov r6,#0ffh
d2:nop
nop
nop
djnz r6,d2
djnz r7,d1
ret
end
;x25165初始化子程序段
write_x25165:;x25165写程序
mov 22h,#08h
write_x25165a:
acall wrsr
acall wren
acall write_1byte
acall delay
acall delay
inc r1
inc dptr
djnz 22h,write_x25165a
ll:acall rsdr
jnb acc.7,lll
ajmp ll
lll:ret
read_x25165:;x25165读程序
mov 22h,#08h
read_x25165a:
acall read_1byte
mov @r1,a
inc r1
inc dptr
acall delay
acall delay
djnz 22h,read_x25165a
ret
wren:clr cs
nop
mov a,#06h
acall sed
nop
setb cs
nop
setb sck
ret
wrsr:clr cs
mov a,#01h
nop
acall sed
mov a,#30h
acall sed
nop
setb cs
setb sck
ret
rsdr:clr cs
mov a,#05h
nop
acall sed
nop
acall red
nop
setb cs
ret
write_1byte:clr cs
nop
mov a,#02h
acall sed
mov a,dph
acall sed
mov a,dpl
acall sed
mov a,@r1
acall sed
nop
setb cs
nop
setb sck
ret
read_1byte:clr cs
mov a,#03h
acall sed
mov a,dph
acall sed
mov a,dpl
acall sed
acall red
setb cs
nop
setb sck
ret
sed:mov r7,#08h
sed1:clr sck
rlc a
mov si,c
setb sck
nop
nop
djnz r7,sed1
ret
red:mov r7,#08h
red1:nop
clr sck
mov c,so
nop
rlc a
setb sck
djnz r7,red1
ret
tim0:push acc
push psw
clr tr0
mov th0,#3ch
mov tl0,#0b0h
djnz 35h,exiti
mov 35h,#10
jbc 21h.1,go
setb 21h.1
go:djnz 34h,exiti
mov 34h,#2
inc r5
cjne r5,#02h,exiti
mov r5,#00h
exiti:pop psw
pop acc
setb tr0
reti