LCD Technical FAQ V35

Contents:



1) About the Author/Contacts

Author: Christopher J. Burian
Subject: LCD [technical] FAQ
Version: 35B
Latest (text) Version: http://www.cen.uiuc.edu/~cburian/lcd.doc
Date: March of 95
E-mail: cburian@uiuc.edu


2) Trademark and Copyright notice

Trademarks and service marks appearing in this FAQ are the property of their respective owners. I can take no responsibility for damage caused by errors or omissions in this work. Copyright 1994, 1995 by Christopher Burian and other contributors. All rights reserved. Permission is granted to distribute and reproduce this FAQ freely as long as this notice and all attributions remain intact.

Errata, comments, and suggestions are most welcome. Please e-mail to: cburian@uiuc.edu


3) LCD FAQ (Frequently Asked Questions list) Introduction

LCDs are manufactured by quite a few different companies. Units typically seen in the surplus market come from Densitron, Epson, Hewlett Packard, Optrex, or Sharp. Common configurations are 16, 20, 24, 32, or 40 characters by 1, 2, or 4 lines. This FAQ sheet applies only to LCD modules with Hitachi 44780 or equivalent controllers.

I've been loose with the term LCD here. One can find LCDs at any level of integration from what looks like a glass slide and will need drivers and controller, to a PCB that includes the row and column drivers, to the modules I'm actually talking about which also include an on-board controller (usually a Hitachi HD44780). I'd recommend staying away from modules that do not say they have a controller or otherwise indicate that it's included, such as by describing the character set or noting an ASCII interface. The units to look for are usually called character-type dot matrix LCD modules.

Most of the modules I've seen use the Hitachi controller. These all use the same interface and memory map. The character set is almost always the same with a mixture of English and Japanese characters, but customized models with different character sets also turn up in the surplus market. Also found are modules with extra segments--fixed numbers or words arranged around the dot matrix display area for extra functions. These extra segments look just like additional 5x7 dot boxes to the controller and can be driven by defining custom characters with appropriate bit patterns to energize these special segments as desired.


3.1) References used to generate this version


My gratitude to correspondents and contributors Chris Abbott, Magnus Andersson, John Edwards, Doug Girling, Frank Hausmann, John Payson, Robert Rolf, Philipp Schaeufele, J. R. Spidell, Frank Vorstenbosch, and Brian Wing. Special thanks and my apologies to any correspondents or contributors whom I might have failed to mention.


3.2) Definitions

Backlit
Uses lamp behind the display instead of reflected light.

Controller
The on-board dedicated microcontroller, such as the Hitachi HD44780 or SMOS SED1130, which acts as an interface between your CPU and the row and column drivers. It may have on-chip ram, or may need external ram. The controller takes care of generating characters, refreshing the display, and so on. The modules discussed in this FAQ have integral controllers.

Driver
LCD modules of all sorts have column and row, or x and y, drivers. To control one of these modules directly from a CPU would take a great deal of time and software overhead, because each bit (dot) has to be written separately, usually 4 dots at a time.

Electroluminescent
A kind of lamp used for backlighting that gives off a cool glow, powered by hi-voltage, high-frequency AC from a dc-ac inverter.

Extended temperature
Modules designed for use in temperatures outside the standard range. Standard range is 0 to 50 C, extended range is -20 to 70 C. Extended range units need -7VDC as well as +5VDC. Standard range units need only +5VDC.

LCD
Liquid Crystal Display

LED
Light Emitting Diode, the other popular backlight

Supertwist
A design that improves contrast


3.3) History of this FAQ

I originally wrote this frustrated by the terse and cryptic datasheets manufacturers supply. I refer to it more often than I write to it. I hope engineers, hobbyists, students, and experimenters find it helpful.

Version 0 released mid 1994
Version 35 released March 1995


4) Sources for Modules

These are the sources I've seen that are most accessible to the hobbyist. If you know of more, please email me.

All Electronics
818-904-0524
B. G. Micro
214-271-5546
Cronin Electronics
617-449-5000
Digikey Corporation
800-DIGIKEY
Herbach & Rademan
215-788-5583
Hosfelt Electronics
800-524-6464

...and hundreds more, no doubt.

