LCD Initialization

Before using the LCD for display purpose, LCD has to be initialized either by the internal reset circuit or sending set of commands to initialize the LCD. It is the user who has to decide whether an LCD has to be initialized by instructions or by internal reset circuit. we will dicuss both ways of initialization one by one.
Initialization by internal Reset Circuit
An internal reset circuit automatically initializes the HD44780U when the power is turned on. The following instructions are executed during the initialization. The busy flag (BF) is kept in the busy state until the initialization ends (BF = 1). The busy state lasts for 10 ms after VCC rises to 4.5 V.
  • Display clear
  • Function set:
    DL = 1; 8-bit interface data
    N = 0; 1-line display
    F = 0; 5 x 8 dot character font
  • Display on/off control:
    D = 0; Display off
    C = 0; Cursor off
    B = 0; Blinking off
  • Entry mode set:
    I/D = 1; Increment by 1
    S = 0; No shift


Note: If the electrical characteristics conditions listed under the table Power Supply Conditions Using Internal Reset Circuit are not met, the internal reset circuit will not operate normally and will fail to initialize the HD44780U. For such a case, initial-ization must be performed by the MCU as explained in the section, Initializing by Instruction.

As mentioned in the Note, there are certain condtions that has to be met, if user want to use initialization by internal reset circuit. These conditions are shown in the Table 5 below.


Table 5: Power Supply condition for Internal Reset circuit

Figure 7 shows the test condition which are to be met for internal reset circuit to be active.


Figure 7: Internal Power Supply reset



Now the problem with the internal reset circuit is, it is highly dependent on power supply, to meet this critical power supply conditions is not hard but are difficult to achive when you are making a simple application. So usually the second menthod i.e. Initialization by instruction is used and is recommended most of the time.

Initialization by instructions
Initializing LCD with instructions is really simple. Given below is a flowchart that describles the step to follow, to initialize the LCD.


Figure 8: Flow chart for LCD initialization



As you can see from the flow chart, the LCD is initialized in the following sequence...

  1. Send command 0x30 - Using 8-bit interface
  2. Delay 20ms
  3. Send command 0x30 - 8-bit interface
  4. Delay 20ms
  5. Send command 0x30 - 8-bit interface
  6. Delay 20ms
  7. Send Function set - see Table 4 for more information
  8. Display Clear command
  9. Set entry mode command - explained below

The first 3 commands are usually not required but are recomended when you are using 4-bit interface. So you can program the LCD starting from step 7 when working with 8-bit interface. Function set command depends on what kind of LCD you are using and what kind of interface you are using (see Table 4 in LCD Command section).
LCD Entry mode:
From Table 3 in command section, you can see that the two bits decide the entry mode for LCD, these bits are:
a) I/D - Increment/Decrement bit
b) S - Display shift.
With these two bits we get four combinations of entry mode which are 0x04,0x05,0x06,0x07 (see table 3 in LCD Command section). So we get different results with these different entry modes. Normally entry mode 0x06 is used which is No shift and auto incremement. I recommend you to try all the possible entry modes and see the results, I am sure you will be surprised.

Programming example for LCD Initialization
LCD_data equ P2    ;LCD Data port
LCD_D7   equ P2.7  ;LCD D7/Busy Flag
LCD_rs   equ P1.0  ;LCD Register Select
LCD_rw   equ P1.1  ;LCD Read/Write
LCD_en   equ P1.2  ;LCD Enable

LCD_init:
         mov   LCD_data,#38H  ;Function set: 2 Line, 8-bit, 5x7 dots
         clr   LCD_rs         ;Selected command register
         clr   LCD_rw         ;We are writing in instruction register
         setb  LCD_en         ;Enable H->
L
         clr   LCD_en
         acall LCD_busy       ;Wait for LCD to process the command
         mov   LCD_data,#0FH  ;Display on, Curson blinking command
         clr   LCD_rs         ;Selected instruction register
         clr   LCD_rw         ;We are writing in instruction register
         setb  LCD_en         ;Enable H->
L
         clr   LCD_en
         acall LCD_busy       ;Wait for LCD to process the command
         mov   LCD_data,#01H  ;Clear LCD

         clr   LCD_rs         ;Selected command register
         clr   LCD_rw         ;We are writing in instruction register
         setb  LCD_en         ;Enable H->
L
         clr   LCD_en

         acall LCD_busy       ;Wait for LCD to process the command
         mov   LCD_data,#06H  ;Entry mode, auto increment with no shift
         clr   LCD_rs         ;Selected command register
         clr   LCD_rw         ;We are writing in instruction register

         setb  LCD_en         ;Enable H->
L
         clr   LCD_en
         acall LCD_busy       ;Wait for LCD to process the command
         ret                  ;Return from routine

Now we can do the same thing in C, I am giving example using Keil C. Similar code can be written for SDCC.

#include <AT89X51.H>
.
#define LCD_data P2
#define LCD_D7   P2_7
#define LCD_rs   P1_0
#define LCD_rw   P1_1
#define LCD_en   P1_2

