You are on page 1of 46

• Character LCD basics

• Pin description of Character LCD


• Understanding how to use character
LCD
• Interfacing with 8051
• LCD stands for Liquid Crystal Display
• Two types:
 Character LCD
 Graphics LCD
• Used to:
 Display information
• LCDs are being widely used, because they are:
 Easy to Interface
 Easy to procure
 Well documented
LCD is finding widespread use. Factors:
• The declining prices of LCD
• The ability to display numbers, characters, and
graphics
• Incorporation of a refreshing controller into the
LCD, thereby relieving the CPU of the task of
refreshing the LCD
• Ease of programming
• A 16×2 Liquid Crystal Display can display 32
characters at a time in two rows
 16 characters in one row
• Each character in the display of size 5×7 pixel
matrix, (although this matrix differs for
different 16×2 LCD modules)
• There are 16 pins in the LCDmodule
• 5 X7 pixel matrix would mean there are 5 pixels in a
row and 7 pixels in a column for display.
• Each pixel will either be black or white to represent a
character.
• The character ‘A’ would be represented as shown:
• Holding LCD towards the user, Leftmost pin is
pin 1 and rightmost is pin 16

• We can divide the LCD pins into following


categories:
 Power (Pin 1,2 and 3)
 Control (Pin 4, 5 and 6)
 Data (Pin 7 through 14)
 Backlight (Pin 15 and 16)
Power pins
• Pin 1 is Ground. Connect it to 0v.
• Pin 2 is VDD.
 You can connect it to 5V or 3.3V (Refer to data sheet of the LCD)
• Pin 3 is contrast pin.
 Atypical character LCD would have black text in foreground
and green/blue background.
 Contrast would control the difference between background and
foreground.
 This pin would be required to make the display more dark (text
dark)
 Connect Pin3 to centre point of potentiometer and adjust
contrast with help of potentiometer.
Control pins
• Pin 4 is RS (Register Select)
 The LCDs have two registers: Command register &data
register in a DDRAMmemory.
 The control instructions like clear LCD or shift the cursor, are
stored in Command Register (also called instructionregister)
 The data to be displayed such as say some character ‘a’ ‘2’ etc, it
is stored in Data register.
 If you need to send command, select the command register by
setting RS=0. If you need to send data to be displayed on LCD,
you would select data registerby setting RS=1
Control pins
• Pin Number 5 is Read/Write pin.
 Typically, you do not read from LCD, you write to it. Hence,
most of times, you would connect it to ground.
 If you would have to read data previously stored it LCD, you
would have to make this pin 1

• Pin 6 is enable pin.


 The transitions of Enable pin are seen as clock for the registers
in LCD. Data is latched on LCD only on positive edges of the
clock (Enable pin).
 Whenever you need to write data or command to a LCD or read
from LCD, you would have to generate a high-to low pulse on
Enable pin . Seeing this transition on LCD, the LCD would
understand that it has to perform a read/write operation.
Data pins
• Pin Number 7 through 14 are data pins.
 You can use 4 data pins or 8 data pins, for programming your
LCD.
 If you decide to use LCD in 4-bit mode, although the
data/command that is to be send to the LCD is of 8-bits width,
you would first send lower 4 bits of data and later you would
send the upper 4-bits, i.e. lower nibble followed by the upper
one.
 Why would one go for 4-bit mode when he/she can send 8-bit
data, at a time?
 4-bit mode saves 4-pins of the microcontroller. If your
application involves multiple interfaces, it would be wiser to
save the pins of microcontroller.
 If the application has no constraints on number of pins, it would
be wiser to use 8-bit mode as LCD writing is a slow speed
operation. You do not send any high priority data to LCD. Hence,
to make your application work faster, prefer 8-bit mode in this
case.
Backlight pins
• Pins 15 and 16 are for controlling Backlight
 Backlight is a LED in background.
 To control the backlight, you would connect pin 15 to positive
voltage and pin 16 to negative voltage. This would light up the
LED.
 Always connect this via a resistor, as you do not want to
damage the LED.
Category Pin Pin Name Function

1 VSS Ground Pin, connected to Ground


Power Pins
2 VDD or Vcc Voltage Pin (+5V or 3.3 V)

Contrast Setting, connected to Vcc thorough a


Contrast Pin 3 V0 or VEE
variable resistor.
Register Select Pin RS=0
4 RS Command mode RS=1 Data
mode
Read/ Write pin, RW=0
Control Pins 5 RW Write mode, RW=1 Read
mode
Enable, a high to low pulse need to enable the LCD
6 E

