First release : 2009/11/14 by Yann Guidon / whygee(a)f-cpu.org
Version 2009/11/15 : added pictures and measurements
Version 2010/12/12 : incoherent table, fixed text with 2x20 instead of 2x16
THIS IS ONLY A FIRST INCOMPLETE DRAFT, NO IMPLEMENTATION HAS BEEN TESTED AT THIS TIME.
Illustrations / schematics are still missing.
French article derived from this work (OpenSilicium 4, oct. 2011)

RFC : Autodetection of display resolution with HD44780-compatible alphanumeric LCD modules

Summary : a few cheap SMT resistors with the right value, soldered on specific bits of the data bus of a HD44780-compatible module, indicate the display's character configuration and resolution, providing enough informations for the CPU's handling routines.

Introduction

The issue that I try to solve with this "proposed protocol" is simple : the HD44780-compatible LCD modules have many flavors and resolutions, but they all look the same to the software that can't guess the actual display resolution and addresses without user intervention. This can become annoying when, like me, you have a growing collection of modules from very different manufacturers and models, saved from old hardware or bought from brokers or on eBay.

small collection of alphanumeric LCD modules, nov. 2009

The resolutions that I have now are 1x8, 1x16, 1x20, 2x16, 2x20, 4x20. From this page and this one (plus some stores), I know that there are also 1x40, 2x8, 2x24, 2x32, 2x40, 4x16 and 4x40. And there are also some variations !

It would be interesting to have a single common set of routines that handle all of these resolutions, but they must know what is hooked. Usually, one would use a set of jumpers or an EEPROM byte to specify the resolution so the software reads this value, adjusts the routines and initialises the LCD module accordingly. Unfortunately, software and hardware constraints may make this unpractical or risky (for example, the jumper is not updated with the LCD module). And all known and trivial methods require user intervention and care. It's now the 21th century, guys, so let's do something modern and smart :-)

More context and constraints

This is not a tutorial and there are better resources everywhere. The reader must be familiar with these unintuitive and strange modules.

The system is meant to contain a microprocessor or microcontroller that is tied to a HD44780-like module with dedicated low-speed pins. Typical applications use a PIC, an AVR or a parallel port (lcdproc-style) for control. My planned applications use a FPGA, which is the same category of circuitry and technology.

The number of required pins is often reduced with the "write-only, nibble mode" where only writes are performed as two consecutive 4-bit data packets :

The microcontroller and the LCD module could be running both with 3.3V or 5V, or from different power rails. Backlight can be present or absent.

Proposed method

The idea is to solder a few SMT resistors as "pull-downs" on the bits 4 to 7 of the data bus. The pins where they are soldered determine the module's resolution, which can be read by the host processor. The data bus is only 4-bit wide and provides 16 combinations, which is just enough for our purpose. This bus should be readable by the host processor, but this does not require an additional pin (since data port direction is an internal signal of most microcontrollers).

(schematics here)

Compatibility

This is mechanically possible because SMT resistors (in 1208, 0805 or even 0603) are smaller than the 0.1" pitch of the module's pins (on a standard display). If only one pin is to be pulled down, a standard 1/4W "through-hole" resistor could also be used.

"Conversion" of an old module requires some soldering skills that can't be realistic in high volume applications but then a custom module could be built. In the future, new modules could include the pull-down resistor(s) as an option, or with dedicated soldering pads. Note that the pull-down configuration is specific to a module, since most controller circuits (HD44780 and clones) can be used for different resolutions.

The method is electrically backwards-compatible with all known protocols and interfaces. For example, it works with mixed-voltage systems, and a modified LCD module works in both 4 and 8-bit wide protocols, with WR used or not.

The only known disadvantage is the additional static current drawn, for which three further enhancements are proposed here. They refine and complement the first idea so please read them all :-)

 

First idea for the reduction of power draw : Use the least resistors possible for the most common models.

