Getting hex values for an HD44780 LCD

I've been trying to get my LCD screen working , and so I've been looking all over the internet for resources. I like the LiquidCrystal library here, but the lack of a second line made me search for something more. I found this really great site: http://home.iae.nl/users/pouweha/lcd/lcd0.shtml#instruction_set That has everything I'll ever need. Unfortunately, it's written for a PIC in... assembly? So I don't understand a whole lot of what's going on. I looked through his code and saw that lcd.commandWrite(0x38) would initialize a 2 line screen, unfortunately, it initializes a 2-line, 40 character screen, while I have a 16 character. What I want to know is, where did this 0x38 come from? I don't understand how to get this number. Also things like:

    MOVLW       0x000               ; disp.off, curs.off, no-blink
    CALL        LCDDMODE
    CALL        LCDCLEAR
    MOVLW       0x004               ; disp.on, curs.off
    CALL        LCDDMODE
LCDEMODE
    ANDLW       0x003               ; Strip upper bits
    IORLW       0x004               ; Function set
    CALL        LCDPUTCMD
    RETURN

How is he getting the numbers used to turn the cursor on/off and blink on/off? I know that chart in the first link lists those, but I don't get how to figure out the numbers. Thanks!

The Hitachi LCD controller chip is initialized for the number of lines, not the number of characters. Here are values for one and two line displays in 4bit and 8bit modes.

define LCD_FUNCTION_4BIT_1LINE 0x20 // 4-bit interface, single line, 5x7 dots

define LCD_FUNCTION_4BIT_2LINES 0x28 // 4-bit interface, dual line, 5x7 dots

define LCD_FUNCTION_8BIT_1LINE 0x30 // 8-bit interface, single line, 5x7 dots

define LCD_FUNCTION_8BIT_2LINES 0x38 // 8-bit interface, dual line, 5x7 dots

I would think that changing

define init1 0x30

to

define init1 0x38

in LiquidCrystal.cpp would make your two line display work.

You may also want to look at the lcd4bit library in the playground, it does support two line displays, frees up four pins, and there is plenty of documentation around showing how to connect it up.

There is a good overview of the Hitachi controller here: http://www.myke.com/lcd.htm

And if you want even more info, google the Hitachi 44780 datasheet

Have fun!

Ok, so the second line always starts at character 41? That helps, here's what I've got so far now: It displays the current song from iTunes (Down, Down, Down, To Mephisto's Cafe in that picture), it displays playing or pause (> or ") and it displays the time and time remaining. If the title is longer than 16 characters it also scrolls.

But I'm still not sure how to get those magic numbers. So, I can accept that 0x38 and 0x30 are constants (are they?), but how about something like turning the display on and off? Or the cursor? Or the cursor blink? That link you sent says "Write 0x010 to turn off the Display", why 0x010? Where does that come from?

it comes from the datasheet for the Hitachi 44780 chip http://www.datasheetcatalog.org/datasheets/400/81271_DS.pdf

The control instructions are about halfway in, (page 24 or so in that pdf)

Ok, I got it figured out. What I really wanted to know was what to do with those numbers. With some help I was able to get it, so looking at a chart like the one in my first post or in that datasheet, say you wanted to turn the screen on, the cursor on, and blink on. That would be 1111, if you wanted the screen on, the cursor off and blink off, it would be 1100, then each of those are just converted to decimal (15 and 12 receptively) and you use that number in commandWrite. Hope that helps if anyone had the same question

Hmm, I didn’t realize that:

But I’m still not sure how to get those magic numbers…That link says “Write 0x010 to turn off the Display”, why 0x010? Where does that come from?

Was a question about how to use those numbers in a program.

Anyway, glad you figured it out.

You will be pleased to know that you don’t need to convert the numbers into decimal, you can write the hex value directly into the command. These examples are from the lcd4bit source code in the playground:

//command bytes for LCD
#define CMD_CLR 0x01
#define CMD_RIGHT 0x1C
#define CMD_LEFT 0x18
#define CMD_HOME 0x02

commandWrite(CMD_CLR); to clear the screen

but you can also write binary values, for 1111 in your example you would
commandWrite(0b1111);

A tip is to check out existing source code for doing something similar to what you want to see if you can find examples and techniques that you can adapt into your own code.

Have fun!