My favorite references are the Optrex databook for dot matrix modules, available from Digikey for $2, and the Amateur Robotics column in the June '94 issue of:

Nuts & Volts magazine
430 Princeland Court
Corona, CA 91719


5) Specifications


5.1) Pin Description

These numbers are the same no matter the physical arrangement of the pins, (for instance, a row along the top on Optrex units, or a 2x7 .100" center array on the side of Sharp units) on 14-pin units. A reader has noted modules with only 10 pins--designed to be used with 4-bit wide data only.

Pin#  Symbol  Level  Function
 1     Vss     GND    Ground
 2     Vcc     +5V    Module power
 3     Vee    note1   Liquid crystal drive
 4     RS_     H/L    Register select, H=data, L=instruction
 5     R/W     H/L    Read/Write, H=read (module->CPU), L=write
(CPU->module)
 6     E       H/L    Enable   
 7     DB0    note2   Data bit 0  (least significant bit)
 8     DB1      "
 9     DB2      "
10     DB3      "
11     DB4      "
12     DB5      "
13     DB6      "
14     DB7      "

Backlight drive: If the module has a back light, it will be driven by a pair of pads separate from the interface pads. Check your datasheet for power requirements. Electroluminescent strips often specify around 200VAC at 400Hz from a DC-AC converter driven off the 5V power supply.

NOTE1: On standard modules Vee is between GND and 5V; on temperature extended modules it is between GND and -7V. The potentiometer is the contrast adjustment.

        Standard:

          +5V ------------*----------- Vcc
                          |
                          /
                  10k to  \<---------- Vee
                  20k pot /
                          \
                          |
          GND ------------*----------- Vss

Temperature extended model:

          +5V ------------------------ Vcc

          GND ------------*----------- Vss
                          |
                          /
                  10k to  \<---------- Vee
                  20k pot /
                          \
                          |
          -7V ------------'

Extended temperature types may also employ fancy temperature correction circuitry to provide automatic contrast adjustment.

For operation over a narrow temperature range (such as always indoors), a pair of resistors can be substituted for the potentiometer. At first, try a 10Kohm resistor between Vcc and Vee, and a 330ohm resistor between Vee and Vss, and adjust from there for optimum contrast.

NOTE2: The data pins DB7-DB0 (or DB7-DB4 when using a 4-bit interface) need to be driven by the CPU for a write, but must be switched to hi-Z (or pulled up with pull-up resistors only) so the module can drive the lines on a read or BUSY FLAG check.

When using a 4-bit wide interface, the most significant nibble is written first (bit7-bit4), then the least significant nybble is written (bit3-bit0) on the next Enable cycle. DB3 to DB0 are left unconnected. The pins have internal pullups, so open- collector drivers may be used with them.

Power consumption: Modules use between 10 and 25mW (2 to 5 mA), not counting the backlight, roughly proportional to number of rows and columns.

CAUTION!

Be careful when hooking power to the module. Reversing +5V and GND will destroy the unit. Carefully examine your datasheet to correctly identify Pin 1.


5.2) Character Set

None of the standard ASCII control codes [chr(1)-chr(31), chr(127)] are implemented.

Standard ASCII is used for chr(32) <space> through chr(125) '}' (<00100000b..01111101b>), except that tilde (~) is replaced by a yen symbol.

The lower case characters do not have decenders. This is because some LCD's (those with 5x7 dots or 5x8 dots) would chop off the bottom. Lower case characters with decenders appear near the top of the character table for use on modules which have 5x11 dot matrices. You can access them readily by adding 128 (<10000000b>, 80x) if you want decenders and have a 5x11 dot unit that will properly display them.

Eight user-defined characters are displayed by chr(0) through chr(7), and redundantly with chr(8) through chr(15). These are sometimes used to implement a comma and lower case characters g, j, p, q, and y with a decender into the cursor row on 5x8 units.

                                Font Table
                                ---- -----
