7_Using_the_LCD

advertisement
Device Drivers – LCD Display
1
Mark Neil - Microprocessor Course
Task Plan
2
 You will create a device driver for a Liquid Crystal
Display (LCD).
 You will have some more practice with useful
assembler commands.
Mark Neil - Microprocessor Course
Conceptual Design
3
 We want to construct :
8-bit data bus
Watch out
+5V on PIN 1
RS,R/W,E
LCD INTERFACE
ATmega128
Board
PORTD Buttons
Mark Neil - Microprocessor Course
LCD DISPLAY
POWERTIP
Useful things to know
4
 The LCD board is viewed as an external SRAM From
the ATMEL STK300+ board.
 The External SRAM option must be enabled:

Set bits on MCUCR
 PORTA is used for address higher bits and data
 PORTC is used for the address lower bits.
Mark Neil - Microprocessor Course
MCU Control Register
5
;
;
;
;
;
;
******* External SRAM setup MCUCR *******
we want read and write activity on RE WR – Bit 7 Set
enable the wait state – Bit 6 Set
Idle Mode – bit 5 Clear
ldi r16, $C0
; Load MCUCR Bits
out MCUCR, r16 ; Write to MCUCR
Mark Neil - Microprocessor Course
The Hitachi LM032XMBL LCD
6
RS
SRAM A14 $4000
R/W
SRAM A15 $8000
E
DB0-DB7
To write commands use: $8000
To write data use:
$C000
To read the Busy flag use: $8000
Mark Neil - Microprocessor Course
Getting Started
7
 Download LCD1.asm from the Lab page.
 In the file you will find routines to initialize the LCD
display, routines that clear the display and routines
that print messages.
 Use them to create an LCD interface of your own and
familiarize yourself with them
Mark Neil - Microprocessor Course
Reminder: Some Useful techniques in Assembler
8
 Setting flags for initializing your program
 Tables in Program Memory
 16 bit counters
 The Skip commands for branching
Mark Neil - Microprocessor Course
Assembler III: Main Program
9
CLR r23
SBR r23, $1
Main:
; Do not execute the initialization every time;
; use bit in r23 to flag whether initialization
; has been done
SBRC r23, 0
rcall Idisp
SBRC r23, 0
CBR r23, $1
;Clear bit no more init
rcall Mess1Out
rcall BigDel
rcall CLRDIS
rcall Mess2Out
rcall BigDel
rcall CLRDIS
rjmp Main
Mark Neil - Microprocessor Course
Tables, Messages, ASCII, Bytes
10
Mess1:
.db 'C','o','s','t','a','s',' ','F','o','u','d','a','s'
Mess1Out:
LDI ZH,HIGH(2*Mess1)
LDI ZL,LOW(2*Mess1)
LDI r18,13
;there are 13 bytes in the mesage
Mess1More:
LPM
;copy data from program memory
MOV r17, r0
;move the byte to r17
sts $C000, r17 ;send the byte to the LCD
rcall busylcd ;wait
DEC r18
;check that we have sent all bytes
BREQ Mess1End ;if yes quit
ADIW ZL, $01
;point to the next location in PM
RJMP Mess1More ;get the next byte
Mess1End:
ret
Mark Neil - Microprocessor Course
Use 16 bit counters for delays
11
DEL49ms:
LDI XH, HIGH(65535)
LDI XL, LOW (65535)
COUNT3:
SBIW XL, 1
BRNE COUNT3
RET
Mark Neil - Microprocessor Course
The Skip assembly commands
12
; A routine the probes the display BUSY bit
;
busylcd:
rcall Del49ms
lds r16, $8000
sbrs r16, 7
ret
rjmp busylcd
;read the lcd BUSY bit
;skip next if busy bit7 is set
;return if clear
;else loop back
You can skip with sbrs,sbrc for testing registers and
with sbis,sbic for testing I/O Ports
Mark Neil - Microprocessor Course
Basic LCD Commands
13
Commands are
written to address
$8000
ldi r16,$XX
sts $8000,r16
Mark Neil - Microprocessor Course
Example: clear the display
14
; This clears the display so we can start all over again
;
CLRDIS:
ldi r16,$01 ; Clear Display send cursor
sts $8000,r16 ; to the most left position
rcall busylcd
ret
In the Hitachi red and white book you will
find all of the commands for the LCD
display.
Mark Neil - Microprocessor Course
Exercise: A User Interface
15
Start
First ?
Yes
Initialize LCD
No
The ATmega103 requests
input by sending a message
to the LCD
Read in Input from
PORTD or the Keyboard
Mark Neil - Microprocessor Course
Send Acknowledge
Message to the LCD
Decode the Input
and do something
Download