Writing hex values to HD44780

I'm working on a project that involves interfacing an LCD with a PIC microcontroller. For now, I'm trying to get it working with an Arduino since I'm not familiar with how it works.

I'm having a really hard time understanding how to write hex values to the LCD in 4-bit mode. My understanding is that, to initialize it, I need to write 0x3 to the LCD three times, and then 0x2 once, with a 5ms delay in between each write. I wouldn't be surprised if I'm wrong, though.

So how do I do this in code?

What Kind of LCD module are you using?

snuu:
I'm working on a project that involves interfacing an LCD with a PIC microcontroller. For now, I'm trying to get it working with an Arduino since I'm not familiar with how it works.

I'm having a really hard time understanding how to write hex values to the LCD in 4-bit mode. My understanding is that, to initialize it, I need to write 0x3 to the LCD three times, and then 0x2 once, with a 5ms delay in between each write. I wouldn't be surprised if I'm wrong, though.

So how do I do this in code?

Are you using the Arduino "LiquidCrystal" library?

krupski:
Are you using the Arduino “LiquidCrystal” library?

I’m trying to get the LCD working without a library, since I want to learn how it works for a project with a PIC microcontroller.

snuu:
I'm trying to get the LCD working without a library, since I want to learn how it works for a project with a PIC microcontroller.

Then I would suggest that you study the datasheet.
The Hitachi data sheet fully describes in great detail what needs to be done.
See figures 23 and 24 on pages 45 and 46 of the datasheet.

The sequence that you initially described in your fist post is part of an initialization command sequence that is used when using 4 bit mode. What you described is incomplete and also not fully correct.
The sequence is a bit complicated because it is designed to ensure that when completed the LCD is in 4 bit mode regardless of what mode/state it was in when the host can only control data pins d4 to d7.
It does this by trying to get the LCD out of 4 bit mode into 8 bit mode to put it back into 4 bit mode .
It is done this way as there is no way to reset the LCD back to 8 bit mode and the LCD could be in any of 3 different states. 8 bit mode, 4 bit mode expecting first nibble, 4 bit mode expecting 2nd nibble.
So the only way to reliably get the LCD into 4 bit mode regardless of which mode the LCD might be in, when the host can only control data pins D4-D7, is to perform a specific sequence of commands.

If you are using 8 bit mode (controlling all 8 data pins) then the LCD is ready to go at power up.
To have robust initialization code, the code should perform a reliable sequence to ensure that the LCD is in 8 bit mode. This could be skipped and still work but the proper initialization sequence is very similar to the 4 bit initialization in that, when finished, it will ensure the LCD is in 8 bit mode regardless of the mode it currently is in when the command sequence is started.

-- bill

bperrybap:
Then I would suggest that you study the datasheet.
The Hitachi data sheet fully describes in great detail what needs to be done.
See figures 23 and 24 on pages 45 and 46 of the datasheet.

What do I do between instructions? Also, what do the various letters mean?

Also, what do the various letters mean?

Excellent question!

Do you have any particular letters in mind?

snuu:
What do I do between instructions?

Whatever you want.
You must honor the low level signal timing for the control and data lines. (see figures 25 and 26 page 58)
And you must honor the instruction timing for the specific instruction as noted in the flow chart.
After initialization is complete you must honor the instruction timings for each instruction as noted in table 6 on page 24. The clear display timing is missing but 2ms is typically used.

Also, what do the various letters mean?

I'm assuming the letters like N, F, I/D, S etc... in the flow chart?
Those are documented in various places, including table 6, and are used quite a bit throughout the datasheet.
You need to read more of the datasheet.
I'd suggest a full reading. It is only 60 pages.
The host interface section starts on page 22.

--- bill