Just to follow up, on the "3 commands",
There really aren't always 3 commands. E is humped 3 times but depending on the LCD mode,
There are either 3 commands or two commands that are processed by the LCD depending on the lcd state when the sequence is started.
-
in 8 bit mode (3 commands)
goto 8 bit mode (essentially a nop as LCD is already in 8 bit mode)
goto 8 bit mode (essentially a nop as LCD is already in 8 bit mode)
goto 8 bit mode (essentially a nop as LCD is already in 8 bit mode) -
in 4 bit mode and in sync with host; lcd expecting first nibble (2 commands)
goto 8 bit mode (sent as 2 nibbles since lcd is in 4 bit mode) - puts lcd into 8 bit mode
goto 8 bit mode (LCD receives this as an 8 bit command as lcd is already in 8 bit mode - essentially a nop) -
in 4 bit mode and out of sync with host; lcd expecting 2nd nibble (2 commands
GARBAGE command (1st byte sent completes unknown command - which is why first delay is so long
goto 8 bit mode (sent as 2 nibbles since lcd is in 4 bit mode) - this puts lcd into 8 bit mode.
So it really does take three "attempts" to reliably put the LCD into 8 bit mode.
--- bill