scifictus,
I went and actually looked at the library code.
It has some issues.
The 4 bit initialization sequence
is definitely wrong which is why it only reliably works from a power up reset.
It is amazing how few people really understand the hd44780 4 bit initialization sequence.
The main point of the sequence is to get the host and lcd back into nibble sync with each other.
His sequence only works if the device is in 8 bit mode, or is in 4 bit mode and already
in nibble sync.
I can work with you to fix it (as it should be a very simple fix)
but I'd prefer to work off line with you to get it resolved & tested so that only
the final working image is in this thread.
I'll also try to contact the original Author.
BTW, which IDE version are you working with?
Don,
Here is what I see:
Notice the nibble command sequence in his code:
which turns into either:
(if in LCD 8 bit mode)
- function set 8 bit mode LCD sees: 0x30
- function set 4 bit mode LCD sees: 0x20
- function set 4 bit mode LCD sees: 0x28
(if LCD in 4 bit mode and in sync)
- function set 8 bit mode LCD sees: 0x32
- function set 4 bit mode LCD sees: 0x28
(if LCD in 4 bit mode but not in sync)
- ???? LCD sees: 0x-3 (leftover upper nibble from previous command, lower nibble 3)
- function set 4 bit mode LCD sees 0x22
- sends a nibble of 0x8
[ LCD and host are now hopelessly out of nibble sync with each other forever until LCD reset]
In order to fix this, the nibble command sequence must be:
As this sequence forces the LCD back to 8 bit mode and then into 4 bit mode
and is guaranteed to get the host and LCD in sync regardless of whether
the LCD is in 8 bit mode, 4 bit mode in sync, or 4 bit mode and out of sync
when the sequence starts.
One thing I don't understand is why this LCD wouldn't work with the standard LiquidCrystal
library that is included with the IDE?
Maybe it requires extended the a few of the delays on some of the commands?
Other issues in this library code:
delayMicroseconds(100000);
100,000 is too large as that function takes an unsigned int which is limited to 16 bits.
(I corrected the code to use a loop with a smaller value
The code is calling waitBusy() after sending
the command to the LCD when it should be before.
This explains the unnecessary delays in the init code after
each command() call in the begin() routine.
These all look like pretty simple fixes and the resulting library
should work on standard hd44780 displays as well.
--- bill