Added new createChar() method. Added new clear() method. Added new scrollDisplayLeft() method. Added new scrollDisplayRight() method. Added support for Arduino alike Custom Character, scroll and clear command interfaces.

Dependents:   mbed_lcd_custom MMA8451_ACELEROMETRO_copy

Fork of TextLCD by The Electronics Nuke

Committer:
mbeded
Date:
Thu Jul 03 21:13:50 2014 +0000
Revision:
34:c382632a6e27
Parent:
33:ec30a01baf4a
Arduino Alike Lcd Library

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