Interfacing LCD

Introduction

LCD is the most common display devices used in different dedicated applications be it the instrumentation, medical equipment, panels, robotics etc. It is quite easy to interface it with the microprocessors or microcontrollers.

We can directly interface a LCD with microcontrollers, however, for interfacing with microprocessors, we need a peripheral device such as 8255. Here in this post we discuss the basics of LCD, its commands, interfacing using 8255 PPI an final a program to initialize LCD to display some user data on it.

PIN Diagram of LCD

Pin number Symbol I/O Description
1 Vss xx GND
2 Vcc xx +5V
3 VEE Xx Power Supply to control contrats (use POT)
4 RS I RS=0 to select command Register, to allow user to send command to LCD

RS=1 to select data register, allowing user to send data for display

5 R/W I R/W=0 : to Write

R/W=1: to read

6 E I/O Enable
7 DB0 I/O The 8-bit data bus

To send any of the command such as clear display or force curser to home position or blink etc, we make RS=0

To display any number or character we send the ASCII code of that and make RS=1, Then send a HIGH to LOW  pulse to E pin to enable the internal latch of LCD,

There are two ways to send characters to LCD

(i)Use delay before sending the next character

(ii)OR Use the busy flag to see if the LCD is ready for next character

8 DB1 I/O
9 DB2 I/O
10 DB3 I/O
11 DB4 I/O
12 DB5 I/O
13 DB6 I/O
14 DB7 I/O

 

Backside of a LCD

LCD devices such as shown in figure have their own controllers like HD44780 an in

terface IC and its associated components to help us use this LCD with the MCU. This IC helps in getting data and command from MPU and process them to display meaningful information onto our LCD Screen

LCD Pixel Formal

Pixels are used to decide the font size on the LCD

Because our LCD is a 16*2 Dot matrix LCD and so it will have (16*2=32) 32 characters in total and each character will be made of 5*8 Pixel Dots.  A Single character with all its Pixel

5×8 pixel

s enabled is shown in the below picture.

So Now, we know that each character has (5*8=40) 40 Pixels and for 32 Characters we will have (32*40) 1280 Pixels. Further, the LCD should also be instructed about the Position of the Pixels.

Mode of Operation

4-bit and 8-bit Mode of LCD:

In 4-bit Mode we send the data nibble by nibble, first upper(D4-D7)  nibble and then lower(D0-D3) nibble. This enables us to send 8 bit data.

In 8-bit mode we can send the 8-bit data directly in one stroke since we use all the 8 data lines.

4-bit mode is widely used to save the number of pins for other tasks. No control pins are used to set these modes. It’s just the way of programming that change

Read and Write Mode of LCD:

Most of the times the programmer will do only write operation on the LCD as it involves commands and data. Reading the LCD is more complex and used by advanced programmers so as such read operation are very rare.

LCD Commands

LCD controllers support number of commands. few of the selected commands are given below.

Command
Meaning
Command
Meaning
00 (00000000)
Clear Display)
02 (0000001x)
Cursor Home.
000001 I/D S
Entry Mode Set S for shift  I/D=1 increment, 0=decrement
83
Cursor line 1 position 3
00001DCB
Display ON/OFF D(Display), C(Cursor) B(blink of char)
08

0C

Display OFF, cursor OFF

Display ON, cursor OFF

Cursor/Display Shift

0001 S/C R/L x x

S/C=1 shift display, =0 move cursor; R/L=0(left)=1(right)
000111xx (1C)
Shift display right
Function Set 001 DL N F  x x
DL=1(8-bit) =0(4-bit); N (no. of lines)=0(one Line, 1(two line) F(font) =1 for 5×10, =0 for 5×7)
38 (00111000)
2 lines and 5×7 matrix
C0
Force cursor to beginning of second line
C1
Jump to second line, position 1
C2
Jump to second line, position 2

Interfacing LCD with 8255

Pin-1 (Vss0) of LCD  connected to GND

Pin-2 connected to Vcc

Pin-3 connected to POT

Port Addresses of 8255:

Assume Even port address. PA=80h, PB=82h, PC=84h, CW=86h

Data lines of LCD are connected at PA of 8255

E, R/W’ and RS pins of LCD are connected to PC2, PC1, PC0 respectively of Port C of 8255

Write a program to display Your name on LCD

Step in programming:

  • Write a command to LCD
  • Give 1-to-0 transition on pin-E of LCD for about 40us to 1.8ms
  • repeat for more command
  • write a data to LCD
  • Give 1-to-0 transition on pin-E of LCD for about 40us to 1.8ms
  • repeat for more data

Program

data segment

   name db “Ravinder”

data ends

code segment

assume : CS: code, DS: data

MOV AX, data

MOV DS, AX

CALL start

HLT

start:         MOV AL, 01H                     ; command to clear LCD

CALL COMMAND

MOV AL, 02H                   ; command to set cursor to home

CALL COMMAND

LEA SI, name               ; pointer to data to be displayed

MOV AH, 8                 ; set counter for no. of characters to be displayed

NEXT:       MOV AL, [SI]             ; read a character from memory

CALL DISP              ; call a routine to display it on LCD

INC SI

DEC AH

JNZ NEXT              ; Repeat if all not yet displayed

RET

COMMAND:

OUT PA, AL         ; write command to port A

MOV AL, 04H ; E=1, R/W’=0, RS=0   ; transition on E

OUT PC, AL

MOV AL, 00   ; E=0,    ; transition on E

OUT PC, AL

CALL DELAY

RET

DISP:

OUT PA, AL       ; send data to port A

MOV AL, 05   ; E=1, R/W’=0, RS=1

OUT PC, AL

MOV AL,00

OUT PC, AL          ; transition on E

CALL DELAY

RET

DELAY:     MOV CX, CNT

L1:             NOP

NOP

LOOP L1

RET

Leave a Reply

Top
error: Content is protected !!