Start with the Data Sheet for the HD44780U Notice that the power up reset, although it does leave the display in a very nice state (page 23), depends on a power supply situation that may or may not be realistic: Rise time from 0.2 to 2.7 or 4.5 volts must be between 0.1 and 10 milliseconds (as per page 50 and 53) for the hardware reset to work.
Given that the display may not come up as reliably as your processor, it's probably best to reset the display by sending it commands. To send a command, you need to hold the E, and R/W lines low, the RS line high, and place the command on the data wires for at least 60ns (tAS page 58 and 49). The 44780 has 8 datalines, which allows any ASCII character and any of the 200 some odd command values to be sent in one cycle, but because io pins are often in short supply, it also supports a 4 bit mode where only the upper 4 data lines are used, but we will get into that more in a minute. Next, bring E high for at least 195nS (tDSW) before dropping it back and, finally, holding the data lines, RS and R/W as before for at least another 20 nS (tAH > tH)
The commands to Initialize the display are described on page 45 (for 8 bit interface) or 46 (for 4 bit interface).
Note that the sequence is the same until you set the bit width in the Function set command, except that if you are using a 4 bit interface, you are setting DB4-DB7 to 0x03 (3 decimal) and not worrying about DB0-DB1. Wasn't it smart of them to make the reset sequence NOT use the lower 4 bits? :o)
Now we can setup the display with the "Function set" command (page 24 and 27). This command is unique because the upper 3 bits (DB7, 6, and 5) are set to 0 0 1. If you are going to use all 8 data lines to talk to the chip, you will send this command with the "DL" or "Data Length" bit (in the DB4 position) set, and that bit will be cleared if you will use only the upper 4 lines (DB7-DB4) to transfer first the high nibble, then the low nibble of each byte of data. You also have to select between the 5x8 and 5x10 pixel fonts, but the 5x10 font is only available on special one line displays . And you must select the number of display lines, but since a 1 line display will work just fine (on the first line) with the 2 line bit set as long as you use the 5x8 font, we almost always just clear "F" and set "N". So use 0x38 (56 decimal) for 8 bit interface and 0x28 (40 decimal) for 4 bit.
If you clear the DL bit, putting the display into 4 bit data transfer mode, then you have to start pulsing the E line twice for each command, placing the upper 4 bits of your data on DB7-DB4 for the first pulse, and the lower 4 bits of your data on those same wires for the second pulse. Since these 4 bit transfers don't start until after that bit is set, you actually have to send the "Function set" command twice: once while still in 8 bit mode using just one pulse on E, where the N and F bits are lost (because you couldn't set DB3-DB0) then again in 4 bit mode using two pulses on E, to set or clear the N and F settings. That was a total of three pulses on E for the two Function set commands because the first one was in 8 bit mode and the second was in 4 bit mode. Other than that, operation continues the same in 8 or 4 bit mode; the only difference is the extra cycle to transfer the lower nibble of each byte of data when in 4 bit mode.
Now that we have the chips attention and have established full communications with it, we can finish up the initialization. The data sheet actually says you must do it like this: Display off, Clear display, Entry mode set, but a lot of people seem to get away with turning the display on (with or without cursor / blink) right at the start or doing other funky things. Since it's just one extra command, following the datasheet exactly is recommended.
Once the display is setup and running, here are some commands you probably want to use. We will list them as defines since that format is probably the most useful.
#define LCDClearDisplay 1 #define LCDCursorHome 2 #define LCDOff 8 ;0x08 turn the display (and the cursor) off. #define LCDOn 12 ;0x0C Turn on the display, but without a cursor #define LCDCursorOn 14 ;0x0E Turn on the cursor (as an underline) as well as the display #define LCDCursorBlink 15 ;0x0F Turn on a blinking block cursor as well as the display #define LCDCursorLeft 16 ;0x10 Move the cursor left by one character #define LCDCursorRight 20 ;0x14 Move the cursor right one letter #define LCDShiftLeft 24 ;0x18 Shift the entire display left one character #define LCDShiftRight 30 ;0x1C Shift the entire display right one character #define LCDGoto 128 ;0x80 Add the location of the character position ; to which you wish to move the cursor
Instead of moving the cursor with home, left, and right commands, you can also set the cursor by sending a command with a value of 128 plus the character location to which you wish to move the cursor. The locations on a four line displays often have an odd arrangement. e.g. On a 20x4 dsplay they are addressed thus (hex addresses):
Line 1: 0x00, 0x01, 0x02 .. 0x13
Line 2: 0x40, 0x41, 0x42 .. 0x53
Line 3: 0x14, 0x15, 0x16 .. 0x27
Line 4: 0x54, 0x55, 0x56 .. 0x67
Switches can be shared with the data lines as long as they are connected via a large resistor to the data line pin and then on to the controller so that if they are pressed while writing data to the LCD, the signal from the controller can "override" the effect of the switch. See: Key Switch Encoding / Decoding: LCD Compatible
Peter [farmerpentium at CWCOM.NET] says:
Developing an LCD driver interface for the LM032LN display took me a lot longer than expected, especially UDGs, and I traced it to quirks in the HD44780A00.
Commands need to be sent twice for reliability. Characters output are no problem though.
The address position command for uploading UDG information needs not only repeating, but also given a settling time - I gave an arbitrary 1.5 ms after each command before sending data.
I also found that "ASCII" 00h, a UDG, is what the display writes as spaces, thus for a clean display this needs to be filled with blanks. Thus I've effectively got only 7 available UDG characters, not 8.
I also found that placing a bit of ferrite around the EN, RS and RW lines seems to help reliability - the circuit is on a breadboard at the moment.
Since the chip will not initialize using busy-polled command routines, I have to use a paced one for initializing, and for simplicity all commands sent are paced. So I'm using a paced driver for sending commands, and a busy-polled driver for sending character and UDG data.
The display is now working reliably, but its had a lot of aggro (over 80 chip rewrites in the course of debugging). So now instead of write piecemeal to the display I've employed the KISS principle, using RAM in the PIC 16F877 as a display buffer - use that and forget display idiosyncrasies... Periodically uploading that to the display takes just over 4 ms. All my PIC routines are interruptible, and the code is written for the PIC16F877.
I've got the EPE Feb-Mar 1997 articles "How to use intelligent LCDs" (and the original magazines), from the vendor of my displays have a photocopied datasheet for the LM032LN, from the internet have 2 or 3 datasheets for the HD44780, have AN587 and from various PIClist-derived websites have various peoples' comments on how-to with this display. It seems they are necessary, sadly. But all the way along, and especially on this list there have been complaints about difficulties with UDGs.
|file: /Techref/io/lcd/44780.htm, 12KB, , updated: 2016/12/4 00:21, local time: 2023/6/9 04:20,
|©2023 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?|
<A HREF="http://www.sxlist.com/techref/io/lcd/44780.htm"> Hitachi 44780, HD44780 LCD, HD44780, LCD Controller</A>
|Did you find what you needed?|
Welcome to sxlist.com!
& kind contributors
just like you!
Please don't rip/copy
Copies of the site on CD
are available at minimal cost.
Welcome to www.sxlist.com!