单片机LCD1602显示程序(汇编),小弟有很多地方不懂,希望高人能加上注释,有助于本人学习

单片机LCD1602显示程序(汇编),小弟有很多地方不懂,希望高人能加上注释,有助于本人学习,第1张

LCD Display Driver Demo.

Timing code assumes 1.2MHz Clock

LCD Registers addresses

LCD_CMD_WR equ 0 ;宏定义

LCD_DATA_WR equ 1

LCD_BUSY_RD equ 2

LCD_DATA_RD equ 3

LCD Commands

LCD_CLS equ 1

LCD_HOME equ 2

LCD_SETMODE equ 4

LCD_SETVISIBLE equ 8

LCD_SHIFT equ 16

LCD_SETFUNCTION equ 32

LCD_SETCGADDR equ 64

LCD_SETDDADDR equ 128

Reset vector

org 0000h;程序开始入口地址0x00

jmp start;跳转到start处

Start of the program

org 0100h

string1a:db ' !! A M A Z I N G !! ';表格,要显示的内容。

db 0

string1b:db '!! A M A Z I N G !! '

db 0

string2:db ' A virtual LM032L... '

db 0

string3:db ' driven by a virtual '

db 0

string4:db ' 8051 processor!'

db 0

start: mov A,#038h 为什么是38h:查1602数据手册,38h的命令

call wrcmd

loop: mov A,#LCD_SETVISIBLE+6 Make the display &blink visible:

call wrcmd

mov R7,#2

loop2:

mov DPTR,#string1a

call wrstr

mov DPTR,#200

call wtms

mov A,#LCD_CLS Clear screen

call wrcmd

mov DPTR,#string1b

call wrstr

mov DPTR,#200

call wtms

mov A,#LCD_CLS Clear screen

call wrcmd

djnz R7,loop2

mov DPTR,#string1a

call wrstr

mov DPTR,#400

call wtms

mov A,#LCD_SETDDADDR+64

call wrcmd

mov DPTR,#string2

call wrslow

mov DPTR,#200

call wtms

mov A,#LCD_CLS Clear screen

call wrcmd

mov DPTR,#string3

call wrslow

mov A,#LCD_SETDDADDR+64

call wrcmd

mov DPTR,#string4

call wrslow

mov A,#LCD_SETVISIBLE+7 Show the blink cursor as well.

call wrcmd

mov DPTR,#2000

call wtms

mov A,#LCD_CLS Clear screen

call wrcmd

jmp loop

Sub routine to write null terminated string at DPTR in program ram.

wrstr: mov R0,#LCD_DATA_WR

wrstr1: clr A

movc A,@A+DPTR

jz wrstr2

movx @R0,A

call wtbusy

inc DPTR

push DPL

push DPH

pop DPH

pop DPL

jmp wrstr1

wrstr2: ret

Sub routine to write null terminated string at DPTR in program ram. Slowly

wrslow: mov R0,#LCD_DATA_WR

wrslw1: clr A

movc A,@A+DPTR

jz wrslw2

movx @R0,A

call wtbusy

inc DPTR

push DPL

push DPH

mov DPTR,#100

call wtms

pop DPH

pop DPL

jmp wrslw1

wrslw2: ret

Sub routine to write command:

wrcmd: mov R0,#LCD_CMD_WR

movx @R0,A

jmp wtbusy

Sub routine to write character:

wrchar: mov R0,#LCD_DATA_WR

movx @R0,A

Subroutine to wait for busy clear

wtbusy: mov R1,#LCD_BUSY_RD

movx A,@r1

jb ACC.7,wtbusy

ret

Wait for number of seconds in A

wtsec: push ACC

call wtms

pop ACC

dec A

jnz wtsec

ret

Wait for number of milliseconds in DPTR

wtms: xrl DPL,#0FFh Can't do DEC DPTR, so do the loop by forming 2's complement

xrl DPH,#0FFh and incrementing instead.

inc DPTR

wtms1: mov TL0,#09Ch 100 ticks before overflow = 1ms at 1.2MHz Clock

mov TH0,#0FFh

mov TMOD,#1 Timer 0 mode 1

setb TCON.4 Timer 0 runs

wtms2: jnb TCON.5,wtms2

clr TCON.4 Timer 0 stops

clr TCON.5

inc DPTR

mov A,DPL

orl A,DPH

jnz wtms1

ret

END

也没去理解AC,只知道第一行第1点的地址是80H,第二行第1 点是C0H。

下面就是你要的程序,仅供参考

RS BIT P1.2 这3位是液晶屏的控制信号,连接方式由具体硬件而定

RW BIT P1.1

E BIT P1.0

ORG 00H

AJMP MAIN

ORG 30H

MAIN:

mov R0,#24

ACALL INITIAL

ACALL DISPLAY调用液晶显示子程序

AJMP MAIN

-------液晶显示---------------------------------------

DISPLAY:   

MOV A,#80H  第一行第1 个点

ACALL WR_CMD

MOV DPTR, #LINE1

ACALL PR_STR

ACALL WR_DATA

DISP1:

MOV A,#1CH         字符左移命令(注:实物中左移命令字为18H)

ACALL WR_CMD

ACALL D05S

DJNZ R0,DISP1

RET

---液晶屏初始化-------------------------------------------------

INITIAL:     

MOV A, #01H

ACALL WR_CMD

MOV A, #38H

ACALL WR_CMD

MOV A, #0CH

ACALL WR_CMD

MOV A, #06H

ACALL WR_CMD

RET

----写液晶指令的子程序------------------------------------------

WR_CMD:

MOV P3, A

CLR RS 写入控制命令

CLR RW

CLR E

ACALL DELAY

SETB E

RET

----写液晶数据---------------------------------------------

WR_DATA:

MOV P3, A

SETB RS 写入数据

CLR RW

CLR E

ACALL DELAY 判断液晶模块是否忙?

SETB E

RET

-----写行字符---------------------------------------------------------------

PR_STR:

CLR   A

MOVC A, @A+DPTR

JZ    END_PR

ACALL WR_DATA

INC   DPTR

AJMP PR_STR

END_PR:   

RET

----查看液晶忙碌信号---------------------------------------------------------

DELAY:

MOV P3,#0FFH 判断液晶显示器是否忙的子程序

CLR RS

SETB RW

CLR E

NOP

SETB E

JB P3.7,DELAY 如果P3.7为高电平表示忙就循环等待

RET

----0.5S延时(按12MHZ算)-----------------------------------------------------------------

D05S: 

MOV R6,#25

MOV R5,#100

MOV R4,#100

DJNZ R4,$

DJNZ R5,$-4

DJNZ R6,$-8

RET

--------------------------------------------------------------------------------------

LINE1:

DB ' ZHU NI YI SHENG PING AN',00H

END


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/7839698.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-10
下一篇 2023-04-10

发表评论

登录后才能评论

评论列表(0条)

保存