My Projects

Published 17 Dec 2018

SPI LCD Driver Library


I have a couple of display panels, one from a Brother Fax-645, the other from a Panasonic KX-T7730 Phone, that I wish to use in Arduino projects. These are 1 line by 16 character LCD status displays, controlled by a Hitachi HD44780 compatible LCD controller/driver chip that uses an SPI serial interface.


Overview

I looked for an Arduino library that would talk to this chip-set, but failed to find one.

I based my library module for this on a standard Arduino library for the Hitachi HD44780 chip, LiquidCrystal.cpp. The programs included here are HelloWorld_SPI.ino, LiquidCrystal_SPI.cpp and LiquidCrystal_SPI.h.

The command set is compatible with the Hitachi HD44780, but I don't know the model of the chip, or even the manufacturer.

Hardware description

The controller is mounted directly on the LCD glass, and the LCD module has a 6 pin, 1mm pitch, PCB flex cable. The displays are a single line of sixteen, 5 by 8 pixel, characters.

SPI LCD pixel layoutThe two modules have different character sets, but the characters in common tend to have exactly the same font design, so they may have the same manufacturer. I experimented a little, but could not get either module to display an 5 by 11 character mode.



Arduino to SPI LCD wiring

The great advantage of these serial SPI LCD modules is the simplicity of the Arduino interface. There are three signal lines MISO (data), SCLK (clock), and SS (select). Plus power (+5V) and ground.

Eight bit commands/data are clocked in, least significant bit (LSB) first, on the rising edge of SCLK. There is no register select so command or data is determined by context : the first thing sent to the LCD after SS is asserted is a command. If you want to just send data to the display, then prefix it with a cursor-positioning or display-on command, then send a stream of data bytes terminated by releasing SS.

I used a 56uS clock cycle for SCLK and 800uS between sending bytes. I have no idea of what the controller chip is exactly, therefore no idea of its actual requirements. Those figures are just from analysing the fax data stream.

There is no “busy” pin, so delays between commands are necessary to give sufficient time for internal processing.

There was no contrast adjustment on these modules (maybe a command programmable feature).

The data pins can be any available Arduino pins.

SPI LCD library

As mentioned earlier the library is based on a standard Arduino HD44780 LCD library. Most hardware commands, including programmable characters, seem to be compatible with the HD44780, but I would need to do a lot of experimentation to find any extended commands.

The functions implemented are:

  • begin(col,row)
    • Initializes the display, usually done once in a sketch's setup() routine.
  • clear()
    • Clears the screen of all pixels and homes the cursor.
  • home()
    • Sets the location for next data output (cursor location) to 0,0.
  • display();
  • noDisplay();
    • Turns the display on or off.
  • blink();
  • noBlink();
    • Turns the blinking cursor on or off.
  • setCursor(col, row)
    • Set location for next character to be displayed.
  • cursor()
    • Show cursor at location ready for next character.
  • noCursor()
    • Turn off cursor display.
  • scrollDisplayLeft()
    • Scroll current line one character to the left.
  • scrollDisplayRight()
    • Scroll current line one character to the right.
  • leftToRight()
    • Normal Western language display mode where words are written starting at the left of the display.
  • rightToLeft()
    • Mode used for Japanese and other languages where characters are written starting at the right of the display.
  • autoScroll()
    • Automatically scroll when the cursor (whether visible or not) reaches the far edge of the display.
  • noAutoscroll()
    • Turns off autoscroll.
  • createChar()
    • Programs one of the 4 user defined, 5×8 pixel characters.

The functions appear to be the same as for the HD44780 but have not been extensively tested for compatibility. There didn't seem to be any need for 4/8 bit interface selection. It is conceivable that the display controller chip might support 4/8 bit modes, but no account of this possibility is included in this driver. So initialisation is simplified.

When writing data to be displayed on the LCD screen it would be more efficient to assert SS, send a positioning command and then a stream of bytes, and de-assert SS when complete. But this driver has a, print.h library compatible, single-character output routine, 'write', which is used to output one character at a time, each preceded by a display-on command.

The original firmware sent an extra code, 0xf8, during startup. On an HD44780 chip this would just be a cursor positioning command (to set data cursor to location 0x78), but this would not be a displayable location, and no data is sent to be displayed. It appears that this may be a reset or other initialisation command.

I finally realised why I sometimes had trouble setting the programmable characters (only 4 available on these chips) - after setting a programmable character future writes also go to the programmable character CGRAM (corrupting it) until you deliberately switch back to the display ram. This is a problem from the original LiquidCrystal.h library - the solution here is that I just reset the cursor to the home location after programming characters.

SPI LCD panel test
LCD module displaying text output of helloWorld_SPI.ino program



The programs (v1.00):

References and Additional Resources

Other Arduino LCD drivers

  • KS0073 SPI LCD, LCD display panel Arduino driver
  • METP0000, NEC µPD7225 based LCD display panel Arduino driver
  • Canon MX300, Canon MX300/310 printer LCD display panel Arduino driver.
  • NEC µPD7228 and μPD16434 LCD display panels Arduino driver
  • Toshiba T6A34 SPI, HD44780 compatible, LCD display panel Arduino driver

If any referenced page no longer exists, try looking for its URL on http://archive.org.