HD44780 Command Codes

Never mind the fact that I've been spending the vast majority of evenings geeking out with Jeff Glass, we've made quite a bit of progress on the Arduino.

After figuring out the pinout on my LCD display on my last post, we then hooked it up to the Arduino, and it worked!  Unfortunatly, it only displayed text on one line, which is no good.  Reading through the data sheet for the HD44780, we realized that there is a ton of different codes you can send the LCD to do useful things (including turning on the second line).  The command code table is on page 24.

The table really isn't very clear, so we spent a lot of time stumbling around, only getting complete garbage on the screen.  Translating from the table's binary representation to decimal values was a pain in the ass, so we first off broke out the good old binconst.h trick to allow us to place binary constants straight in the code.  After futzing around for a while, we think we've figured out most of the command codes and what they do:
  • 12 - Turn off the cursor
  • 24 - scroll the text left, this is good because it's done by the controller and has much less flicker than doing it by lcd.clear(), lcd.printIn(string+1);
  • 28 - scroll the text right
  • 56 - turn on second line.  It divides the 80 byte buffer between the two lines, so to write on the second line, you need to make sure the printIn(string) string is 40 byes long for the first line, then it will print at the beginning of the second line.  How I'm handling this is I have a 40 char buffer for the first line, which I then copy text into, printIn it, then can print whatever I want, and will go onto the second line.
So those were the command codes we found useful.  We didn't bother to figure out how to undo them, since it was just easier to call lcd.init() again.  This is unlikely, but anyone have any of the other command codes out of that ridiculously cryptic table on the data sheet they found useful?

Popular Posts