What are sequence to initialize HD44780

Status
Not open for further replies.

Daljeet12

Member level 4
Joined
Jun 16, 2018
Messages
78
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
648
What are sequence to initialize HD44780 display device ?
.
https://www.sparkfun.com/datasheets/LCD/HD44780.pdf

Details are given in page 42 to initialize in 4 bit mode but the table it seems confusing me

1. Display clear
2. Function set:
3. Display on/off control:
4. Entry mode set: Increment

What are sequence to initialize HD44780 in 4 bit mode ?
 

Hi,

I assume there are millions of examples, code examples, design notes, descriptions, even video tutorials.
Maybe the most often explained item....

The datasheet tells all you need to know.
You say it's confusing, but don't tell what is confusing to you.

Why don't you just use available code, use code examples....
You also could try to write your own code...test your code ... and if it does not work as expected:
* show your code
* show your schematic
* tell us what you expect
* tell us what not is like expected

Klaus
 

My question is in the context of datasheet. I have only one question I do not understand table given in page 42

Hi,
The datasheet tells all you need to know.
You say it's confusing, but don't tell what is confusing to you.Klaus
I said table given in page 42 is confusing me. I do not understand the sequence given for 4 bit mode which sequence I will need if I want to operate it without a any microcontroller.
 

Hi,

Table12 shows the sequence. It shows the steps, the signals, the order...
I really don't know what is unclear.

You may go on speaking in riddles...you risk that nobody can answer your question.

The sequence is for the display to operate as desired, not for the microcontroller.
But may I ask how you want to operate a display without a microcontroller? ...or at least something similar to a microcontroller.

Klaus
 

I do not understand table given in page 42

This is the bit mappings of the data/control pins, necessary to configurate and or opperate the LCD; there is no much to 'understand' there, just set these pins acording timmings and order defined at flowcharts on pages 45 and 46.

I do not understand the sequence given for 4 bit mode

Keep in mind that as default, the LCD is set to 4-bit mode.

if I want to operate it without a any microcontroller.

Maybe you are more confused than you thought; You won't succeed without any minimally elaborate state machine (in this case, a microcontroller.) to interface with the LCD controller chipset.
 
figure 24 4 bit interface

To initialize in 4-bit mode following commands should be used:

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
delayms(15);
lcd cmd(0x03);  //000011
delayms(5); 
lcd cmd(0x03);  //000011
delay ms(1);    
lcd_cmd(0x03);  //000011
delay ms(1); 
lcd cmd(0x02);  //000010   Sets to 4-bit operation
delay ms(1);
 
lcd cmd(0x08);  // Turn off display
lcd cmd(0x01);  //Clear display delay;
lcd_cmd(0x06);  //Set cursor move direction




Did i miss a any sequence ?
 

The sequence isn't correct for 4-bit mode software initialization. The first four "lcd_cmd" writes are 8-bit-like commands with single E cycle, after setting 4-bit mode, you are using 4-bit commands with dual E cycle. If lcd_cmd() is a dual cycle write, you need a different function for single cycle action. Please implement the "initializing by instruction" code more exactly.

Keep in mind that as default, the LCD is set to 4-bit mode.
Not quite right. The internal reset defaults to 8-bit mode. If you can rely on it, part of the init sequence can be bypassed. It's however usually assumed that the power on timing may not result in a successful reset and registers have arbitrary content, thus it's a good idea to perform the complete software initialization.
 

Below is the original Hitachi specification. How can you use a function lcd_cmd() both for 8-bit and 4-bit writes? Please show your implementation of lcd_cmd().

 
How can you use a function lcd_cmd() both for 8-bit and 4-bit writes? Please show your implementation of lcd_cmd().


I would expect this type of function


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void lcd_cmd( int cmd, int ms)
{
   RS = Low;
   R/W = Low; 
   lcdcommand = cmd;
   EN = High; 
   delayms(ms); 
   EN = Low; 
}
Void main ()
{
    void lcd_cmd( 0x03 , 2);
    void lcd_cmd( 0x03 , 2);
    void lcd_cmd( 0x02 , 2);
}



This is not a complete code. But this idea is on my mind. I will make functions, one will pass the command and another will pass the data
 

The function is o.k. for 8-bit mode. In 4-bit mode, you'll send two nibbles sequentially.
 

Hi,

Again just incomplete code.
I can't find out what "lcdcommand" means...and how your wiring is.

Your delay is inbetween EN =1 and EN = 0. For this time the datasheet says PW_EH_min = 230ns. Maybe a NOP is sufficient.
Depending on microcontroller and it's clock frequency ... which we don't know.
Your delay function is in milliseconds .... every millisecond (granularity) = about 4000 times PW_EH_min.

Klaus
 

Hi,

Page 22, section Interfacing to the MPU
And also in the 4-bit initialisation section.

Klaus
 

It is also a good idea to implement checking the Busy Flag when writing to the LCD-display.

This way you are always ready for the next command, and it is not necessary to add delays.

Some of the commands take longer time to execute for the LCD, and reading the BF will automatically adjust the driver to that.

TOK
 

Hi,

Page 22, section Interfacing to the MPU
And also in the 4-bit initialisation section.

Klaus

Let us take the example
The 8-bit data is 0100 0001.
In 4-bit mode, we split the 8-bit value into two 4-bit parts
This will 0100 send first and then this will send 0100

RS = Low;
R/W = Low;
lcdcommand = 0100 0001;
EN = High;
delayms(ms);
EN = Low;

This is how i should send
 

Hi,

Your example is useless without port setup...
This will 0100 send first and then this will send 0100
How is this done in your code.

Strictly follow Figure 9.

Klaus
 
Referring to the previous code, I would suggest something like

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void lcd_cmd2(int cmd, int ms)
{
   RS = Low;
   R/W = Low; 
   lcdport = cmd >> 4;
   EN = High; 
   delay_us(1); 
   EN = Low; 
   delay_us(1); 
   lcdport = cmd & 0xf;
   EN = High; 
   delay_us(1); 
   EN = Low; 
   delay_ms(ms); 
}

 
Referring to the previous code, I would suggest something like

I have improved my code a bit. Hopefully this will help me understand 4 bit mode

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
//PIC16F877A and Xc8  
// CONFIG
#pragma config FOSC = HS        // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = ON        // Watchdog Timer Enable bit (WDT enabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)
 
// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.
 
#define _XTAL_FREQ 20000000 //Specify the XTAL crystal FREQ
#include <xc.h>
 
#define RS         RB1
#define RW         RB2
#define EN         RB2
#define lcdport    PORTA
 
void  initialize (void)
{
   PORTA = 0;
   PORTB = 0;
   TRISA = 0b00000000;
   TRISB = 0b00000000;  
 
}
 
void Delay_us (int us)
{
    int i;
    for (i=0; i<us; i++)
    {
   
    }
}
void lcd_cmd(unsigned char cmd)
{
   RS = 0;
   RW = 0; 
   lcdport = cmd >> 4;
   EN = 1; 
   Delay_us(1); 
   EN = 0; 
   Delay_us(1); 
   
   lcdport = cmd & 0xf;
   EN = 1; 
   Delay_us(1); 
   EN = 1; 
   Delay_us(1); 
}
 
void main(void)
{
    
    //initialize port pins
    initialize ();   
    lcd_cmd (0x03);
       
    while(1)
    {
  
    }
    return;
}

 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…