; created by perry.peng 2012/7/12
delay5us: acall delay2us
nop
nop
ret ; ACALL + RET = 4 cycles, total 8 cycles.
delayTas: acall delay2us
nop
ret
delayTd: acall delay2us
acall delay2us
ret
delayTpw: acall delay5us
acall delay5us
acall delay5us
acall delay5us
acall delay5us
acall delay2us
nop
ret
delay50us: push 0
mov r0, #9
repWx: acall delay5us
djnz r0, repWx
pop 0
acall delay2us
ret
delay1ms: push 0
mov r1, #10
repWy: acall delay50us
djnz r1, repWy
pop 0
acall delay2us
ret
reset: clr RST
mov r1, #100
repWz: acall delay50us
djnz r1, repWz
setb RST
ret
init: clr EP
setb PSB ; use paralell mode.
acall reset
lcall delay1ms
mov a, #0x30 ; 功能设定, b0011xRxx, R=1扩充指令集动作
lcall wcmd
lcall delay1ms
mov a, #0x08 ; 显示状态(b00001DCB), D=0整体显示OFF, C=1游标ON, B=1游标位置ON
lcall wcmd
lcall delay1ms
mov a, #0x01 ; 清除显示(b00000001), 将DDRAM填满20H, DDRAM的地址计数器(AC)到00H
lcall wcmd
lcall delay1ms
mov a, #0x02 ; 地址归位(b0000001x), D=0整体显示OFF, C=1游标ON, B=1游标位置ON
lcall wcmd
lcall delay1ms
mov a, #0x06 ; 进入点(b000001IS), 指定在资料的读取与写入时,设定游标移动方向及指定显示的移位
lcall wcmd
lcall delay1ms
mov a, #0x80 ; 设定DDRAM地址(b1xxxxxxx), xxxxxxx = 7bit address.
lcall wcmd
lcall delay1ms
mov a, #0x40 ; 设定CGRAM地址(b01xxxxxx), xxxxxx = 6bit address.
lcall wcmd
lcall delay1ms
mov a, #0x0c ; 显示状态(b00001DCB), D=1整体显示ON, C=1游标ON, B=1游标位置ON
lcall wcmd
lcall delay1ms
ret
ready: clr RS
setb RW
lcall delayTas
setb EP
lcall delayTd
mov a, P0
lcall delayTpw
clr EP
lcall delayTpw
jb BSY, ready
ret
rcmd: clr RS
setb RW
lcall delayTas
setb EP
lcall delayTd
mov a, P0
lcall delayTpw
clr EP
lcall delayTpw
ret
rdat: ;lcall ready
setb RS
setb RW
lcall delayTas
setb EP
lcall delayTd
mov a, P0
lcall delayTpw
clr EP
lcall delayTpw
ret
wcmd: ;lcall ready
clr RS
clr RW
mov P0, a
lcall delayTas
setb EP
lcall delayTpw
clr EP
lcall delayTpw
ret
wdat: ;lcall ready
setb RS
clr RW
mov P0, a
lcall delayTas
setb EP
lcall delayTpw
clr EP
lcall delayTpw
ret
setpz: mov r6, #0x80 ; a = x(0 ~ 127), dpl = y(0 ~ 32), dph = p(0 | ~0)
jnb A05, LN32R
orl 6, #0x08
LN32R: anl a, #0x1f
orl a, #0x80
lcall wcmd ; row addr.
mov a, dpl
anl a, #0x7f
mov b, #16
div ab
orl a, r6
writeX: lcall wcmd ; column addr.
clr a
lcall wdat
lcall wdat
lcall delay1ms
lcall delay1ms
lcall delay1ms
lcall delay1ms
lcall delay1ms
ret
clear: ;mov a, #0x36 ;
;lcall wcmd
mov a, r0
setb A07
lcall wcmd
mov a, r1
orl a, #0x88
lcall wcmd
ret
refresh: mov a, #0x36 ;
lcall wcmd
mov dpl, #0x00
mov dph, #0x00
mov r0, #0x80
drawR: mov r1, #0x80
drawC: mov a, r0
anl a, #0x9f
lcall wcmd ; 写入行地址(0 ~ 0x1f),
mov b, r1
mov a, r0 ; 判断是否是高半屏
jnb A05, drawH ; 超过32为高半屏部分。
orl b, #0x08 ; 高半屏的列地址
drawH: mov a, b ; 列地址。
lcall wcmd
push 0
mov a, dpl
;orl a, #0x80
mov r0, a
movx a, @r0
lcall wdat
inc dpl
mov a, dpl
;orl a, #0x80
mov r0, a
movx a, @r0
lcall wdat
inc dpl
pop 0
inc r1
cjne r1, #0x88, drawC
inc r0
cjne r0, #0xc0, drawR
mov a, #0x30 ;
lcall wcmd
ret
.area CSEG (CODE)
.area CONST (CODE)
str_ready:
.ascii "Ready!!!"
.db 0x0d, 0x0a, 0x00
str_invalid_cmd:
.ascii "ERROR: ERR_ILLEGAL_FUNCTION."
.db 0x0d, 0x0a, 0x00
.area XINIT (CODE)
.area CABS (ABS,CODE)