LCD Driver
Application Note
Electronic Gardener
Mark Kudryk, Kim Ellis
October 28, 1998
 

Introduction

The following is a guide to construct a driver for an Emerging Display EC16220YLYU LCD Screen from the FLEX10K20 FPGA.  This app note will outline how the driver was constructed for the Electronic Gardener, which used two EC16220YLYU LCD screens in order to create a 4-line-by-16-character LCD screen.
 

Entity

The LCD driver took as inputs a single line, byte-by-byte, and wrote each byte to the appropriate line and position on that line on the lcd screen.  The entity declaration is as follows:

entity lcd is
 port (data_in: in std_logic_vector (7 downto 0);
    line_select: in std_logic_vector (1 downto 0);
    ready_for_line, byte_request: out std_logic;
    new_line_request, byte_valid: in std_logic;

    clock, reset: in std_logic;

    data_out: out std_logic_vector (7 downto 0);
    read_write, register_select, enable0, enable1: out std_logic);
end entity lcd;

line_select is how the calling module choses to display the line it gives the driver on 1 of the four lines, number 0 thru 3.

ready_for_line is how the lcd_driver indicates to the calling module that it has completed writing the last line and is ready for a new one.

new_line_request is the response of the calling module to a high signal on ready_for_line.

byte_request is set high when the lcd_driver is ready to accept a new byte from the calling module, after receiving acknowledgement from the calling module that it's ready to provide a new line.

byte_line is set high when the calling module has placed valid data on the input bus, data_in.

read_write is how the driver indicates to the lcd whether a read or write operation will be performed; for this driver, read_write will always be a logic zero (write).

register_select indicates whether the data on the data_out bus to the lcd is data to be displayed on the screen or an instruction for the lcd, such as an address.

enable0 and enable1 is how the driver chooses between the two lcd screens.
 

LCD Pins

 
Pin
Signal
Description
1
Vss
GND
2
Vdd
5V Power rail
3
Vo
Contrast Voltage
4
RS
Register select
5
R/W'
Read/Write - always set to '0'
6
E
enable
7
DB0
Data bus
8
DB1
Data Bus
9
DB2
Data Bus
10
DB3
Data Bus
11
DB4
Data Bus
12
DB5
Data Bus
13
DB6
Data Bus
14
DB7
Data Bus
 

Driver Structure

The LCD Driver has two separate yet equally important parts to it: a data part, and a control part.

The control part is a state machine that is responsible for writing the instructions to the lcd screen, coordinating the initialization sequence upon reset, and coordinating the transfer of data from the calling module to the lcd screen.

The data part is a latched connection between data_in and data_out, interrupted only by a multiplexor that allows the control part to send instructions out to the lcd screen.  This is shown in the figure below.
 

 

Clock Frequency

The LCD driver is operated at a very low clock frequency, around 10kHz.  This is because the FLEX10K20 does not permit a tristate bus, which would be required if the driver was to read from the lcd screen.  This is usually done to check whether or not the screen is ready to accept another instruction or character.  However, each instruction is guaranteed by the manufacturer to be completed within a certain time period.  These periods range from 37 us to 1.5 ms, so if the control state machine waits for a specified period of time after something is written, it is not necessary to read from the lcd screen.

A low clock frequency is chosen because it results in a fewer number of clock cycles that need to be counted off.
 

Initialization Pattern

Upon start-up or reset, the LCD needs to be initialized by sending it the following data.  register_select and read_write should be set to logic '0'.
 
  1. DB = 30        - wait for 4.1 ms
  2. DB = 30        - wait for 100 us
  3. DB = 30        - wait for 37 us
  4. DB = 0011NF11  - N = 0 for 1 lines, 1 for 2 lines of display; F = 0 for 5x8 characters, 1 for 5x10; wait for 37 us
  5. DB = 08        - turn display off; wait for 37 us
  6. DB = 01        - display clear; wait for 1.52 ms
  7. DB = 000001MS  - M = 0 to decrement address count, 1 to increment; S = 0 for cursor shift off, 1 for on; wait for 37 us
  8. DB = 0C        - turn display on; wait for 37 us
After this, the lcd is ready to display data.
 
 

Displaying Data

When the lcd has been requested to display a line of data, it first must reset the start address for the line, and set the appropriate enable signal high.  The top two lines are accessed by the enable0 line, the bottom two by the enable1 line.  The top line of a single screen is access by setting the address in the lcd screen to hex 80, the lower line to hex C0.  After a byte is written, the lcd screen automated increments the address counter to the next position.
After the data has been written to the lcd screen, wait 37 us before writing the next byte.  This will save you the trouble of finding a way to read from the lcd screen using the FLEX10K20.