LSN   x0  x1  x2  x3  x4  x5  x6  x7  x8  x9  xA  xB  xC  xD  xE  xF
MSN +---------------------------------------------------------------
0x  | cg0 cg1 cg2 cg3 cg4 cg5 cg6 cg7 cg0 cg1 cg2 cg3 cg4 cg5 cg6 cg7
1x  | <------------------------- UNDEFINED ------------------------->
2x  |      !   "   #   $   %   &   '   (   )   *   +   ,   -   .   /
3x  |  0   1   2   3   4   5   6   7   8   9   :   ;   <   =   >   ?
4x  |  @   A   B   C   D   E   F   G   H   I   J   K   L   M   N   O
5x  |  P   Q   R   S   T   U   V   W   X   Y   Z   [  (*)  ]   ^   _
6x  |  `   a   b   c   d   e   f   g   h   i   j   k   l   m   n   o
7x  |  p   q   r   s   t   u   v   w   x   y   z   {   |   }  --> <--
8x  | <------------------------- UNDEFINED ------------------------->
9x  | <------------------------- UNDEFINED ------------------------->
Ax  |     (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*)
Bx  |  -  (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*)
Cx  | (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*)
Dx  | (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*) (*)
Ex  | (*) (*) (*) (*) (*) (*) (*) (g) (*) (*) (j) (*) (*) (*) (*) (*)
Fx  | (p) (q) (*) (*) (*) (*) (*) (*) (*) (y) (*) (*) (*) (*) (*) (*)

Notes:

     cg0-cg7  user-definable characters
     (chr)    lower-case character with descenders
     (*)      see list below:
        Hex     Decimal Meaning
        ---     ---     -------
        5C       92     Yen
        A0      160     (blank)
        A1      161     katakana
        :        :         :
        A5      165     katakana (looks like dot in center)
        :        :         :
        DF      223     katakana (looks like degree symbol)
        E0      224     LC alpha
        E1      225     "a" with umlaut ("a) (German)
        E2      226     LC beta (or German es-szet) with descender
        E3      227     LC epsilon
        E4      228     LC mu with descender
        E5      229     LC sigma
        E6      230     LC rho
        E7      231     "g" with descender
        E8      232     radical (square root sign)
        E9      233     "- |" (Katakana?)
        EA      234     "j" with descender
        EB      235     tiny 3 by 3 'x' in upper left corner
        EC      236     cent sign
        ED      237     pounds sterling
        EE      238     "n" with tilde (Spanish) or overbar
        EF      239     "o" with umlaut ("o) (German)
        F0      240     "p" with descender
        F1      241     "q" with descender
        F2      242     LC theta
        F3      243     infinity (lazy-8)
        F4      244     LC omega
        F5      245     "u" with umlaut ("u) (German)
        F6      246     UC sigma
        F7      247     LC pi
        F8      248     "x" with overbar
        F9      249     "y" with descender
        FA      250     katakana
        FB      251     katakana        
        FC      252     katakana
        FD      253     division symbol (:-)
        FE      254     (blank)
        FF      255     solid black cursor

(Font table by Doug Girling)


5.3) Instruction Set

Binary data from bit7 to bit 0. If using a 4-bit interface, bit7-bit4 of data are sent first, then bit3-bit0, on successive enable cycles. No delay is required between these cycles (except that the minimum E time (450ns) and TcycE time (1us) must be met).


5.4) Write Operations

                                _
Note: RS=0 (except as noted), R/W=0, command/data from CPU to LCD on
bit7 to bit0, x=don't care.




5.5) Read Operations

               _
RS as noted, R/W=1, bit7 to bit0 output from LCD to CPU. 



5.6) Timing

Execution times: Clear display 1.64ms; home cursor 40 us to 1.64ms depending on how far display is scrolled; all others 40us, except read busy flag which is complete in a single enable cycle (or two cycles in 4-bit mode), and character generator ram reads and writes which should be separated by 120us delays. These execution times mean that after an operation, the CPU must do Busy Flag checks until the BF (bit 7) is 0, or, when the connection to the module >from the CPU is write-only, wait more than the execution time before the next operation. These are maximum execution times, some units (in particular those with 5x11 dot matrices) will execute some instructions faster.

WRITE:

         ______ _____________________________ ___________
     RS  ______X_________valid_RS_level______X__________
               |                             |
               |                             |
               |<--tAS-->|        tAH-->|    |<-- 
         ______|         |              |    |____________
     R/W ______\_________|___R/W_low____|____/_____________
                         |              |
                         |<----PWEH---->| 
                         |              |
                         |<-------------|-------TcycE----->|     
                         |______________|                  |_________
     E   ________________/              \__________________/
                    tR-->||<--       -->||<--tF
                                        ||
                             |<--tDSW-->||
                             |        -->|   |<--tWH
           __________________|_______________|________________
     D0-D7 __________________X__valid_data___X____________

READ:

         ______ _____________________________ ___________
     RS  ______X_________valid_RS_level______X__________
               |                             |
               |                             |
               |<--tAS-->|        tAH-->|    |<-- 
         ______|_________|__   _    ____|____|____________
     R/W ______/         |  R/W high    |    \_____________
                         |              |
                         |<----PWEH---->| 
                         |              |
                         |<-------------|-------TcycE----->|     
                         |______________|                  |_________
     E   ________________/              \__________________/
                    tR-->||<--       -->||<--tF
                         |              ||
                  tDDr-->|   |<--       ||
                             |        -->|   |<--tRH
          ___________________|_______________|________________
     data ___________________X__valid_data___X____________


Generally, there are no max time requirements on the user except Enable rise and fall times. An LCD module can be driven with just toggle switches for data, RS, and R/W, and a debounced pushbutton on the enable line.


5.7) Memory map

Character generator RAM appears to reside at locations 64-127 and display RAM seems to be at locations 128-255. This is an artifact of the control scheme. They are actually separate non- contiguous blocks of RAM.


5.8) Custom Characters

The display has 64 bytes of CG RAM, which supports 8 user-definable characters, each defined as a 5X8 character in an 8X8 block. The 5X8 region is right-justified. Note that in 5X10 matrix mode, only 4 user-defined characters are supported, using 11 bytes each.

        CG Address      CG Data
                        D7-----------D0
        x+0             x x x 1 1 1 1 1         *****
        x+1             x x x 1 0 0 0 0         *
        x+2             x x x 1 0 0 0 1         *   *
        x+3             x x x 1 1 1 1 1   =     *****
        x+4             x x x 1 0 0 0 1         *   *
        x+5             x x x 1 0 0 0 0         *
        x+6             x x x 1 0 0 0 0         *
        x+7             x x x 0 0 0 0 0         (cursor line)

Where "x" is the base address for the character: CG0=0, CG1=8, CG2=16, CG3=24, CG4=32, CG5=40, CG6=48, CG7=56.

As you can see in the above figure, each byte of CG data represents 1 row of pixels in the character, with D0 being the rightmost pixel, and D4 being the leftmost (the upper 3 bits are not displayed). The first address for a character is the topmost row, while the 7th is the bottom. (The 8th is ORed with the cursor underbar). A '1' in any pixel position becomes a dark pixel on the display.

CG RAM occupies a separate address space from the data display (DD) RAM. One must set the (first) CG address before writing any CG data. Each write automatically increments/decrements the CG address pointer to the next location. Remember to set the display back to DD addressing mode before trying to write characters to be displayed.

As an example, we'll define character #3 to be the above symbol by first reading the DD address, writing the CG address to the start of the character's RAM, writing the successive rows of pixel data, then restoring the addressing mode back to DD addressing (which requires the DD address we saved at the beginning.

        RS R/W D7----D0
        0  1  (baaaaaaa)        Read current DD address
        0  0   01011000         Set CG RAM address to char #3
                                             (3x8=24=11000b)
        1  0   00011111         Write top row of pixels
        1  0   00010000                 :
        1  0   00010001                 :
        1  0   00011111                 :
        1  0   00010001                 :
        1  0   00010000                 :
        1  0   00010000         Write bottom row of pixels
        1  0   00000000         Write cursor row (descender)
        0  0   1aaaaaaa         Restore DD mode (& address)

NB. There should be a 120 uSec delay between successive reads or writes.

(This Section Written by Doug Girling)


5.9) Addressing Display RAM

In the list below, "line 1" is the topmost line, and "line n" is the bottommost line. On each line, the leftmost character has the lowest address, and addresses increase to the right. Also, DD RAM addresses are shown without the 80h mode bit set.

16x1 module
Arranged as two 8-character lines side by side.

"Line 1" (left) addresses are 00h to 07h
"Line 2" (right) addresses are 40h to 47h

As you write characters to the module, the cursor will automatically increment until you get to the 9th character--you have to move the cursor to address 40h before writing the 9th character on the 1x16 module.

16x2 module
Two lines by 16 chars

Line 1 addresses are 00h to 0Fh
Line 2 addresses are 40h to 4Fh

20x1 module

Line 1 addresses are 00h to 13h

20x2 module

Line 1 addresses are 00h to 13h
[the command to set address is 80h-93h]
Line 2 addresses are 40h to 53h
[the command to set address is C0h-D3h]

20x4 module

Line 1 addresses are 00h to 13h
Line 2 addresses are 40h to 53h
Line 3 addresses are 14h to 27h
Line 4 addresses are 54h to 67h

40x2 module

Line 1 addresses are 00h to 27h
Line 2 addresses are 40h to 67h


The full 128 bytes of display RAM exist no matter how many characters appear on the display. These extra bytes can be typed on when display window scrolling is enabled, or they can be used to store other information--external data RAM for the CPU, if you like.


5.10) Initialization

Modules with Hitachi controllers will properly self-initialize if Vcc rises from 0 to 4.5v in a period between .1mS and 10mS. I suppose an RC circuit would be needed to keep powerup rise time as slow as .1ms, so the manual initialization will be required in most applications. If you do use auto-initialization, it will come up in this mode: 8-bit interface, 1/8 duty cycle (1 line mode), 5x7 font, cursor increment right, no shift. On most displays, you want to switch to 1/16 duty cycle (2 line mode) because for all but the 20x1, there are two logical lines as the controller sees it. If you have an 5x11-size character dot matrix module, you'll want to switch to the 5x10 font as well (the 11th line is the cursor).


5.10.1) Initialization for 8-bit Operation

<POWER ON>

<Wait 15ms>

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0   0   0   0   1   1   x   x   x   x    x=don't care

<Wait 4.1ms>

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0   0   0   0   1   1   x   x   x   x

<Wait 100us>

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0   0   0   0   1   1   x   x   x   x

<Wait 4.1ms>

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0   0   0   0   1   1   1   F   x   x    8-bit operation
                                         1/16 duty cycle
                                         F=font, 
                                         1 for 5x11 dot matrix
                                         0 for 5x8 dot matrix

<Wait 40us>

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0   0   0   0   0   0   1   0   0   0    Display off, 
                                         cursor off,
                                         blink off

<Wait 40us>

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0   0   0   0   0   0   0   0   0   1    Clear screen, 
                                         cursor home

<Wait 1.64m>

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0
0   0   0   0   0   0   0   1   1   0    Increment cursor to 
                                         the right when writing,
                                         don't shift screen

<Wait 40us>

<INITIALIZATION COMPLETE>

NOTE: Remember to turn the display back on and set up the cursor as desired with an On/Off Control command.


5.10.2) Initialization for 4-bit operation

The module powers up in 8-bit mode. The initial startup instructions are sent in 8-bit mode, with the lower four bits (which are not connected) of each instruction as don't cares.

After the fourth instruction, which switches the module to 4-bit operation, the control bytes are sent on consecutive enable cycles (no delay is required between nybbles). Most significant is sent first, followed immediately by least significant nybble.

<POWER ON>

<Wait 15ms>

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 
0   0   0   0   1   1  n/c n/c n/c n/c  

<Wait 4.1ms>

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 
0   0   0   0   1   1  n/c n/c n/c n/c 

<Wait 100us>

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 
0   0   0   0   1   1  n/c n/c n/c n/c 

<Wait 4.1ms>

RS R/W DB7 DB6 DB5 DB4 DB3 DB2 DB1 DB0 
0   0   0   0   1   0  n/c n/c n/c n/c   set 4-bit operation

<Wait 40us>

RS R/W DB7 DB6 DB5 DB4 
0   0   0   0   1   0
                        
0   0   1   F   x   x   4-bit operation
                        1/16 duty cycle
                        F=font, 1 for 5x11 dot matrix
                                0 for 5x8 dot matrix
                        x=don't care

<Wait 40us>

RS R/W DB7 DB6 DB5 DB4 
0   0   0   0   0   0   

0 0 1 0 0 0 Display off, cursor off, blink off


<Wait 40us>

RS R/W DB7 DB6 DB5 DB4
0   0   0   0   0   0   

0 0 0 0 0 1 Clear screen, cursor home


<Wait 1.64ms>

RS R/W DB7 DB6 DB5 DB4 
0   0   0   0   0   0   

0 0 0 1 1 0 Increment cursor to the right when writing, don't shift screen


<Wait 40us>

<INITIALIZATION COMPLETE>

NOTE: Remember to turn the display back on and set up the cursor as desired with an On/Off Control command.


6) Interfacing


6.1) Manual test circuit

                                         __________
                                        |          |
                        GND---*---------| 1        |
                              <         |          |
             contrast    10K   ><--.    |          |
                              <    |    |          |
                        +5V---*---------| 2        |
                                   |    |          |
                                    `---| 3        |
           RS                           |          |
    ,-----switch------------------------| 4        |          
    |                                   |          |
    |      +5V-----.           GND------| 5        |
    |              |                    |          |
    |              # 3.3k pullup resis. |          |
    |   Enable     |  |\                |          |
    *--pushbutton--*--|  >o-------------| 6        |
    |              |  |/ 74LS04 inverter|          |
    |             ---                   |          |
    |             --- 1uF cap           |          |
    |              |                    |          |
    |    DB0       GND                  |          |
    *---switch--------------------------| 7        |
    |                                   |          |
    |    DB1                            |          |
    *---switch--------------------------| 8        |
    |                                   |          |
   ~~~                                 ~~~        ~~~
   ~~~                                 ~~~        ~~~
    |    DB7                            |          |
    *---switch--------------------------| 14       |
    |                                   |__________|
    |
    GND