Data Pins, Stores the Data to be displayed on


Data Pins 7-14 D0-D7
LCD or the command instructions
15 LED+ or A To power the Backlight +5V
Backlight Pins 16 LED- or K Backlight Ground
• RS: RS is the register select pin. You need to set it to 1, if you are
sending some data to be displayed on LCD.
– And you will set it to 0 if you are sending some command
instruction like clear the screen(hex code 01).

• RW: This is Read/write pin, you will set it to 0, if you are going
to write some data on LCD.
– And set it to 1, if you are reading from LCD module.
– Generally this is set to 0, because you do not have need to
read data from LCD.

• E: This pin is used to enable the module when a high to low pulse
is given to it.
– That transition from HIGH to LOW makes the module
ENABLE.
Hex
Command to LCD Instruction Register
Code
0F LCD ON, cursor ON
01 Clear display screen
02 Return home
04 Decrement cursor (shift cursor to left)
06 Increment cursor (shift cursor to right)
05 Shift display right
07 Shift display left
0E Display ON, cursor blinking
80 Force cursor to beginning of first line
C0 Force cursor to beginning of second line
38 2 lines and 5×7 matrix
83 Cursor line 1 position 3
3C Activate second line
08 Display OFF, cursor OFF
C1 Jump to second line, position 1
OC Display ON, cursor OFF
• Commonly used LCD instructions
• Each command is a 8-bit hexadecimal data
Command Interpretation
30 H LCD interprets this as the user would like to set LCD in 8-bit mode,
use only 1 line (row) of LCD and the font size of 5X7 (i.e. 5 dots
(pixels) in row and 7 dots (pixels) in a column)

38 H Same as above, two lines would be used


20 H LCD interprets this as the user would like to set LCD in 4-bit mode,
use only 1 line (row) of LCD and the font size of 5X7 (i.e. 5 dots
(pixels) in row and 7 dots (pixels) in a column)

28 H same as above, two lines would be used.


0E H Display is on, cursor is also on and is blinking
06 H Shift the cursor right
01 H Clear the display (i.e. the contents of LCD registers will be
erased)
80H-8FH Cursor positions in first row
C0H-CFH Cursor positions in second row
🞂 Steps for displaying a character or data
• RS=1; Register select should be high

• R/W=0; Read/Write pin should be low.

• E=1->0; enable pin should be given high to


low pulse

🞂 Steps to send a command to the LCD


• RS=0; Register select should be low
• R/W=1; Read/Write pin should be high

• E=1->0; enable pin should be given high to


🞂 low pulse
RET
🞂 Keyboards are organized in a matrix of rows and
columns
🞂 The CPU accesses both rows and columns through ports
🞂 Therefore, with two 8-bit ports, an 8 x 8 matrix of keys
can be connected to a microprocessor
🞂 When a key is pressed, a row and a column make a
contact ƒ Otherwise;there is no connectionbetween rows
and columns
🞂 IBM PC keyboards, a single microcontroller takes
care of hardware and software interfacing
🞂 It is the function of the microcontroller to scan the
keyboard continuously to detect and identify the
key pressed
🞂 ‰
To detect a pressed key, the microcontroller grounds all rows by
providing 0 to the output latch, then it reads the columns
🞂 If the data read from columns is D3 – D0 = 1111, no key has
been pressed and the process continues till key press is
detected
🞂 If one of the column bits has a zero, this means that a key
press has occurred ƒFor example,
🞂 if D3 – D0 = 1101, this means that a key in the D1 column
has been pressed ƒ
🞂 After detecting a key press, microcontroller will go through the
process of identifying the key
🞂 Starting with the top row, the microcontroller
grounds it by providing a low to row D0 only
🞂 It reads the columns, if the data read is all 1s, no key in
that row is activated and the process is moved to the
next row
🞂 ‰
It grounds the next row, reads the columns, and
checks for any zero
🞂 This process continues until the row is identified ‰
🞂 After identification of the row in which the key has
been pressed
🞂 Find out which column the pressed key belongs to
TERFACING TOPIC 6

MEMORY AND I/O INTERFACING


i. External ROM (program memory) Interfacing

P1 P0 D0-D7

EA A0
| ROM/
8051 LATCH A7 EPROM
ALE
clock
A8 Address
P3 | lines
A15
PSEN OE

FIGURE 1 INTERFACING OF ROM/EPROM TO µC 8051.

above figure shows how to access or interface ROM to 8051.


