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.

Dependents:   GPSDevice TestTextLCD SD to Flash Data Transfer DrumMachine ... more

Fork of TextLCD by Simon Ford

Example

Hello World! for the TextLCD

#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_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4);   // SPI bus, 74595 expander, CS pin, LCD Type  
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 Slaveaddress, LCD Type, Device Type
//TextLCD_SPI_N lcd(&spi_lcd, p8, p9);               // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032_3V3   
//TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C bus, Slaveaddress, LCD Type, BL=NC, LCDTCtrl=ST7032_3V3  

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

Revisions of TextLCD.h

Revision Date Message Actions
23:d47f226efb24 2014-04-02 Docs update File  Diff  Annotate
22:35742ec80c24 2014-04-02 Refactored TextLCD bus version to fix issue with pins default defined as NC.; Note: I2C and SPI versions now need to be declared as TextLCD_I2C() or TextLCD_SPI() in user code. File  Diff  Annotate
21:9eb628d9e164 2014-04-01 Refactored in Abstract Base class and Derived classes for Bus interface, I2C portexpander interface and SPI shiftregister interface.; This was needed to solve problem with recent mbed lib and DigitalOut pins that are default defined as 'NC'. File  Diff  Annotate
20:e0da005a777f 2013-05-13 Added support for Backlight control; Added portdefinitions for I2C/TWI LCD2004 Module from DFROBOT File  Diff  Annotate
19:c747b9e2e7b8 2013-04-19 Beta version supporting WS0010 and ST7036 DC/DC converters File  Diff  Annotate
18:bd65dc10f27f 2013-03-09 Added some UDCs, Updated documentation. File  Diff  Annotate
17:652ab113bc2e 2013-03-02 Added support for Display On/Off. Improved 4bit bootprocess. File  Diff  Annotate
16:c276b75e6585 2013-02-20 Cleaned up and Commented File  Diff  Annotate
15:b70ebfffb258 2013-02-19 Working testversion for 40x4.; Fixed cursor problems.; Fixed UDC problems, always return to DD RAM. File  Diff  Annotate
14:0c32b66b14b8 2013-02-10 Added support for I2C and SPI bus interfaces File  Diff  Annotate
13:24506ba22480 2013-02-09 First version with I2C interface, refactored code File  Diff  Annotate
12:6bf9d9957d31 2013-02-05 Updated Documentation File  Diff  Annotate
11:9ec02df863a1 2013-02-05 Added User Defined Character support File  Diff  Annotate
10:dd9b3a696acd 2013-02-04 Added support for 24x4 LCDs using KS0078 controller; Added Cursor On/Off File  Diff  Annotate
9:0893d986e717 2013-01-31 Tested on several LCD types File  Diff  Annotate
8:03116f75b66e 2013-01-29 TextLCD Update to fix memoryaddress problems File  Diff  Annotate
7:44f34c09bd37 2010-12-04 Update pin names to d4-d7 File  Diff  Annotate
6:e4cb7ddee0d3 2010-11-23 Published as a library File  Diff  Annotate
5:a53b3e2d6f1e 2010-05-29 (none) File  Diff  Annotate
3:2a46d5820a78 2010-05-27 (none) File  Diff  Annotate
2:227356c7d12c 2010-05-27 (none) File  Diff  Annotate
1:ac48b187213c 2010-05-27 (none) File  Diff  Annotate
0:edfb85c53631 2010-05-22 (none) File  Diff  Annotate