📄 lcd4.asm
字号:
;************************************************
;* LCD driver routines for AVR's *
;* *
;* MicroLan Search Algorithm *
;* Requires DS1820sub.asm *
;* *
;* Copyright 2001-2003 Wayne Peacock *
;* Wayne Peacock 7th July 2001 *
;* Version 1.02 *
;* For 2x24bit LCD Board (4bit Mode) *
;************************************************
;* See Schematic for Hardware connections *
;* *
;* Disclaimer: *
;* The Author takes no responsibility for the *
;* use of this code. Use at your own risk! *
;* *
;* This code or part there of is licensed only *
;* for private use and NOT for commercial use. *
;* *
;* Please contact the author 'Wayne Peacock' *
;* <wpeacock@senet.com.au> before using the code*
;* or part there of in a commercial project. *
;************************************************
; Requires the following
;.def text = r0 ; Text MUST be 0
;.def data = r17
;.def temp = r16
; Zreg ;Pointer to Data
;************************************************
;* LCD Panel in 4 bit mode *
;* *
;* Pin Connections *
;* *
;* PB4 --> D4 *
;* PB5 --> D5 *
;* PB6 --> D6 *
;* PB7 --> D7 *
;* *
;* PB3 --> E *
;* PB2 --> R/W (1 = READ, 0 = WRITE) *
;* PB1 --> RS (1 = DATA, 0 = CONTROL) *
;************************************************
;************************************************
;* LCD CONSTANTS *
;************************************************
.equ E = 3
.equ RS = 1
.equ RW = 2
.equ BF = 7 ; Busy Flag D7
.equ LCDD = $17 ; (LCD Data Direction) DDRB
.equ LCDP = $18 ; (LCD Data Port) PORTB
.equ LCDI = $16 ; (LCD Data Input) PINB
;************************************************
;* Setup LCD Panel Port *
;* Input: None *
;* Returns: None *
;* Requires: data *
;************************************************
lcdinit:
; Clear LCD Pins
cbi LCDP,E ; LCD Enable Inactive
; Make Pins Output
in data, LCDD
ori data, 0b11111110 ; Make all LCD pins outputs
out LCDD, data
; 4 Bit Mode
in data, LCDP
andi data, 0b00001111 ; Clear Data Nibble
ori data, 0x20 ; One 4bit instruction (2 = 4bit)
out LCDP, data ; Load command onto LCD Data Port
cbi LCDP,RW ; Write Mode
cbi LCDP,RS ; RS low (command)
sbi LCDP,E ; Enable --> high (50us to next instruction)
nop ; 375ns delay (Must be greater than 220ns)
nop
cbi LCDP,E ; Enable Inactive
; Repeat Command to make sure panel got it!
nop
nop
cbi LCDP,RW ; Write Mode
cbi LCDP,RS ; RS low (command)
sbi LCDP,E ; Enable --> high (50us to next instruction)
nop ; 375ns delay (Must be greater than 220ns)
nop
cbi LCDP,E ; Enable Inactive
ret
;************************************************
;* Command(char data) *
;* Input: data *
;* Returns: None *
;* Requires: temp *
;* *
;* 0x38 8 bits / 2Lines *
;* 0x0F Display On / Cursor Flashing *
;* 0x0C Display on - No Cursor *
;* 0x01 Clear Display *
;* 0xC0 Bottom Line *
;* 0x80 Top Line *
;************************************************
command:
rcall waitlcd ; Make sure it's ready
cbi LCDP,RS ; RS low (command)
rcall lcdwr_0
ret
lcdwr_0:
push data ; Push data onto stack
;swap data
andi data, 0xF0
in temp, LCDP
andi temp, 0b00001111 ; Clear Data Nibble
or temp, data ; One 4bit instruction (2 = 4bit)
out LCDP, temp ; Load command onto LCD Data Port
cbi LCDP,RW ; Write Mode
sbi LCDP,E ; Enable --> high (50us to next instruction)
nop ; 375ns delay (Must be greater than 220ns)
nop
cbi LCDP,E ; Enable Inactive
nop
nop
nop
; second nibble to send
pop data
swap data
andi data, 0xF0
in temp, LCDP
andi temp, 0b00001111 ; Clear Data Nibble
or temp, data ; One 4bit instruction (2 = 4bit)
out LCDP, temp ; Load command onto LCD Data Port
nop
nop
sbi LCDP,E ; Enable --> high (50us to next instruction)
nop ; 375ns delay (Must be greater than 220ns)
nop
cbi LCDP,E ; Enable Inactive
ret
;************************************************
;* OneChar(char data) *
;* Input: data *
;* Returns: None *
;* Requires: temp *
;* *
;************************************************
onechar:
rcall waitlcd ; Make sure it's ready
sbi LCDP,RS ; RS high (data)
rcall lcdwr_0
ret
;************************************************
;* WriteData(*Zreg) 0x00 to End *
;* Input: Data at address of Z pointer *
;* Returns: None *
;* Requires: temp *
;* data *
;* text (Must be r0) *
;************************************************
writedata:
lpm ; Load Program Memory (Get from Flash!)
tst text ; Check for more characters
breq wd2 ; End of Text
rcall waitlcd ; Wait for LCD ready
sbi LCDP,RS ; RS high (data)
mov data, text
rcall lcdwr_0
adiw ZL,1 ; Inc Z Pointer
rjmp writedata ; Repeat until 00
wd2: ret ; Finished here
;************************************************
;* Wait for LCD panel *
;* Input: None *
;* Output: None *
;* Requires: temp *
;************************************************
waitlcd:
; Make data pins input
in temp, LCDD
andi temp, 0b00001111 ; Make all Data LCD pins inputs
out LCDD, temp
sbi LCDP,RW ; Read Mode
cbi LCDP,RS ; RS Low (command)
sbi LCDP,E ; Enable --> High
nop ; ns delay
nop
sbic LCDI,BF ; Check for Busy flag, Skip if ready
rjmp wlcd2 ; Not ready!
cbi LCDP,E ; Enable Inactive
; Second nibble
nop
nop
sbi LCDP,E ; Enable --> High
nop ; ns delay
nop
nop
cbi LCDP,E ; Enable Inactive
; Make data pins output
cbi LCDP,RW ; Write Mode
in temp, LCDD
ori temp, 0b11111110 ; Make all LCD pins outputs
out LCDD, temp
ret
wlcd2: cbi LCDP,E ; Enable Inactive
; Second nibble
nop
nop
sbi LCDP,E ; Enable --> High
nop ; ns delay
nop
nop
cbi LCDP,E ; Enable Inactive
rjmp waitlcd ; Repeat until ready
; End of File!
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -