Electronic – Power-up Initialization of HD44780 LCD Module

hd44780lcd

I'm using an HD44780 clone LCD module a KS0066U. Everything works ok on the module except when I rapidly power cycle the device (on->off->on). For some reason a very short interruption in the power causes the display module to improperly initialize as a 1-line LCD instead of a 2-line LCD display. What would cause this behavior? Is there any way to prevent it in software?

EDIT: I'm using the display controller in 4-bit mode not 8-bit mode.

Best Answer

I changed my initialization code so that it sent the upper 4-bit nibble of the function set command twice. Following which I resent the upper 4-bit nibble followed by the lower 4-bit nibble. This does not match the datasheet which seems to indicate that you can send the upper 4-bit nibble then send the function set command upper 4-bit followed by lower 4-bit.

// Works sometimes pseudo-code
port=0x20;
e=1; e=0;
port=0x20;
e=1; e=0;
port=0xC0;
e=1; e=0;

// Works all the time pseudo-code
port=0x20;
e=1; e=0;
e=1; e=0;
port=0x20;
e=1; e=0;
port=0xC0;
e=1; e=0;