Post on 14-Apr-2018
7/27/2019 A Note on Character LCD Displays
http://slidepdf.com/reader/full/a-note-on-character-lcd-displays 1/11
1
A Note on Character LCD Displays
There are many display devices used by the hobbyists. LCD displays are one of the most sophisticateddisplay devices used by them. Once you learn how to interface it, it will be the easiest and very reliableoutput device used by you! More, for micro controller based project, not every time any debugger can beused. So LCD displays can be used to test the outputs. Obviously, for last possibility, you need to knowhow to use this stuff pretty well.
Note 1: We have sub divided this article for easy navigation as shown below:-
1. Pin Configuration 2. Block Diagram 3. Control and Display Commands 4. LCD Interfacing 5. LCDInitialization
Note 2: If you are interested in reading about working of LCD – we have an excellent article for you –Working of Liquid Crystal Displays (LCD)
Hitachi has set up a mile stone by its LCD controller IC. All the LCD displays use the sameor any one of the IC s based upon the architecture introduced by Hitachi.
Ok, one minute, all I‟m talking about is the character LCD display and not Graphical LCD Display.
Most of the LCD Displays available in the market are 16X2 (That means, the LCD displays are capableof displaying 2 lines each having 16 Characters a), 20X4 LCD Displays (4 lines, 20 characters). It has14 pins. It uses 8lines for parallel data plus 3 control signals, 2 connections to power, one more forcontrast adjustment and two connections for LED back light. Let us have a look to typical pinconfigurations:
Pin Configuration table for a 16X2 LCD character display:-
Pin Number Symbol Function 1 Vss Ground Terminal2 Vcc Positive Supply3 Vdd Contrast adjustment4 RS Register Select; 0→Instruction Register, 1→Data Register 5 R/W Read/write Signal; 1→Read, 0→ Write 6 E Enable; Falling edge7 DB0
Bi-directional data bus, data transfer is performed once, thru DB0 to
DB7, in the case of interface data length is 8-bits; and twice, throughDB4 to DB7 in the case of interface data length is 4-bits. Upper four bits first then lower four bits.
8 DB19 DB2
10 DB311 DB412 DB513 DB614 DB715 LED-(K) Back light LED cathode terminal16 LED+(A) Back Light LED anode terminal
7/27/2019 A Note on Character LCD Displays
http://slidepdf.com/reader/full/a-note-on-character-lcd-displays 2/11
2
Data/Signals/Execution of LCD
Now that was all about the signals and the hardware. Let us come to data, signals and execution.
LCD accepts two types of signals, one is data, and another is control. These signals are recognized bythe LCD module from status of the RS pin. Now data can be read also from the LCD display, by pullingthe R/W pin high. As soon as the E pin is pulsed, LCD display reads data at the falling edge of the pulseand executes it, same for the case of transmission.
LCD display takes a time of 39-43µS to place a character or execute a command. Except forclearing display and to seek cursor to home position it takes 1.53ms to 1.64ms. Any attempt to send anydata before this interval may lead to failure to read data or execution of the current data in some devices.Some devices compensate the speed by storing the incoming data to some temporary registers.
LCD displays have two RAMs, naming DDRAM and CGRAM. DDRAM registers in which position which character in the ASCII chart would be displayed. Each byte of DDRAM represents eachunique position on the LCD display. The LCD controller reads the information from the DDRAM anddisplays it on the LCD screen. CGRAM allows user to define their custom characters. For that purpose,address space for first 16 ASCII characters are reserved for users. After CGRAM has been setup to
display characters, user can easily display their custom characters on the LCD screen.
Images of LCD Display:-
LCD - Front View
7/27/2019 A Note on Character LCD Displays
http://slidepdf.com/reader/full/a-note-on-character-lcd-displays 3/11
3
LCD - Back View
Block Diagram of LCD Display:-
LCD - Block Diagram
7/27/2019 A Note on Character LCD Displays
http://slidepdf.com/reader/full/a-note-on-character-lcd-displays 4/11
4
Control and display commands
Instruction Instruction Code Instruction Code
Description Executi
time RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0Read DataFrom RAM
1 1 D7 D6 D5 D4 D3 D2 D1 D0Read data frominternal RAM
1.531.64m
Write data toRAM
1 0 D7 D6 D5 D4 D3 D2 D1 D0Write data intointernal RAM(DDRAM/CGRAM)
1.531.64m
Busy flag &Address
0 1 BF AC6 AC5 AC4 AC3 AC2 AC1 AC0
Busy flag (BF: 1→LCD Busy) andcontents of addresscounter in bits AC6-AC0.
39 µ
Set DDRAMAddress
0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC0Set DDRAM addressin address counter.
39 µ
Set CGRAMAddress
0 0 0 1 AC5 AC4 AC3 AC2 AC1 AC0Set CGRAM Addressin address counter.
39 µ
Function Set 0 0 0 0 1 DL N F X X
Set interface data
length (DL:4bit/8bit), Numbersof display line (N: 1-line/2-line) displayfont type (F:0→ 5×8dots, F:1→ 5×11dots)
39 µ
Cursor or Display Shift
0 0 0 0 0 1 S/C R/L X X
Set cursor movingand display shiftcontrol bit, and thedirection without
changing DDRAMdata
39 µ
Display &Cursor On/Off
0 0 0 0 0 0 1 D C B
SetDisplay(D),Cursor(C)and cursor blink(b)on/off control
39 µ
Entry ModeSet
0 0 0 0 0 0 0 1 I/D SH
Assign cursor moving direction andenable shift entiredisplay.
0µs
Return Home 0 0 0 0 0 0 0 0 1 X
Set DDRAM Address
to “00H” from ACand return cursor toits original position if shifted.
43µs
Clear Display 0 0 0 0 0 0 0 0 0 1
Write “20H” toDDRAM and setDDRAM Address to“00H” from AC
43µs
7/27/2019 A Note on Character LCD Displays
http://slidepdf.com/reader/full/a-note-on-character-lcd-displays 5/11
5
AC -Address Counter
Outline
Now the instruction can be divided mainly in four kinds
1) Function set instructions
2) Address set instructions
3) Data transfer instructions with internal RAM
4) Others
Details of the Instructions
1) Read Data from RAM
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB
1 1 D7 D6 D5 D4 D3 D2 D1 D0
Read 8bit binary data from DDRAM/CGRAM
The selection of RAM is set by the previous address set instruction. If the address set instruction ofRAM is not performed before this instruction, the data that is read first is invalid, because the directionof AC is not determined. If the RAM data is read several times without RAM address set instruction before read operation, the correct RAM data from the second, but the first data would be incorrect, asthere is no time to transfer RAM data. In case of DDRAM read operation, cursor shift instruction playsthe same role as DDRAM address set instruction; it also transfers RAM data to the output data registers.
After read operation, the data address counter is automatically increased or decreased by 1 according tothe entry mode. After CGRAM read operation, display shift may not be executed properly.
*In case of RAM write operation, AC is increased or decreased by 1 like that of the read operation. Inthis time AC indicates the next address position, but the previous data can only by the read instruction.
2) Write data to ram
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB1 0 D7 D6 D5 D4 D3 D2 D1 D0
Write binary 8bit data to DDRAM/CGRAM. The selection of CGRAM or DRAM is set by the previousaddress set instruction; DDRAM address set, CGRAM address set. RAM set instruction can alsodetermine the AC direction to RAM.
After write operation, the address is automatically increased or decreased by 1 according to the entrymode.
7/27/2019 A Note on Character LCD Displays
http://slidepdf.com/reader/full/a-note-on-character-lcd-displays 6/11
6
3) Read Busy Flag and Address
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 1 BF AC6 AC5 AC4 AC3 AC2 AC1 AC
By making this read out operation, it can be determined if the LCD is performing some internaloperation or not. If Busy Flag (BF) is high, some internal operation is going inside the LCD at that particular moment. To perform further operation the data source (e.g. micro controller) must wait for theBF to go low. Here, the address counter value can also be read.
4) Set DDRAM Address
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 0 1 AC6 AC5 AC4 AC3 AC2 AC1 AC
Set DDRAM address to AC, this instruction makes DDRAM data available from MPU. In 1-line displaymode, DDRAM address rangers from “00H” to “4FH”. In 2-line display mode, DDRAM address in thefirst line ranges from “00H” to “27H”, and DDRAM address in the 2nd line is from “40H” to “67H”.
5) Set CGRAM address
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 0 0 1 AC5 AC4 AC3 AC2 AC1 AC
Set CGRAM address to AC. This instruction makes CGRAM data available from MPU.
6) Function Set
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB
0 0 0 0 1 DL N F X X
DL: Interface data length control bit
DL=‟1‟ means 8bit mode of data transfer.
DL=‟0‟ means 4bit mode of data transfer
When 4 bit mode is activated, the data needs to be transferred in two parts, first higher 4bits, and thenlower 4 bits.
N: display line number control bit
N=‟1‟ will allows to characters to display in 2-lines
N=‟0‟ will allows to characters to display in the first line only
7/27/2019 A Note on Character LCD Displays
http://slidepdf.com/reader/full/a-note-on-character-lcd-displays 7/11
7
F: display font control bit
F=‟0‟ will use 5×8 dots format display mode
F=‟1‟ will use 5×11 dots format display mode
7) Cursor or display Shift
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 0 0 0 0 1 S/C R/L X X
Without writing or reading the display data, shifting right/left cursor position or display.
This instruction is made to correct or search or display data. During 2-line display mode, cursor movesto the 2nd line after the 40th digit of the 1st line.
When displayed data is shifted repeatedly, each line shifts individually.
When display shift is performed, the contents of the address counter are not changed.
8) Display On/Off Control
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 0 0 0 0 0 1 D C B
This instruction controls Display, Cursor and cursor blink.
D: Display On/Off control bit
D=‟1‟ means entire display is turned on
D=‟0‟ means entire display is turned off. But Display data remains in DDRAM.
C: cursor On/Off control bit
C=‟1‟ turns on the cursor
C=‟0‟ turns off the cursor. But I/D register retains the data
B: Cursor blink On/Off control bit
B=‟1‟ makes cursor blink periodically.
B=‟0‟ stops the cursor to blink and cursor looks steady if the Cursor is turned on.
7/27/2019 A Note on Character LCD Displays
http://slidepdf.com/reader/full/a-note-on-character-lcd-displays 8/11
8
9) Entry Mode Set
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 0 0 0 0 0 0 1 I/D SH
This instruction sets the moving direction of cursor and display.
When I/D= ‟1‟ cursor moves to the right and DDRAM address is increased by 1.
When I/D= ‟0‟ cursor moves to the left and DDRAM address is decreased by 1.
CGRAM operates in the same way in this setting.
10) Return Home
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 0 0 0 0 0 0 0 1 X
This instruction sets the address counter to „00H‟, and returns the cursor to the first column of first line.And if display is shifted previously, this instruction shifts this too. The DDRAM contents don‟t changein this instruction.
11) Clear display
RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 0 0 0 0 0 0 0 0 1
Clear all the display data by writing “20H” (ASCII code of „space‟ character) to all DDRAM address,AND set value DDRAM address counter (AC) to “00H”. It returns the cursor to the first column of firstline and sets the entry mode to increment mode (I/D=‟1‟).
8-bit and 4-bit interfacing of LCD
Now the question is how to display data in the LCD or give command to it. There is two modes of data
transfer are supported by LCD displays. One is 4bit mode, another is 8 bit mode. To transfer data In 8 bit mode, first put your data in the 8bit bus, then put command in the command bus and then pulse theenable signal.
To send data in 4bit mode; first put upper 4bit in the 4 bit data bus connected to 4MSB pins ofLCD display, then put control signals in the control bus, then pulse the E pin once. Next put the lower 4 bit in the data bus and pulse the E pin again. Here is a flowchart simply describing it.
7/27/2019 A Note on Character LCD Displays
http://slidepdf.com/reader/full/a-note-on-character-lcd-displays 9/11
9
LCD Display Interfacing – Flowchart:-
LCD Interfacing - Flowchart
LCD Initialisation
We are pretty familiar how to send data. But before displaying characters on the LCD display, it must beconfigured first. To configure an LCD display, four command words must be sent to LCD in either 4 bitmode, or in 8 bit mode. The commands are:
1. Function set
2. Display On/Off control
3. Entry mode set
4. Display Clear
7/27/2019 A Note on Character LCD Displays
http://slidepdf.com/reader/full/a-note-on-character-lcd-displays 10/11
10
Here is a flow chart of the initialization sequence of LCD display.
LCD Initialization
Displaying Custom Characters
All these character display modules got the feature to create 8 user defined characters (ASCII Codes0…7) in addition to the ROM fixed codes.
1.) The command “CG RAM Address Set” defines the ASCII code (Bit 3, 4, 5) and the dot line (Bit 0, 1,2) of the new character. Example demonstrates creating ASCII code “00H”.
2.) Doing 8 times the write command “Data Write” defines line by line the new character. 8th bytestands for the cursor line.
3.) The new defined character can be used as a “normal” ASCII code (0…7); use with “DD RAMAddress Set” and “Data Write”.
7/27/2019 A Note on Character LCD Displays
http://slidepdf.com/reader/full/a-note-on-character-lcd-displays 11/11
11
Now let us look up the character set that can be displayed using the LCD Displayed
0×00 0×10 0×20 0×30 0×40 0×50 0×60 0×70 0×80 to 0xd0 0xE0 0xF00×00 CG1 0 @ P ` p
CUSTOMREGIONAL
CHARACHTERS
Α 0×01 CG2 ! 1 A Q a q Ä0×02 CG3 “ 2 B R b r Β θ 0×03 CG4 # 3 C S c s Ε 0×04 CG5 $ 4 D T d t Μ Ω 0×05 CG6 % 5 E U e u Σ ϋ 0×06 CG7 & 6 F V v Ρ Σ 0×07 CG8 7 G W g w G π 0×08 CG1 ( 8 H X h x √
0×09 CG2 ) 9 I Y i y ¯¹ y0x0A CG3 * : J Z j z J0x0B CG4 + ; K [ k {0x0C CG5 , < L ¥ l |0x0D CG6 - = M ] m }0x0E CG7 . > N ^ n → 0x0F CG8 / ? O _ o ← █
CG→ CGRAM User Defined Character
Custom Regional characters vary from manufacturer to manufacturer. The Greek letters may or may notappear. It too depends upon the design.