In TextLCD_I2C_N Class, added void setContrast(unsigned char c) function as temporary. This is for ST7032i non-volume type contrast control.
Dependents: LPC1114_data_logger RTC_w_COM Frequency_Counter_w_GPS_1PPS CW_Decoder_using_FFT_on_F446 ... more
Fork of TextLCD by
In TextLCD_I2C_N Class, added void setContrast(unsigned char c) function as temporary.
TextLCD.h@29:986538f94abe, 2014-06-15 (annotated)
- Committer:
- kenjiArai
- Date:
- Sun Jun 15 03:22:32 2014 +0000
- Revision:
- 29:986538f94abe
- Parent:
- 28:30fa94f7341c
- Child:
- 30:4c57a022a56c
Added setContrast() function for ST7032i
Who changed what in which revision?
User | Revision | Line number | New 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 |
wim | 21:9eb628d9e164 | 10 | * 2014, v08: WH, Refactored in Base and Derived Classes to deal with mbed lib change regarding 'NC' defined DigitalOut pins |
wim | 25:6162b31128c9 | 11 | * 2014, v09: WH/EO, Added Class for Native SPI controllers such as ST7032 |
kenjiArai | 29:986538f94abe | 12 | * 2014, v10: WH, Added Class for Native I2C controllers such as ST7032i, Added support for MCP23008 I2C portexpander, Added support for Adafruit module |
kenjiArai | 29:986538f94abe | 13 | * 2014, v11: SW, added setContrast function for ST7032i only by JH1PJL |
simon | 1:ac48b187213c | 14 | * |
simon | 1:ac48b187213c | 15 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
simon | 1:ac48b187213c | 16 | * of this software and associated documentation files (the "Software"), to deal |
simon | 1:ac48b187213c | 17 | * in the Software without restriction, including without limitation the rights |
simon | 1:ac48b187213c | 18 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
simon | 1:ac48b187213c | 19 | * copies of the Software, and to permit persons to whom the Software is |
simon | 1:ac48b187213c | 20 | * furnished to do so, subject to the following conditions: |
simon | 2:227356c7d12c | 21 | * |
simon | 1:ac48b187213c | 22 | * The above copyright notice and this permission notice shall be included in |
simon | 1:ac48b187213c | 23 | * all copies or substantial portions of the Software. |
simon | 2:227356c7d12c | 24 | * |
simon | 1:ac48b187213c | 25 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
simon | 1:ac48b187213c | 26 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
simon | 1:ac48b187213c | 27 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
simon | 1:ac48b187213c | 28 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
simon | 1:ac48b187213c | 29 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
simon | 1:ac48b187213c | 30 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
simon | 1:ac48b187213c | 31 | * THE SOFTWARE. |
simon | 1:ac48b187213c | 32 | */ |
simon | 1:ac48b187213c | 33 | |
simon | 1:ac48b187213c | 34 | #ifndef MBED_TEXTLCD_H |
simon | 1:ac48b187213c | 35 | #define MBED_TEXTLCD_H |
simon | 1:ac48b187213c | 36 | |
simon | 1:ac48b187213c | 37 | #include "mbed.h" |
simon | 2:227356c7d12c | 38 | |
simon | 5:a53b3e2d6f1e | 39 | /** A TextLCD interface for driving 4-bit HD44780-based LCDs |
simon | 2:227356c7d12c | 40 | * |
wim | 16:c276b75e6585 | 41 | * Currently supports 8x1, 8x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels |
wim | 27:22d5086f6ba6 | 42 | * Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or SPI bus shiftregister (74595). |
wim | 27:22d5086f6ba6 | 43 | * Supports some controllers with native I2C or SP interface. Supports some controllers that provide internal DC/DC converters for VLCD or VLED. |
simon | 2:227356c7d12c | 44 | * |
simon | 2:227356c7d12c | 45 | * @code |
simon | 2:227356c7d12c | 46 | * #include "mbed.h" |
simon | 2:227356c7d12c | 47 | * #include "TextLCD.h" |
simon | 5:a53b3e2d6f1e | 48 | * |
wim | 16:c276b75e6585 | 49 | * // I2C Communication |
wim | 16:c276b75e6585 | 50 | * I2C i2c_lcd(p28,p27); // SDA, SCL |
wim | 16:c276b75e6585 | 51 | * |
wim | 16:c276b75e6585 | 52 | * // SPI Communication |
wim | 16:c276b75e6585 | 53 | * SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK |
wim | 16:c276b75e6585 | 54 | * |
wim | 22:35742ec80c24 | 55 | * //TextLCD lcd(p15, p16, p17, p18, p19, p20); // RS, E, D4-D7, LCDType=LCD16x2, BL=NC, E2=NC, LCDTCtrl=HD44780 |
wim | 28:30fa94f7341c | 56 | * //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, 74595 expander, CS pin, LCD Type |
wim | 22:35742ec80c24 | 57 | * TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type |
wim | 21:9eb628d9e164 | 58 | * //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type |
wim | 27:22d5086f6ba6 | 59 | * //TextLCD_SPI_N lcd(&spi_lcd, p8, p9); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032_3V3 |
wim | 28:30fa94f7341c | 60 | * //TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C bus, Slaveaddress, LCD Type, BL=NC, LCDTCtrl=ST7032_3V3 |
simon | 5:a53b3e2d6f1e | 61 | * |
simon | 2:227356c7d12c | 62 | * int main() { |
wim | 16:c276b75e6585 | 63 | * lcd.printf("Hello World!\n"); |
simon | 2:227356c7d12c | 64 | * } |
simon | 2:227356c7d12c | 65 | * @endcode |
simon | 2:227356c7d12c | 66 | */ |
wim | 8:03116f75b66e | 67 | |
wim | 26:bd897a001012 | 68 | |
wim | 26:bd897a001012 | 69 | //Pin Defines for I2C PCF8574/PCF8574A or MCP23008 and SPI 74595 bus expander interfaces |
wim | 13:24506ba22480 | 70 | //LCD and serial portexpanders should be wired accordingly |
wim | 20:e0da005a777f | 71 | // |
wim | 26:bd897a001012 | 72 | //Select Hardware module (one option only) |
wim | 28:30fa94f7341c | 73 | #define DEFAULT 1 |
wim | 28:30fa94f7341c | 74 | #define ADAFRUIT 0 |
wim | 26:bd897a001012 | 75 | #define DFROBOT 0 |
wim | 26:bd897a001012 | 76 | |
wim | 26:bd897a001012 | 77 | |
wim | 26:bd897a001012 | 78 | #if (DEFAULT==1) |
wim | 20:e0da005a777f | 79 | //Definitions for hardware used by WH |
wim | 26:bd897a001012 | 80 | //This hardware supports the I2C bus expander (PCF8574/PCF8574A or MCP23008) and SPI bus expander (74595) interfaces |
wim | 26:bd897a001012 | 81 | // |
wim | 13:24506ba22480 | 82 | //Note: LCD RW pin must be connected to GND |
wim | 15:b70ebfffb258 | 83 | // E2 is used for LCD40x4 (second controller) |
wim | 26:bd897a001012 | 84 | // BL may be used to control backlight |
wim | 15:b70ebfffb258 | 85 | #define D_LCD_PIN_D4 0 |
wim | 15:b70ebfffb258 | 86 | #define D_LCD_PIN_D5 1 |
wim | 15:b70ebfffb258 | 87 | #define D_LCD_PIN_D6 2 |
wim | 15:b70ebfffb258 | 88 | #define D_LCD_PIN_D7 3 |
wim | 15:b70ebfffb258 | 89 | #define D_LCD_PIN_RS 4 |
wim | 15:b70ebfffb258 | 90 | #define D_LCD_PIN_E 5 |
wim | 15:b70ebfffb258 | 91 | #define D_LCD_PIN_E2 6 |
wim | 15:b70ebfffb258 | 92 | #define D_LCD_PIN_BL 7 |
wim | 13:24506ba22480 | 93 | |
wim | 20:e0da005a777f | 94 | #define D_LCD_PIN_RW D_LCD_PIN_E2 |
wim | 20:e0da005a777f | 95 | |
wim | 26:bd897a001012 | 96 | //Select I2C Portexpander type (one option only) |
wim | 26:bd897a001012 | 97 | #define PCF8574 1 |
wim | 26:bd897a001012 | 98 | #define MCP23008 0 |
wim | 26:bd897a001012 | 99 | #endif |
wim | 20:e0da005a777f | 100 | |
wim | 26:bd897a001012 | 101 | #if (ADAFRUIT==1) |
wim | 26:bd897a001012 | 102 | //Definitions for i2cspilcdbackpack from Adafruit, See http://www.ladyada.net/products/i2cspilcdbackpack |
wim | 26:bd897a001012 | 103 | //This hardware supports both an I2C expander (MCP23008) and an SPI expander (74595) selectable by a jumper. |
wim | 26:bd897a001012 | 104 | // |
wim | 26:bd897a001012 | 105 | //Note: LCD RW pin must be kept LOW |
wim | 26:bd897a001012 | 106 | // E2 is not available on this hardware and so it does not support LCD40x4 (second controller) |
wim | 26:bd897a001012 | 107 | // BL is used to control backlight |
wim | 26:bd897a001012 | 108 | #define D_LCD_PIN_0 0 |
wim | 26:bd897a001012 | 109 | #define D_LCD_PIN_RS 1 |
wim | 26:bd897a001012 | 110 | #define D_LCD_PIN_E 2 |
wim | 26:bd897a001012 | 111 | #define D_LCD_PIN_D4 3 |
wim | 26:bd897a001012 | 112 | #define D_LCD_PIN_D5 4 |
wim | 26:bd897a001012 | 113 | #define D_LCD_PIN_D6 5 |
wim | 26:bd897a001012 | 114 | #define D_LCD_PIN_D7 6 |
wim | 26:bd897a001012 | 115 | #define D_LCD_PIN_BL 7 |
wim | 26:bd897a001012 | 116 | |
wim | 26:bd897a001012 | 117 | #define D_LCD_PIN_E2 D_LCD_PIN_0 |
wim | 26:bd897a001012 | 118 | |
wim | 26:bd897a001012 | 119 | //Force I2C portexpander type |
wim | 26:bd897a001012 | 120 | #define PCF8574 0 |
wim | 26:bd897a001012 | 121 | #define MCP23008 1 |
wim | 26:bd897a001012 | 122 | #endif |
wim | 26:bd897a001012 | 123 | |
wim | 26:bd897a001012 | 124 | #if (DFROBOT==1) |
wim | 20:e0da005a777f | 125 | //Definitions for LCD2004 Module from DFROBOT, See http://arduino-info.wikispaces.com/LCD-Blue-I2C |
wim | 26:bd897a001012 | 126 | //This hardware uses PCF8574 and is different from earlier/different Arduino I2C LCD displays |
wim | 26:bd897a001012 | 127 | // |
wim | 20:e0da005a777f | 128 | //Note: LCD RW pin must be kept LOW |
wim | 26:bd897a001012 | 129 | // E2 is not available on default Arduino hardware and so it does not support LCD40x4 (second controller) |
wim | 20:e0da005a777f | 130 | // BL is used to control backlight |
wim | 20:e0da005a777f | 131 | #define D_LCD_PIN_RS 0 |
wim | 20:e0da005a777f | 132 | #define D_LCD_PIN_RW 1 |
wim | 20:e0da005a777f | 133 | #define D_LCD_PIN_E 2 |
wim | 20:e0da005a777f | 134 | #define D_LCD_PIN_BL 3 |
wim | 20:e0da005a777f | 135 | #define D_LCD_PIN_D4 4 |
wim | 20:e0da005a777f | 136 | #define D_LCD_PIN_D5 5 |
wim | 20:e0da005a777f | 137 | #define D_LCD_PIN_D6 6 |
wim | 20:e0da005a777f | 138 | #define D_LCD_PIN_D7 7 |
wim | 20:e0da005a777f | 139 | |
wim | 20:e0da005a777f | 140 | #define D_LCD_PIN_E2 D_LCD_PIN_RW |
wim | 26:bd897a001012 | 141 | |
wim | 26:bd897a001012 | 142 | //Force I2C portexpander type |
wim | 26:bd897a001012 | 143 | #define PCF8574 1 |
wim | 26:bd897a001012 | 144 | #define MCP23008 0 |
wim | 20:e0da005a777f | 145 | #endif |
wim | 13:24506ba22480 | 146 | |
wim | 26:bd897a001012 | 147 | //Bitpattern Defines for I2C PCF8574/PCF8574A, MCP23008 and SPI 74595 Bus expanders |
wim | 13:24506ba22480 | 148 | // |
wim | 13:24506ba22480 | 149 | #define D_LCD_D4 (1<<D_LCD_PIN_D4) |
wim | 13:24506ba22480 | 150 | #define D_LCD_D5 (1<<D_LCD_PIN_D5) |
wim | 13:24506ba22480 | 151 | #define D_LCD_D6 (1<<D_LCD_PIN_D6) |
wim | 13:24506ba22480 | 152 | #define D_LCD_D7 (1<<D_LCD_PIN_D7) |
wim | 13:24506ba22480 | 153 | #define D_LCD_RS (1<<D_LCD_PIN_RS) |
wim | 13:24506ba22480 | 154 | #define D_LCD_E (1<<D_LCD_PIN_E) |
wim | 13:24506ba22480 | 155 | #define D_LCD_E2 (1<<D_LCD_PIN_E2) |
wim | 13:24506ba22480 | 156 | #define D_LCD_BL (1<<D_LCD_PIN_BL) |
wim | 20:e0da005a777f | 157 | //#define D_LCD_RW (1<<D_LCD_PIN_RW) |
wim | 20:e0da005a777f | 158 | |
wim | 20:e0da005a777f | 159 | #define D_LCD_BUS_MSK (D_LCD_D4 | D_LCD_D5 | D_LCD_D6 | D_LCD_D7) |
wim | 20:e0da005a777f | 160 | #define D_LCD_BUS_DEF 0x00 |
wim | 13:24506ba22480 | 161 | |
wim | 26:bd897a001012 | 162 | /* PCF8574/PCF8574A I2C portexpander slave address */ |
wim | 26:bd897a001012 | 163 | #define PCF8574_SA0 0x40 |
wim | 26:bd897a001012 | 164 | #define PCF8574_SA1 0x42 |
wim | 26:bd897a001012 | 165 | #define PCF8574_SA2 0x44 |
wim | 26:bd897a001012 | 166 | #define PCF8574_SA3 0x46 |
wim | 26:bd897a001012 | 167 | #define PCF8574_SA4 0x48 |
wim | 26:bd897a001012 | 168 | #define PCF8574_SA5 0x4A |
wim | 26:bd897a001012 | 169 | #define PCF8574_SA6 0x4C |
wim | 26:bd897a001012 | 170 | #define PCF8574_SA7 0x4E |
wim | 26:bd897a001012 | 171 | |
wim | 26:bd897a001012 | 172 | #define PCF8574A_SA0 0x70 |
wim | 26:bd897a001012 | 173 | #define PCF8574A_SA1 0x72 |
wim | 26:bd897a001012 | 174 | #define PCF8574A_SA2 0x74 |
wim | 26:bd897a001012 | 175 | #define PCF8574A_SA3 0x76 |
wim | 26:bd897a001012 | 176 | #define PCF8574A_SA4 0x78 |
wim | 26:bd897a001012 | 177 | #define PCF8574A_SA5 0x7A |
wim | 26:bd897a001012 | 178 | #define PCF8574A_SA6 0x7C |
wim | 26:bd897a001012 | 179 | #define PCF8574A_SA7 0x7E |
wim | 26:bd897a001012 | 180 | |
wim | 26:bd897a001012 | 181 | /* MCP23008 I2C portexpander slave address */ |
wim | 26:bd897a001012 | 182 | #define MCP23008_SA0 0x40 |
wim | 26:bd897a001012 | 183 | #define MCP23008_SA1 0x42 |
wim | 26:bd897a001012 | 184 | #define MCP23008_SA2 0x44 |
wim | 26:bd897a001012 | 185 | #define MCP23008_SA3 0x46 |
wim | 26:bd897a001012 | 186 | #define MCP23008_SA4 0x48 |
wim | 26:bd897a001012 | 187 | #define MCP23008_SA5 0x4A |
wim | 26:bd897a001012 | 188 | #define MCP23008_SA6 0x4C |
wim | 26:bd897a001012 | 189 | #define MCP23008_SA7 0x4E |
wim | 26:bd897a001012 | 190 | |
wim | 26:bd897a001012 | 191 | |
wim | 26:bd897a001012 | 192 | /* MCP23008 I2C portexpander internal registers */ |
wim | 26:bd897a001012 | 193 | #define IODIR 0x00 |
wim | 26:bd897a001012 | 194 | #define IPOL 0x01 |
wim | 26:bd897a001012 | 195 | #define GPINTEN 0x02 |
wim | 26:bd897a001012 | 196 | #define DEFVAL 0x03 |
wim | 26:bd897a001012 | 197 | #define INTCON 0x04 |
wim | 26:bd897a001012 | 198 | #define IOCON 0x05 |
wim | 26:bd897a001012 | 199 | #define GPPU 0x06 |
wim | 26:bd897a001012 | 200 | #define INTF 0x07 |
wim | 26:bd897a001012 | 201 | #define INTCAP 0x08 |
wim | 26:bd897a001012 | 202 | #define GPIO 0x09 |
wim | 26:bd897a001012 | 203 | #define OLAT 0x0A |
wim | 26:bd897a001012 | 204 | |
wim | 26:bd897a001012 | 205 | |
wim | 26:bd897a001012 | 206 | /* ST7032I I2C slave address */ |
wim | 26:bd897a001012 | 207 | #define ST7032_SA 0x7C |
wim | 26:bd897a001012 | 208 | |
wim | 13:24506ba22480 | 209 | |
wim | 13:24506ba22480 | 210 | /** Some sample User Defined Chars 5x7 dots */ |
wim | 11:9ec02df863a1 | 211 | const char udc_ae[] = {0x00, 0x00, 0x1B, 0x05, 0x1F, 0x14, 0x1F, 0x00}; //æ |
wim | 11:9ec02df863a1 | 212 | const char udc_0e[] = {0x00, 0x00, 0x0E, 0x13, 0x15, 0x19, 0x0E, 0x00}; //ø |
wim | 11:9ec02df863a1 | 213 | const char udc_ao[] = {0x0E, 0x0A, 0x0E, 0x01, 0x0F, 0x11, 0x0F, 0x00}; //å |
wim | 11:9ec02df863a1 | 214 | const char udc_AE[] = {0x0F, 0x14, 0x14, 0x1F, 0x14, 0x14, 0x17, 0x00}; //Æ |
wim | 11:9ec02df863a1 | 215 | const char udc_0E[] = {0x0E, 0x13, 0x15, 0x15, 0x15, 0x19, 0x0E, 0x00}; //Ø |
wim | 18:bd65dc10f27f | 216 | const char udc_Ao[] = {0x0E, 0x0A, 0x0E, 0x11, 0x1F, 0x11, 0x11, 0x00}; //Å |
wim | 18:bd65dc10f27f | 217 | const char udc_PO[] = {0x04, 0x0A, 0x0A, 0x1F, 0x1B, 0x1B, 0x1F, 0x00}; //Padlock Open |
wim | 18:bd65dc10f27f | 218 | const char udc_PC[] = {0x1C, 0x10, 0x08, 0x1F, 0x1B, 0x1B, 0x1F, 0x00}; //Padlock Closed |
wim | 11:9ec02df863a1 | 219 | |
wim | 11:9ec02df863a1 | 220 | const char udc_0[] = {0x18, 0x14, 0x12, 0x11, 0x12, 0x14, 0x18, 0x00}; // |> |
wim | 11:9ec02df863a1 | 221 | const char udc_1[] = {0x03, 0x05, 0x09, 0x11, 0x09, 0x05, 0x03, 0x00}; // <| |
wim | 11:9ec02df863a1 | 222 | const char udc_2[] = {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00}; // | |
wim | 11:9ec02df863a1 | 223 | const char udc_3[] = {0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x14, 0x00}; // || |
wim | 11:9ec02df863a1 | 224 | const char udc_4[] = {0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x00}; // ||| |
wim | 11:9ec02df863a1 | 225 | const char udc_5[] = {0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x00}; // = |
wim | 11:9ec02df863a1 | 226 | const char udc_6[] = {0x15, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x15, 0x00}; // checkerboard |
wim | 11:9ec02df863a1 | 227 | const char udc_7[] = {0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x10, 0x00}; // \ |
wim | 11:9ec02df863a1 | 228 | |
wim | 13:24506ba22480 | 229 | const char udc_degr[] = {0x06, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00}; // Degree symbol |
wim | 13:24506ba22480 | 230 | |
wim | 13:24506ba22480 | 231 | const char udc_TM_T[] = {0x1F, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; // Trademark T |
wim | 13:24506ba22480 | 232 | const char udc_TM_M[] = {0x11, 0x1B, 0x15, 0x11, 0x00, 0x00, 0x00, 0x00}; // Trademark M |
wim | 13:24506ba22480 | 233 | |
wim | 13:24506ba22480 | 234 | //const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Full |
wim | 13:24506ba22480 | 235 | //const char udc_Bat_Ha[] = {0x0E, 0x11, 0x13, 0x17, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Half |
wim | 13:24506ba22480 | 236 | //const char udc_Bat_Lo[] = {0x0E, 0x11, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x00}; // Battery Low |
wim | 13:24506ba22480 | 237 | const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Full |
wim | 13:24506ba22480 | 238 | const char udc_Bat_Ha[] = {0x0E, 0x11, 0x11, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Half |
wim | 13:24506ba22480 | 239 | const char udc_Bat_Lo[] = {0x0E, 0x11, 0x11, 0x11, 0x11, 0x1F, 0x1F, 0x00}; // Battery Low |
wim | 18:bd65dc10f27f | 240 | const char udc_AC[] = {0x0A, 0x0A, 0x1F, 0x11, 0x0E, 0x04, 0x04, 0x00}; // AC Power |
wim | 13:24506ba22480 | 241 | |
wim | 18:bd65dc10f27f | 242 | //const char udc_smiley[] = {0x00, 0x0A, 0x00, 0x04, 0x11, 0x0E, 0x00, 0x00}; // Smiley |
wim | 18:bd65dc10f27f | 243 | //const char udc_droopy[] = {0x00, 0x0A, 0x00, 0x04, 0x00, 0x0E, 0x11, 0x00}; // Droopey |
wim | 18:bd65dc10f27f | 244 | //const char udc_note[] = {0x01, 0x03, 0x05, 0x09, 0x0B, 0x1B, 0x18, 0x00}; // Note |
wim | 18:bd65dc10f27f | 245 | |
wim | 18:bd65dc10f27f | 246 | //const char udc_bar_1[] = {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00}; // Bar 1 |
wim | 18:bd65dc10f27f | 247 | //const char udc_bar_2[] = {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}; // Bar 11 |
wim | 18:bd65dc10f27f | 248 | //const char udc_bar_3[] = {0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x1C, 0x00}; // Bar 111 |
wim | 18:bd65dc10f27f | 249 | //const char udc_bar_4[] = {0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x17, 0x00}; // Bar 1111 |
wim | 18:bd65dc10f27f | 250 | //const char udc_bar_5[] = {0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Bar 11111 |
wim | 13:24506ba22480 | 251 | |
wim | 28:30fa94f7341c | 252 | //const char udc_ch_1[] = {0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00}; // Hor bars 4 |
wim | 28:30fa94f7341c | 253 | //const char udc_ch_2[] = {0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f}; // Hor bars 4 (inverted) |
wim | 28:30fa94f7341c | 254 | //const char udc_ch_3[] = {0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15, 0x15}; // Ver bars 3 |
wim | 28:30fa94f7341c | 255 | //const char udc_ch_4[] = {0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a, 0x0a}; // Ver bars 3 (inverted) |
wim | 28:30fa94f7341c | 256 | //const char udc_ch_yr[] = {0x08, 0x0f, 0x12, 0x0f, 0x0a, 0x1f, 0x02, 0x02}; // Year (kanji) |
wim | 28:30fa94f7341c | 257 | //const char udc_ch_mo[] = {0x0f, 0x09, 0x0f, 0x09, 0x0f, 0x09, 0x09, 0x13}; // Month (kanji) |
wim | 28:30fa94f7341c | 258 | //const char udc_ch_dy[] = {0x1f, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11, 0x1F}; // Day (kanji) |
wim | 28:30fa94f7341c | 259 | //const char udc_ch_mi[] = {0x0C, 0x0a, 0x11, 0x1f, 0x09, 0x09, 0x09, 0x13}; // minute (kanji) |
wim | 28:30fa94f7341c | 260 | |
wim | 11:9ec02df863a1 | 261 | |
wim | 11:9ec02df863a1 | 262 | /** A TextLCD interface for driving 4-bit HD44780-based LCDs |
wim | 11:9ec02df863a1 | 263 | * |
wim | 22:35742ec80c24 | 264 | * @brief Currently supports 8x1, 8x2, 12x2, 12x4, 16x1, 16x2, 16x4, 20x2, 20x4, 24x2, 24x4, 40x2 and 40x4 panels |
wim | 27:22d5086f6ba6 | 265 | * Interface options include direct mbed pins, I2C portexpander (PCF8474/PCF8574A or MCP23008) or SPI bus shiftregister (74595) and some native I2C or SPI devices |
wim | 11:9ec02df863a1 | 266 | * |
wim | 11:9ec02df863a1 | 267 | */ |
wim | 21:9eb628d9e164 | 268 | class TextLCD_Base : public Stream { |
simon | 1:ac48b187213c | 269 | public: |
simon | 1:ac48b187213c | 270 | |
simon | 2:227356c7d12c | 271 | /** LCD panel format */ |
simon | 1:ac48b187213c | 272 | enum LCDType { |
wim | 8:03116f75b66e | 273 | LCD8x1, /**< 8x1 LCD panel */ |
wim | 13:24506ba22480 | 274 | LCD8x2, /**< 8x2 LCD panel */ |
wim | 18:bd65dc10f27f | 275 | LCD8x2B, /**< 8x2 LCD panel (actually 16x1) */ |
wim | 15:b70ebfffb258 | 276 | LCD12x2, /**< 12x2 LCD panel */ |
wim | 28:30fa94f7341c | 277 | // LCD12x3, /**< 12x3 LCD panel, special mode PCF21XX */ |
wim | 15:b70ebfffb258 | 278 | LCD12x4, /**< 12x4 LCD panel */ |
wim | 28:30fa94f7341c | 279 | // LCD12x4B, /**< 12x4 LCD panel, special mode PCF21XX */ |
wim | 13:24506ba22480 | 280 | LCD16x1, /**< 16x1 LCD panel (actually 8x2) */ |
wim | 8:03116f75b66e | 281 | LCD16x2, /**< 16x2 LCD panel (default) */ |
wim | 8:03116f75b66e | 282 | LCD16x2B, /**< 16x2 LCD panel alternate addressing */ |
wim | 28:30fa94f7341c | 283 | // LCD16x3, /**< 16x3 LCD panel, special mode ST7036 */ |
wim | 8:03116f75b66e | 284 | LCD16x4, /**< 16x4 LCD panel */ |
wim | 8:03116f75b66e | 285 | LCD20x2, /**< 20x2 LCD panel */ |
wim | 8:03116f75b66e | 286 | LCD20x4, /**< 20x4 LCD panel */ |
wim | 9:0893d986e717 | 287 | LCD24x2, /**< 24x2 LCD panel */ |
wim | 10:dd9b3a696acd | 288 | LCD24x4, /**< 24x4 LCD panel, special mode KS0078 */ |
wim | 15:b70ebfffb258 | 289 | LCD40x2, /**< 40x2 LCD panel */ |
wim | 15:b70ebfffb258 | 290 | LCD40x4 /**< 40x4 LCD panel, Two controller version */ |
simon | 1:ac48b187213c | 291 | }; |
simon | 1:ac48b187213c | 292 | |
wim | 19:c747b9e2e7b8 | 293 | /** LCD Controller Device */ |
wim | 19:c747b9e2e7b8 | 294 | enum LCDCtrl { |
wim | 28:30fa94f7341c | 295 | HD44780, /**< HD44780 (default) */ |
wim | 28:30fa94f7341c | 296 | WS0010, /**< WS0010 OLED Controller */ |
wim | 28:30fa94f7341c | 297 | ST7036, /**< ST7036 3V3 with Booster */ |
wim | 28:30fa94f7341c | 298 | ST7032_3V3, /**< ST7032 3V3 with Booster */ |
wim | 28:30fa94f7341c | 299 | ST7032_5V /**< ST7032 5V no Booster */ |
wim | 28:30fa94f7341c | 300 | // PCF210X, /**< PCF210X 5V no Booster */ |
wim | 28:30fa94f7341c | 301 | // PCF211X /**< PCF211X 3V3 with Booster */ |
wim | 19:c747b9e2e7b8 | 302 | }; |
wim | 19:c747b9e2e7b8 | 303 | |
wim | 19:c747b9e2e7b8 | 304 | |
wim | 10:dd9b3a696acd | 305 | /** LCD Cursor control */ |
wim | 10:dd9b3a696acd | 306 | enum LCDCursor { |
wim | 17:652ab113bc2e | 307 | CurOff_BlkOff = 0x00, /**< Cursor Off, Blinking Char Off */ |
wim | 17:652ab113bc2e | 308 | CurOn_BlkOff = 0x02, /**< Cursor On, Blinking Char Off */ |
wim | 17:652ab113bc2e | 309 | CurOff_BlkOn = 0x01, /**< Cursor Off, Blinking Char On */ |
wim | 17:652ab113bc2e | 310 | CurOn_BlkOn = 0x03 /**< Cursor On, Blinking Char On */ |
wim | 17:652ab113bc2e | 311 | }; |
wim | 17:652ab113bc2e | 312 | |
wim | 17:652ab113bc2e | 313 | |
wim | 17:652ab113bc2e | 314 | /** LCD Display control */ |
wim | 17:652ab113bc2e | 315 | enum LCDMode { |
wim | 17:652ab113bc2e | 316 | DispOff = 0x00, /**< Display Off */ |
wim | 17:652ab113bc2e | 317 | DispOn = 0x04 /**< Display On */ |
wim | 10:dd9b3a696acd | 318 | }; |
wim | 10:dd9b3a696acd | 319 | |
wim | 20:e0da005a777f | 320 | /** LCD Backlight control */ |
wim | 20:e0da005a777f | 321 | enum LCDBacklight { |
wim | 20:e0da005a777f | 322 | LightOff, /**< Backlight Off */ |
wim | 20:e0da005a777f | 323 | LightOn /**< Backlight On */ |
wim | 20:e0da005a777f | 324 | }; |
wim | 10:dd9b3a696acd | 325 | |
simon | 2:227356c7d12c | 326 | |
simon | 2:227356c7d12c | 327 | #if DOXYGEN_ONLY |
simon | 2:227356c7d12c | 328 | /** Write a character to the LCD |
simon | 2:227356c7d12c | 329 | * |
simon | 2:227356c7d12c | 330 | * @param c The character to write to the display |
simon | 2:227356c7d12c | 331 | */ |
simon | 2:227356c7d12c | 332 | int putc(int c); |
simon | 2:227356c7d12c | 333 | |
simon | 2:227356c7d12c | 334 | /** Write a formated string to the LCD |
simon | 2:227356c7d12c | 335 | * |
simon | 2:227356c7d12c | 336 | * @param format A printf-style format string, followed by the |
simon | 2:227356c7d12c | 337 | * variables to use in formating the string. |
simon | 2:227356c7d12c | 338 | */ |
simon | 2:227356c7d12c | 339 | int printf(const char* format, ...); |
simon | 2:227356c7d12c | 340 | #endif |
simon | 2:227356c7d12c | 341 | |
simon | 2:227356c7d12c | 342 | /** Locate to a screen column and row |
simon | 2:227356c7d12c | 343 | * |
simon | 2:227356c7d12c | 344 | * @param column The horizontal position from the left, indexed from 0 |
simon | 2:227356c7d12c | 345 | * @param row The vertical position from the top, indexed from 0 |
simon | 2:227356c7d12c | 346 | */ |
simon | 1:ac48b187213c | 347 | void locate(int column, int row); |
simon | 2:227356c7d12c | 348 | |
wim | 10:dd9b3a696acd | 349 | |
wim | 10:dd9b3a696acd | 350 | /** Return the memoryaddress of screen column and row location |
wim | 10:dd9b3a696acd | 351 | * |
wim | 10:dd9b3a696acd | 352 | * @param column The horizontal position from the left, indexed from 0 |
wim | 10:dd9b3a696acd | 353 | * @param row The vertical position from the top, indexed from 0 |
wim | 10:dd9b3a696acd | 354 | * @param return The memoryaddress of screen column and row location |
wim | 10:dd9b3a696acd | 355 | */ |
wim | 9:0893d986e717 | 356 | int getAddress(int column, int row); |
wim | 10:dd9b3a696acd | 357 | |
wim | 10:dd9b3a696acd | 358 | |
wim | 10:dd9b3a696acd | 359 | /** Set the memoryaddress of screen column and row location |
wim | 10:dd9b3a696acd | 360 | * |
wim | 10:dd9b3a696acd | 361 | * @param column The horizontal position from the left, indexed from 0 |
wim | 10:dd9b3a696acd | 362 | * @param row The vertical position from the top, indexed from 0 |
wim | 10:dd9b3a696acd | 363 | */ |
wim | 9:0893d986e717 | 364 | void setAddress(int column, int row); |
wim | 9:0893d986e717 | 365 | |
wim | 10:dd9b3a696acd | 366 | |
wim | 22:35742ec80c24 | 367 | /** Clear the screen and locate to 0,0 |
wim | 22:35742ec80c24 | 368 | */ |
simon | 1:ac48b187213c | 369 | void cls(); |
simon | 2:227356c7d12c | 370 | |
wim | 10:dd9b3a696acd | 371 | /** Return the number of rows |
wim | 10:dd9b3a696acd | 372 | * |
wim | 10:dd9b3a696acd | 373 | * @param return The number of rows |
wim | 10:dd9b3a696acd | 374 | */ |
simon | 1:ac48b187213c | 375 | int rows(); |
wim | 10:dd9b3a696acd | 376 | |
wim | 10:dd9b3a696acd | 377 | /** Return the number of columns |
wim | 10:dd9b3a696acd | 378 | * |
wim | 10:dd9b3a696acd | 379 | * @param return The number of columns |
wim | 10:dd9b3a696acd | 380 | */ |
wim | 10:dd9b3a696acd | 381 | int columns(); |
simon | 2:227356c7d12c | 382 | |
wim | 11:9ec02df863a1 | 383 | /** Set the Cursormode |
wim | 11:9ec02df863a1 | 384 | * |
wim | 17:652ab113bc2e | 385 | * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn) |
wim | 11:9ec02df863a1 | 386 | */ |
wim | 17:652ab113bc2e | 387 | void setCursor(LCDCursor cursorMode); |
wim | 17:652ab113bc2e | 388 | |
wim | 17:652ab113bc2e | 389 | |
wim | 17:652ab113bc2e | 390 | /** Set the Displaymode |
wim | 17:652ab113bc2e | 391 | * |
wim | 17:652ab113bc2e | 392 | * @param displayMode The Display mode (DispOff, DispOn) |
wim | 17:652ab113bc2e | 393 | */ |
wim | 21:9eb628d9e164 | 394 | void setMode(LCDMode displayMode); |
wim | 11:9ec02df863a1 | 395 | |
wim | 20:e0da005a777f | 396 | /** Set the Backlight mode |
wim | 20:e0da005a777f | 397 | * |
wim | 21:9eb628d9e164 | 398 | * @param backlightMode The Backlight mode (LightOff, LightOn) |
wim | 20:e0da005a777f | 399 | */ |
wim | 21:9eb628d9e164 | 400 | void setBacklight(LCDBacklight backlightMode); |
wim | 20:e0da005a777f | 401 | |
wim | 11:9ec02df863a1 | 402 | |
wim | 11:9ec02df863a1 | 403 | /** Set User Defined Characters |
wim | 11:9ec02df863a1 | 404 | * |
wim | 11:9ec02df863a1 | 405 | * @param unsigned char c The Index of the UDC (0..7) |
wim | 12:6bf9d9957d31 | 406 | * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits) |
wim | 11:9ec02df863a1 | 407 | */ |
wim | 11:9ec02df863a1 | 408 | void setUDC(unsigned char c, char *udc_data); |
wim | 11:9ec02df863a1 | 409 | |
kenjiArai | 29:986538f94abe | 410 | // JH1PJL from here -> |
kenjiArai | 29:986538f94abe | 411 | /** Set Contrast |
kenjiArai | 29:986538f94abe | 412 | * |
kenjiArai | 29:986538f94abe | 413 | * @param unsigned char c contrast data |
kenjiArai | 29:986538f94abe | 414 | */ |
kenjiArai | 29:986538f94abe | 415 | void setContrast(unsigned char c); |
kenjiArai | 29:986538f94abe | 416 | // JH1PJL <- to here |
kenjiArai | 29:986538f94abe | 417 | |
simon | 1:ac48b187213c | 418 | protected: |
wim | 13:24506ba22480 | 419 | |
wim | 21:9eb628d9e164 | 420 | /** LCD controller select, mainly used for LCD40x4 |
wim | 21:9eb628d9e164 | 421 | */ |
wim | 19:c747b9e2e7b8 | 422 | enum _LCDCtrl_Idx { |
wim | 15:b70ebfffb258 | 423 | _LCDCtrl_0, /*< Primary */ |
wim | 15:b70ebfffb258 | 424 | _LCDCtrl_1, /*< Secondary */ |
wim | 15:b70ebfffb258 | 425 | }; |
wim | 21:9eb628d9e164 | 426 | |
wim | 21:9eb628d9e164 | 427 | /** Create a TextLCD_Base interface |
wim | 21:9eb628d9e164 | 428 | * @brief Base class, can not be instantiated |
wim | 21:9eb628d9e164 | 429 | * |
wim | 21:9eb628d9e164 | 430 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 21:9eb628d9e164 | 431 | * @param ctrl LCD controller (default = HD44780) |
wim | 21:9eb628d9e164 | 432 | */ |
wim | 21:9eb628d9e164 | 433 | TextLCD_Base(LCDType type = LCD16x2, LCDCtrl ctrl = HD44780); |
wim | 21:9eb628d9e164 | 434 | |
wim | 15:b70ebfffb258 | 435 | |
simon | 1:ac48b187213c | 436 | // Stream implementation functions |
simon | 1:ac48b187213c | 437 | virtual int _putc(int value); |
simon | 1:ac48b187213c | 438 | virtual int _getc(); |
simon | 1:ac48b187213c | 439 | |
wim | 21:9eb628d9e164 | 440 | /** Low level methods for LCD controller |
wim | 21:9eb628d9e164 | 441 | */ |
wim | 13:24506ba22480 | 442 | void _init(); |
wim | 15:b70ebfffb258 | 443 | void _initCtrl(); |
wim | 13:24506ba22480 | 444 | int _address(int column, int row); |
wim | 21:9eb628d9e164 | 445 | void _setCursor(LCDCursor show); |
wim | 17:652ab113bc2e | 446 | void _setUDC(unsigned char c, char *udc_data); |
wim | 21:9eb628d9e164 | 447 | void _setCursorAndDisplayMode(LCDMode displayMode, LCDCursor cursorType); |
wim | 13:24506ba22480 | 448 | |
wim | 21:9eb628d9e164 | 449 | /** Low level write operations to LCD controller |
wim | 21:9eb628d9e164 | 450 | */ |
wim | 17:652ab113bc2e | 451 | void _writeNibble(int value); |
Sissors | 24:fb3399713710 | 452 | virtual void _writeByte(int value); |
wim | 15:b70ebfffb258 | 453 | void _writeCommand(int command); |
wim | 15:b70ebfffb258 | 454 | void _writeData(int data); |
wim | 15:b70ebfffb258 | 455 | |
wim | 21:9eb628d9e164 | 456 | /** Pure Virtual Low level writes to LCD Bus (serial or parallel) |
wim | 21:9eb628d9e164 | 457 | */ |
wim | 21:9eb628d9e164 | 458 | virtual void _setEnable(bool value) = 0; |
wim | 21:9eb628d9e164 | 459 | virtual void _setRS(bool value) = 0; |
wim | 21:9eb628d9e164 | 460 | virtual void _setBL(bool value) = 0; |
wim | 21:9eb628d9e164 | 461 | virtual void _setData(int value) = 0; |
wim | 13:24506ba22480 | 462 | |
wim | 13:24506ba22480 | 463 | |
wim | 13:24506ba22480 | 464 | //Display type |
simon | 1:ac48b187213c | 465 | LCDType _type; |
simon | 1:ac48b187213c | 466 | |
wim | 21:9eb628d9e164 | 467 | //Display mode |
wim | 17:652ab113bc2e | 468 | LCDMode _currentMode; |
wim | 17:652ab113bc2e | 469 | |
wim | 19:c747b9e2e7b8 | 470 | //Controller type |
wim | 19:c747b9e2e7b8 | 471 | LCDCtrl _ctrl; |
wim | 19:c747b9e2e7b8 | 472 | |
wim | 15:b70ebfffb258 | 473 | //Controller select, mainly used for LCD40x4 |
wim | 19:c747b9e2e7b8 | 474 | _LCDCtrl_Idx _ctrl_idx; |
wim | 15:b70ebfffb258 | 475 | |
wim | 13:24506ba22480 | 476 | // Cursor |
simon | 1:ac48b187213c | 477 | int _column; |
simon | 1:ac48b187213c | 478 | int _row; |
wim | 15:b70ebfffb258 | 479 | LCDCursor _currentCursor; |
simon | 1:ac48b187213c | 480 | }; |
simon | 1:ac48b187213c | 481 | |
wim | 23:d47f226efb24 | 482 | //--------- End TextLCD_Base ----------- |
wim | 22:35742ec80c24 | 483 | |
wim | 22:35742ec80c24 | 484 | |
wim | 22:35742ec80c24 | 485 | |
wim | 23:d47f226efb24 | 486 | //--------- Start TextLCD Bus ----------- |
wim | 21:9eb628d9e164 | 487 | |
wim | 21:9eb628d9e164 | 488 | /** Create a TextLCD interface for using regular mbed pins |
wim | 21:9eb628d9e164 | 489 | * |
wim | 21:9eb628d9e164 | 490 | */ |
wim | 21:9eb628d9e164 | 491 | class TextLCD : public TextLCD_Base { |
wim | 21:9eb628d9e164 | 492 | public: |
wim | 21:9eb628d9e164 | 493 | /** Create a TextLCD interface for using regular mbed pins |
wim | 21:9eb628d9e164 | 494 | * |
wim | 21:9eb628d9e164 | 495 | * @param rs Instruction/data control line |
wim | 21:9eb628d9e164 | 496 | * @param e Enable line (clock) |
wim | 21:9eb628d9e164 | 497 | * @param d4-d7 Data lines for using as a 4-bit interface |
wim | 21:9eb628d9e164 | 498 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 21:9eb628d9e164 | 499 | * @param bl Backlight control line (optional, default = NC) |
wim | 21:9eb628d9e164 | 500 | * @param e2 Enable2 line (clock for second controller, LCD40x4 only) |
wim | 21:9eb628d9e164 | 501 | * @param ctrl LCD controller (default = HD44780) |
wim | 21:9eb628d9e164 | 502 | */ |
wim | 21:9eb628d9e164 | 503 | 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); |
wim | 21:9eb628d9e164 | 504 | |
wim | 22:35742ec80c24 | 505 | |
wim | 22:35742ec80c24 | 506 | /** Destruct a TextLCD interface for using regular mbed pins |
wim | 22:35742ec80c24 | 507 | * |
wim | 22:35742ec80c24 | 508 | * @param none |
wim | 22:35742ec80c24 | 509 | * @return none |
wim | 22:35742ec80c24 | 510 | */ |
wim | 22:35742ec80c24 | 511 | virtual ~TextLCD(); |
wim | 22:35742ec80c24 | 512 | |
wim | 21:9eb628d9e164 | 513 | private: |
wim | 21:9eb628d9e164 | 514 | //Low level writes to LCD Bus (serial or parallel) |
wim | 21:9eb628d9e164 | 515 | virtual void _setEnable(bool value); |
wim | 21:9eb628d9e164 | 516 | virtual void _setRS(bool value); |
wim | 21:9eb628d9e164 | 517 | virtual void _setBL(bool value); |
wim | 21:9eb628d9e164 | 518 | virtual void _setData(int value); |
wim | 21:9eb628d9e164 | 519 | |
wim | 22:35742ec80c24 | 520 | /** Regular mbed pins bus |
wim | 22:35742ec80c24 | 521 | */ |
wim | 22:35742ec80c24 | 522 | DigitalOut _rs, _e; |
wim | 22:35742ec80c24 | 523 | BusOut _d; |
wim | 22:35742ec80c24 | 524 | |
wim | 22:35742ec80c24 | 525 | /** Optional Hardware pins for the Backlight and LCD40x4 device |
wim | 22:35742ec80c24 | 526 | * Default PinName value is NC, must be used as pointer to avoid issues with mbed lib and DigitalOut pins |
wim | 22:35742ec80c24 | 527 | */ |
wim | 22:35742ec80c24 | 528 | DigitalOut *_bl, *_e2; |
wim | 21:9eb628d9e164 | 529 | }; |
wim | 21:9eb628d9e164 | 530 | |
wim | 22:35742ec80c24 | 531 | |
wim | 23:d47f226efb24 | 532 | //----------- End TextLCD --------------- |
wim | 21:9eb628d9e164 | 533 | |
wim | 21:9eb628d9e164 | 534 | |
wim | 23:d47f226efb24 | 535 | //--------- Start TextLCD_I2C ----------- |
wim | 22:35742ec80c24 | 536 | |
wim | 22:35742ec80c24 | 537 | |
wim | 26:bd897a001012 | 538 | /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander |
wim | 21:9eb628d9e164 | 539 | * |
wim | 21:9eb628d9e164 | 540 | */ |
wim | 21:9eb628d9e164 | 541 | class TextLCD_I2C : public TextLCD_Base { |
wim | 21:9eb628d9e164 | 542 | public: |
wim | 26:bd897a001012 | 543 | /** Create a TextLCD interface using an I2C PCF8574 (or PCF8574A) or MCP23008 portexpander |
wim | 21:9eb628d9e164 | 544 | * |
wim | 21:9eb628d9e164 | 545 | * @param i2c I2C Bus |
wim | 26:bd897a001012 | 546 | * @param deviceAddress I2C slave address (PCF8574 or PCF8574A, default = PCF8574_SA0 = 0x40) |
wim | 21:9eb628d9e164 | 547 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 21:9eb628d9e164 | 548 | * @param ctrl LCD controller (default = HD44780) |
wim | 21:9eb628d9e164 | 549 | */ |
wim | 26:bd897a001012 | 550 | TextLCD_I2C(I2C *i2c, char deviceAddress = PCF8574_SA0, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780); |
wim | 21:9eb628d9e164 | 551 | |
wim | 21:9eb628d9e164 | 552 | private: |
wim | 21:9eb628d9e164 | 553 | //Low level writes to LCD Bus (serial or parallel) |
wim | 21:9eb628d9e164 | 554 | virtual void _setEnable(bool value); |
wim | 21:9eb628d9e164 | 555 | virtual void _setRS(bool value); |
wim | 21:9eb628d9e164 | 556 | virtual void _setBL(bool value); |
wim | 26:bd897a001012 | 557 | virtual void _setData(int value); |
wim | 26:bd897a001012 | 558 | |
wim | 26:bd897a001012 | 559 | // Write data to MCP23008 I2C portexpander |
wim | 26:bd897a001012 | 560 | void _write_register (int reg, int value); |
wim | 21:9eb628d9e164 | 561 | |
wim | 21:9eb628d9e164 | 562 | //I2C bus |
wim | 21:9eb628d9e164 | 563 | I2C *_i2c; |
wim | 21:9eb628d9e164 | 564 | char _slaveAddress; |
wim | 21:9eb628d9e164 | 565 | |
wim | 21:9eb628d9e164 | 566 | // Internal bus mirror value for serial bus only |
wim | 21:9eb628d9e164 | 567 | char _lcd_bus; |
wim | 21:9eb628d9e164 | 568 | |
wim | 21:9eb628d9e164 | 569 | }; |
wim | 21:9eb628d9e164 | 570 | |
wim | 21:9eb628d9e164 | 571 | |
wim | 23:d47f226efb24 | 572 | //---------- End TextLCD_I2C ------------ |
wim | 22:35742ec80c24 | 573 | |
wim | 22:35742ec80c24 | 574 | |
wim | 22:35742ec80c24 | 575 | |
wim | 23:d47f226efb24 | 576 | //--------- Start TextLCD_SPI ----------- |
wim | 22:35742ec80c24 | 577 | |
wim | 21:9eb628d9e164 | 578 | |
wim | 21:9eb628d9e164 | 579 | /** Create a TextLCD interface using an SPI 74595 portexpander |
wim | 21:9eb628d9e164 | 580 | * |
wim | 21:9eb628d9e164 | 581 | */ |
wim | 21:9eb628d9e164 | 582 | class TextLCD_SPI : public TextLCD_Base { |
wim | 21:9eb628d9e164 | 583 | public: |
wim | 21:9eb628d9e164 | 584 | /** Create a TextLCD interface using an SPI 74595 portexpander |
wim | 21:9eb628d9e164 | 585 | * |
wim | 21:9eb628d9e164 | 586 | * @param spi SPI Bus |
wim | 21:9eb628d9e164 | 587 | * @param cs chip select pin (active low) |
wim | 21:9eb628d9e164 | 588 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 21:9eb628d9e164 | 589 | * @param ctrl LCD controller (default = HD44780) |
wim | 21:9eb628d9e164 | 590 | */ |
wim | 21:9eb628d9e164 | 591 | TextLCD_SPI(SPI *spi, PinName cs, LCDType type = LCD16x2, LCDCtrl ctrl = HD44780); |
wim | 21:9eb628d9e164 | 592 | |
wim | 21:9eb628d9e164 | 593 | |
wim | 21:9eb628d9e164 | 594 | private: |
wim | 21:9eb628d9e164 | 595 | //Low level writes to LCD Bus (serial or parallel) |
wim | 21:9eb628d9e164 | 596 | virtual void _setEnable(bool value); |
wim | 21:9eb628d9e164 | 597 | virtual void _setRS(bool value); |
wim | 21:9eb628d9e164 | 598 | virtual void _setBL(bool value); |
wim | 21:9eb628d9e164 | 599 | virtual void _setData(int value); |
wim | 21:9eb628d9e164 | 600 | virtual void _setCS(bool value); |
wim | 21:9eb628d9e164 | 601 | |
wim | 21:9eb628d9e164 | 602 | //Low level writes to LCD serial bus only |
wim | 21:9eb628d9e164 | 603 | void _writeBus(); |
wim | 21:9eb628d9e164 | 604 | |
wim | 21:9eb628d9e164 | 605 | // SPI bus |
wim | 21:9eb628d9e164 | 606 | SPI *_spi; |
wim | 21:9eb628d9e164 | 607 | DigitalOut _cs; |
wim | 21:9eb628d9e164 | 608 | |
wim | 21:9eb628d9e164 | 609 | // Internal bus mirror value for serial bus only |
wim | 21:9eb628d9e164 | 610 | char _lcd_bus; |
wim | 21:9eb628d9e164 | 611 | |
wim | 21:9eb628d9e164 | 612 | }; |
wim | 21:9eb628d9e164 | 613 | |
wim | 23:d47f226efb24 | 614 | //---------- End TextLCD_SPI ------------ |
wim | 21:9eb628d9e164 | 615 | |
Sissors | 24:fb3399713710 | 616 | |
Sissors | 24:fb3399713710 | 617 | |
wim | 26:bd897a001012 | 618 | //--------- Start TextLCD_SPI_N ----------- |
Sissors | 24:fb3399713710 | 619 | |
wim | 25:6162b31128c9 | 620 | /** Create a TextLCD interface using a controller with native SPI interface |
Sissors | 24:fb3399713710 | 621 | * |
Sissors | 24:fb3399713710 | 622 | */ |
wim | 25:6162b31128c9 | 623 | class TextLCD_SPI_N : public TextLCD_Base { |
Sissors | 24:fb3399713710 | 624 | public: |
wim | 25:6162b31128c9 | 625 | /** Create a TextLCD interface using a controller with native SPI interface |
Sissors | 24:fb3399713710 | 626 | * |
Sissors | 24:fb3399713710 | 627 | * @param spi SPI Bus |
Sissors | 24:fb3399713710 | 628 | * @param cs chip select pin (active low) |
Sissors | 24:fb3399713710 | 629 | * @param rs Instruction/data control line |
Sissors | 24:fb3399713710 | 630 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
Sissors | 24:fb3399713710 | 631 | * @param bl Backlight control line (optional, default = NC) |
wim | 26:bd897a001012 | 632 | * @param ctrl LCD controller (default = ST7032_3V3) |
Sissors | 24:fb3399713710 | 633 | */ |
wim | 26:bd897a001012 | 634 | TextLCD_SPI_N(SPI *spi, PinName cs, PinName rs, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3); |
wim | 25:6162b31128c9 | 635 | virtual ~TextLCD_SPI_N(void); |
Sissors | 24:fb3399713710 | 636 | |
Sissors | 24:fb3399713710 | 637 | private: |
Sissors | 24:fb3399713710 | 638 | virtual void _setEnable(bool value); |
Sissors | 24:fb3399713710 | 639 | virtual void _setRS(bool value); |
Sissors | 24:fb3399713710 | 640 | virtual void _setBL(bool value); |
Sissors | 24:fb3399713710 | 641 | virtual void _setData(int value); |
Sissors | 24:fb3399713710 | 642 | virtual void _writeByte(int value); |
Sissors | 24:fb3399713710 | 643 | |
Sissors | 24:fb3399713710 | 644 | // SPI bus |
Sissors | 24:fb3399713710 | 645 | SPI *_spi; |
Sissors | 24:fb3399713710 | 646 | DigitalOut _cs; |
Sissors | 24:fb3399713710 | 647 | DigitalOut _rs; |
Sissors | 24:fb3399713710 | 648 | DigitalOut *_bl; |
Sissors | 24:fb3399713710 | 649 | |
Sissors | 24:fb3399713710 | 650 | }; |
Sissors | 24:fb3399713710 | 651 | |
wim | 25:6162b31128c9 | 652 | //---------- End TextLCD_SPI_N ------------ |
Sissors | 24:fb3399713710 | 653 | |
wim | 26:bd897a001012 | 654 | |
wim | 26:bd897a001012 | 655 | //--------- Start TextLCD_I2C_N ----------- |
wim | 26:bd897a001012 | 656 | |
wim | 26:bd897a001012 | 657 | /** Create a TextLCD interface using a controller with native I2C interface |
wim | 26:bd897a001012 | 658 | * |
wim | 26:bd897a001012 | 659 | */ |
wim | 26:bd897a001012 | 660 | class TextLCD_I2C_N : public TextLCD_Base { |
wim | 26:bd897a001012 | 661 | public: |
wim | 26:bd897a001012 | 662 | /** Create a TextLCD interface using a controller with native I2C interface |
wim | 26:bd897a001012 | 663 | * |
wim | 26:bd897a001012 | 664 | * @param i2c I2C Bus |
wim | 28:30fa94f7341c | 665 | * @param deviceAddress I2C slave address (default = ST7032_SA = 0x7C) |
wim | 26:bd897a001012 | 666 | * @param type Sets the panel size/addressing mode (default = LCD16x2) |
wim | 28:30fa94f7341c | 667 | * @param bl Backlight control line (optional, default = NC) |
wim | 26:bd897a001012 | 668 | * @param ctrl LCD controller (default = ST7032_3V3) |
wim | 26:bd897a001012 | 669 | */ |
wim | 28:30fa94f7341c | 670 | TextLCD_I2C_N(I2C *i2c, char deviceAddress = ST7032_SA, LCDType type = LCD16x2, PinName bl = NC, LCDCtrl ctrl = ST7032_3V3); |
wim | 26:bd897a001012 | 671 | virtual ~TextLCD_I2C_N(void); |
wim | 26:bd897a001012 | 672 | |
wim | 26:bd897a001012 | 673 | private: |
wim | 26:bd897a001012 | 674 | virtual void _setEnable(bool value); |
wim | 26:bd897a001012 | 675 | virtual void _setRS(bool value); |
wim | 26:bd897a001012 | 676 | virtual void _setBL(bool value); |
wim | 26:bd897a001012 | 677 | virtual void _setData(int value); |
wim | 26:bd897a001012 | 678 | virtual void _writeByte(int value); |
wim | 26:bd897a001012 | 679 | |
wim | 26:bd897a001012 | 680 | //I2C bus |
wim | 26:bd897a001012 | 681 | I2C *_i2c; |
wim | 26:bd897a001012 | 682 | char _slaveAddress; |
wim | 26:bd897a001012 | 683 | |
wim | 28:30fa94f7341c | 684 | // controlbyte to select between data and command. Internal value for serial bus only |
wim | 28:30fa94f7341c | 685 | char _controlbyte; |
wim | 28:30fa94f7341c | 686 | |
wim | 28:30fa94f7341c | 687 | DigitalOut *_bl; |
wim | 26:bd897a001012 | 688 | }; |
wim | 26:bd897a001012 | 689 | |
wim | 26:bd897a001012 | 690 | //---------- End TextLCD_I2C_N ------------ |
wim | 26:bd897a001012 | 691 | |
wim | 26:bd897a001012 | 692 | |
simon | 1:ac48b187213c | 693 | #endif |