Initialization or Reset
Each time power to the module is turned on, an initialization (reset) procedure must be executed. This procedure consists of sending an initial group of instructions to configure the display for normal programming execution. Each module will automatically perform this procedure on power-up (using internal circuitry). However, for this to happen properly, the power supply rise time must meet the parameters shown below. To absolutely insure proper initialization, it might be best to turn the module power on and then send the proper initialization instructions from the microprocessor.
The following instructions are automatically executed by each module on Power Up:
Instruction
Code
Equivalent Hex Code
(1) Clear DisplayThe busy flag is kept in the busy state (BF=1) until initialization ends. The time is 15 ms. 10000000 80(Busy Flag)
(2) Function SetDL=1: 8 bits wide
Interface DataN=0: 1-line Display

F=0: 5 X 7 dot character font

00110000 30( 1st Instruction)
(3) Display ON/OFF Controltd=0: Display OFF (Blank)C=0: Cursor OFF
B=0: Blink OFF
00001000 08
(4) Entry Mode Set I/O=1: +1 (Increment)S=0: No shift 00000110 06
(5) DD RAM is selected
Because initialization may not be performed completely depending on the rise time of the power supply when it is turned on, pay attention to the adjacent time relationship. ^toff stipulates the time of power OFF for power supply instantaneous dip, or when power supply repeats ON and OFF.
As mentioned above, since some power supplies may not meet the above parameters, it may be better to absolutely ensure proper initialization by sending the following additional initialization instructions from the microprocessor after the above automatic initialization has taken place.  These suggested codes create an automatically-incremented, steady line cursor, which is different from the automatic initialization.  Also, note that the initial hex code 30,34 or 38 is sent twice to ensure the module enters the 8-bit data length mode without fail.  All initialization is performed with RS and R/W, both 0 (low).  Allow 15ms after initialization before sending additional software codes to display module.

Display Initialization

Real world power supplies dictate that the LCD be formally initialized.  These brief software codes tell the display microprocessor how to handle incoming data and how to physically configure the display.  Suggested here are initialization codes which create an automatically incremented, steady, line cursor.  All initialization is performed with RS=R/W=0.
FOR 8 BIT DATA BUS

      8 bit, 1 line, 5 x 7…30,30,06,0E,01
      8 bit, 1 line, 5 x 10..34,34,06,0E,01
      8 bit, 2 lines, 5 x 7..38,38,06,0E,01

NOTE:  RS & R/W must be 0.

It is possible to write to just one line of a two line display.  Using the 30 instruction will improve the contrast ration by eliminating line 2.

Four bit machines may also operate the display module.  Initialization is crucial and this format should be closely followed.  As 4 bit operation requires that data be sent twice over the D4-D7 bus, memory requirements are doubled.  An advantage is the ability to embed all 4 data bits, RS and R/W in a standard 8 bit wide memory.  The 8 bit data bus demands at least 9 bits of memory.

(assuming R/W is held low)

4 bit, 1 line, 5 x 7…2, 0, 2, 0, 0, 6, 0, E, 0, 1

NOTE:  The single terminating ’1′ is crucial.

For 5 x 10 or 2 lines change the repeated 20 code to repeated 24 or 28.
ie.  2, 4, 2, 4, 0, 6,  E, 0, 1 etc.

Sample Programs
Here is a program which illustrates the simplicity of the LCD modules.  The program writes two lines to the display, pausing after the first one is transmitted.  The program is provided in both 8 and 4 bit versions.  Display initialization must be complete before transmitting these codes.  A star below a particular data code indicates a command and therefore RS must be set Low.  All other entries set RS High.
8 bit (line 1)
20,20,53,48,45,4C,4C,59,27,53  Pause now or send OE.
S H E L L Y ‘ S(line 2)
C0,4C,43,20,4D,4F,44,55,4C,45,53  Pause now or send OE.
L C  M O D U L E S

To transmit this program on a 4 bit data bus, initialize properly and then double enter the 8 bit code.

ie.  5,3,4,8,4,C,4,C,5,9 etc.
Each 4 bit entry must be accompanied by an enable pulse to latch the data.