The resolutions 1x8, 1x16, 2x16 and 2x20 seem to be most used so they should have the least resistors.

  • 1x8 is the failsafe and defaut value (all pins left floating so the controller's internal pull-ups make this value appear) it is assigned the value "1111" (no resistor).
  • The next resolutions use one resistor at a different position :
  • There are 6 combinations with 2 resistors : they are allocated to the remaing "probable" resolutions.
  • 3 resistors give the 4 remaining combinations, and the "unlikely" resolutions :
  • 4 resistors : this configuration draws the most current so it is left for extensions of this method, for example "read the bits 0 to 3".
  • Note: the very large resolutions (like 4x40) require two almost independent controller chips. They share the R/S, RW and data bus but they have their own E signal. This is not covered here.

    Summary :

             bits 7
    value   downto 4    function
      0     "0000"    Reserved (extension)
      1     "0001"    4x16
      2     "0010"    4x40
      3     "0011"    1x20
      4     "0100"    Reserved (alternate configuration for a resolution)
      5     "0101"    1x40
      6     "0110"    2x24
      7     "0111"    4x20
      8     "1000"    Reserved (alternate configuration for a resolution)
      9     "1001"    2x8
     10     "1010"    2x32
     11     "1011"    2x20
     12     "1100"    2x40
     13     "1101"    2x16
     14     "1110"    1x16
     15     "1111"    1x8 / fallback / LCD absent
    

    (Each "0" on the data bus is implemented by a single pull-down resistor)

    Second idea for the reduction of power draw : optimise the pull-down resistors' value.

    The system should work with 3.3V or mixed voltages. Most HD44780 are compatible with the 3.3V but the value of the pull-down resistor must be correctly chosen.

  • Low state : CMOS pins require 0.3×Vdd on a pin to ensure that a low level is detected. The voltage needs to be lower than 1V on the LCD's pin if it is powered by a 5V rail. With a typical pull-up current of 125μA, the resistor must be lower than 1V/0.000125A=8KΩ. Given that the configuration is read only once during power-up, when there is no activity on these pins, a resistor between 7KΩ and 8KΩ is all that's needed.
  • High state : if a 3.3V device needs to bring the LCD's data pin high, the 8KΩ resistor will draw 412μA (instead of sinking 125μA without). The Thevenin drop must be minimal because CMOS inputs are high with a voltage above 0.7*5V=3.5V, which is already 0.2V above the host's 3.3V rail.
    The whole 4-bit bus could draw up to about 2mA if all the pins are tied to Vss, or even more if more resistors and lower values are required. This is almost nothing for a prototype but this could potentially alter the characteristics of a widely deployed system.
  • Note 1 : CMOS pins draw more current when their input is close to Vdd/2 so there is a compromise to find : either the pull-down resistor is larger and the port consumes more current, either the former is smaller and draws more current but the port is closer to the ground rail and consumes nothing. So don't be tempted to increase the resistor's value, because its effect is mitigated by the following idea.

    Note 2 : I have used the "typical" value of 125μA as provided by Hitachi when the module is powered by 5V. With this voltage, the maximum pull-up current is 250μA. From 2.7 to 4.5V, the typical value is 50μA and maximum 120μA. It appears that these pull-ups are just MOS transistors used as resistors, not as constant current sources, so the current depends directly on the LCD's supply voltage. In case of doubts and if power consumption is not an issue, the additional pull-down resistor's value can be as low as 4.7KΩ for example.

    Third idea for the reduction of power draw : pull down only when needed

    The Data/Instruction signal (RS) can be used instead of the Vss pin. This signal is present on all the interfaces and does not interfere with the other signals :

  • When low, RS pulls down the tied data pin(s). The sum of all pull-down currents (which depends on the supply voltage and the number of resistors) flows into RS but it is usually less than 1mA.
  • When held high by the host, RS draws almost no current because it is almost at the same voltage as the LCD module. When the host drives one of the tied data pins low, it sees a larger pull-up current on this data pin (equivalent to the pull-down current when RS is low) which also flows through RS.
  • When floating, RS is pulled high through the LCD's RS pin as well as the other data pins. No power draw occurs if the tied data pin(s) is/are also left floating.
  • When no activity occurs on the LCD bus, just let if float. This is "free" in most case, when the data direction signal for all the pins is kept inside the host chip.

    (schematics here)

    Examples

    Note that according to the Hitachi datasheet, the E pin has no pull-up or pull-down. It is the responsibility of the host circuit to ensure that a valid voltage is present. In the following example, a high-value pull-down is added but check your datasheet and double-check the voltage by measuring it.

    2x16 characters

    The first example takes a module bought several years ago in a store. It is a cheap but good quality clone of the original designs. I had soldered the pins back then. Adding a standard 7.5KΩ resistor was quite easy. The only potential problem is the proximity of the resistor's legs with the other pads, which could lead to shorts if very badly handled. The legs are tough, though, so no need to insulate here.

    Since the display has 2 lines of 16 characters, the corresponding code is "1101". Each "0" corresponds to one resistor and each bit is numbered from right to left, from D4 to D7, so here only one resistor is required, from pin 4 (R/S) to pin 12 (D5).

    1x16 characters

    The next cobaye is an old 1x16 module with an original HD44780A QFP controller. Still in its factory bag, no connector has been soldered yet and this intervention should not keep me from doing it in the future. So I opted for a small 0805 SMT resistor, soldered on the ring of the pad, trying not to fill the plated through hole with solder.

    With a resolution of 1x16, the code is "1110" so the resistor is soldered on pin 11 (D4). A fine insulated wire is then brought to pin 4 (E) and that's it. Note that the resistor is 8.2KΩ because I had nothing better.

    Measurements

    After "enhancing" the 1x16 module, I connected it to my test devices. The module is based on a old HD44780A that is specified to work at 5V so no 3.3V test has been performed.

    When R/S and RW are shorted to ground, I measure a DC current of 0.23mA in the R/S pin (this is is the sum of the pull-ups of D4 and R/S) and 0.91V on D4. When D4 is forced to 5V, I find 0.6mA on this pin, while it takes about 0.11mA to take a pulled-up pin to the ground.

    This matches the previous estimations quite well and overall, with R/S and RW tied to 0V, the whole circuit draws only 0.7mA. When they are left floating (and E tied to 0V to prevent undetermined states), the consumption is down to 0.3mA, just as the datasheet states !

    So if you develop a power-sensitive device, let most pins float when unused. The short pulses on the R/S pin make the pull-down-induced current negligible. A 4.7K resistor would increase the noise margin because the measured 0.91V is OK for 5V CMOS but too close to the limit of detection with 3.3V.

    It seems that the module is suitable with a 3.3V host processor (in write-only mode) because the current limitation of the integrated pull-ups (added with internal diodes on the host's pins) limit the host's pin voltage. At worst, the LCD could power the host through these pull-ups, just like it is able to dimly ligh red diodes (this can be avoided by shutting down the LCD's power supply).

    Host processor algorithm

    To be continued... probably.