You are on page 1of 4

Title : Interfacing LCD with microcontroller

Name: Siti Nor Nabilah binti Yahya


Date : 23 March 2009

Abstract

Liquid crystal displays (LCDs) are a passive display technology. This means they do not emit
light because they use the ambient light in the environment. By manipulating this light, they
display images using very little power. This has made LCDs the preferred technology whenever
low power consumption and compact size are critical. This application note explains how LCD is
used to display a character. The main scope of this application note is to describe how LCD
interfaces with microcontroller. It also will teach simple programming code for LCD interfacing.

Keywords

LCD

Introduction

In this application note liquid crystal display JHD 162A is used to interfacing with microcontroller.
In interfacing the LCD, the major task is the initialization sequence. Therefore we have to send
command bytes to the LCD to set the interface mode, display mode, address counter,
increment direction, set contrast of LCD and horizontal or vertical addressing mode.

Objective

To describe how liquid crystal display(LCD) interface wit microcontroller.

Function of JHD 162A

Pin No Name Function Use


1 Vss Ground
2 Vdd +ve Supply 5v Volts Regulated DC
3 Vee Contrast This is used to set the
contrast1
4 RS Register Set Register select
signal:Instruction
register (when
writing)
Busy flag & address
counter (When
reading):Data register
(when writing &
reading)
5 R/W Read / Write Read/write select
signal
for writing and for
reading
6 E Enable Operation (data
read/write) enable
Title : Interfacing LCD with microcontroller
Name: Siti Nor Nabilah binti Yahya
Date : 23 March 2009

signal
7 D0 Data Bit 0
8 D1 Data Bit 1
9 D2 Data Bit 2
10 D3 Data Bit 3
11 D4 Data Bit 4
12 D5 Data Bit 5
13 D6 Data Bit 6
14 D7 Data Bit 7
15 LED + 5 V of backlight Positive supply for
back light if available
16 LED - 0V of backlight

JHD 162A interfacing with microcontroller circuit

Circuit discription

Connect pins RS ,RW ,E ,D0 - D7 to pins on the micro controller and connect Data bus on port A
and the RS , RW , E on port B . We can save pins by using LCD in Nibble Mode (4 data pins )
and permanently grounding the RW line ( always in write mode ). To avoid losing battery we
can ignore the connection of pin 15 and 16 of the LCD.
Title : Interfacing LCD with microcontroller
Name: Siti Nor Nabilah binti Yahya
Date : 23 March 2009

Using C programming for interfacing

Function Procedure Code


void initialize () First the Ports to which the /*LCD_DATA_PORT = 0x00;*/
LCD are set to output LCD_DATA_DDR = 0xff;
Then the data Port is given LCD_CONTROL_DDR=0xff;
the value 0b00111111
then the lcd port is pulsed LCD_DATA_PORT = 0b00111111;
3 times to accept the
data . After that the Data pulse_enable();
command 0b00111011 is lcd_delay(100);
sent for a 2 line display
5x7 character set etc pulse_enable();
Then the data command lcd_delay(100);
for shift is sent
At last the screen is pulse_enable();
cleared and a delay is lcd_delay(100);
made for it to take place
lcd_write_byte(CTRL,0b00111011);
lcd_write_byte(CTRL,0b00001100);
lcd_write_byte(CTRL,0b00000001);
lcd_delay(100);
lcd_write_byte(CTRL,0b00000110);
//lcd_delay(100);

void cls() Clear screen lcd_write_byte(CTRL,0x01);


This send the Clear screen lcd_delay(50);
command to the LCD
void lcd_write_byte(unsigned This command writes the LCD_DATA_PORT = byte ;
char control, unsigned char appropriate byte to the lcd if (control == DATA )
byte)* setting the RS line LCD_CONTROL_PORT |=
appropriately for a register LCD_RS_NO; else
or a command as passed LCD_CONTROL_PORT &=
The Port is set to the data ~LCD_RS_NO;
which is to be sent and the
RS line is set for Command pulse_enable();
or Data and the it is lcd_delay(2);
Pulsed

void pulse_enable() This command sets the lcd LCD_CONTROL_PORT |=


enable line high for a short LCD_EN_NO;
period of time which make asm("nop ");
the Lcd to Accept the data LCD_CONTROL_PORT &=
or command at its ports ~LCD_EN_NO;
lcd_delay(2);
Title : Interfacing LCD with microcontroller
Name: Siti Nor Nabilah binti Yahya
Date : 23 March 2009

void lcd_str(char *ptr) This is used to print a line while (*ptr != 0x00)
of text on the lcd lcd_write_byte(DATA,*ptr++);
void lcd_goto(unsigned char This is used to set the unsigned char addr;
column, unsigned char line) LCD's current cursor from line--;
where it will continue column--;
printing addr = (line * 0x40) + column;
This 40 is the address of lcd_write_byte(CTRL, addr | 0x80);
the next line to be added
it is OR'ed with 0x80 to
make the MSB 1 .

Conclusion

This application note has explained the detail how LCD can be interfacing by showing the circuit
diagram and the example and the description of simple c programming for the interfacing with
microcontroller.

You might also like