?? 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 + -