void LCD_init()
{
     LCD_data = 0x38;     //Function set: 2 Line, 8-bit, 5x7 dots
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->
L
     LCD_en   = 0;
     LCD_busy();          //Wait for LCD to process the command
     LCD_data = 0x0F;     //Display on, Curson blinking command
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->
L
     LCD_en   = 0;
     LCD_busy();          //Wait for LCD to process the command
     LCD_data = 0x01;     //Clear LCD
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->
L
     LCD_en   = 0;
     LCD_busy();          //Wait for LCD to process the command
     LCD_data = 0x06;     //Entry mode, auto increment with no shift
     LCD_rs   = 0;        //Selected command register
     LCD_rw   = 0;        //We are writing in data register
     LCD_en   = 1;        //Enable H->
L
     LCD_busy();

}

With the help of the above code, you are able to initialize the LCD. Now there is a function/subroutine coming in the code i.e. LCD_busy, which is used to put delay for LCD so that there should not be any command or data sent to the LCD untill it finish executing the command. More on this delay routine is explained in the next section.

Share it! Like it!

Conversation

Mon May 04 2015, 09:06 AM
wasim
hi all , im doing my attendance project using EM-18 rfid ,my project issue is when the card is swiped its not getting read , plz help me
Sat May 02 2015, 04:30 AM
sharmi
hi am electronic student am doing project in vehicle monitoring system with arm processor using can protocol.i need proteus simulation result output using can and arm for displaying temperature ,gas and ldr sensor value
ExperimenterUK
Fri May 01 2015, 09:24 PM
months ! is this a very big track or a very slow kart ?
Fri May 01 2015, 06:40 AM
shaygan
Hey I am s mechanical eng student and I would like to make a countdown clock for my go-kart team but we need more digits , like MM,WW, DD, HH , mm , ss , ms (month , week , day , hour , minute , sec , milli sec) .. can anybody help and tell me to how make such thing in big scale ?
ExperimenterUK
Mon Apr 27 2015, 08:14 PM
@Janvier This project is in assembly. It is unlikely anyone has a 'c' code
Mon Apr 27 2015, 04:47 PM
Janvier
hello! can u help me to find c code for a project called " automatic light controller with visitor counter". Best regards.
ExperimenterUK
Mon Apr 27 2015, 05:27 AM
@mostfa.. it's a browser thing. Check your settings/try another browser.
Sat Apr 25 2015, 06:16 AM
rohan_verma
sir this circuit is tested?can i use it directly on developing PCB
Sat Apr 25 2015, 06:13 AM
rohan_verma
MSCOMM32.ocx cannot be copied in the systems folder even with administration rights.
Fri Apr 24 2015, 01:58 AM
mostfa
please fix the LCD Interfacing Tutorial as all pictures is gone

Downloads

Comments

manmanan120
Tue May 05 2015, 01:34 PM
Santhoshkumar458
Mon May 04 2015, 11:19 AM
israelo
Sun May 03 2015, 11:57 AM
djsamfisher
Fri May 01 2015, 07:15 AM
0pus0ne
Wed Apr 29 2015, 11:10 PM
ingsilor
Tue Apr 28 2015, 01:13 PM
Seven
Thu Apr 23 2015, 12:02 AM
killbillpandey
Wed Apr 22 2015, 09:07 PM

Online

Guests: 45, Members: 0 ...

most ever online: 182184
(Members: , Guests: 182184) on 06 Aug 2010: 05:37 AM

Members: 37635
Newest member: manmanan120
Forum Activity
ExperimenterUK Avatar
Posted By ExperimenterUK
Tue May 05 2015, 05:58 PM
What if we took ceramic capacitor of higher values...
ankitbajaj01 Avatar
Posted By ankitbajaj01
Mon May 04 2015, 05:02 PM
@Electrolytic Capacitor...Putting 220uF cap at 14V...
ankitbajaj01 Avatar
Posted By ankitbajaj01
Mon May 04 2015, 04:58 PM
Hello ExperimenterUK...@Ceramic CapacitorWhat if w...
ElectronicManiac Avatar
Posted By ElectronicManiac
Mon May 04 2015, 04:13 PM
I tried making a proteus file but it is not simula...
ElectronicManiac Avatar
Posted By ElectronicManiac
Mon May 04 2015, 04:11 PM
I tried making a proteus file but it is not simula...
ExperimenterUK Avatar
Posted By ExperimenterUK
Sun May 03 2015, 06:12 PM
How the value of this capacitor helps? Does smalle...
ankitbajaj01 Avatar
Posted By ankitbajaj01
Sun May 03 2015, 04:34 PM
Hello ExperimenterUK...Attaching the existing powe...
ExperimenterUK Avatar
Posted By ExperimenterUK
Thu Apr 30 2015, 10:03 PM
But Let me know that if I place 2200uF cap instead...
ankitbajaj01 Avatar
Posted By ankitbajaj01
Thu Apr 30 2015, 05:51 PM
Hello ExperimenterUK...I will be showing you the p...
ExperimenterUK Avatar
Posted By ExperimenterUK
Wed Apr 29 2015, 08:33 PM
Hello ExperimenterUK...My confidence gets boost up...