0% found this document useful (0 votes)
102 views

4-Bit LCD Interface Notes

4-bit LCD Interface Notes - Dr. Eric M. Schwart, John A. Martiney - Dept. of Electrical and Computer Engineering - University of Florida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
102 views

4-Bit LCD Interface Notes

4-bit LCD Interface Notes - Dr. Eric M. Schwart, John A. Martiney - Dept. of Electrical and Computer Engineering - University of Florida
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

University of Florida EEL4744 Dr. Eric M.

Schwartz
Dept. of Electrical and Computer Engineering John A. Martiney, TA
Page 1/7 Revision 0 15-Mar-12
4-bit LCD Interface Notes
LCD Panel Pinouts and Connections to CPU (for data bus connectivity)
Verify that the position of pin 1 on your
LCD board. There should be a 1 next to LCD Board Pinout
pin 1 and a 10 next to pin 10. My LCD
board is arranged as shown to the right.
The register select signal (RS) can be
viewed as an address input and can be LCD
connected directly to the CPUs address
pin A0. This bit selects between the two
addressable registers called Command
(with A0=0) and Data (with A0=1).
The enable pin (E) is the chip select/enable 10 1
for the LCD. A memory mapped decoded
E signal must be created for enabling/disabling this device. The LCD can be considered a write-only device. [If
you want to read from the device, DB7 is the busy flag (BF) that when clear means the LCD is ready for the
next command. If this is done the delays in the below flow chart are unnecessary.]
You can verify that your LCD works properly before connecting your LCD data pins. Give power to the device
and twist the potentiometer one way or the other until you see black lines appear.
Data or commands are read at the falling edge of E.

P / LCD Wiring diagram CPU


R/W Decode
P A0 Circuitry

D3-0

Potentiometer DB7-4 RS R/W


VDD S
VO LCD E
VSS

From the Densitron LM2022 LCD specifications


posted on our website.

Parameter (in ns) Symbol Min Max


Enable Cycle Time TCYC 500
Enable Pulse Width PWEH 230
Enable Rise/Fall Time tEr / tEf 20
Address Setup Time tAS 40
Address Hold Time tAH 10
Write Data Setup Time tDSW 80
Write Data Hold Time tDHW 10
University of Florida EEL4744 Dr. Eric M. Schwartz
Dept. of Electrical and Computer Engineering John A. Martiney, TA
Page 2/7 Revision 0 15-Mar-12
4-bit LCD Interface Notes
Important Notes regarding 4-bit mode:
The difference between 4-bit and 8-bit LCD operation is that data is sent out as nibbles instead
of a single byte. DB7:DB4 are used to transfer nibbles to/from the LCD module (DB7 is the
MSB). Commands and data are still 8 bits long, but are transferred as two 4-bit nibbles on the
LCD data bus lines LCD Pin assignments
DB7:DB4. The most Adapted from the Densitron LM2022 LCD SpecSheet
significant nibble Pin # Symbol I/O Function
should be transferred 1 VSS - Ground (0V)
first, followed by the 2 VDD - Logic Supply Voltage (+5V)
3 VO - LC Drive voltage for contrast adjustment
least significant
4 RS I Register Select 0: Command Register
nibble. There must be 1: Data Register
a delay (approx. 1.5 5 R/W I Read/Write 0: Data Write (Module MPU)
ms) between each 1: Data Read (Module MPU)
nibble transfer. The 6 E I Enable Signal Active High
optimal contrast for the 7 DB4 I/O Bi-directional data bus line 4 (LSB)
8 DB5 I/O Bi-directional data bus line 5
LCD (Vo) is 3.3 - 3.7V.
9 DB6 I/O Bi-directional data bus line 6
10 DB7 I/O Bi-directional data bus line 7 (MSB)

Initialization for 4-bit operation


