Manuals, Timing, Ham Radio, Test Equipment

Help keep this site free:
(More Info)
        

LCD I2C Driver

Inexpensive 16x2 and 20x4 LCD displays are available from a variety of sources like Adafruit and eBay. They typically use the Hitachi HD44780 chip or a clone. Here is an example of a 4x20 display:

These are very convenient for many microcontroller projects and are easy to drive.

The interface supports two modes of operation: 8 bit data bus and 4 bit data bus. Since you also need 3 additional pins for control (you may be able to do with 2 in most cases), even the 4 bit interface requires at least 6 I/O ports from the microcontroller.

I do have 4 bit drivers for the HD44780 on this web site, intended for the 8051 but easily adaptable to other microcontrollers.

However, in some cases, 6 bits is still more than you have available.

Enters the I2C port. For a long time now, I have been using the I2C bus to interface with non-volatile memory, real time clocks, port expanders and other chips. It occured to me that I could drive an HD44780 compatible display through the I2C bus using an NXP I/O Expander like the PCF8574. I built a breadboard and wrote the code and voila, instant LCD for projects that were designed without one.

After building a few breadboards and talking to my friends about it, I realized that the exact circuit I had designed was available from eBay for a little over one US$ (see picture below).

Search eBay for "I2C LCD". A number of different models are available and I cannot guaranty that they all work the same. The one I bought looks like this:

The driver code is intended for the 8051. It can easily be used with other microcontrollers. If you are not familiar with the 8051, you may be puzzled by keywords like xdata, sbit and such. These refer to specific features of the 8051 architecture, and if you want to use this code with another microcontroller family, you will have to convert it.

The main features of the driver are as follows:

  • uses the 4bit interface
  • supports any resolution from 1x8 to 4x20 and even larger by resizing buffers
  • supports cursor movements and cursor on/off
  • supports LCD and Vacuum Fluorescent (VFD) displays
  • requires one short delay routine (I use a software loop, you could use a timer but for such a short delay, I do not see the need), most other LCD functions work well with the I2C bus inherent delays.
  • requires an I2C driver
  • written for the Keil PK51 compiler (available for free when used with Silabs chips)

Note that this driver does not implement the I2C protocol. You will need another driver for that. I happen to have an I2C driver for the 8051 on this site as well.