NOTE: Extended temperature range modules need the non-grounded end of the potentiometer tied to -7VDC instead of +5VDC.


6.2) Interfacing to a CPU Bus

These modules use an interface like those in Motorola (68xx) and MOS Technology (65xx) systems. R/W on the module can come from the R/W line on the CPU, which is set up about the same time as the address, while RS can be selected by the low order address line A0. Select Enable by ANDing the output from your address decoding and the E clock. Address decoding can be done with a magnitude comparator like the 74LS688, or if you have address space to spare, with partial address decode like running A13-A14 into a 74LS138 3-to-8 demux, or just the inverse of the high order address line (hogging a big chunk of address space).

    68xx
    65xx                                   LCD
    -----.                                .-----
     D0  |--------------------------------| D0
     :   |               :                |
     D7  |--------------------------------| D7
       _ |                                |   _
     R/W |--------------------------------| R/W
         |                        .---.   |
     E   |------------------------|   |   |
         |      .----------.      | & |---| E
     A0  |------|          |      |   |   |
     :   |  :   | (Decode) |------|   |   `-----
     A15 |------|          | CS(h)`---'
    -----'      `----------'
        Motorola bus interface

Because Intel (e.g., 8080, 8085, 8048) and Zilog (e.g., Z80) CPUs use separate read and write lines, and they are not set up ahead of time, R/W as well as RS must be set via address lines. Then the Enable signal may be generated from (NOT(/RD AND /WR)) AND PSEN):

 80xx
 Z80
  _ |         .------.                                            _
 RD |------*--| S  Q |----------------------------------------- R/W
  _ |      |  |      |
 WR |---*--+--| R    |
    |   |  |  `------'
        |  |  .---.                                   .---.
        |  `--| & |O--*-------------------------------|   |--- E
        `-----|   |   |  .---.     R         .---.    | & |
              `---'   `--|   |O--v^v^v^v--*--| & |O---|   |
                         `---'            |  `---'    `---'
                                       C ===
                                        __|_
                                       / / /