port 0 is used as multiplexed data & address lines.
it gives lower order (A7-A0) 8 bit address in initial T cycle & higher
order (A8-A15) used as data bus.
8 bit address is latched using external latch & ALE signal from 8051.
port 2 provides higher order (A15-A8) 8 bit address.
PSEN is used to activate the output enable signal of external
ROM/EPROM.

ii. External RAM (data memory) Interfacing

P1 D0 data
P0 | lines
D7
RAM
8051 LATCH A0
ALE clock |
A7 address
lines

RD P3 P2

Chapter: 6 MEMORY AND I/O INTERFACING


WR WR OE

FIGURE 2 INTERFACING OF RAM(DATA MEMORY) TO µC 8051.

above figure shows how to connect or interface external RAM(data


memory) to 8051.
Port 0 is used as multiplexed data & address lines.
address lines are decoded using external latch & ALE signal from 8051
to provide lower order (A7-A0) address lines.
port 2 gives higher order address lines.
RD & WR signals from 8051 selects the memory read & memory write
operations respectively.
RD & WR signals: generally P3.6 & P3.7 pins of port 3 are used
to generate memory read and memory write
signals.
remaining pins of port 3 i.e. P3.0-P3.5 can be used for other
functions.

2
LINEAR AND ABSOLUTE DECODING
i. Absolute Decoding
all higher address lines : decoded to select memory chip for
specific logic levels.
for other logic levels memory chip is disabled.
generally used in large memory systems.
figure below shows memory interfacing using absolute decoding.

Vss
P0.7 D7-D0
EA |
P0.0
74LS373 A7-A0

ALE G OC 16k x 8
8051 RAM
P2.0
| A8-A13
P2.5
P2.6
P2.7 CS

PSEN
P3.6 WR

P3.7 RD

FIGURE 3 MEMORY (RAM) INTERFACING USING ABSOLUTE DECODING.

ii. Linear Decoding (Partial Decoding)


for small systems : individual higher order address lines used
to select memory chip.

replacing the hardware by


decoding logic.

reducing the cost of decoding, drawback is- multiple addresses.


as shown in figure below, A14 line is directly connected to chip
select line, A15 line not connected anywhere, kept open.
so, status of A15- not considered for generation of chip select
signal.

Chapter: 6 MEMORY AND I/O INTERFACING


Vss
P0.7 D7-D0
EA |
P0.0
74LS373 A7-A0

ALE G OC 16 x 8
8051 RAM
P2.0
| A8-A13
P2.5
P2.6 CS (A14)
P2.7 A15

PSEN
P3.6 WR

P3.7 RD

FIGURE 4 MEMORY (RAM) INTERFACING USING LINEAR DECODING.

1
Address Mapping(Memory Map)
i. Absolute Decoding
Address A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 HEX
adrs.
starting 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0000H
end 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3FFFH
ii. Linear Decoding
Address A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 HEX
adrs.
starting 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0000H
end x 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3FFFH

Comparison between Full address(Absolute) & Partial address (Linear) Decoding.

Full Adress(Absolute) | Partial Address(Linear


Decoding | Decoding

i. all higher address lines are |i. few or individual address lines
decoded to select memory or | are decoded to select memory or
I/O device. | I/O device.
ii. more hardware : decoding |ii. less hardware : decoding logic.
logic. | (sometimes none.)
iii. decoding circuit : higher |iii. decoding circuit : less cost.
cost. |
iv. No multiple addresses. |iv. multiple addresses possible.
v. used in large systems. |v. used in small systems.

Solved Examples:
Example 1: Design a µController system using 8051.Interface the external RAM
of size 16k x 8.
Solution: Given, Memory size: 16k
that means we require 2n=16k :: n address lines
here n=14 :: A0 to A13 address lines are required.
A14 and A15 are connected through OR gate to CS pin of external RAM.
when A14 and A15 both are low (logic ‘0’), external data memory(RAM) is
selected.
Address Decoding(Memory Map)for 16k x 8 RAM.
Address A15 A14 A13 A12 A11 A10 A9 A8 A7 A6 A5 A4 A3 A2 A1 A0 HEX
adrs.

Chapter: 6 MEMORY AND I/O INTERFACING


starting 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0000H
end 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 3FFFH
Vss
P0.7 D7-D0
EA |
P0.0
74LS373 A7-A0

ALE G OC 16k x 8
8051 RAM
P2.0
| A8-A13
P2.5
P2.6
P2.7 CS

PSEN
P3.6 WR

P3.7 RD
FIGURE 5 16K X 8 MEMORY (RAM) INTERFACING TO µC 8051.
4
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner
Scanned by CamScanner

You might also like