MCS-51汇编 8051单片机汇编LCD12864绘图操作

本文介绍了一段针对单片机LCD显示模块的初始化代码及其内部使用的延时程序。通过具体指令序列实现LCD的功能配置、显示状态设置、显示清除等功能。此外,还包含了用于确保数据传输正确性的准备和读取命令。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

; 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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值