NB. R & C must be chosen to delay the rising edge of the enable pulse at least 140ns.

Using the data bus method limits CPU clock speed because of the tDDR read delay and the TcycE and PWEH requirements of the Hitachi controller.

(This Section Written by Doug Girling)


6.3) Interfacing to a CPU Port

In the case where a direct bus interface is not desired, or is impractical (e.g., many microcontrollers don't provide an external data/address bus, or do so at the expense of reassigning too many pins), the LCD module can be connected via an I/O port.

Whether you use a 4-bit or an 8-bit interface, those port pins driving the LCD's data lines must be bidirectional if you wish to read from the LCD. Remember too that you'll have to write your code to switch the port's data direction bits whenever you switch >from reading to writing or visa versa. If you don't expect to ever be reading back from the LCD, you can conserve resources by grounding R/W, saving a pin, and thus using digital outputs instead of bidirectional ports.

You may be able to eliminate the need for a software-generated enable (E) signal if the particular port you are using automatically generates a handshake strobe. In practical terms, most ports only generate a strobe on output, and expect a strobe on input, so this approach is most likely applicable to write-only configurations.


6.4) 4-Bit Port Interface

Another interface is to drive the module in 4-bit mode using 7 I/O bits from a port.

           |     .--------
           |     |
       P.7 |<--->| DB7
       P.6 |<--->| DB6
       P.5 |<--->| DB5
       P.4 |<--->| DB4
       P.3 |---->| R/W
       P.2 |---->| RS
       P.1 |---->| E
       P.0 |--nc |
           |     `--------

First, put the most significant nybble on P7-P4, and the appropriate R/W and RS signals on P3 and P2, and P1 low. Then toggle P1 high. Then toggle P1 low again. Then put the least significant nybble on P7-P4, toggle P1 high, toggle P1 low. Forty microseconds later, you can send the next character.

Sample in-line assembly code, by Jordan Nicol, for implementation under Dunfield's Micro-C for the Miniboard can be found on ftp cher.media.mit.edu. It uses port pins PA7-PA3 for 4-bit data and PC6 and 7 for RS and E.


6.5) 8-Bit Port Interface

If you have port pins to spare, then an 8-bit interface can be done with 11 port pins (10 for write only).

           |     .--------
           |     |
       PA0 |<--->| DB0
       PA1 |<--->| DB1
       PA2 |<--->| DB2
       PA3 |<--->| DB3
       PA4 |<--->| DB4
       PA5 |<--->| DB5
       PA6 |<--->| DB6
       PA7 |<--->| DB7
           |     |
       PB0 |---->| R/W
       PB1 |---->| RS
       PB2 |---->| E
       PB3 |--nc  `--------
       PB4 |--nc
       PB5 |--nc
       PB6 |--nc
       PB7 |--nc
           |


