28
Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC.

Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Embed Size (px)

DESCRIPTION

Department of Electronic & Electrical Engineering Resources  Powertip PC1601A 1x16 LCD data sheet (not much help)  Hitachi HD44780 data sheet (lots of detail)   (recommended)  (I pinched this code)  lcd4bitHello.asm (my example code ) 

Citation preview

Page 1: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

LCD character display (parallel interface).

How to interface a LCD character display to a PIC.

Page 2: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Applications

Used in many devices which need a simple monochrome display:

FAX machines Phones. Industrial test equipment Volt meters Student projects ? Etc . . .

Page 3: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Resources

Powertip PC1601A 1x16 LCD data sheet (not much help) Hitachi HD44780 data sheet (lots of detail) http://en.wikipedia.org/wiki/Hitachi_HD44780_LCD_controller http://www.8051projects.net/lcd-interfacing/introduction.php (recommended) http://www.piclist.com/techref/microchip/4bitlcd-b.htm (I pinched this code) lcd4bitHello.asm (my example code ) http://www.geocities.com/dinceraydin/lcd/intro.htm

Page 4: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

POWERTIP PC 1601A Schematic

Showing the HD44780U and the LCD displayHD44780 (another micro controller!)

Page 5: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Hitachi HD44780 LCD microcontroller

The HD44780 is a dot-matrix LCD controller Lots of LCDs use this controller. It provides the functionality and memory to drive the LCD. It allows you to use simple interface to drive the display A single HD44780 can display

one 8 characters line OR two 8 character lines one 16 character line (pretending to be 2 lines)

Can be driven using just 6 connection to the PIC

Page 6: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

PIN Descriptions

VSS Power supply (GND)VCC Power supply (+5V)VEE Contrast adjustRS 0 = Instruction input 1 = Data inputR/W 0 = Write to LCD module 1 = Read from LCD moduleEN Enable signalD0-7 Data bus lines 0-7

Page 7: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Connections (4 bit mode)

RW can be set low because we will not be reading from device4bit mode does not use D0-3

Page 8: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Sending data/instructions to the LCD

Data sent to the LCD controller can be either an:

Instruction (if RS is high) Data (character) (if RS is low)

To send a value (Data/Instruction) to the LCD

Set RS appropriately Put value onto lines D4-7 Strobe E (low high low)

Page 9: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

LCD Instructions (RS high) --- examples:

Clear LCD Position the cursor Set direction of cursor Set address of cursor Set 4/8 bit mode Set single / two line mode More . . .

Page 10: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Display Data RAM (DDRAM)

Characters are stored by the HD44780 in Display data RAM (DDRAM)

This has a capacity of 80 characters (bytes). 

 DD RAM address is the position of the cursor

The DD RAM address layout for 2 line display is.

Page 11: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC
Page 12: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC
Page 13: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Initializing the device.

If you are lucky the device will initialize itself on power up.

However this will only happen if some conditions are met (e.g. time to go from zero to full power).

It is best to do a full software reset . . . . makes sure the device is initialized properly.

Page 14: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Reset sequence of LCD (see lcd_init).

Wait for about 20mS Send the first init value (0x30) Wait for about 10mS Send second init value (0x30) Wait for about 1mS Send third init value (0x30) Wait for 1mS Select bus width (0x20 for 4-bit) Wait for 1mS

Page 15: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

8 8bit version

Page 16: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Switching to 4 bit Mode

We want to use 4bit mode. But controller starts in 8 bit mode!

We can switch to 4bit mode by sending

B'0010000' ; DL=0 sets 4 bit mode (note D0-3 can be zero).

Page 17: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

4 Bit mode

Once in 4 bit mode we can send an 8 bit instructions as 2 nibbles.

High nibble first. See routine lcd_send_w in the example code

Page 18: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Writing characters to the LCD.

Each character be represented by a byte of data Each location on the display has an address. The controller has a cursor (address of the next character to be

written) We write a character to the display by

Setting RS high Put character code on data lines Strobe E

The cursor is moved ready for the next character.

Page 19: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Character codes.

Page 20: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Example program lcd4bitHello.asm

Example that displays Hello on the LCD display.

Initializes the LCD Clears the LCD Sends 'H' 'e' 'l' 'l' 'o'

Page 21: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Demo: lcd4bitHelloWorld.asm

Page 22: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Screen Configurations

There are various LCD screen sizes. Common ones are

8X1 (one row of 8 characters) 16x1 16x2 20x2 20x4

The driver uses an address to define the position of a character.

The location of an address on the display depends on the device.

Some 16x1 devices behave differently from others!!!

Page 23: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

The PC 1601A 16x1 LCD display

From the controllers point of view it is a 2 line device.

The first 8 characters are on line 1 The second 8 characters are on line 2

Each line can have 40 characters (only 8 displayed) There are display shift operations which use this feature.

Page 24: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Addresses of characters for PC 1601A

The second 8 characters start at address 40!!

This is because the connections to the controller are like a second line with 40 characters per line!!!!!

Page 25: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Solution to the exercise

To send characters to the second 8 locations

Send a instruction to set the cursor address to 40

Send more characters

Page 26: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

Set cursor address instruction.

Page 27: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

HD44780 driving a 2 line LCD

Page 28: Department of Electronic & Electrical Engineering LCD character display (parallel interface). How to interface a LCD character display to a PIC

Department of Electronic & Electrical Engineering

2 rows mapped onto 1 row.