1602显示屏显示第一行和第二行数字怎么输入程序

1602显示屏显示第一行和第二行数字怎么输入程序,第1张

1、首先我们打开KeilμVision编译器,新建一个工程,然后保存在硬盘上的位置。

2、其次导入51单片机的头文件以及LCD1602的头文件。创建一个延时函数,可以传入想要具体延时的时长,其内部实现是由一个二重循环,两个循环的次数相乘积。

3、最后最后在主函数中首先执行LCD1602的初始化函数,首先创建一个无限循环,然后添加两个字符串,这里以两行显示百度经验的网址为例,再进行延时以及使用清屏函数进行刷新。

这个是1602内部结构决定的,你只需要在初始化的时候先设置三次显示,然后再设置你的其他要求。

芯片厂家推荐的用法:

INT:

MOV

A,#30H

MOV

DATR,#CW_ADD

MOV

R2,#03H

INT1:

MOVX

@DPTR,A

CALL

DELAY

DJNZ

R2,INT1

这上面就是1602对于51单片机推荐的初始化之前加的三次模式设置

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


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

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

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

发表评论

登录后才能评论

评论列表(0条)

保存