6.6) Interfacing to the Parallax BASIC STAMP

Sample program with physical hookup described in commented code can be found on the ftp site wpi.wpi.edu in the /stamp directory. It's a CPU port hookup as described above. The application also involves use of a radio control servo.


6.7) Interfacing to the Intel 8051 family of microcontrollers

Sample program and schematics appear in the application note AB-39 in the Intel Embedded Control Applications book for 1988 and probably other years.


6.8) Interfacing to the Motorola 68HC11 microcontrollers

Sample programs and circuit descriptions can be found at the MIT cher.media.mit.edu ftp site. There is the Miniboard hookup mentioned above, and the use of an LCD module on the 6.270 robot control boards.


6.9) Interfacing to the Microchip PIC microcontrollers

Sample program and schematics appear in the application note AN587 in the Microchip Embedded Control Handbook for 1994/95.


6.10) Serial Interface

A way to save even more I/O space is to use a serial interface, requiring just 3 digital output port pins. It uses a shift register with serial-in, parallel-out, and output latch. This setup allows the convenient coding of a parallel interface (just writing the data to the USART transmit buffer) and low pin count of a serial interface.

               ________________         __________
_____         |  74LS595       |       |          |
     |        |              QA|-------|DB4       |
     |--------|>ser. clock   QB|-------|DB5       |
