+ Post New Thread
Results 1 to 19 of 19
  1. #1
    Member level 2
    Points: 518, Level: 4

    Join Date
    Jun 2018
    Posts
    53
    Helped
    0 / 0
    Points
    518
    Level
    4

    What are sequence to initialize HD44780

    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 ?

    •   AltAdvertisement

        
       

  2. #2
    Super Moderator
    Points: 80,975, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,421
    Helped
    3728 / 3728
    Points
    80,975
    Level
    69

    Re: What are sequence to initialize HD44780

    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
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  3. #3
    Member level 2
    Points: 518, Level: 4

    Join Date
    Jun 2018
    Posts
    53
    Helped
    0 / 0
    Points
    518
    Level
    4

    Re: What are sequence to initialize HD44780

    Quote Originally Posted by KlausST View Post
    Hi,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

    Quote Originally Posted by KlausST View Post
    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.



  4. #4
    Super Moderator
    Points: 80,975, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,421
    Helped
    3728 / 3728
    Points
    80,975
    Level
    69

    Re: What are sequence to initialize HD44780

    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
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  5. #5
    Super Moderator
    Points: 30,090, Level: 42
    andre_teprom's Avatar
    Join Date
    Nov 2006
    Location
    Brazil
    Posts
    8,978
    Helped
    1138 / 1138
    Points
    30,090
    Level
    42
    Blog Entries
    9

    Re: What are sequence to initialize HD44780

    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.
    --------------------------------------------------------------------------------------------------
    Part of the world that you live in, You are the part that you're giving ( Renaissance )


    1 members found this post helpful.

  6. #6
    Member level 2
    Points: 518, Level: 4

    Join Date
    Jun 2018
    Posts
    53
    Helped
    0 / 0
    Points
    518
    Level
    4

    Re: What are sequence to initialize HD44780

    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 ?



  7. #7
    Super Moderator
    Points: 264,095, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    46,147
    Helped
    14034 / 14034
    Points
    264,095
    Level
    100

    Re: What are sequence to initialize HD44780

    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.



    •   AltAdvertisement

        
       

  8. #8
    Member level 2
    Points: 518, Level: 4

    Join Date
    Jun 2018
    Posts
    53
    Helped
    0 / 0
    Points
    518
    Level
    4

    Re: What are sequence to initialize HD44780

    Quote Originally Posted by FvM View Post
    The sequence isn't correct for 4-bit mode software initialization.
    .
    But It's given in the datasheet

    look at here

    Click image for larger version. 

Name:	LCD 4 bit.jpg 
Views:	3 
Size:	107.8 KB 
ID:	157070



    •   AltAdvertisement

        
       

  9. #9
    Super Moderator
    Points: 264,095, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    46,147
    Helped
    14034 / 14034
    Points
    264,095
    Level
    100

    Re: What are sequence to initialize HD44780

    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().

    Click image for larger version. 

Name:	4-bit-init.PNG 
Views:	3 
Size:	61.1 KB 
ID:	157071


    1 members found this post helpful.

  10. #10
    Member level 2
    Points: 518, Level: 4

    Join Date
    Jun 2018
    Posts
    53
    Helped
    0 / 0
    Points
    518
    Level
    4

    Re: What are sequence to initialize HD44780

    Quote Originally Posted by FvM View Post
    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



  11. #11
    Super Moderator
    Points: 264,095, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    46,147
    Helped
    14034 / 14034
    Points
    264,095
    Level
    100

    Re: What are sequence to initialize HD44780

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



  12. #12
    Super Moderator
    Points: 80,975, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,421
    Helped
    3728 / 3728
    Points
    80,975
    Level
    69

    Re: What are sequence to initialize HD44780

    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
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  13. #13
    Member level 2
    Points: 518, Level: 4

    Join Date
    Jun 2018
    Posts
    53
    Helped
    0 / 0
    Points
    518
    Level
    4

    Re: What are sequence to initialize HD44780

    Quote Originally Posted by FvM View Post
    . In 4-bit mode, you'll send two nibbles sequentially.
    I don't understand it. Can you tell where it is written in the datasheet



  14. #14
    Super Moderator
    Points: 80,975, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,421
    Helped
    3728 / 3728
    Points
    80,975
    Level
    69

    Re: What are sequence to initialize HD44780

    Hi,

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

    Klaus
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.



  15. #15
    Full Member level 6
    Points: 4,327, Level: 15

    Join Date
    Nov 2005
    Location
    Norway
    Posts
    345
    Helped
    75 / 75
    Points
    4,327
    Level
    15

    Re: What are sequence to initialize HD44780

    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



  16. #16
    Member level 2
    Points: 518, Level: 4

    Join Date
    Jun 2018
    Posts
    53
    Helped
    0 / 0
    Points
    518
    Level
    4

    Re: What are sequence to initialize HD44780

    Quote Originally Posted by KlausST View Post
    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



    •   AltAdvertisement

        
       

  17. #17
    Super Moderator
    Points: 80,975, Level: 69
    Achievements:
    7 years registered
    Awards:
    Most Frequent Poster 3rd Helpful Member

    Join Date
    Apr 2014
    Posts
    16,421
    Helped
    3728 / 3728
    Points
    80,975
    Level
    69

    Re: What are sequence to initialize HD44780

    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
    Please donīt contact me via PM, because there is no time to respond to them. No friend requests. Thank you.


    1 members found this post helpful.

  18. #18
    Super Moderator
    Points: 264,095, Level: 100
    Awards:
    1st Helpful Member

    Join Date
    Jan 2008
    Location
    Bochum, Germany
    Posts
    46,147
    Helped
    14034 / 14034
    Points
    264,095
    Level
    100

    Re: What are sequence to initialize HD44780

    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); 
    }


    2 members found this post helpful.

  19. #19
    Member level 2
    Points: 518, Level: 4

    Join Date
    Jun 2018
    Posts
    53
    Helped
    0 / 0
    Points
    518
    Level
    4

    Re: What are sequence to initialize HD44780

    Quote Originally Posted by FvM View Post
    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;
    }



--[[ ]]--