Thursday, February 5, 2015

Murphy's Law about 4x40 LCD displays

Well, the 4x40 LCD display is sick - Murphy's law about a project states that while you move your first steps you find some devastating problem, enough to kill more the project value than the project feasibility.

I bought this "untested 4x40 LCD display, should work" at a HAM-fair in Pescara, Italy, some 7-8 years ago, "too cheap to not to buy". And now - only now - I understand why it was so dirt cheap.

It is a 40466 revision 2, based on HD44100FS and HD44780A00 chips (thus the Japanese font version). And now I also notice that manufacturing date on the right side: March 29, 1996.

And it has problems:


It has a number of hardware/software problems, most of all:

1) does not work correctly with any of the Arduino LiquidCrystal libraries (including Extended, 4x40, etc), many commands either do not work or just crash;

2) it has a large area (from the 3rd to the 34th character cell of the first two lines) that is not correctly drawn (apparently the vertical control lines are shifted). No, the font commands did not change the result.

So I began to write my own display driver from scratch using the HD44780 documentation.

After some experimenting I found a few reliably working bits:
- a screen initialization sequence
- the "move cursor" instruction
- the "print a character" instruction
- the "show/dontshow cursor" function.

This is sufficient to make it work. For example, I had to implement a clear screen function moving cursors to home and printing 80 blank spaces, because the LCD clear screen command does not work. I had to implement a memory map and a "known last cursor position" thing as well. But -hey!- it now works, including backspace, tab, scroll, and a single flashing cursor (yes, normaly it shows two cursors! 4x40 displays are actually two 4x20 in a single case).

A minimal Hello World program only requires 1676 bytes of flash space.

3 comments:

  1. Good day ,
    I have to use the 40466 40x4 LCD . I am reading fro you tha there are some problems.
    Could you please share few example on how to use it ?
    My e_mail is: iw2fvo@yahoo.com or the present one.
    Thanks for helping.
    regards,
    Ambro

    ReplyDelete
  2. Hi, it has been a while but I would also be most grateful for a copy of your homebrew driver code, as I have an interesting custom display/buttons board which uses the same chips, 2x 40x02 LCD's side by side, and I was hoping to interface to an Arduino. Got as far as mapping the pinout of the connector, you have already warned me I might struggle to get Arduino libraries to work, but a working example would be fantastic! Thanks, Alex

    ReplyDelete
  3. Actually, the Arduino LiquidCrystal library worked perfectly. A minimum of hacking it to enable twin displays, and I've got this old display working... https://twitter.com/alexgibson3d/status/1447914468630048777/photo/1

    ReplyDelete