Counter

Dependencies:   EthernetInterface NTPClient SDFileSystem TextLCD WebSocketClient mbed-rtos mbed Socket lwip-eth lwip-sys lwip FATFileSystem

Committer:
Tuxitheone
Date:
Mon Feb 29 18:59:15 2016 +0000
Revision:
0:ecaf3e593122
TankCounter

Who changed what in which revision?

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