📄 lcd8字.asm
字号:
.include"8515def.inc"
.def temp=r16
.def temp1=r17
.def temp2=r18
.def cnt=r20
.def cnt1=r21
.org $0000
rjmp reset
.org $0300
reset: ldi temp,low(ramend) ;设置堆栈指针。
out spl,temp
ldi temp,high(ramend)
out sph,temp
ldi temp,$ff ;设置D口输出,B口作输入。
out ddrd,temp
out portd,temp
clr temp
out ddrb,temp
out portb,temp
rcall syset ;调用系统设置。
lp8: clr cnt1 ;循环程序。
lp81: clr cnt
ldi temp1,$80 ;设置第一行显示寄存器起址。(第二行为$a8)
rcall contd
lp82: cp cnt1,cnt
brne lp83
ldi temp1,$38 ;字形8的代码为$38。
lp84: rcall writd
inc cnt
cpi cnt,$10
brne lp82
ldi temp,$55 ;设置延时常数。
rcall delay
inc cnt1
cpi cnt1,$10
brne lp81
rjmp lp8
lp83: ldi temp1,$20
rjmp lp84
CONTD: LDI TEMP,0B00110000 ;写控制字入LCD中
OUT PORTD,TEMP
RCALL DELT3
CBI PORTD,$05 ;使E=0 ,LCD片选有效
RCALL DELT3
SBI PORTD,$05
BUSYY: WDR
SBIC PINB,$07 ;读取DB7=PINB7是否为0,为0则非忙跳过一行
RJMP BUSYY ;DB7=1为忙,跳回BUSYY再等待DB7=0以写入
LDI TEMP,0b00100000 ;写入数据写入控制字
OUT PORTD,TEMP
RCALL DELT3 ;延时以免AVR速度太快而使LCD无法工作
LDI TEMP,$ff ;设定B口为输出
OUT DDRB,TEMP
OUT PORTB,TEMP1 ;要写入LCD的数据TEMP1输出到PORTB
WDR
CBI PORTD,$05
RCALL DELT3
LDI TEMP,0B00111000
OUT PORTD,TEMP
CLR TEMP
OUT DDRB,TEMP
OUT PORTB,TEMP
RET
WRITD: LDI TEMP,0B00110000 ;写数据入LCD中
OUT PORTD,TEMP
RCALL DELT3 ;延时以免AVR速度太快而使LCD无法工作
CBI PORTD,$05 ;使E=0, LCD片选有效
RCALL DELT3
SBI PORTD,$05
BUZY1: WDR
SBIC PINB,$07 ;读取DB7=PINB7是否为0,为0则非忙跳过一行
RJMP BUZY1 ;DB7=1为忙,跳回BUSY1再等待DB7=0以写入
LDI TEMP,0B00101000 ;写控制字入LCD中
OUT PORTD,TEMP
OUT PORTB,TEMP1 ;要写入LCD的数据TEMP1输出到PORTB
LDI TEMP,$ff ;设定B口为输入
OUT DDRB,TEMP
CBI PORTD,$05 ;使E=0, LCD片选有效
RCALL DELT3 ;延时以免AVR速度太快而使LCD无法工作
LDI TEMP,0B00111000 ;写控制字入LCD中
OUT PORTD,TEMP
RCALL DELT3
CLR TEMP ;PORTB为输入
OUT DDRB,TEMP
OUT PORTB,TEMP ;PORTB为三态输入
RET
syset: ldi temp1,$01 ;清屏设定
rcall contd
ldi temp,$50 ;设置时间常数
rcall delay
ldi temp1,$38 ;2行 5*7显示设定
rcall contd
ldi temp1,$06 ;自动增量,显示不移位
rcall contd
ldi temp1,$0c ;字形开关ON,光标开关OFF
rcall contd
ret
DELT3: ldi temp2,$24
DT111: wdr
dec temp2
brne dt111
ret
delay: push temp
m1: push temp
m2: push temp
m3: dec temp
brne m3
pop temp
dec temp
brne m2
pop temp
dec temp
brne m1
pop temp
dec temp
brne delay
ret
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -