Clarification on HD44780 20x4

Discussion in 'Embedded Systems and Microcontrollers' started by dmarciano, Apr 26, 2012.

  1. dmarciano

    Thread Starter Member

    Oct 10, 2007
    21
    0
    I'm planning on using a 44780 20x4 LCD display in my project. I've laid out all the messages that will need to be display and the 20x4 will work really nicely. I controlling the display with a PIC from Microchip in 4-bit mode. I've only worked with 16x2 displays in the past and I'm having some trouble understanding the 20x4 since all the books I have, example codes I've found online, all use the 16x2. So I have two questions:

    The command for setting the interface (8-bit/4-bit), display lines, and character font is 001DNF** where:

    D - Interface length; 1=8-bit 0=4-bit
    N - Number of display lines; 1=2 0=1
    F - Character font; 1=5x10 0=5x7

    So if I have a 20x4 display, how do I indicate 4 lines instead of just one or two? Do I just set it to 2 lines?

    The second question I have is that according to the book I have on 44780-devices the start address of each line is:

    1st line - 00H
    2nd line - 40H
    3rd line - 20H
    4th line - 40H

    This doesn't make sense that the 2nd and 4th line start at the same address. I got this from the book "Programming and Customizing the PIC Microcontroller 3rd Edition". However on a website I found they list it as this:

    1st line - 00H
    2nd line - 40H
    3rd line - 14H
    4th line - 54H

    I found this at http://www.8052.com/tutlcd2.php. This seems to make more sense because, as I understand it, the 3rd line is a continuation of the 1st line and if a string more then 16 characters is written to the 1st line, it will automatically wrap to the 3rd. This also the reason why, I assume, you need to select 2 lines when initializing the LCD module?

    Are my assumptions with this device correct? If I got something wrong I look forward to hearing the correct way to do this (especially the starting address of each line since I will be writing different data to each line so it is important for me to know this). I wish the datasheet was a little more clear on this.

    The datasheet I found for the 44780 doesn't address either of these two points specifically.

    Thanks in advance for any help in this matter.
     
  2. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,361
    The interface for 16x2, 20x2, 20x4 etc is the same.
    Treat the interface as if it were 128x1.
    For a 2-line display the second line begins at the 64th position.

    For a 4-line display, lines 1 and 3 will occupy the first 64 locations.
    Hence line 1 begins at position 0 = 00H
    Line 3 begins at position 20 = 14H

    Lines 2 and 4 occupy the second 64 locations.
    Hence line 2 begins at position 64 = 40H
    Line 4 begins at position 84 = 54H

    To move the cursor directly to any position, add 128 = 80H to the positions given above and send this to the instruction register.
    You do not have to use hex values. You can use decimal values if you desire.
     
    Last edited: Apr 26, 2012
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    A 20X4 display is actually a 40X2 display. 40 characters ´ 2 lines in the LCD controller are converted into 20 characters ´ 4 lines on the LCD panel. Consequently, the end address of line 1 and the start address of line 3 are consecutive. Also, the end address
    of line 2 and the start address of line 4 are consecutive.
    [​IMG]
     
  4. dmarciano

    Thread Starter Member

    Oct 10, 2007
    21
    0
    So then I would be correct in the assumption that a 21 character string written starting at the begin of line 1 would continue into line 3, but a 41 character string would not wrap to the 2nd line but would start overwriting line 1 again, correct?
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I am not sure. But if you set up the display to auto increment the DD RAM pointer. The 41 character string would end on line two first postion I think
     
  6. MrChips

    Moderator

    Oct 2, 2009
    12,440
    3,361
    A 41-character string would show 20 characters on line 1, 20 characters on line 3.
    The 41st character would not appear on the screen.

    I have a 20x4 display and would have to test this to be certain.
     
    Last edited: Apr 26, 2012
  7. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    I did a test. To me it seems like MrChips was correct. On my display if fills up line 1 and 3. But then nothing is written to the dispaly. And that is because line 2 start at adress 40 hex. That is 64 decimal(DoH). I mixed things up. Setting the display on auto increment and writing a very long string (index starting at 0). It will write to line 1 and 3 as said before. Everything from postion 40 to 63 decimal will be written into nothing. Then it will start to fill up line 2. Hope I got it correct now
     
  8. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,388
    1,605
Loading...