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

Committer:
wim
Date:
Fri Apr 19 19:36:37 2013 +0000
Revision:
19:c747b9e2e7b8
Parent:
18:bd65dc10f27f
Child:
20:e0da005a777f
Beta version supporting WS0010 and ST7036 DC/DC converters

Who changed what in which revision?

UserRevisionLine numberNew contents of line
simon 1:ac48b187213c 1 /* mbed TextLCD Library, for a 4-bit LCD based on HD44780
simon 6:e4cb7ddee0d3 2 * Copyright (c) 2007-2010, sford, http://mbed.org
wim 13:24506ba22480 3 * 2013, v01: WH, Added LCD types, fixed LCD address issues, added Cursor and UDCs
wim 15:b70ebfffb258 4 * 2013, v02: WH, Added I2C and SPI bus interfaces
wim 15:b70ebfffb258 5 * 2013, v03: WH, Added support for LCD40x4 which uses 2 controllers
wim 17:652ab113bc2e 6 * 2013, v04: WH, Added support for Display On/Off, improved 4bit bootprocess
wim 18:bd65dc10f27f 7 * 2013, v05: WH, Added support for 8x2B, added some UDCs
wim 19:c747b9e2e7b8 8 * 2013, v06: WH, Added support for devices that use internal DC/DC converters
simon 1:ac48b187213c 9 *
simon 1:ac48b187213c 10 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 1:ac48b187213c 11 * of this software and associated documentation files (the "Software"), to deal
simon 1:ac48b187213c 12 * in the Software without restriction, including without limitation the rights
simon 1:ac48b187213c 13 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 1:ac48b187213c 14 * copies of the Software, and to permit persons to whom the Software is
simon 1:ac48b187213c 15 * furnished to do so, subject to the following conditions:
simon 2:227356c7d12c 16 *
simon 1:ac48b187213c 17 * The above copyright notice and this permission notice shall be included in
simon 1:ac48b187213c 18 * all copies or substantial portions of the Software.
simon 2:227356c7d12c 19 *
simon 1:ac48b187213c 20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 1:ac48b187213c 21 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 1:ac48b187213c 22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 1:ac48b187213c 23 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 1:ac48b187213c 24 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 1:ac48b187213c 25 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 1:ac48b187213c 26 * THE SOFTWARE.
simon 1:ac48b187213c 27 */
simon 1:ac48b187213c 28
simon 1:ac48b187213c 29 #ifndef MBED_TEXTLCD_H
simon 1:ac48b187213c 30 #define MBED_TEXTLCD_H
simon 1:ac48b187213c 31
simon 1:ac48b187213c 32 #include "mbed.h"
simon 2:227356c7d12c 33
wim 15:b70ebfffb258 34
simon 5:a53b3e2d6f1e 35 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
simon 2:227356c7d12c 36 *
wim 16:c276b75e6585 37 * Currently supports 8x1, 8x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels
wim 16:c276b75e6585 38 * Interface options include direct mbed pins, I2C portexpander (PCF8474) or SPI bus shiftregister (74595)
wim 19:c747b9e2e7b8 39 * Supports some controllers that provide internal DC/DC converters for VLCD or VLED.
simon 2:227356c7d12c 40 *
simon 2:227356c7d12c 41 * @code
simon 2:227356c7d12c 42 * #include "mbed.h"
simon 2:227356c7d12c 43 * #include "TextLCD.h"
simon 5:a53b3e2d6f1e 44 *
wim 16:c276b75e6585 45 * // I2C Communication
wim 16:c276b75e6585 46 * I2C i2c_lcd(p28,p27); // SDA, SCL
wim 16:c276b75e6585 47 *
wim 16:c276b75e6585 48 * // SPI Communication
wim 16:c276b75e6585 49 * SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK
wim 16:c276b75e6585 50 *
wim 16:c276b75e6585 51 * TextLCD lcd(p15, p16, p17, p18, p19, p20); // RS, E, D4-D7, LCDType=LCD16x2
wim 16:c276b75e6585 52 * //TextLCD lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, CS pin, LCD Type
wim 16:c276b75e6585 53 * //TextLCD lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type
wim 19:c747b9e2e7b8 54 * //TextLCD lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type
simon 5:a53b3e2d6f1e 55 *
simon 2:227356c7d12c 56 * int main() {
wim 16:c276b75e6585 57 * lcd.printf("Hello World!\n");
simon 2:227356c7d12c 58 * }
simon 2:227356c7d12c 59 * @endcode
simon 2:227356c7d12c 60 */
wim 8:03116f75b66e 61
wim 13:24506ba22480 62
wim 16:c276b75e6585 63 //Pin Defines for I2C PCF8574 and SPI 74595 Bus interfaces
wim 13:24506ba22480 64 //LCD and serial portexpanders should be wired accordingly
wim 13:24506ba22480 65 //Note: LCD RW pin must be connected to GND
wim 15:b70ebfffb258 66 // E2 is used for LCD40x4 (second controller)
wim 13:24506ba22480 67 // BL may be used for future expansion to control backlight
wim 13:24506ba22480 68 //
wim 15:b70ebfffb258 69 #define D_LCD_PIN_D4 0
wim 15:b70ebfffb258 70 #define D_LCD_PIN_D5 1
wim 15:b70ebfffb258 71 #define D_LCD_PIN_D6 2
wim 15:b70ebfffb258 72 #define D_LCD_PIN_D7 3
wim 15:b70ebfffb258 73 #define D_LCD_PIN_RS 4
wim 15:b70ebfffb258 74 #define D_LCD_PIN_E 5
wim 15:b70ebfffb258 75 #define D_LCD_PIN_E2 6
wim 15:b70ebfffb258 76 #define D_LCD_PIN_BL 7
wim 13:24506ba22480 77
wim 13:24506ba22480 78 #define D_LCD_BUS_MSK 0x0F
wim 15:b70ebfffb258 79 #define D_LCD_BUS_DEF 0x00
wim 13:24506ba22480 80
wim 13:24506ba22480 81 //Bitpattern Defines for I2C PCF8574 and SPI 74595 Bus
wim 13:24506ba22480 82 //
wim 13:24506ba22480 83 #define D_LCD_D4 (1<<D_LCD_PIN_D4)
wim 13:24506ba22480 84 #define D_LCD_D5 (1<<D_LCD_PIN_D5)
wim 13:24506ba22480 85 #define D_LCD_D6 (1<<D_LCD_PIN_D6)
wim 13:24506ba22480 86 #define D_LCD_D7 (1<<D_LCD_PIN_D7)
wim 13:24506ba22480 87 #define D_LCD_RS (1<<D_LCD_PIN_RS)
wim 13:24506ba22480 88 #define D_LCD_E (1<<D_LCD_PIN_E)
wim 13:24506ba22480 89 #define D_LCD_E2 (1<<D_LCD_PIN_E2)
wim 13:24506ba22480 90 #define D_LCD_BL (1<<D_LCD_PIN_BL)
wim 13:24506ba22480 91
wim 13:24506ba22480 92
wim 13:24506ba22480 93 /** Some sample User Defined Chars 5x7 dots */
wim 11:9ec02df863a1 94 const char udc_ae[] = {0x00, 0x00, 0x1B, 0x05, 0x1F, 0x14, 0x1F, 0x00}; //æ
wim 11:9ec02df863a1 95 const char udc_0e[] = {0x00, 0x00, 0x0E, 0x13, 0x15, 0x19, 0x0E, 0x00}; //ø
wim 11:9ec02df863a1 96 const char udc_ao[] = {0x0E, 0x0A, 0x0E, 0x01, 0x0F, 0x11, 0x0F, 0x00}; //Ã¥
wim 11:9ec02df863a1 97 const char udc_AE[] = {0x0F, 0x14, 0x14, 0x1F, 0x14, 0x14, 0x17, 0x00}; //Æ
wim 11:9ec02df863a1 98 const char udc_0E[] = {0x0E, 0x13, 0x15, 0x15, 0x15, 0x19, 0x0E, 0x00}; //Ø
wim 18:bd65dc10f27f 99 const char udc_Ao[] = {0x0E, 0x0A, 0x0E, 0x11, 0x1F, 0x11, 0x11, 0x00}; //Ã…
wim 18:bd65dc10f27f 100 const char udc_PO[] = {0x04, 0x0A, 0x0A, 0x1F, 0x1B, 0x1B, 0x1F, 0x00}; //Padlock Open
wim 18:bd65dc10f27f 101 const char udc_PC[] = {0x1C, 0x10, 0x08, 0x1F, 0x1B, 0x1B, 0x1F, 0x00}; //Padlock Closed
wim 11:9ec02df863a1 102
wim 11:9ec02df863a1 103 const char udc_0[] = {0x18, 0x14, 0x12, 0x11, 0x12, 0x14, 0x18, 0x00}; // |>
wim 11:9ec02df863a1 104 const char udc_1[] = {0x03, 0x05, 0x09, 0x11, 0x09, 0x05, 0x03, 0x00}; // <|
wim 11:9ec02df863a1 105 const char udc_2[] = {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00}; // |
wim 11:9ec02df863a1 106 const char udc_3[] = {0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00}; // ||
wim 11:9ec02df863a1 107 const char udc_4[] = {0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00}; // |||
wim 11:9ec02df863a1 108 const char udc_5[] = {0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00}; // =
wim 11:9ec02df863a1 109 const char udc_6[] = {0x15, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x15, 0x00}; // checkerboard
wim 11:9ec02df863a1 110 const char udc_7[] = {0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x10, 0x00}; // \
wim 11:9ec02df863a1 111
wim 13:24506ba22480 112 const char udc_degr[] = {0x06, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00}; // Degree symbol
wim 13:24506ba22480 113
wim 13:24506ba22480 114 const char udc_TM_T[] = {0x1F, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; // Trademark T
wim 13:24506ba22480 115 const char udc_TM_M[] = {0x11, 0x1B, 0x15, 0x11, 0x00, 0x00, 0x00, 0x00}; // Trademark M
wim 13:24506ba22480 116
wim 13:24506ba22480 117 //const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Full
wim 13:24506ba22480 118 //const char udc_Bat_Ha[] = {0x0E, 0x11, 0x13, 0x17, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Half
wim 13:24506ba22480 119 //const char udc_Bat_Lo[] = {0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x00}; // Battery Low
wim 13:24506ba22480 120 const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Full
wim 13:24506ba22480 121 const char udc_Bat_Ha[] = {0x0E, 0x11, 0x11, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Half
wim 13:24506ba22480 122 const char udc_Bat_Lo[] = {0x0E, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x1F, 0x00}; // Battery Low
wim 18:bd65dc10f27f 123 const char udc_AC[] = {0x0A, 0x0A, 0x1F, 0x11, 0x0E, 0x04, 0x04, 0x00}; // AC Power
wim 13:24506ba22480 124
wim 18:bd65dc10f27f 125 //const char udc_smiley[] = {0x00, 0x0A, 0x00, 0x04, 0x11, 0x0E, 0x00, 0x00}; // Smiley
wim 18:bd65dc10f27f 126 //const char udc_droopy[] = {0x00, 0x0A, 0x00, 0x04, 0x00, 0x0E, 0x11, 0x00}; // Droopey
wim 18:bd65dc10f27f 127 //const char udc_note[] = {0x01, 0x03, 0x05, 0x09, 0x0B, 0x1B, 0x18, 0x00}; // Note
wim 18:bd65dc10f27f 128
wim 18:bd65dc10f27f 129 //const char udc_bar_1[] = {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00}; // Bar 1
wim 18:bd65dc10f27f 130 //const char udc_bar_2[] = {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}; // Bar 11
wim 18:bd65dc10f27f 131 //const char udc_bar_3[] = {0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x00}; // Bar 111
wim 18:bd65dc10f27f 132 //const char udc_bar_4[] = {0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x00}; // Bar 1111
wim 18:bd65dc10f27f 133 //const char udc_bar_5[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Bar 11111
wim 13:24506ba22480 134
wim 11:9ec02df863a1 135
wim 11:9ec02df863a1 136 /** A TextLCD interface for driving 4-bit HD44780-based LCDs
wim 11:9ec02df863a1 137 *
wim 16:c276b75e6585 138 * Currently supports 8x1, 8x2, 12x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels
wim 11:9ec02df863a1 139 *
wim 11:9ec02df863a1 140 */
simon 1:ac48b187213c 141 class TextLCD : public Stream {
simon 1:ac48b187213c 142 public:
simon 1:ac48b187213c 143
simon 2:227356c7d12c 144 /** LCD panel format */
simon 1:ac48b187213c 145 enum LCDType {
wim 8:03116f75b66e 146 LCD8x1, /**< 8x1 LCD panel */
wim 13:24506ba22480 147 LCD8x2, /**< 8x2 LCD panel */
wim 18:bd65dc10f27f 148 LCD8x2B, /**< 8x2 LCD panel (actually 16x1) */
wim 15:b70ebfffb258 149 LCD12x2, /**< 12x2 LCD panel */
wim 15:b70ebfffb258 150 LCD12x4, /**< 12x4 LCD panel */
wim 13:24506ba22480 151 LCD16x1, /**< 16x1 LCD panel (actually 8x2) */
wim 8:03116f75b66e 152 LCD16x2, /**< 16x2 LCD panel (default) */
wim 8:03116f75b66e 153 LCD16x2B, /**< 16x2 LCD panel alternate addressing */
wim 8:03116f75b66e 154 LCD16x4, /**< 16x4 LCD panel */
wim 8:03116f75b66e 155 LCD20x2, /**< 20x2 LCD panel */
wim 8:03116f75b66e 156 LCD20x4, /**< 20x4 LCD panel */
wim 9:0893d986e717 157 LCD24x2, /**< 24x2 LCD panel */
wim 10:dd9b3a696acd 158 LCD24x4, /**< 24x4 LCD panel, special mode KS0078 */
wim 15:b70ebfffb258 159 LCD40x2, /**< 40x2 LCD panel */
wim 15:b70ebfffb258 160 LCD40x4 /**< 40x4 LCD panel, Two controller version */
simon 1:ac48b187213c 161 };
simon 1:ac48b187213c 162
wim 19:c747b9e2e7b8 163 /** LCD Controller Device */
wim 19:c747b9e2e7b8 164 enum LCDCtrl {
wim 19:c747b9e2e7b8 165 HD44780, /**< HD44780 (default) */
wim 19:c747b9e2e7b8 166 WS0010, /**< WS0010 OLED Controller */
wim 19:c747b9e2e7b8 167 ST7063 /**< ST7063 */
wim 19:c747b9e2e7b8 168 };
wim 19:c747b9e2e7b8 169
wim 19:c747b9e2e7b8 170
wim 10:dd9b3a696acd 171 /** LCD Cursor control */
wim 10:dd9b3a696acd 172 enum LCDCursor {
wim 17:652ab113bc2e 173 CurOff_BlkOff = 0x00, /**< Cursor Off, Blinking Char Off */
wim 17:652ab113bc2e 174 CurOn_BlkOff = 0x02, /**< Cursor On, Blinking Char Off */
wim 17:652ab113bc2e 175 CurOff_BlkOn = 0x01, /**< Cursor Off, Blinking Char On */
wim 17:652ab113bc2e 176 CurOn_BlkOn = 0x03 /**< Cursor On, Blinking Char On */
wim 17:652ab113bc2e 177 };
wim 17:652ab113bc2e 178
wim 17:652ab113bc2e 179
wim 17:652ab113bc2e 180 /** LCD Display control */
wim 17:652ab113bc2e 181 enum LCDMode {
wim 17:652ab113bc2e 182 DispOff = 0x00, /**< Display Off */
wim 17:652ab113bc2e 183 DispOn = 0x04 /**< Display On */
wim 10:dd9b3a696acd 184 };
wim 10:dd9b3a696acd 185
wim 10:dd9b3a696acd 186
wim 15:b70ebfffb258 187 /** Create a TextLCD interface for using regular mbed pins
simon 2:227356c7d12c 188 *
simon 2:227356c7d12c 189 * @param rs Instruction/data control line
simon 2:227356c7d12c 190 * @param e Enable line (clock)
simon 7:44f34c09bd37 191 * @param d4-d7 Data lines for using as a 4-bit interface
simon 2:227356c7d12c 192 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 19:c747b9e2e7b8 193 * @param e2 Enable2 line (clock for second controller, LCD40x4 only)
wim 19:c747b9e2e7b8 194 * @param ctrl LCD controller (default = HD44780)
simon 2:227356c7d12c 195 */
wim 19:c747b9e2e7b8 196 TextLCD(PinName rs, PinName e, PinName d4, PinName d5, PinName d6, PinName d7, LCDType type = LCD16x2, PinName e2 = NC, LCDCtrl ctrl = HD44780);
wim 13:24506ba22480 197
wim 13:24506ba22480 198 /** Create a TextLCD interface using an I2C PC8574 portexpander
wim 13:24506ba22480 199 *
wim 13:24506ba22480 200 * @param i2c I2C Bus
wim 13:24506ba22480 201 * @param deviceAddress I2C slave address (PCF8574)
wim 13:24506ba22480 202 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 19:c747b9e2e7b8 203 * @param ctrl LCD controller (default = HD44780)
wim 13:24506ba22480 204 */
wim 19:c747b9e2e7b8 205 TextLCD(I2C *i2c, char deviceAddress, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
wim 13:24506ba22480 206
wim 13:24506ba22480 207
wim 13:24506ba22480 208 /** Create a TextLCD interface using an SPI 74595 portexpander
wim 13:24506ba22480 209 *
wim 13:24506ba22480 210 * @param spi SPI Bus
wim 13:24506ba22480 211 * @param cs chip select pin (active low)
wim 13:24506ba22480 212 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 19:c747b9e2e7b8 213 * @param ctrl LCD controller (default = HD44780)
wim 13:24506ba22480 214 */
wim 19:c747b9e2e7b8 215 TextLCD(SPI *spi, PinName cs, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780);
wim 13:24506ba22480 216
simon 2:227356c7d12c 217
simon 2:227356c7d12c 218 #if DOXYGEN_ONLY
simon 2:227356c7d12c 219 /** Write a character to the LCD
simon 2:227356c7d12c 220 *
simon 2:227356c7d12c 221 * @param c The character to write to the display
simon 2:227356c7d12c 222 */
simon 2:227356c7d12c 223 int putc(int c);
simon 2:227356c7d12c 224
simon 2:227356c7d12c 225 /** Write a formated string to the LCD
simon 2:227356c7d12c 226 *
simon 2:227356c7d12c 227 * @param format A printf-style format string, followed by the
simon 2:227356c7d12c 228 * variables to use in formating the string.
simon 2:227356c7d12c 229 */
simon 2:227356c7d12c 230 int printf(const char* format, ...);
simon 2:227356c7d12c 231 #endif
simon 2:227356c7d12c 232
simon 2:227356c7d12c 233 /** Locate to a screen column and row
simon 2:227356c7d12c 234 *
simon 2:227356c7d12c 235 * @param column The horizontal position from the left, indexed from 0
simon 2:227356c7d12c 236 * @param row The vertical position from the top, indexed from 0
simon 2:227356c7d12c 237 */
simon 1:ac48b187213c 238 void locate(int column, int row);
simon 2:227356c7d12c 239
wim 10:dd9b3a696acd 240
wim 10:dd9b3a696acd 241 /** Return the memoryaddress of screen column and row location
wim 10:dd9b3a696acd 242 *
wim 10:dd9b3a696acd 243 * @param column The horizontal position from the left, indexed from 0
wim 10:dd9b3a696acd 244 * @param row The vertical position from the top, indexed from 0
wim 10:dd9b3a696acd 245 * @param return The memoryaddress of screen column and row location
wim 10:dd9b3a696acd 246 */
wim 9:0893d986e717 247 int getAddress(int column, int row);
wim 10:dd9b3a696acd 248
wim 10:dd9b3a696acd 249
wim 10:dd9b3a696acd 250 /** Set the memoryaddress of screen column and row location
wim 10:dd9b3a696acd 251 *
wim 10:dd9b3a696acd 252 * @param column The horizontal position from the left, indexed from 0
wim 10:dd9b3a696acd 253 * @param row The vertical position from the top, indexed from 0
wim 10:dd9b3a696acd 254 */
wim 9:0893d986e717 255 void setAddress(int column, int row);
wim 9:0893d986e717 256
wim 10:dd9b3a696acd 257
simon 2:227356c7d12c 258 /** Clear the screen and locate to 0,0 */
simon 1:ac48b187213c 259 void cls();
simon 2:227356c7d12c 260
wim 10:dd9b3a696acd 261 /** Return the number of rows
wim 10:dd9b3a696acd 262 *
wim 10:dd9b3a696acd 263 * @param return The number of rows
wim 10:dd9b3a696acd 264 */
simon 1:ac48b187213c 265 int rows();
wim 10:dd9b3a696acd 266
wim 10:dd9b3a696acd 267 /** Return the number of columns
wim 10:dd9b3a696acd 268 *
wim 10:dd9b3a696acd 269 * @param return The number of columns
wim 10:dd9b3a696acd 270 */
wim 10:dd9b3a696acd 271 int columns();
simon 2:227356c7d12c 272
wim 11:9ec02df863a1 273 /** Set the Cursormode
wim 11:9ec02df863a1 274 *
wim 17:652ab113bc2e 275 * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn)
wim 11:9ec02df863a1 276 */
wim 17:652ab113bc2e 277 void setCursor(LCDCursor cursorMode);
wim 17:652ab113bc2e 278
wim 17:652ab113bc2e 279
wim 17:652ab113bc2e 280 /** Set the Displaymode
wim 17:652ab113bc2e 281 *
wim 17:652ab113bc2e 282 * @param displayMode The Display mode (DispOff, DispOn)
wim 17:652ab113bc2e 283 */
wim 17:652ab113bc2e 284 void setMode(TextLCD::LCDMode displayMode);
wim 11:9ec02df863a1 285
wim 11:9ec02df863a1 286
wim 11:9ec02df863a1 287 /** Set User Defined Characters
wim 11:9ec02df863a1 288 *
wim 11:9ec02df863a1 289 * @param unsigned char c The Index of the UDC (0..7)
wim 12:6bf9d9957d31 290 * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits)
wim 11:9ec02df863a1 291 */
wim 11:9ec02df863a1 292 void setUDC(unsigned char c, char *udc_data);
wim 11:9ec02df863a1 293
simon 1:ac48b187213c 294 protected:
wim 14:0c32b66b14b8 295 /* LCD Bus control */
wim 13:24506ba22480 296 enum _LCDBus {
wim 14:0c32b66b14b8 297 _PinBus, /*< Regular mbed pins */
wim 14:0c32b66b14b8 298 _I2CBus, /*< I2C PCF8574 Portexpander */
wim 15:b70ebfffb258 299 _SPIBus /*< SPI 74595 Shiftregister */
wim 13:24506ba22480 300 };
wim 13:24506ba22480 301
wim 15:b70ebfffb258 302 /* LCD controller select, mainly used for LCD40x4 */
wim 19:c747b9e2e7b8 303 enum _LCDCtrl_Idx {
wim 15:b70ebfffb258 304 _LCDCtrl_0, /*< Primary */
wim 15:b70ebfffb258 305 _LCDCtrl_1, /*< Secondary */
wim 15:b70ebfffb258 306 };
wim 15:b70ebfffb258 307
simon 1:ac48b187213c 308 // Stream implementation functions
simon 1:ac48b187213c 309 virtual int _putc(int value);
simon 1:ac48b187213c 310 virtual int _getc();
simon 1:ac48b187213c 311
wim 15:b70ebfffb258 312 //Low level methods for LCD controller
wim 13:24506ba22480 313 void _init();
wim 15:b70ebfffb258 314 void _initCtrl();
wim 13:24506ba22480 315 int _address(int column, int row);
wim 15:b70ebfffb258 316 void _setCursor(TextLCD::LCDCursor show);
wim 17:652ab113bc2e 317 void _setUDC(unsigned char c, char *udc_data);
wim 17:652ab113bc2e 318 void _setCursorAndDisplayMode(TextLCD::LCDMode displayMode, TextLCD::LCDCursor cursorType);
wim 13:24506ba22480 319
wim 15:b70ebfffb258 320 //Low level write operations to LCD controller
wim 17:652ab113bc2e 321 void _writeNibble(int value);
wim 15:b70ebfffb258 322 void _writeByte(int value);
wim 15:b70ebfffb258 323 void _writeCommand(int command);
wim 15:b70ebfffb258 324 void _writeData(int data);
wim 15:b70ebfffb258 325
wim 13:24506ba22480 326 //Low level writes to LCD Bus (serial or parallel)
wim 13:24506ba22480 327 void _setEnable(bool value);
wim 13:24506ba22480 328 void _setRS(bool value);
wim 13:24506ba22480 329 void _setData(int value);
wim 14:0c32b66b14b8 330 void _setCS(bool value);
wim 14:0c32b66b14b8 331
wim 13:24506ba22480 332 //Low level writes to LCD serial bus only
wim 13:24506ba22480 333 void _writeBus();
wim 13:24506ba22480 334
wim 13:24506ba22480 335
wim 13:24506ba22480 336 // Regular mbed pins bus
wim 15:b70ebfffb258 337 DigitalOut _rs, _e, _e2;
simon 1:ac48b187213c 338 BusOut _d;
wim 13:24506ba22480 339
wim 13:24506ba22480 340 // I2C bus
wim 13:24506ba22480 341 I2C *_i2c;
wim 13:24506ba22480 342 unsigned char _slaveAddress;
wim 13:24506ba22480 343
wim 13:24506ba22480 344 // SPI bus
wim 14:0c32b66b14b8 345 SPI *_spi;
wim 14:0c32b66b14b8 346 DigitalOut _cs;
wim 13:24506ba22480 347
wim 13:24506ba22480 348 //Bus Interface type
wim 13:24506ba22480 349 _LCDBus _busType;
wim 13:24506ba22480 350
wim 15:b70ebfffb258 351 // Internal bus mirror value for serial bus only
wim 13:24506ba22480 352 char _lcd_bus;
wim 13:24506ba22480 353
wim 13:24506ba22480 354 //Display type
simon 1:ac48b187213c 355 LCDType _type;
simon 1:ac48b187213c 356
wim 17:652ab113bc2e 357 //Display type
wim 17:652ab113bc2e 358 LCDMode _currentMode;
wim 17:652ab113bc2e 359
wim 19:c747b9e2e7b8 360 //Controller type
wim 19:c747b9e2e7b8 361 LCDCtrl _ctrl;
wim 19:c747b9e2e7b8 362
wim 15:b70ebfffb258 363 //Controller select, mainly used for LCD40x4
wim 19:c747b9e2e7b8 364 _LCDCtrl_Idx _ctrl_idx;
wim 15:b70ebfffb258 365
wim 13:24506ba22480 366 // Cursor
simon 1:ac48b187213c 367 int _column;
simon 1:ac48b187213c 368 int _row;
wim 15:b70ebfffb258 369 LCDCursor _currentCursor;
simon 1:ac48b187213c 370 };
simon 1:ac48b187213c 371
simon 1:ac48b187213c 372 #endif