HD44780 and compatible Text LCD controllers (4bit, I2C or SPI I/F)

Library for Text LCD panels using the 4-bit HD44780 LCD display controller or compatible types.

Hello World

Import programTextLCD_HelloWorld2

Hello World demo for Enhanced TextLCD lib.

Library

Import libraryTextLCD

Updated for more display types. Fixed memoryaddress confusion in address() method. Added new getAddress() method. Added support for UDCs, Backlight control and other features such as control through I2C and SPI port expanders and controllers with native I2C and SPI interfaces. Refactored to fix issue with pins that are default declared as NC.

Datasheet

https://developer.mbed.org/users/wim/notebook/textlcd-enhanced

Notes

This library provides an enhanced forked version of the basic library for Text LCD panels using the 4-bit HD44780 LCD display controller. The new lib supports several ways of connecting with mbed:

  • Direct connection with mbed pins using a 4 bit parallel bus (same as original TextLCD)
  • Serial connection using mbed I2C bus and a PCF8574, PCF8574A or MCP23008 portexpander
  • Serial connection using mbed SPI bus and a 74595 shiftregister
  • Serial connection using mbed I2C or SPI bus and a controller with native I2C or SPI interface support

Note that there are several compatible LCD controllers around (e.g. KS0066, SPC780, SED1278, LC7985A). There are also controllers available that are compatible and provide additional features like an increased number of segment drivers for more characters or internal LCD contrast voltage generators (e.g. KS0073, KS0078, ST7036, SSD1803 and WS0010 (OLED driver)) or native I2C or SPI support (eg ST7032i).

Example

#include "mbed.h"
#include "TextLCD.h"
 
// Host PC Communication channels
Serial pc(USBTX, USBRX); // tx, rx
 
// I2C Communication
I2C i2c_lcd(p28,p27); // SDA, SCL
 
// SPI Communication
SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK

//TextLCD lcd(p15, p16, p17, p18, p19, p20);                // RS, E, D4-D7, LCDType=LCD16x2, BL=NC, E2=NC, LCDTCtrl=HD44780
TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type
//TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 addr, LCD Type, Ctrl Type
//TextLCD_I2C lcd(&spi_lcd, p8, TextLCD::LCD24x4D); // SPI bus, CS pin, LCD Type
 
int main() {
    pc.printf("LCD Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows());
    
    for (int row=0; row<lcd.rows(); row++) {
      int col=0;
      
      pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));      
//      lcd.putc('-');
      lcd.putc('0' + row);      
      
      for (col=1; col<lcd.columns()-1; col++) {    
        lcd.putc('*');
      }
 
      pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));      
      lcd.putc('+');
        
    }    
    
// Show cursor as blinking character
    lcd.setCursor(TextLCD::CurOff_BlkOn);
 
// Set and show user defined characters. A maximum of 8 UDCs are supported by the HD44780.
// They are defined by a 5x7 bitpattern. 
    lcd.setUDC(0, (char *) udc_0);  // Show |>
    lcd.putc(0);    
    lcd.setUDC(1, (char *) udc_1);  // Show <|
    lcd.putc(1);    
 
}

Handbook Page

More info is here