CPU  |        |              QC|-------|DB6       |
OUT  |--------|>latch        QD|-------|DB7       |
PORT |        |              QE|-------|RS        |
     |--------|serial data   QF|-------|E         |
_____|        |              QG|--nc   |          |
       10Kohm |              QH|--nc   |          |
       pullup |                |       |          |
   +5V--^^^---|\Reset          |   .---|R/W       |
        .-----|\OE             |   |   |__________|
        |     |________________|   |
        GND                        GND

The Amateur Robotics column in June '94 Nuts & Volts demonstrated how to use this technique with the 68hc11's SPI port, using MOSI, SCK, and /SS. This would be especially handy with a non- networked 68HC11-based Miniboard single-board computer, which has MOSI, MISO, SCK, and /SS conveniently routed to the top left corner where resistor pack 2 goes. The experimenter could put the contrast potentiometer and latch on a daughterboard mounted underneath the LCD module.

An alternative with a less expensive shift register has the low pincount advantage, but requires bit manipulation of port pins:

_____                                   __________
     |                                 |          |
     |---------------------------------|E         | 
     |         ________________        |          |   
     |        |  74LS164       |       |          |
     |        |              QA|-------|DB4       |
     |--------|>ser. clock   QB|-------|DB5       |
CPU  |        |              QC|-------|DB6       |
OUT  |        |              QD|-------|DB7       |
PORT |        |              QE|-------|RS        |
     |--------|serial data   QF|--nc   |          |