The module powers up in 8-bit mode. The initial start-up instructions are sent in 8-bit mode, with
the lower four bits (which are not connected) of each instruction as don't cares. The first block
of the flow chart is described below. See the LCD notes on the website for more similar info.
<POWER ON>
<Wait at least 15ms>
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0 0 0 0 1 1 n/c n/c n/c n/c
<Wait at least 4.1ms>
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0 0 0 0 1 1 n/c n/c n/c n/c
<Wait at least 100us>
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0 0 0 0 1 1 n/c n/c n/c n/c
<Wait 4.1ms>

(4-bit operation)
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0 0 0 0 1 0 n/c n/c n/c n/c
University of Florida EEL4744 Dr. Eric M. Schwartz
Dept. of Electrical and Computer Engineering John A. Martiney, TA
Page 3/7 Revision 0 15-Mar-12
4-bit LCD Interface Notes
Normal Further Initialization
<Wait 40us or till BF=0>

(Two lines) [DB=$28]


RS R/W DB7 DB6 DB5 DB4
0 0 0 0 1 0
0 0 1 0 0 0
<Wait 40us or till BF=0>

(Display on; cursor on; blink on) [DB=$0F]


RS R/W DB7 DB6 DB5 DB4
0 0 0 0 0 0
0 0 1 1 1 1
<Wait 40us or till BF=0>

(Clear screen; cursor home) [DB=$01]


RS R/W DB7 DB6 DB5 DB4
0 0 0 0 0 0
0 0 0 0 0 1
<Wait 1.64ms or till BF=0>

<INITIALIZATION COMPLETE>

Other useful Commands


*(Increment cursor to the right when writing; dont shift screen) [DB=$06]
RS R/W DB7 DB6 DB5 DB4
0 0 0 0 0 0
0 0 0 1 1 0
<Wait 40us or till BF=0>

(Display off; cursor off; blink off) [DB=$08]


RS R/W DB7 DB6 DB5 DB4
0 0 0 0 0 0
0 0 1 0 0 0
<Wait 40us or till BF=0>
University of Florida EEL4744 Dr. Eric M. Schwartz
Dept. of Electrical and Computer Engineering John A. Martiney, TA
Page 4/7 Revision 0 15-Mar-12
4-bit LCD Interface Notes
LCD Initialization

Initializations for LCD


Communications
Display, Cursor, Blink
4-bit Mode Enable
Write out $0F with a
Write $33, $32 with delay between each
a delay between nibble
each nibble

Clear Home
Enable 2-line mode
Write out $01 with a
Write out $28 with a delay between each
delay between each nibble
nibble

Ready to Write Data


to LCD Data

NOTE: LCD Command is BaseAddr + $00


LCD Data is BaseAddr + $01
University of Florida EEL4744 Dr. Eric M. Schwartz
Dept. of Electrical and Computer Engineering John A. Martiney, TA
Page 5/7 Revision 0 15-Mar-12
4-bit LCD Interface Notes
MORE LCD COMMANDS

Command Code Delay


