Hello World demo for Enhanced TextLCD lib.

Dependencies:   TextLCD mbed

Dependents:   Opener-6

The Enhanced TextLCD lib supports more display types than the original lib. Added support for User Defined Characters (UDCs), Backlight control and other features such as control through I2C and SPI port expanders and controllers with native I2C and SPI interfaces. See here for more info.

Committer:
wim
Date:
Sun Mar 29 13:12:07 2015 +0000
Revision:
4:a3e4bb2053cb
Parent:
3:f238b4f7874f
Hello World demo of Enhanced TextLCD library. This lib supports HD44780 based controllers using 4bit parallel bus on mbed pins, I2C or SPI expanders. The libs also supports native I2C or SPI interfaces on several HD44780 compatible controllers.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
wim 4:a3e4bb2053cb 1 /* Hello World! for the TextLCD Enhanced Library*/
wim 0:a75049de1a82 2
wim 0:a75049de1a82 3 #include "mbed.h"
wim 0:a75049de1a82 4 #include "TextLCD.h"
wim 4:a3e4bb2053cb 5
wim 0:a75049de1a82 6 // Host PC Communication channels
wim 0:a75049de1a82 7 Serial pc(USBTX, USBRX); // tx, rx
wim 4:a3e4bb2053cb 8
wim 0:a75049de1a82 9 // I2C Communication
wim 4:a3e4bb2053cb 10 I2C i2c_lcd(p9,p10); // SDA, SCL
wim 4:a3e4bb2053cb 11 //I2C i2c_lcd(p28,p27); // SDA, SCL
wim 4:a3e4bb2053cb 12
wim 0:a75049de1a82 13 // SPI Communication
wim 0:a75049de1a82 14 SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK
wim 0:a75049de1a82 15
wim 4:a3e4bb2053cb 16 // LCD instantiation
wim 4:a3e4bb2053cb 17 //TextLCD lcd(p15, p16, p17, p18, p19, p20, TextLCD::LCD20x2); // 4bit bus: rs, e, d4-d7
wim 4:a3e4bb2053cb 18 TextLCD_I2C lcd(&i2c_lcd, 0x40, TextLCD::LCD20x4); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type
wim 4:a3e4bb2053cb 19 //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C exp: I2C bus, PCF8574 Slaveaddress, LCD Type, Ctrl Type
wim 4:a3e4bb2053cb 20 //TextLCD_I2C lcd(&spi_lcd, p8, TextLCD::LCD24x4D); // I2C exp: SPI bus, CS pin, LCD Type
wim 4:a3e4bb2053cb 21 //TextLCD_SPI_N lcd(&spi_lcd, p8, p9, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // SPI native: SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032
wim 4:a3e4bb2053cb 22 //TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C native: I2C bus, slaveaddress, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032 =Ok
wim 4:a3e4bb2053cb 23 //TextLCD_I2C_N lcd(&i2c_lcd, SSD1803_SA1, TextLCD::LCD20x4D, NC, TextLCD::SSD1803_3V3); // I2C native: I2C bus, slaveaddress, LCDType=LCD20x4D, BL=NC, LCDTCtrl=SSD1803 =Ok
wim 4:a3e4bb2053cb 24
wim 4:a3e4bb2053cb 25 int main() {
wim 4:a3e4bb2053cb 26 Timer t;
wim 0:a75049de1a82 27
wim 4:a3e4bb2053cb 28 pc.printf("TextLCD Enhanced Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows());
wim 4:a3e4bb2053cb 29
wim 4:a3e4bb2053cb 30 for (int row=0; row<lcd.rows(); row++) {
wim 4:a3e4bb2053cb 31 int col=0;
wim 4:a3e4bb2053cb 32
wim 4:a3e4bb2053cb 33 pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));
wim 4:a3e4bb2053cb 34 // lcd.putc('-');
wim 4:a3e4bb2053cb 35 lcd.putc('0' + row);
wim 4:a3e4bb2053cb 36
wim 4:a3e4bb2053cb 37 for (col=1; col<lcd.columns()-1; col++) {
wim 4:a3e4bb2053cb 38 lcd.putc('*');
wim 4:a3e4bb2053cb 39 }
wim 4:a3e4bb2053cb 40
wim 4:a3e4bb2053cb 41 pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row));
wim 4:a3e4bb2053cb 42 lcd.putc('+');
wim 4:a3e4bb2053cb 43 }
wim 0:a75049de1a82 44
wim 4:a3e4bb2053cb 45 // Fill screen again and time it
wim 4:a3e4bb2053cb 46 t.start();
wim 3:f238b4f7874f 47
wim 4:a3e4bb2053cb 48 for (int row=0; row<lcd.rows(); row++) {
wim 4:a3e4bb2053cb 49 int col=0;
wim 4:a3e4bb2053cb 50
wim 4:a3e4bb2053cb 51 lcd.putc('0' + row);
wim 4:a3e4bb2053cb 52
wim 4:a3e4bb2053cb 53 for (col=1; col<lcd.columns()-1; col++) {
wim 4:a3e4bb2053cb 54 lcd.putc('*');
wim 4:a3e4bb2053cb 55 }
wim 4:a3e4bb2053cb 56
wim 4:a3e4bb2053cb 57 lcd.putc('+');
wim 4:a3e4bb2053cb 58 }
wim 4:a3e4bb2053cb 59 t.stop();
wim 4:a3e4bb2053cb 60 pc.printf("All my hard work took %f sec\r\n", t.read());
wim 1:ef419b21167d 61
wim 4:a3e4bb2053cb 62 // Show cursor as blinking character
wim 4:a3e4bb2053cb 63 lcd.setCursor(TextLCD::CurOff_BlkOn);
wim 4:a3e4bb2053cb 64
wim 4:a3e4bb2053cb 65 // Set and show user defined characters. A maximum of 8 UDCs are supported by the HD44780.
wim 4:a3e4bb2053cb 66 // They are defined by a 5x7 bitpattern.
wim 4:a3e4bb2053cb 67 lcd.setUDC(0, (char *) udc_0); // Show |>
wim 4:a3e4bb2053cb 68 lcd.putc(0);
wim 4:a3e4bb2053cb 69 lcd.setUDC(1, (char *) udc_1); // Show <|
wim 4:a3e4bb2053cb 70 lcd.putc(1);
wim 4:a3e4bb2053cb 71
wim 4:a3e4bb2053cb 72 pc.printf("Bye now\r\n");
wim 4:a3e4bb2053cb 73 }
wim 3:f238b4f7874f 74
wim 3:f238b4f7874f 75
wim 0:a75049de1a82 76