Control Codes LCD MODULE CONtrOL CODES WITH “RS” LINE=0
cellpadding=0 cellspacing=0>

cellspacing=0>

C0 00000001 Clear display and memory, home cursor
02 00000010 Home cursor, also returns display to original position
03 00000011 Home cursor, also returns display to original position 4
04 00000100 Cursor and display travel upon data entry to the left
05 00000101 Shift display with data entry to the right
06 00000110 Cursor travel upon data entry to the right
07 00000111 Shift display with data entry to the left
08 00001000 Display and cursor “OFF” (all memory retained)
09 00001001 Do not use
0A 00001010 Display and cursor “OFF” (all memory retained)
0B 00001011 Display “OFF”
0C 00001100 Display “ON”, cursor “OFF”
0D 00001101 Display “OFF”, lf/CR (line feed, carrier return)
0E 00001110 Display “ON”, cursor line “ON”
0F 00001111 Display “ON”, block and line “ON”
10 00010000 Shift cursor to the left
11 00010001 Shift cursor to the left
12 00010010 Shift cursor to the left
13 00010011 Shift cursor to the left
14 00010100 Shift cursor to the right
15 00010101 Shift cursor to the right
16 00010110 Shift cursor to the right
17 00010111 Shift cursor to the right
18 00011000 Shift display without data to the left
19 00011001 Shift display wthout data to the left
IC 00011100 Shift display without data to the right
ID 00011101 Do not use
lE 00011110 Do not use
IF 00011111 Do not use
20 00100000 One line 5×7 format (4 bit data bus)
24 00100100 One line 5×10 format ( 4 bit data bus)
28 00101000 Two line 5×7 format (4 bit data bus)
30 00110000 One line 5×7 format (8 bit data bus)
34 00110100 One line 5×10 format (8 bit data bus)
38 00111000 Two line 5×7 format (8 bit data bus)
80 10000000 Home first line
C0 11000000 Home second line
80 to 8F Top line 16 characters
80 to 97 Top line 24 characters
80 to A7 Top line 40 characters
C0 to CF Second line 16 characters
C0 to D7 Second line 24 characters
C0 to E7 Second line 40 characters

Programming the Custom Character Generator RAM(Eight User Created Custom Characters)
The character generator (CG) RAM allows eight custom 5×8 characters or four custom 5×11 characters to be user created and programmed. Once programmed, the newly-created characters or symbols are accessed exactly as if they were in ROM. However, since RAM is volatile memory, power must be continuously maintained. Otherwise, the programming format must be programmed into non-volatile external ROM and sent to the display following each display initialization. All dots of the character matrix may be programmed, including the cursor position, if desired.


The module’s RAM is divided into two parts: data display and character generator (not to be confused with 192-character generator ROM). The CG portion of RAM is located between hex 40 and 7F, and -is contiguous. Locations 40 thru 47 hold the first custom CG character, 48 thru 4F the second, 50 thru 57 the third, and so forth, to 78 thru 7F for the eighth custom CG character. If, during initialization, the display was programmed to automatically increment, then only the single initial address, 40, need be sent. Consecutive row data will automatically appear at 41, 42, etc. until the complete character is formed. All 8 custom CG characters can be programmed in 64 consecutive “writes” after sending the single initial address 40.

CG RAM is 8 bits wide, although only the right-most 5 bits are used for a custom CG character row. The left-most dot of the character row corresponds to D4 in the most significant nibble (XXXD4) of the data bus code with the remaining 4 dots in the row corresponding to the least significant nibble (D3 thru D0), D0 being the right-most dot. Thus, hex 1F equals all dots on and hex 00 equals all dots off. Other examples include hex 15 (HLHLH) equal to 3 dots on and hex 0A (LHLHL) equal to 2 dots on. In each case, the key 5 bits of the 8-bit code, program one row of custom CG character. When all 7 or 8 rows are programmed, that character is complete. A graphic example is shown below.



Note: addressing not now required, hex 48 is next in the sequence.