Clear Display, Cursor to Home $01 1.65ms
Cursor to Home $02 1.65ms
Entry Mode:
Cursor Decrement, Shift off $04 40s
Cursor Decrement, Shift on $05 40s
Cursor Increment, Shift off $06 40s
Cursor Increment, Shift on $07 40s
Display Control:
Display, Cursor, and Cursor Blink off $08 40s
Display on, Cursor and Cursor Blink off $0C 40s
Display and Cursor on, Cursor Blink off $0E 40s
Display, Cursor, and Cursor Blink on $0F 40s
Cursor / Display Shift: (nondestructive move)
Cursor shift left $10 40s
Cursor shift right $14 40s
Display shift left $18 40s
Display shift right $1C 40s
Display Function (2 rows for 4-bit data; big) $2C 40s
Display Function (2 rows for 4-bit data; small)) $28 40s
Display Function (1 row for 4-bit data; big) $24 40s
Display Function (1 row for 4-bit data; small) $20 40s
Display Function (2 rows for 8-bit data; big) $3C 40s
Display Function (2 rows for 8-bit data; small) $38 40s
Display Function (1 row for 8-bit data; big) $34 40s
Display Function (1 row for 8-bit data; small) $30 40s
Move cursor to beginning of second row $C0 40s
Character Generator RAM Address set $40-$7F 40s
Display RAM Address set $80-$FF 40s
University of Florida EEL4744 Dr. Eric M. Schwartz
Dept. of Electrical and Computer Engineering John A. Martiney, TA
Page 6/7 Revision 0 15-Mar-12
4-bit LCD Interface Notes
LCD Character Codes
University of Florida EEL4744 Dr. Eric M. Schwartz
Dept. of Electrical and Computer Engineering John A. Martiney, TA
Page 7/7 Revision 0 15-Mar-12
4-bit LCD Interface Notes
SUMMARY OF LCD COMMANDS
Instruction Code Description
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
Clears display and returns cursor to the
Clear display 0 0 0 0 0 0 0 0 0 1 home position (address 0).
Returns cursor to home position (address
0). Also returns display being shifted to
Cursor home 0 0 0 0 0 0 0 0 1 * the original position. DDRAM contents
remains unchanged.
Sets cursor move direction (I/D),
specifies to shift the display (S). These
Entry mode set 0 0 0 0 0 0 0 1 I/D S operations are performed during data
read/write.
Sets On/Off of all display (D), cursor
Display On/Off
0 0 0 0 0 0 1 D C B On/Off (C) and blink of cursor position
control character (B).
Sets cursor-move or display-shift (S/C),
Cursor/display shift 0 0 0 0 0 1 S/C R/L * * shift direction (R/L). DDRAM contents
remains unchanged.
Sets interface data length (DL), number
Function set 0 0 0 0 1 DL N F * * of display line (N) and character font(F).
Sets the CGRAM address. CGRAM data
Set CGRAM address 0 0 0 1 CGRAM address is sent or received after this setting.
Set DDRAM Sets the DDRAM address. DDRAM data
0 0 1 DDRAM address is sent or received after this setting.
address
Reads Busy-flag (BF) indicating internal
Read busy-flag and
0 1 BF DDRAM address operation is being performed and reads
address counter address counter contents.
Write to CGRAM or
1 0 write data Writes data to CGRAM or DDRAM.
DDRAM
Read from CGRAM
1 1 read data Reads data from CGRAM or DDRAM.
or DDRAM
Schwartz, Eric M. EEL 4744: Microprocessor Applications. LCD Commands. 17 Mar. 2002.
<http://mil.ufl.edu/4744/docs/lcdmanual/commands.html>.

Bit names Notes:


Bit Settings DDRAM = Display Data RAM.
CGRAM = Character Generator
I/D 0 = Decrement cursor position 1 = Increment cursor position
RAM.
S 0 = No display shift 1 = Display shift DDRAM address corresponds
D 0 = Display off 1 = Display on to cursor position.
C 0 = Cursor off 1 = Cursor on Address Counter is used for
both DDRAM and CGRAM.
B 0 = Cursor blink off 1 = Cursor blink on
*= Don't care.
S/C 0 = Move cursor 1 = Shift display DL: 0 = 4-bit interface; 1 = 8-bit
R/L 0 = Shift left 1 = Shift right interface
DL 0 = 4-bit interface 1 = 8-bit interface N: 0 = 1 line; 1 = 2 lines
F: 0 = 5x7 dots; 1 = 5x10 dots
N 0 = 1/8 or 1/11 Duty (1 line) 1 = 1/16 Duty (2 lines)
For more info, see:
F 0 = 5x7 dots 1 = 5x10 dots http://mil.ufl.edu/4744/docs/lcd
BF 0 = Can accept instruction 1 = Internal operation in progress manual/commands.html

You might also like