_____|        |              QG|--nc   |          |
       10Kohm |              QH|--nc   |          |
       pullup |                |       |          |
   +5V--^^^---|\Clear          |   .---|R/W       |
              |                |   |   |__________|
              |________________|   |
                                   GND

Save another I/O line with this idea from Robert Rolf:

"On your SPI example, you can free up the latch line by using the clock line with a diode, pullup, and capacitor. I use the SPI in normally high mode, rising clock for data bits. 10K pullup, 10nF to GND, and the clock through diode pulls it low. After all the bits are shifted in, the RC times-out, and clocks [latches] the '595."


7) LCD Controller chip pinout

NEC UPD44780 LCD Display Controller Pinouts:

PIN DEFINITION

 1  SEG 22
 2  SEG 21
 3  SEG 20
 4  SEG 19                    666665555555555444444444
 5  SEG 18                    432109876543210987654321
 6  SEG 17                  65                        40
 7  SEG 16                  66                        39
 8  SEG 15                  67                        38
 9  SEG 14                  68                        37
10  SEG 13                  69                        36
11  SEG 12                  70                        35
12  SEG 11                  71                        34
13  SEG 10                  72                        33
14  SEG  9                  73      UPD44780 TOP      32
15  SEG  8                  74                        31
16  SEG  7                  75                        30
17  SEG  6                  76                        29
18  SEG  5                  77                        28
19  SEG  4                  78   NOTCHED CORNER       27
20  SEG  3                  79  /AND POSSIBLE DOT     26
21  SEG  2                  80 o                      25
22  SEG  1                   \         111111111122222
23  GND                       123456789012345678901234
24  OSC  1
 
25  OSC  2
26  V1
27  V2
28  V3
29  V4
30  V5
31  CL   1
32  CL   2
33  VCC
34  M         - 
35  D         -
36  RS        - Reset, assert once
37  R/W*      - Hold low for write operation
38  E         - Clock low to latch data.
39  DB  0     - The data bus
40  DB  1     -
 
41  DB  2     -
42  DB  3     -
43  DB  4     -
44  DB  5     -
45  DB  6     -
46  DB  7     -
47  COM  1
48  COM  2
49  COM  3
50  COM  4
51  COM  5
52  COM  6
53  COM  7
54  COM  8
55  COM  9
56  COM 10
57  COM 11
58  COM 12
59  COM 13
60  COM 14
61  COM 15
62  COM 16
63  SEG 40
64  SEG 39

65  SEG 38
66  SEG 37
67  SEG 36
68  SEG 35
69  SEG 34
70  SEG 33
71  SEG 32
72  SEG 31
73  SEG 30
74  SEG 29
75  SEG 28
76  SEG 27
77  SEG 26
78  SEG 25
79  SEG 24
80  SEG 23

(This Section Written by Frank Hausman)


8) FTP Sites & Links to Other Information

This FAQ

ftp.ee.ualberta.ca /pub/cookbook/misc/unsorted 4-bit interface sample in-line assembly code, by Jordan Nicol, for implementation under Dunfield's Micro-C for the Miniboard. It uses port pins PA7-PA3 for 4-bit data and PC6 and PC7 for RS and E.

cher.media.mit.edu

Parallax Basic Stamp applications

wpi.wpi.edu /stamp (Also see below)

PIC FAQ

Link to PROCESSOR FAQs

Link to a list of a lot of FTP sites for PROCESSORS


Please check attribution for Author. Processed by filipg@paranoia.com [Feedback Form] [mailto]. The most recent version is available on the WWW server http://www.paranoia.com/~filipg [Copyright] [Disclaimer]