Gabriel Scodiero / Mbed 2 deprecated Onda_lcd1

Dependencies:   mbed

Committer:
Gabiuas
Date:
Tue May 21 00:51:20 2019 +0000
Revision:
1:0ada46075897
Ondas

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gabiuas 1:0ada46075897 1 /* mbed TextLCD Library, for LCDs based on HD44780 controllers
Gabiuas 1:0ada46075897 2 * Copyright (c) 2007-2010, sford, http://mbed.org
Gabiuas 1:0ada46075897 3 * 2013, v01: WH, Added LCD types, fixed LCD address issues, added Cursor and UDCs
Gabiuas 1:0ada46075897 4 * 2013, v02: WH, Added I2C and SPI bus interfaces
Gabiuas 1:0ada46075897 5 * 2013, v03: WH, Added support for LCD40x4 which uses 2 controllers
Gabiuas 1:0ada46075897 6 * 2013, v04: WH, Added support for Display On/Off, improved 4bit bootprocess
Gabiuas 1:0ada46075897 7 * 2013, v05: WH, Added support for 8x2B, added some UDCs
Gabiuas 1:0ada46075897 8 * 2013, v06: WH, Added support for devices that use internal DC/DC converters
Gabiuas 1:0ada46075897 9 * 2013, v07: WH, Added support for backlight and include portdefinitions for LCD2004 Module from DFROBOT
Gabiuas 1:0ada46075897 10 * 2014, v08: WH, Refactored in Base and Derived Classes to deal with mbed lib change regarding 'NC' defined pins
Gabiuas 1:0ada46075897 11 * 2014, v09: WH/EO, Added Class for Native SPI controllers such as ST7032
Gabiuas 1:0ada46075897 12 * 2014, v10: WH, Added Class for Native I2C controllers such as ST7032i, Added support for MCP23008 I2C portexpander, Added support for Adafruit module
Gabiuas 1:0ada46075897 13 * 2014, v11: WH, Added support for native I2C controllers such as PCF21XX, Improved the _initCtrl() method to deal with differences between all supported controllers
Gabiuas 1:0ada46075897 14 * 2014, v12: WH, Added support for native I2C controller PCF2119 and native I2C/SPI controllers SSD1803, ST7036, added setContrast method (by JH1PJL) for supported devices (eg ST7032i)
Gabiuas 1:0ada46075897 15 * 2014, v13: WH, Added support for controllers US2066/SSD1311 (OLED), added setUDCBlink() method for supported devices (eg SSD1803), fixed issue in setPower()
Gabiuas 1:0ada46075897 16 * 2014, v14: WH, Added support for PT6314 (VFD), added setOrient() method for supported devices (eg SSD1803, US2066), added Double Height lines for supported devices,
Gabiuas 1:0ada46075897 17 * added 16 UDCs for supported devices (eg PCF2103), moved UDC defines to TextLCD_UDC file, added TextLCD_Config.h for feature and footprint settings.
Gabiuas 1:0ada46075897 18 * 2014, v15: WH, Added AC780 support, added I2C expander modules, fixed setBacklight() for inverted logic modules. Fixed bug in LCD_SPI_N define
Gabiuas 1:0ada46075897 19 * 2014, v16: WH, Added ST7070 and KS0073 support, added setIcon(), clrIcon() and setInvert() method for supported devices
Gabiuas 1:0ada46075897 20 * 2015, v17: WH, Clean up low-level _writeCommand() and _writeData(), Added support for alternative fonttables (eg PCF21XX), Added ST7066_ACM controller for ACM1602 module
Gabiuas 1:0ada46075897 21 * 2015, v18: WH, Performance improvement I2C portexpander
Gabiuas 1:0ada46075897 22 * 2015, v19: WH, Fixed Adafruit I2C/SPI portexpander pinmappings, fixed SYDZ Backlight
Gabiuas 1:0ada46075897 23 * 2015, v20: WH, Fixed occasional Init fail caused by insufficient wait time after ReturnHome command (0x02), Added defines to reduce memory footprint (eg LCD_ICON),
Gabiuas 1:0ada46075897 24 * Fixed and Added more fonttable support for PCF2119R_3V3, Added HD66712 controller.
Gabiuas 1:0ada46075897 25 * 2015, v21: WH, Added LCD32x2 defines and code, Fixed KS0073 DL=1 init for SPI, Added defines to reduce memory footprint (LCD_TWO_CTRL, LCD_CONTRAST, LCD_UTF8_FONT)
Gabiuas 1:0ada46075897 26 * Added SPLC792A controller, Added UTF8_2_LCD decode for Cyrilic font (By Andriy Ribalko). Added setFont()
Gabiuas 1:0ada46075897 27 *
Gabiuas 1:0ada46075897 28 * Permission is hereby granted, free of charge, to any person obtaining a copy
Gabiuas 1:0ada46075897 29 * of this software and associated documentation files (the "Software"), to deal
Gabiuas 1:0ada46075897 30 * in the Software without restriction, including without limitation the rights
Gabiuas 1:0ada46075897 31 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
Gabiuas 1:0ada46075897 32 * copies of the Software, and to permit persons to whom the Software is
Gabiuas 1:0ada46075897 33 * furnished to do so, subject to the following conditions:
Gabiuas 1:0ada46075897 34 *
Gabiuas 1:0ada46075897 35 * The above copyright notice and this permission notice shall be included in
Gabiuas 1:0ada46075897 36 * all copies or substantial portions of the Software.
Gabiuas 1:0ada46075897 37 *
Gabiuas 1:0ada46075897 38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
Gabiuas 1:0ada46075897 39 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
Gabiuas 1:0ada46075897 40 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
Gabiuas 1:0ada46075897 41 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
Gabiuas 1:0ada46075897 42 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
Gabiuas 1:0ada46075897 43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
Gabiuas 1:0ada46075897 44 * THE SOFTWARE.
Gabiuas 1:0ada46075897 45 */
Gabiuas 1:0ada46075897 46 #include "mbed.h"
Gabiuas 1:0ada46075897 47 #include "TextLCD.h"
Gabiuas 1:0ada46075897 48 #include "TextLCD_UDC.inc"
Gabiuas 1:0ada46075897 49 #include "TextLCD_UTF8.inc"
Gabiuas 1:0ada46075897 50
Gabiuas 1:0ada46075897 51 /** Create a TextLCD_Base interface
Gabiuas 1:0ada46075897 52 *
Gabiuas 1:0ada46075897 53 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Gabiuas 1:0ada46075897 54 * @param ctrl LCD controller (default = HD44780)
Gabiuas 1:0ada46075897 55 */
Gabiuas 1:0ada46075897 56 TextLCD_Base::TextLCD_Base(LCDType type, LCDCtrl ctrl) : _type(type), _ctrl(ctrl) {
Gabiuas 1:0ada46075897 57
Gabiuas 1:0ada46075897 58 // Extract LCDType data
Gabiuas 1:0ada46075897 59
Gabiuas 1:0ada46075897 60 // Columns encoded in b15..b8
Gabiuas 1:0ada46075897 61 _nr_cols = (_type & LCD_T_COL_MSK) >> LCD_T_COL_SHFT;
Gabiuas 1:0ada46075897 62
Gabiuas 1:0ada46075897 63 // Rows encoded in b23..b16
Gabiuas 1:0ada46075897 64 _nr_rows = (_type & LCD_T_ROW_MSK) >> LCD_T_ROW_SHFT;
Gabiuas 1:0ada46075897 65
Gabiuas 1:0ada46075897 66 // Addressing mode encoded in b27..b24
Gabiuas 1:0ada46075897 67 _addr_mode = _type & LCD_T_ADR_MSK;
Gabiuas 1:0ada46075897 68
Gabiuas 1:0ada46075897 69 // Font table, encoded in LCDCtrl
Gabiuas 1:0ada46075897 70 _font = _ctrl & LCD_C_FNT_MSK;
Gabiuas 1:0ada46075897 71 }
Gabiuas 1:0ada46075897 72
Gabiuas 1:0ada46075897 73 /** Init the LCD Controller(s)
Gabiuas 1:0ada46075897 74 * Clear display
Gabiuas 1:0ada46075897 75 * @param _LCDDatalength dl sets the datalength of data/commands
Gabiuas 1:0ada46075897 76 * @return none
Gabiuas 1:0ada46075897 77 */
Gabiuas 1:0ada46075897 78 void TextLCD_Base::_init(_LCDDatalength dl) {
Gabiuas 1:0ada46075897 79
Gabiuas 1:0ada46075897 80 wait_ms(100); // Wait 100ms to ensure powered up
Gabiuas 1:0ada46075897 81
Gabiuas 1:0ada46075897 82 #if (LCD_TWO_CTRL == 1)
Gabiuas 1:0ada46075897 83 // Select and configure second LCD controller when needed
Gabiuas 1:0ada46075897 84 if(_type==LCD40x4) {
Gabiuas 1:0ada46075897 85 _ctrl_idx=_LCDCtrl_1; // Select 2nd controller
Gabiuas 1:0ada46075897 86 _initCtrl(dl); // Init 2nd controller
Gabiuas 1:0ada46075897 87 }
Gabiuas 1:0ada46075897 88 #endif
Gabiuas 1:0ada46075897 89
Gabiuas 1:0ada46075897 90 // Select and configure primary LCD controller
Gabiuas 1:0ada46075897 91 _ctrl_idx=_LCDCtrl_0; // Select primary controller
Gabiuas 1:0ada46075897 92 _initCtrl(dl); // Init primary controller
Gabiuas 1:0ada46075897 93
Gabiuas 1:0ada46075897 94 // Clear whole display and Reset Cursor location
Gabiuas 1:0ada46075897 95 // Note: This will make sure that some 3-line displays that skip topline of a 4-line configuration
Gabiuas 1:0ada46075897 96 // are cleared and init cursor correctly.
Gabiuas 1:0ada46075897 97 cls();
Gabiuas 1:0ada46075897 98 }
Gabiuas 1:0ada46075897 99
Gabiuas 1:0ada46075897 100 /** Init the LCD controller
Gabiuas 1:0ada46075897 101 * Set number of lines, fonttype, no cursor etc
Gabiuas 1:0ada46075897 102 * The controller is accessed in 4-bit parallel mode either directly via mbed pins or through I2C or SPI expander.
Gabiuas 1:0ada46075897 103 * Some controllers also support native I2C or SPI interfaces.
Gabiuas 1:0ada46075897 104 *
Gabiuas 1:0ada46075897 105 * @param _LCDDatalength dl sets the 4 or 8 bit datalength of data/commands. Required for some native serial modes that dont work when DL=0.
Gabiuas 1:0ada46075897 106 * @return none
Gabiuas 1:0ada46075897 107 *
Gabiuas 1:0ada46075897 108 * Note: some configurations are commented out because they have not yet been tested due to lack of hardware
Gabiuas 1:0ada46075897 109 */
Gabiuas 1:0ada46075897 110 void TextLCD_Base::_initCtrl(_LCDDatalength dl) {
Gabiuas 1:0ada46075897 111 int _bias_lines=0; // Set Bias and lines (Instr Set 1), temporary variable.
Gabiuas 1:0ada46075897 112 int _lines=0; // Set lines (Ext Instr Set), temporary variable.
Gabiuas 1:0ada46075897 113
Gabiuas 1:0ada46075897 114 this->_setRS(false); // command mode
Gabiuas 1:0ada46075897 115
Gabiuas 1:0ada46075897 116 if (dl == _LCD_DL_4) {
Gabiuas 1:0ada46075897 117 // The Controller could be in 8 bit mode (power-on reset) or in 4 bit mode (warm reboot) at this point.
Gabiuas 1:0ada46075897 118 // Follow this procedure to make sure the Controller enters the correct state. The hardware interface
Gabiuas 1:0ada46075897 119 // between the uP and the LCD can only write the 4 most significant bits (Most Significant Nibble, MSN).
Gabiuas 1:0ada46075897 120 // In 4 bit mode the LCD expects the MSN first, followed by the LSN.
Gabiuas 1:0ada46075897 121 //
Gabiuas 1:0ada46075897 122 // Current state: 8 bit mode | 4 bit mode, MSN is next | 4 bit mode, LSN is next
Gabiuas 1:0ada46075897 123 //-------------------------------------------------------------------------------------------------
Gabiuas 1:0ada46075897 124 _writeNibble(0x3); // set 8 bit mode (MSN) and dummy LSN, | set 8 bit mode (MSN), | set dummy LSN,
Gabiuas 1:0ada46075897 125 // remains in 8 bit mode | remains in 4 bit mode | remains in 4 bit mode
Gabiuas 1:0ada46075897 126 wait_ms(15); //
Gabiuas 1:0ada46075897 127
Gabiuas 1:0ada46075897 128 _writeNibble(0x3); // set 8 bit mode (MSN) and dummy LSN, | set dummy LSN, | set 8bit mode (MSN),
Gabiuas 1:0ada46075897 129 // remains in 8 bit mode | change to 8 bit mode | remains in 4 bit mode
Gabiuas 1:0ada46075897 130 wait_ms(15); //
Gabiuas 1:0ada46075897 131
Gabiuas 1:0ada46075897 132 _writeNibble(0x3); // set 8 bit mode (MSN) and dummy LSN, | set 8 bit mode (MSN) and dummy LSN, | set dummy LSN,
Gabiuas 1:0ada46075897 133 // remains in 8 bit mode | remains in 8 bit mode | change to 8 bit mode
Gabiuas 1:0ada46075897 134 wait_ms(15); //
Gabiuas 1:0ada46075897 135
Gabiuas 1:0ada46075897 136 // Controller is now in 8 bit mode
Gabiuas 1:0ada46075897 137
Gabiuas 1:0ada46075897 138 _writeNibble(0x2); // Change to 4-bit mode (MSN), the LSN is undefined dummy
Gabiuas 1:0ada46075897 139 wait_us(40); // most instructions take 40us
Gabiuas 1:0ada46075897 140
Gabiuas 1:0ada46075897 141 // Controller is now in 4-bit mode
Gabiuas 1:0ada46075897 142 // Note: 4/8 bit mode is ignored for most native SPI and I2C devices. They dont use the parallel bus.
Gabiuas 1:0ada46075897 143 // However, _writeNibble() method is void anyway for native SPI and I2C devices.
Gabiuas 1:0ada46075897 144 }
Gabiuas 1:0ada46075897 145 else {
Gabiuas 1:0ada46075897 146 // Reset in 8 bit mode, final Function set will follow
Gabiuas 1:0ada46075897 147 _writeCommand(0x30); // Function set 0 0 1 DL=1 N F x x
Gabiuas 1:0ada46075897 148 wait_ms(1); // most instructions take 40us
Gabiuas 1:0ada46075897 149 }
Gabiuas 1:0ada46075897 150
Gabiuas 1:0ada46075897 151 // Device specific initialisations: DC/DC converter to generate VLCD or VLED, number of lines etc
Gabiuas 1:0ada46075897 152 switch (_ctrl) {
Gabiuas 1:0ada46075897 153
Gabiuas 1:0ada46075897 154 case KS0073:
Gabiuas 1:0ada46075897 155 // Initialise Display configuration
Gabiuas 1:0ada46075897 156 switch (_type) {
Gabiuas 1:0ada46075897 157 // case LCD6x1:
Gabiuas 1:0ada46075897 158 case LCD8x1: //8x1 is a regular 1 line display
Gabiuas 1:0ada46075897 159 // case LCD8x2B: //8x1 is a 16x1 line display
Gabiuas 1:0ada46075897 160 case LCD12x1:
Gabiuas 1:0ada46075897 161 case LCD16x1:
Gabiuas 1:0ada46075897 162 case LCD20x1:
Gabiuas 1:0ada46075897 163 case LCD24x1:
Gabiuas 1:0ada46075897 164 // case LCD32x1: // EXT pin is High, extension driver needed
Gabiuas 1:0ada46075897 165 // case LCD40x1: // EXT pin is High, extension driver needed
Gabiuas 1:0ada46075897 166 // case LCD52x1: // EXT pin is High, extension driver needed
Gabiuas 1:0ada46075897 167 _function = dl | 0x02; // Set function, 0 0 1 DL, N, RE(0), DH, REV
Gabiuas 1:0ada46075897 168 // Note: 4 bit mode is NOT ignored for native SPI !
Gabiuas 1:0ada46075897 169 // DL=1 (8 bits bus), DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 170 // N=0 (1-line mode), N=1 (2-line mode), dont care for 4 line mode
Gabiuas 1:0ada46075897 171 // RE=0 (Dis. Extended Regs, special mode for KS0073)
Gabiuas 1:0ada46075897 172 // DH=1 (Disp shift enable, special mode for KS0073)
Gabiuas 1:0ada46075897 173 // REV=0 (Reverse normal, special mode for KS0073)
Gabiuas 1:0ada46075897 174
Gabiuas 1:0ada46075897 175 _function_1 = dl | 0x04; // Set function, 0 0 1 DL, N, RE(1), BE, LP (Ext Regs)
Gabiuas 1:0ada46075897 176 // Note: 4 bit mode is NOT ignored for native SPI !
Gabiuas 1:0ada46075897 177 // DL=1 (8 bits bus), DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 178 // N=0 (1-line mode), N=1 (2-line mode), dont care for 4 line mode
Gabiuas 1:0ada46075897 179 // RE=1 (Ena Extended Regs, special mode for KS0073)
Gabiuas 1:0ada46075897 180 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073)
Gabiuas 1:0ada46075897 181 // LP=0 (LP=1 Low power mode, LP=0 Normal)
Gabiuas 1:0ada46075897 182
Gabiuas 1:0ada46075897 183 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
Gabiuas 1:0ada46075897 184 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073)
Gabiuas 1:0ada46075897 185 break;
Gabiuas 1:0ada46075897 186
Gabiuas 1:0ada46075897 187 // case LCD12x3D: // Special mode for KS0073, KS0078 and PCF21XX
Gabiuas 1:0ada46075897 188 // case LCD12x3D1: // Special mode for KS0073, KS0078 and PCF21XX
Gabiuas 1:0ada46075897 189 case LCD12x4D: // Special mode for KS0073, KS0078 and PCF21XX
Gabiuas 1:0ada46075897 190 // case LCD16x3D: // Special mode for KS0073, KS0078
Gabiuas 1:0ada46075897 191 // case LCD16x3D1: // Special mode for KS0073, KS0078
Gabiuas 1:0ada46075897 192 // case LCD16x4D: // Special mode for KS0073, KS0078
Gabiuas 1:0ada46075897 193 case LCD20x4D: // Special mode for KS0073, KS0078
Gabiuas 1:0ada46075897 194 _function = dl | 0x02; // Set function, 0 0 1 DL, N, RE(0), DH, REV
Gabiuas 1:0ada46075897 195 // Note: 4 bit mode is NOT ignored for native SPI !
Gabiuas 1:0ada46075897 196 // DL=1 (8 bits bus), DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 197 // N=0 (1-line mode), N=1 (2-line mode), dont care for 4 line mode
Gabiuas 1:0ada46075897 198 // RE=0 (Dis. Extended Regs, special mode for KS0073)
Gabiuas 1:0ada46075897 199 // DH=1 (Disp shift enable, special mode for KS0073)
Gabiuas 1:0ada46075897 200 // REV=0 (Reverse normal, special mode for KS0073)
Gabiuas 1:0ada46075897 201
Gabiuas 1:0ada46075897 202 _function_1 = dl | 0x04; // Set function, 0 0 1 DL, N, RE(1), BE, LP (Ext Regs)
Gabiuas 1:0ada46075897 203 // Note: 4 bit mode is NOT ignored for native SPI !
Gabiuas 1:0ada46075897 204 // DL=1 (8 bits bus), DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 205 // N=0 (1-line mode), N=1 (2-line mode), dont care for 4 line mode
Gabiuas 1:0ada46075897 206 // RE=1 (Ena Extended Regs, special mode for KS0073)
Gabiuas 1:0ada46075897 207 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073)
Gabiuas 1:0ada46075897 208 // LP=0 (LP=1 Low power mode, LP=0 Normal)
Gabiuas 1:0ada46075897 209
Gabiuas 1:0ada46075897 210 _function_x = 0x01; // Ext Function set 0000 1 FW BW NW (Ext Regs)
Gabiuas 1:0ada46075897 211 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073)
Gabiuas 1:0ada46075897 212 break;
Gabiuas 1:0ada46075897 213
Gabiuas 1:0ada46075897 214 // case LCD6x2:
Gabiuas 1:0ada46075897 215 case LCD8x2:
Gabiuas 1:0ada46075897 216 case LCD16x2:
Gabiuas 1:0ada46075897 217 // case LCD16x1C:
Gabiuas 1:0ada46075897 218 case LCD20x2:
Gabiuas 1:0ada46075897 219 case LCD24x2:
Gabiuas 1:0ada46075897 220 case LCD32x2:
Gabiuas 1:0ada46075897 221 // All other LCD types are initialised as 2 Line displays
Gabiuas 1:0ada46075897 222 _function = dl | 0x0A; // Set function, 0 0 1 DL, N, RE(0), DH, REV
Gabiuas 1:0ada46075897 223 // Note: 4 bit mode is NOT ignored for native SPI !
Gabiuas 1:0ada46075897 224 // DL=1 (8 bits bus), DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 225 // N=1 (2-line mode), N=0 (1-line mode)
Gabiuas 1:0ada46075897 226 // RE=0 (Dis. Extended Regs, special mode for KS0073)
Gabiuas 1:0ada46075897 227 // DH=1 (Disp shift enable, special mode for KS0073)
Gabiuas 1:0ada46075897 228 // REV=0 (Reverse normal, special mode for KS0073)
Gabiuas 1:0ada46075897 229
Gabiuas 1:0ada46075897 230 _function_1 = dl | 0x0C; // Set function, 0 0 1 DL, N, RE(1), BE, LP (Ext Regs)
Gabiuas 1:0ada46075897 231 // Note: 4 bit mode is NOT ignored for native SPI !
Gabiuas 1:0ada46075897 232 // DL=1 (8 bits bus), DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 233 // N=1 (2 line mode), N=0 (1-line mode)
Gabiuas 1:0ada46075897 234 // RE=1 (Ena Extended Regs, special mode for KS0073)
Gabiuas 1:0ada46075897 235 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073)
Gabiuas 1:0ada46075897 236 // LP=0 (LP=1 Low power mode, LP=0 Normal)
Gabiuas 1:0ada46075897 237
Gabiuas 1:0ada46075897 238 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
Gabiuas 1:0ada46075897 239 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073)
Gabiuas 1:0ada46075897 240 break;
Gabiuas 1:0ada46075897 241
Gabiuas 1:0ada46075897 242 default:
Gabiuas 1:0ada46075897 243 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 244 break;
Gabiuas 1:0ada46075897 245 } // switch type
Gabiuas 1:0ada46075897 246
Gabiuas 1:0ada46075897 247 // init special features
Gabiuas 1:0ada46075897 248 _writeCommand(0x20 | _function_1);// Function set 001 DL N RE(1) BE LP (Ext Regs)
Gabiuas 1:0ada46075897 249 // DL=0 (4 bits bus), DL=1 (8 bits mode)
Gabiuas 1:0ada46075897 250 // N=0 (1 line mode), N=1 (2 line mode)
Gabiuas 1:0ada46075897 251 // RE=1 (Ena Extended Regs, special mode for KS0073)
Gabiuas 1:0ada46075897 252 // BE=0 (Blink Enable/Disable, CG/SEG RAM, special mode for KS0073)
Gabiuas 1:0ada46075897 253 // LP=0 (LP=1 Low power mode, LP=0 Normal)
Gabiuas 1:0ada46075897 254
Gabiuas 1:0ada46075897 255 _writeCommand(0x08 | _function_x); // Ext Function set 0000 1 FW BW NW (Ext Regs)
Gabiuas 1:0ada46075897 256 // FW=0 (5-dot font, special mode for KS0073)
Gabiuas 1:0ada46075897 257 // BW=0 (Cur BW invert disable, special mode for KS0073)
Gabiuas 1:0ada46075897 258 // NW=0 (1,2 Line), NW=1 (4 line, special mode for KS0073)
Gabiuas 1:0ada46075897 259
Gabiuas 1:0ada46075897 260 _writeCommand(0x10); // Scroll/Shift set 0001 DS/HS4 DS/HS3 DS/HS2 DS/HS1 (Ext Regs)
Gabiuas 1:0ada46075897 261 // Dotscroll/Display shift enable (Special mode for KS0073)
Gabiuas 1:0ada46075897 262
Gabiuas 1:0ada46075897 263 _writeCommand(0x80); // Scroll Quantity set 1 0 SQ5 SQ4 SQ3 SQ2 SQ1 SQ0 (Ext Regs)
Gabiuas 1:0ada46075897 264 // Scroll quantity (Special mode for KS0073)
Gabiuas 1:0ada46075897 265
Gabiuas 1:0ada46075897 266 _writeCommand(0x20 | _function); // Function set 001 DL N RE(0) DH REV (Std Regs)
Gabiuas 1:0ada46075897 267 // DL=0 (4 bits bus), DL=1 (8 bits mode)
Gabiuas 1:0ada46075897 268 // N=0 (1 line mode), N=1 (2 line mode)
Gabiuas 1:0ada46075897 269 // RE=0 (Dis. Extended Regs, special mode for KS0073)
Gabiuas 1:0ada46075897 270 // DH=1 (Disp shift enable/disable, special mode for KS0073)
Gabiuas 1:0ada46075897 271 // REV=0 (Reverse/Normal, special mode for KS0073)
Gabiuas 1:0ada46075897 272 break; // case KS0073 Controller
Gabiuas 1:0ada46075897 273
Gabiuas 1:0ada46075897 274
Gabiuas 1:0ada46075897 275 case KS0078:
Gabiuas 1:0ada46075897 276 // Initialise Display configuration
Gabiuas 1:0ada46075897 277 switch (_type) {
Gabiuas 1:0ada46075897 278 case LCD8x1: //8x1 is a regular 1 line display
Gabiuas 1:0ada46075897 279 case LCD8x2B: //8x2B is a special case of 16x1
Gabiuas 1:0ada46075897 280 // case LCD12x1:
Gabiuas 1:0ada46075897 281 case LCD16x1:
Gabiuas 1:0ada46075897 282 // case LCD20x1:
Gabiuas 1:0ada46075897 283 case LCD24x1:
Gabiuas 1:0ada46075897 284 _function = dl | 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs)
Gabiuas 1:0ada46075897 285 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 286 // N=0 (1 line mode), N=1 (2 line mode)
Gabiuas 1:0ada46075897 287 // RE=0 (Dis. Extended Regs, special mode for KS0078)
Gabiuas 1:0ada46075897 288 // DH=1 (Disp shift enable, special mode for KS0078)
Gabiuas 1:0ada46075897 289 // REV=0 (Reverse normal, special mode for KS0078)
Gabiuas 1:0ada46075897 290
Gabiuas 1:0ada46075897 291 _function_1 = dl | 0x04; // Function set 001 DL N RE(1) BE 0 (Ext Regs)
Gabiuas 1:0ada46075897 292 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 293 // N=0 (1 line mode), N=1 (2 line mode)
Gabiuas 1:0ada46075897 294 // RE=1 (Ena Extended Regs, special mode for KS0078)
Gabiuas 1:0ada46075897 295 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0078)
Gabiuas 1:0ada46075897 296 // 0
Gabiuas 1:0ada46075897 297
Gabiuas 1:0ada46075897 298 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
Gabiuas 1:0ada46075897 299 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0078)
Gabiuas 1:0ada46075897 300 break;
Gabiuas 1:0ada46075897 301
Gabiuas 1:0ada46075897 302 // case LCD12x3D: // Special mode for KS0073, KS0078 and PCF21XX
Gabiuas 1:0ada46075897 303 // case LCD12x3D1: // Special mode for KS0073, KS0078 and PCF21XX
Gabiuas 1:0ada46075897 304 // case LCD12x4D: // Special mode for KS0073, KS0078 and PCF21XX
Gabiuas 1:0ada46075897 305 // case LCD16x3D: // Special mode for KS0073, KS0078
Gabiuas 1:0ada46075897 306 // case LCD16x4D: // Special mode for KS0073, KS0078
Gabiuas 1:0ada46075897 307 // case LCD20x4D: // Special mode for KS0073, KS0078
Gabiuas 1:0ada46075897 308 // case LCD24x3D: // Special mode for KS0078
Gabiuas 1:0ada46075897 309 // case LCD24x3D1: // Special mode for KS0078
Gabiuas 1:0ada46075897 310 case LCD24x4D: // Special mode for KS0078
Gabiuas 1:0ada46075897 311 _function = dl | 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs)
Gabiuas 1:0ada46075897 312 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 313 // N=0 (dont care for 4 line mode)
Gabiuas 1:0ada46075897 314 // RE=0 (Dis. Extended Regs, special mode for KS0078)
Gabiuas 1:0ada46075897 315 // DH=1 (Disp shift enable, special mode for KS0078)
Gabiuas 1:0ada46075897 316 // REV=0 (Reverse normal, special mode for KS0078)
Gabiuas 1:0ada46075897 317
Gabiuas 1:0ada46075897 318 _function_1 = dl | 0x04; // Function set 001 DL N RE(1) BE 0 (Ext Regs)
Gabiuas 1:0ada46075897 319 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 320 // N=0 (1 line mode), N=1 (2 line mode)
Gabiuas 1:0ada46075897 321 // RE=1 (Ena Extended Regs, special mode for KS0078)
Gabiuas 1:0ada46075897 322 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0078)
Gabiuas 1:0ada46075897 323 // 0
Gabiuas 1:0ada46075897 324
Gabiuas 1:0ada46075897 325 _function_x = 0x01; // Ext Function set 0000 1 FW BW NW (Ext Regs)
Gabiuas 1:0ada46075897 326 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0078)
Gabiuas 1:0ada46075897 327 break;
Gabiuas 1:0ada46075897 328
Gabiuas 1:0ada46075897 329 // case LCD6x2:
Gabiuas 1:0ada46075897 330 case LCD8x2:
Gabiuas 1:0ada46075897 331 case LCD16x2:
Gabiuas 1:0ada46075897 332 // case LCD16x1C:
Gabiuas 1:0ada46075897 333 case LCD20x2:
Gabiuas 1:0ada46075897 334 case LCD24x2:
Gabiuas 1:0ada46075897 335 case LCD32x2:
Gabiuas 1:0ada46075897 336 case LCD40x2:
Gabiuas 1:0ada46075897 337 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
Gabiuas 1:0ada46075897 338 _function = dl | 0x0A; // Function set 001 DL N RE(0) DH REV (Std Regs)
Gabiuas 1:0ada46075897 339 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 340 // N=1 (1 line mode), N=1 (2 line mode)
Gabiuas 1:0ada46075897 341 // RE=0 (Dis. Extended Regs, special mode for KS0078)
Gabiuas 1:0ada46075897 342 // DH=1 (Disp shift enable, special mode for KS0078)
Gabiuas 1:0ada46075897 343 // REV=0 (Reverse normal, special mode for KS0078)
Gabiuas 1:0ada46075897 344
Gabiuas 1:0ada46075897 345 _function_1 = dl | 0x0C; // Function set 001 DL N RE(1) BE 0 (Ext Regs)
Gabiuas 1:0ada46075897 346 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 347 // N=1 (1 line mode), N=1 (2 line mode)
Gabiuas 1:0ada46075897 348 // RE=1 (Ena Extended Regs, special mode for KS0078)
Gabiuas 1:0ada46075897 349 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0078)
Gabiuas 1:0ada46075897 350 // 0
Gabiuas 1:0ada46075897 351
Gabiuas 1:0ada46075897 352 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
Gabiuas 1:0ada46075897 353 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0078)
Gabiuas 1:0ada46075897 354 break;
Gabiuas 1:0ada46075897 355
Gabiuas 1:0ada46075897 356 default:
Gabiuas 1:0ada46075897 357 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 358 break;
Gabiuas 1:0ada46075897 359 } // switch type
Gabiuas 1:0ada46075897 360
Gabiuas 1:0ada46075897 361 // init special features
Gabiuas 1:0ada46075897 362 _writeCommand(0x20 | _function_1);// Function set 001 DL N RE(1) BE 0 (Ext Regs)
Gabiuas 1:0ada46075897 363 // DL=0 (4 bits bus), DL=1 (8 bits mode)
Gabiuas 1:0ada46075897 364 // N=0 (1 line mode), N=1 (2 line mode)
Gabiuas 1:0ada46075897 365 // RE=1 (Ena Extended Regs, special mode for KS0078)
Gabiuas 1:0ada46075897 366 // BE=0 (Blink Enable/Disable, CG/SEG RAM, special mode for KS0078)
Gabiuas 1:0ada46075897 367 // 0
Gabiuas 1:0ada46075897 368
Gabiuas 1:0ada46075897 369 _writeCommand(0x08 | _function_x); // Ext Function set 0000 1 FW BW NW (Ext Regs)
Gabiuas 1:0ada46075897 370 // FW=0 (5-dot font, special mode for KS0078)
Gabiuas 1:0ada46075897 371 // BW=0 (Cur BW invert disable, special mode for KS0078)
Gabiuas 1:0ada46075897 372 // NW=0 (1,2 Line), NW=1 (4 line, special mode for KS0078)
Gabiuas 1:0ada46075897 373
Gabiuas 1:0ada46075897 374 _writeCommand(0x10); // Scroll/Shift set 0001 DS/HS4 DS/HS3 DS/HS2 DS/HS1 (Ext Regs)
Gabiuas 1:0ada46075897 375 // Dotscroll/Display shift enable (Special mode for KS0078)
Gabiuas 1:0ada46075897 376
Gabiuas 1:0ada46075897 377 _writeCommand(0x80); // Scroll Quantity set 1 0 SQ5 SQ4 SQ3 SQ2 SQ1 SQ0 (Ext Regs)
Gabiuas 1:0ada46075897 378 // Scroll quantity (Special mode for KS0078)
Gabiuas 1:0ada46075897 379
Gabiuas 1:0ada46075897 380 _writeCommand(0x20 | _function); // Function set 001 DL N RE(0) DH REV (Std Regs)
Gabiuas 1:0ada46075897 381 // DL=0 (4 bits bus), DL=1 (8 bits mode)
Gabiuas 1:0ada46075897 382 // N=0 (1 line mode), N=1 (2 line mode)
Gabiuas 1:0ada46075897 383 // RE=0 (Dis. Extended Regs, special mode for KS0078)
Gabiuas 1:0ada46075897 384 // DH=1 (Disp shift enable/disable, special mode for KS0078)
Gabiuas 1:0ada46075897 385 // REV=0 (Reverse/Normal, special mode for KS0078)
Gabiuas 1:0ada46075897 386 break; // case KS0078 Controller
Gabiuas 1:0ada46075897 387
Gabiuas 1:0ada46075897 388 case ST7032_3V3:
Gabiuas 1:0ada46075897 389 // ST7032 controller: Initialise Voltage booster for VLCD. VDD=3V3
Gabiuas 1:0ada46075897 390 // Note: very similar to SPLC792A
Gabiuas 1:0ada46075897 391 case ST7032_5V:
Gabiuas 1:0ada46075897 392 // ST7032 controller: Disable Voltage booster for VLCD. VDD=5V
Gabiuas 1:0ada46075897 393
Gabiuas 1:0ada46075897 394 // Initialise Display configuration
Gabiuas 1:0ada46075897 395 switch (_type) {
Gabiuas 1:0ada46075897 396 case LCD8x1: //8x1 is a regular 1 line display
Gabiuas 1:0ada46075897 397 case LCD8x2B: //8x2B is a special case of 16x1
Gabiuas 1:0ada46075897 398 // case LCD12x1:
Gabiuas 1:0ada46075897 399 case LCD16x1:
Gabiuas 1:0ada46075897 400 // case LCD20x1:
Gabiuas 1:0ada46075897 401 case LCD24x1:
Gabiuas 1:0ada46075897 402 _function = 0x00; // FUNCTION SET 0 0 1 DL=0 (4 bit), N=0 (1-line display mode), F=0 (5*7dot), 0, IS
Gabiuas 1:0ada46075897 403 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 404 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 405 break;
Gabiuas 1:0ada46075897 406
Gabiuas 1:0ada46075897 407 case LCD12x3D: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 408 case LCD12x3D1: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 409 case LCD12x4D: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 410 case LCD16x3G: // Special mode for ST7036
Gabiuas 1:0ada46075897 411 case LCD24x4D: // Special mode for KS0078
Gabiuas 1:0ada46075897 412 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 413 break;
Gabiuas 1:0ada46075897 414
Gabiuas 1:0ada46075897 415 default:
Gabiuas 1:0ada46075897 416 // All other LCD types are initialised as 2 Line displays
Gabiuas 1:0ada46075897 417 _function = 0x08; // FUNCTION SET 0 0 1 DL=0 (4 bit), N=1 (2-line display mode), F=0 (5*7dot), 0, IS
Gabiuas 1:0ada46075897 418 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 419 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 420 break;
Gabiuas 1:0ada46075897 421 } // switch type
Gabiuas 1:0ada46075897 422
Gabiuas 1:0ada46075897 423 // init special features
Gabiuas 1:0ada46075897 424 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N F 0 IS=1 Select Instr Set = 1
Gabiuas 1:0ada46075897 425
Gabiuas 1:0ada46075897 426 _writeCommand(0x1C); // Internal OSC frequency adjustment Framefreq=183HZ, Bias will be 1/4 (Instr Set=1)
Gabiuas 1:0ada46075897 427 // Note: Bias and Osc register not available on SPLC792A
Gabiuas 1:0ada46075897 428
Gabiuas 1:0ada46075897 429 _contrast = LCD_ST7032_CONTRAST;
Gabiuas 1:0ada46075897 430 _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast Low bits, 0 1 1 1 C3 C2 C1 C0 (IS=1)
Gabiuas 1:0ada46075897 431
Gabiuas 1:0ada46075897 432
Gabiuas 1:0ada46075897 433 if (_ctrl == ST7032_3V3) {
Gabiuas 1:0ada46075897 434 // _icon_power = 0x04; // Icon display off (Bit3=0), Booster circuit is turned on (Bit2=1) (IS=1)
Gabiuas 1:0ada46075897 435 _icon_power = 0x0C; // Icon display on (Bit3=1), Booster circuit is turned on (Bit2=1) (IS=1)
Gabiuas 1:0ada46075897 436 // Note: Booster circuit always on for SPLC792A, Bit2 is dont care
Gabiuas 1:0ada46075897 437 // Saved to allow contrast change at later time
Gabiuas 1:0ada46075897 438 }
Gabiuas 1:0ada46075897 439 else {
Gabiuas 1:0ada46075897 440 // _icon_power = 0x00; // Icon display off, Booster circuit is turned off (IS=1)
Gabiuas 1:0ada46075897 441 _icon_power = 0x08; // Icon display on, Booster circuit is turned off (IS=1)
Gabiuas 1:0ada46075897 442 // Saved to allow contrast change at later time
Gabiuas 1:0ada46075897 443 }
Gabiuas 1:0ada46075897 444 _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Set Icon, Booster and Contrast High bits, 0 1 0 1 Ion Bon C5 C4 (IS=1)
Gabiuas 1:0ada46075897 445 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 446
Gabiuas 1:0ada46075897 447 _writeCommand(0x68 | (LCD_ST7032_RAB & 0x07)); // Voltage follower, 0 1 1 0 FOn=1, Ampl ratio Rab2=1, Rab1=0, Rab0=0 (IS=1)
Gabiuas 1:0ada46075897 448 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 449
Gabiuas 1:0ada46075897 450 _writeCommand(0x20 | _function); // Select Instruction Set = 0
Gabiuas 1:0ada46075897 451
Gabiuas 1:0ada46075897 452 break; // case ST7032_3V3 Controller
Gabiuas 1:0ada46075897 453 // case ST7032_5V Controller
Gabiuas 1:0ada46075897 454
Gabiuas 1:0ada46075897 455 case ST7036_3V3:
Gabiuas 1:0ada46075897 456 // ST7036 controller: Initialise Voltage booster for VLCD. VDD=3V3
Gabiuas 1:0ada46075897 457 // Note: supports 1,2 (LCD_T_A) or 3 lines (LCD_T_G)
Gabiuas 1:0ada46075897 458 case ST7036_5V:
Gabiuas 1:0ada46075897 459 // ST7036 controller: Disable Voltage booster for VLCD. VDD=5V
Gabiuas 1:0ada46075897 460 // Note: supports 1,2 (LCD_T_A) or 3 lines (LCD_T_G)
Gabiuas 1:0ada46075897 461
Gabiuas 1:0ada46075897 462 // Initialise Display configuration
Gabiuas 1:0ada46075897 463 switch (_type) {
Gabiuas 1:0ada46075897 464 case LCD8x1: //8x1 is a regular 1 line display
Gabiuas 1:0ada46075897 465 case LCD8x2B: //8x2D is a special case of 16x1
Gabiuas 1:0ada46075897 466 // case LCD12x1:
Gabiuas 1:0ada46075897 467 case LCD16x1:
Gabiuas 1:0ada46075897 468 case LCD24x1:
Gabiuas 1:0ada46075897 469 _function = 0x00; // Set function, 0 0 1 DL=0 (4-bit Databus), N=0 (1 Line), DH=0 (5x7font), IS2, IS1 (Select Instruction Set)
Gabiuas 1:0ada46075897 470 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 471 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 472
Gabiuas 1:0ada46075897 473 _bias_lines = 0x04; // Bias: 1/5, 1 or 2-Lines LCD
Gabiuas 1:0ada46075897 474 break;
Gabiuas 1:0ada46075897 475
Gabiuas 1:0ada46075897 476 // case LCD12x3G: // Special mode for ST7036
Gabiuas 1:0ada46075897 477 case LCD16x3G: // Special mode for ST7036
Gabiuas 1:0ada46075897 478 _function = 0x08; // Set function, 0 0 1 DL=0 (4-bit Databus), N=1 (2 Line), DH=0 (5x7font), IS2,IS1 (Select Instruction Set)
Gabiuas 1:0ada46075897 479 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 480 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 481
Gabiuas 1:0ada46075897 482 _bias_lines = 0x05; // Bias: 1/5, 3-Lines LCD
Gabiuas 1:0ada46075897 483 break;
Gabiuas 1:0ada46075897 484
Gabiuas 1:0ada46075897 485 // case LCD12x3D1: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 486 // case LCD16x3D1: // Special mode for SSD1803
Gabiuas 1:0ada46075897 487 case LCD12x4D: // Special mode for PCF2116
Gabiuas 1:0ada46075897 488 case LCD24x4D: // Special mode for KS0078
Gabiuas 1:0ada46075897 489 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 490 break;
Gabiuas 1:0ada46075897 491
Gabiuas 1:0ada46075897 492 default:
Gabiuas 1:0ada46075897 493 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
Gabiuas 1:0ada46075897 494 _function = 0x08; // Set function, 0 0 1 DL=0 (4-bit Databus), N=1 (2 Line), DH=0 (5x7font), IS2,IS1 (Select Instruction Set)
Gabiuas 1:0ada46075897 495 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 496 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 497
Gabiuas 1:0ada46075897 498 _bias_lines = 0x04; // Bias: 1/5, 1 or 2-Lines LCD
Gabiuas 1:0ada46075897 499 break;
Gabiuas 1:0ada46075897 500 } // switch type
Gabiuas 1:0ada46075897 501
Gabiuas 1:0ada46075897 502
Gabiuas 1:0ada46075897 503 // init special features
Gabiuas 1:0ada46075897 504 _writeCommand(0x20 | _function | 0x01); // Set function, IS2,IS1 = 01 (Select Instr Set = 1)
Gabiuas 1:0ada46075897 505 _writeCommand(0x10 | _bias_lines); // Set Bias and 1,2 or 3 lines (Instr Set 1)
Gabiuas 1:0ada46075897 506
Gabiuas 1:0ada46075897 507 _contrast = LCD_ST7036_CONTRAST;
Gabiuas 1:0ada46075897 508 _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast, 0 1 1 1 C3 C2 C1 C0 (Instr Set 1)
Gabiuas 1:0ada46075897 509
Gabiuas 1:0ada46075897 510 if (_ctrl == ST7036_3V3) {
Gabiuas 1:0ada46075897 511 _icon_power = 0x0C; // Set Icon, Booster, Contrast High bits, 0 1 0 1 Ion=1 Bon=1 C5 C4 (Instr Set 1)
Gabiuas 1:0ada46075897 512 // _icon_power = 0x04; // Set Icon, Booster, Contrast High bits, 0 1 0 1 Ion=0 Bon=1 C5 C4 (Instr Set 1)
Gabiuas 1:0ada46075897 513 // Saved to allow contrast change at later time
Gabiuas 1:0ada46075897 514 }
Gabiuas 1:0ada46075897 515 else {
Gabiuas 1:0ada46075897 516 _icon_power = 0x08; // Set Icon, Booster, Contrast High bits, 0 1 0 1 Ion=1 Bon=0 C5 C4 (Instr Set 1)
Gabiuas 1:0ada46075897 517 // _icon_power = 0x00; // Set Icon, Booster, Contrast High bits, 0 1 0 1 Ion=0 Bon=0 C5 C4 (Instr Set 1)
Gabiuas 1:0ada46075897 518 }
Gabiuas 1:0ada46075897 519
Gabiuas 1:0ada46075897 520 _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Set Contrast C5, C4 (Instr Set 1)
Gabiuas 1:0ada46075897 521 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 522
Gabiuas 1:0ada46075897 523 _writeCommand(0x68 | (LCD_ST7036_RAB & 0x07)); // Voltagefollower On = 1, Ampl ratio Rab2, Rab1, Rab0 = 1 0 1 (Instr Set 1)
Gabiuas 1:0ada46075897 524 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 525
Gabiuas 1:0ada46075897 526 _writeCommand(0x20 | _function); // Set function, IS2,IS1 = 00 (Select Instruction Set = 0)
Gabiuas 1:0ada46075897 527
Gabiuas 1:0ada46075897 528 break; // case ST7036_3V3 Controller
Gabiuas 1:0ada46075897 529 // case ST7036_5V Controller
Gabiuas 1:0ada46075897 530
Gabiuas 1:0ada46075897 531 case ST7070:
Gabiuas 1:0ada46075897 532 // Initialise Display configuration
Gabiuas 1:0ada46075897 533 switch (_type) {
Gabiuas 1:0ada46075897 534 case LCD8x1: //8x1 is a regular 1 line display
Gabiuas 1:0ada46075897 535 case LCD8x2B: //8x2D is a special case of 16x1
Gabiuas 1:0ada46075897 536 // case LCD12x1:
Gabiuas 1:0ada46075897 537 case LCD16x1:
Gabiuas 1:0ada46075897 538 case LCD24x1:
Gabiuas 1:0ada46075897 539 _function = dl | 0x00; // Set function, 0 0 1 DL=0 (4-bit Databus), N=0 (1 Line), EXT=0, x, x
Gabiuas 1:0ada46075897 540 // Note: 4 bit mode is NOT ignored for native SPI !
Gabiuas 1:0ada46075897 541 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 542 break;
Gabiuas 1:0ada46075897 543
Gabiuas 1:0ada46075897 544 // case LCD12x3D1: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 545 // case LCD16x3D1: // Special mode for SSD1803
Gabiuas 1:0ada46075897 546 case LCD12x4D: // Special mode for PCF2116
Gabiuas 1:0ada46075897 547 case LCD24x4D: // Special mode for KS0078
Gabiuas 1:0ada46075897 548 // case LCD12x3G: // Special mode for ST7036
Gabiuas 1:0ada46075897 549 case LCD16x3G: // Special mode for ST7036
Gabiuas 1:0ada46075897 550 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 551 break;
Gabiuas 1:0ada46075897 552
Gabiuas 1:0ada46075897 553 default:
Gabiuas 1:0ada46075897 554 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
Gabiuas 1:0ada46075897 555 _function = dl | 0x08; // Set function, 0 0 1 DL, N=1 (2 Line), EXT=0, x, x
Gabiuas 1:0ada46075897 556 // Note: 4 bit mode is NOT ignored for native SPI !
Gabiuas 1:0ada46075897 557 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 558 break;
Gabiuas 1:0ada46075897 559 } // switch type
Gabiuas 1:0ada46075897 560
Gabiuas 1:0ada46075897 561 // _writeCommand(0x00); // NOP, make sure to sync SPI
Gabiuas 1:0ada46075897 562
Gabiuas 1:0ada46075897 563 // init special features
Gabiuas 1:0ada46075897 564 _writeCommand(0x20 | _function | 0x04); // Set function, 0 0 1 DL N EXT=1 x x (Select Instr Set = 1)
Gabiuas 1:0ada46075897 565
Gabiuas 1:0ada46075897 566 _writeCommand(0x04 | 0x00); // Set Bias resistors 0 0 0 0 0 1 Rb1,Rb0= 0 0 (Extern Res) (Instr Set 1)
Gabiuas 1:0ada46075897 567
Gabiuas 1:0ada46075897 568 _writeCommand(0x40 | 0x00); // COM/SEG directions 0 1 0 0 C1, C2, S1, S2 (Instr Set 1)
Gabiuas 1:0ada46075897 569 // C1=1: Com1-8 -> Com8-1; C2=1: Com9-16 -> Com16-9
Gabiuas 1:0ada46075897 570 // S1=1: Seg1-40 -> Seg40-1; S2=1: Seg41-80 -> Seg80-41
Gabiuas 1:0ada46075897 571
Gabiuas 1:0ada46075897 572 _writeCommand(0x20 | _function); // Set function, EXT=0 (Select Instr Set = 0)
Gabiuas 1:0ada46075897 573
Gabiuas 1:0ada46075897 574 break; // case ST7070 Controller
Gabiuas 1:0ada46075897 575
Gabiuas 1:0ada46075897 576 case SSD1803_3V3:
Gabiuas 1:0ada46075897 577 // SSD1803 controller: Initialise Voltage booster for VLCD. VDD=3V3
Gabiuas 1:0ada46075897 578 // Note: supports 1,2, 3 or 4 lines
Gabiuas 1:0ada46075897 579 // case SSD1803_5V:
Gabiuas 1:0ada46075897 580 // SSD1803 controller: No Voltage booster for VLCD. VDD=5V
Gabiuas 1:0ada46075897 581
Gabiuas 1:0ada46075897 582 // Initialise Display configuration
Gabiuas 1:0ada46075897 583 switch (_type) {
Gabiuas 1:0ada46075897 584 case LCD8x1: //8x1 is a regular 1 line display
Gabiuas 1:0ada46075897 585 case LCD8x2B: //8x2D is a special case of 16x1
Gabiuas 1:0ada46075897 586 // case LCD12x1:
Gabiuas 1:0ada46075897 587 case LCD16x1:
Gabiuas 1:0ada46075897 588 case LCD24x1:
Gabiuas 1:0ada46075897 589 _function = 0x00; // Set function 0 0 1 DL N DH RE(0) IS
Gabiuas 1:0ada46075897 590 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 591 // DL=0 4-bit Databus,
Gabiuas 1:0ada46075897 592 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 593 // N=0 1 Line / 3 Line
Gabiuas 1:0ada46075897 594 // DH=0 Double Height disable
Gabiuas 1:0ada46075897 595 // IS=0
Gabiuas 1:0ada46075897 596
Gabiuas 1:0ada46075897 597 _function_1 = 0x02; // Set function, 0 0 1 DL N BE RE(1) REV
Gabiuas 1:0ada46075897 598 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 599 // DL=0 4-bit Databus,
Gabiuas 1:0ada46075897 600 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 601 // N=0 1 Line / 3 Line
Gabiuas 1:0ada46075897 602 // BE=0 Blink Enable off, special feature of SSD1803
Gabiuas 1:0ada46075897 603 // REV=0 Reverse off, special feature of SSD1803
Gabiuas 1:0ada46075897 604
Gabiuas 1:0ada46075897 605 _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW
Gabiuas 1:0ada46075897 606 // NW=0 1-Line LCD (N=0)
Gabiuas 1:0ada46075897 607 break;
Gabiuas 1:0ada46075897 608
Gabiuas 1:0ada46075897 609 case LCD12x3D: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 610 // case LCD12x3D1: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 611 case LCD16x3D: // Special mode for KS0078
Gabiuas 1:0ada46075897 612 // case LCD16x3D1: // Special mode for SSD1803
Gabiuas 1:0ada46075897 613 // case LCD20x3D: // Special mode for SSD1803
Gabiuas 1:0ada46075897 614 _function = 0x00; // Set function 0 0 1 DL N DH RE(0) IS
Gabiuas 1:0ada46075897 615 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 616 // DL=0 4-bit Databus,
Gabiuas 1:0ada46075897 617 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 618 // N=0 1 Line / 3 Line
Gabiuas 1:0ada46075897 619 // DH=0 Double Height disable
Gabiuas 1:0ada46075897 620 // IS=0
Gabiuas 1:0ada46075897 621
Gabiuas 1:0ada46075897 622 _function_1 = 0x02; // Set function, 0 0 1 DL N BE RE(1) REV
Gabiuas 1:0ada46075897 623 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 624 // DL=0 4-bit Databus,
Gabiuas 1:0ada46075897 625 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 626 // N=0 1 Line / 3 Line
Gabiuas 1:0ada46075897 627 // BE=0 Blink Enable off, special feature of SSD1803
Gabiuas 1:0ada46075897 628 // REV=0 Reverse off, special feature of SSD1803
Gabiuas 1:0ada46075897 629
Gabiuas 1:0ada46075897 630 _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW
Gabiuas 1:0ada46075897 631 // NW=1 3-Line LCD (N=0)
Gabiuas 1:0ada46075897 632 break;
Gabiuas 1:0ada46075897 633
Gabiuas 1:0ada46075897 634 // case LCD10x2D: // Special mode for SSD1803, 4-line mode but switch to double height font
Gabiuas 1:0ada46075897 635 case LCD10x4D: // Special mode for SSD1803
Gabiuas 1:0ada46075897 636 case LCD20x4D: // Special mode for SSD1803
Gabiuas 1:0ada46075897 637 _function = 0x08; // Set function 0 0 1 DL N DH RE(0) IS
Gabiuas 1:0ada46075897 638 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 639 // DL=0 4-bit Databus,
Gabiuas 1:0ada46075897 640 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 641 // N=1 4 Line
Gabiuas 1:0ada46075897 642 // DH=0 Double Height disable
Gabiuas 1:0ada46075897 643 // IS=0
Gabiuas 1:0ada46075897 644
Gabiuas 1:0ada46075897 645 _function_1 = 0x0A; // Set function, 0 0 1 DL N BE RE(1) REV
Gabiuas 1:0ada46075897 646 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 647 // DL=0 4-bit Databus,
Gabiuas 1:0ada46075897 648 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 649 // N=1 4 Line
Gabiuas 1:0ada46075897 650 // BE=0 Blink Enable off, special feature of SSD1803
Gabiuas 1:0ada46075897 651 // REV=0 Reverse off, special feature of SSD1803
Gabiuas 1:0ada46075897 652
Gabiuas 1:0ada46075897 653 _lines = 0x01; // Ext function set 0 0 0 0 1 FW BW NW
Gabiuas 1:0ada46075897 654 // NW=1 4-Line LCD (N=1)
Gabiuas 1:0ada46075897 655 break;
Gabiuas 1:0ada46075897 656
Gabiuas 1:0ada46075897 657 case LCD16x3G: // Special mode for ST7036
Gabiuas 1:0ada46075897 658 case LCD24x4D: // Special mode for KS0078
Gabiuas 1:0ada46075897 659 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 660 break;
Gabiuas 1:0ada46075897 661
Gabiuas 1:0ada46075897 662 default:
Gabiuas 1:0ada46075897 663 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
Gabiuas 1:0ada46075897 664 _function = 0x08; // Set function 0 0 1 DL N DH RE(0) IS
Gabiuas 1:0ada46075897 665 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 666 // DL=0 4-bit Databus,
Gabiuas 1:0ada46075897 667 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 668 // N=1 2 line / 4 Line
Gabiuas 1:0ada46075897 669 // DH=0 Double Height disable
Gabiuas 1:0ada46075897 670 // RE=0
Gabiuas 1:0ada46075897 671 // IS=0
Gabiuas 1:0ada46075897 672
Gabiuas 1:0ada46075897 673 _function_1 = 0x0A; // Set function, 0 0 1 DL N BE RE(1) REV
Gabiuas 1:0ada46075897 674 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 675 // DL=0 4-bit Databus,
Gabiuas 1:0ada46075897 676 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 677 // N=1 2 line / 4 Line
Gabiuas 1:0ada46075897 678 // BE=0 Blink Enable off, special feature of SSD1803
Gabiuas 1:0ada46075897 679 // RE=1
Gabiuas 1:0ada46075897 680 // REV=0 Reverse off, special feature of SSD1803
Gabiuas 1:0ada46075897 681
Gabiuas 1:0ada46075897 682 _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW
Gabiuas 1:0ada46075897 683 // NW=0 2-Line LCD (N=1)
Gabiuas 1:0ada46075897 684 break;
Gabiuas 1:0ada46075897 685 } // switch type
Gabiuas 1:0ada46075897 686
Gabiuas 1:0ada46075897 687
Gabiuas 1:0ada46075897 688 // init special features
Gabiuas 1:0ada46075897 689 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
Gabiuas 1:0ada46075897 690 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 691
Gabiuas 1:0ada46075897 692 _writeCommand(0x06); // Set ext entry mode, 0 0 0 0 0 1 BDC=1 COM1-32, BDS=0 SEG100-1 "Bottom View" (Ext Instr Set)
Gabiuas 1:0ada46075897 693 // _writeCommand(0x05); // Set ext entry mode, 0 0 0 0 0 1 BDC=0 COM32-1, BDS=1 SEG1-100 "Top View" (Ext Instr Set)
Gabiuas 1:0ada46075897 694 wait_ms(5); // Wait to ensure completion or SSD1803 fails to set Top/Bottom after reset..
Gabiuas 1:0ada46075897 695
Gabiuas 1:0ada46075897 696 _writeCommand(0x08 | _lines); // Set ext function 0 0 0 0 1 FW BW NW 1,2,3 or 4 lines (Ext Instr Set)
Gabiuas 1:0ada46075897 697
Gabiuas 1:0ada46075897 698 _writeCommand(0x10); // Double Height and Bias, 0 0 0 1 UD2=0, UD1=0, BS1=0 Bias 1/5, DH=0 (Ext Instr Set)
Gabiuas 1:0ada46075897 699
Gabiuas 1:0ada46075897 700 // _writeCommand(0x76); // Set TC Control, 0 1 1 1 0 1 1 0 (Ext Instr Set)
Gabiuas 1:0ada46075897 701 // _writeData(0x02); // Set TC data, 0 0 0 0 0 TC2,TC1,TC0 = 0 1 0 (Ext Instr Set)
Gabiuas 1:0ada46075897 702
Gabiuas 1:0ada46075897 703 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N DH RE(0) IS=1 Select Instruction Set 1
Gabiuas 1:0ada46075897 704 // Select Std Instr set, Select IS=1
Gabiuas 1:0ada46075897 705
Gabiuas 1:0ada46075897 706 _contrast = LCD_SSD1_CONTRAST;
Gabiuas 1:0ada46075897 707 _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast 0 1 1 1 C3, C2, C1, C0 (Instr Set 1)
Gabiuas 1:0ada46075897 708
Gabiuas 1:0ada46075897 709 // _icon_power = 0x04; // Icon off, Booster on (Instr Set 1)
Gabiuas 1:0ada46075897 710 _icon_power = 0x0C; // Icon on, Booster on (Instr Set 1)
Gabiuas 1:0ada46075897 711 // Saved to allow contrast change at later time
Gabiuas 1:0ada46075897 712 _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Set Power, Icon and Contrast, 0 1 0 1 Ion Bon C5 C4 (Instr Set 1)
Gabiuas 1:0ada46075897 713 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 714
Gabiuas 1:0ada46075897 715 _writeCommand(0x68 | (LCD_SSD1_RAB & 0x07)); // Set Voltagefollower 0 1 1 0 Don = 1, Ampl ratio Rab2, Rab1, Rab0 = 1 1 0 (Instr Set 1)
Gabiuas 1:0ada46075897 716 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 717
Gabiuas 1:0ada46075897 718 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
Gabiuas 1:0ada46075897 719 // Select Extended Instruction Set 1
Gabiuas 1:0ada46075897 720 _writeCommand(0x10); // Shift/Scroll enable, 0 0 0 1 DS4/HS4 DS3/HS3 DS2/HS2 DS1/HS1 (Ext Instr Set 1)
Gabiuas 1:0ada46075897 721
Gabiuas 1:0ada46075897 722
Gabiuas 1:0ada46075897 723 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 724 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 725
Gabiuas 1:0ada46075897 726 break; // case SSD1803 Controller
Gabiuas 1:0ada46075897 727
Gabiuas 1:0ada46075897 728
Gabiuas 1:0ada46075897 729 // Note1: The PCF21XX family of controllers has several types that dont have an onboard voltage generator for V-LCD.
Gabiuas 1:0ada46075897 730 // You must supply this LCD voltage externally and not try to enable VGen.
Gabiuas 1:0ada46075897 731 // Note2: The early versions of PCF2116 controllers (eg PCF2116C) can not generate sufficiently negative voltage for the LCD at a VDD of 3V3.
Gabiuas 1:0ada46075897 732 // You must supply this voltage externally and not enable VGen or you must use a higher VDD (e.g. 5V) and enable VGen.
Gabiuas 1:0ada46075897 733 // More recent versions of the controller (eg PCF2116K) have an improved VGen that will work with 3V3.
Gabiuas 1:0ada46075897 734 // Note3: See datasheet, PCF2116 and other types provide a V0 pin to control the LCD contrast voltage that is provided by VGen. This pins allows
Gabiuas 1:0ada46075897 735 // contrast control similar to that of pin 3 on the standard 14pin LCD module connector.
Gabiuas 1:0ada46075897 736 // You can disable VGen by connecting Vo to VDD. VLCD will then be used directly as LCD voltage.
Gabiuas 1:0ada46075897 737 // Note4: PCF2113 and PCF2119 are different wrt to VLCD generator! There is no V0 pin. The contrast voltage is software controlled by setting the VA and VB registers.
Gabiuas 1:0ada46075897 738 // Vgen is automatically switched off when the contrast voltage VA or VB is set to 0x00. Note that certain limits apply to allowed values for VA and VB.
Gabiuas 1:0ada46075897 739 // Note5: See datasheet, members of the PCF21XX family support different numbers of rows/columns. Not all can support 3 or 4 rows.
Gabiuas 1:0ada46075897 740 // Note6: See datasheet, the PCF21XX-C and PCF21XX-K use a non-standard character set. This may result is strange looking text when not corrected..
Gabiuas 1:0ada46075897 741
Gabiuas 1:0ada46075897 742 case PCF2103_3V3:
Gabiuas 1:0ada46075897 743 // PCF2103 controller: No Voltage generator for VLCD, VDD=3V3..5V, VLCD input controls contrast voltage.
Gabiuas 1:0ada46075897 744 // Initialise Display configuration
Gabiuas 1:0ada46075897 745 switch (_type) {
Gabiuas 1:0ada46075897 746 case LCD24x1:
Gabiuas 1:0ada46075897 747 _function = 0x00; //FUNCTION SET 0 0 1 DL=0 4-bit, 0, M=0 1-line/24 chars display mode, 0, H=0
Gabiuas 1:0ada46075897 748 //Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 749 break;
Gabiuas 1:0ada46075897 750
Gabiuas 1:0ada46075897 751 // case LCD12x1D: //Special mode for PCF21XX, Only top line used
Gabiuas 1:0ada46075897 752 case LCD12x2:
Gabiuas 1:0ada46075897 753 _function = 0x04; //FUNCTION SET 0 0 1 DL=0 4-bit, 0, M=1 2-line/12 chars display mode, 0, H=0
Gabiuas 1:0ada46075897 754 //Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 755 break;
Gabiuas 1:0ada46075897 756
Gabiuas 1:0ada46075897 757 default:
Gabiuas 1:0ada46075897 758 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 759 break;
Gabiuas 1:0ada46075897 760
Gabiuas 1:0ada46075897 761 } // switch type
Gabiuas 1:0ada46075897 762
Gabiuas 1:0ada46075897 763 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
Gabiuas 1:0ada46075897 764 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 765
Gabiuas 1:0ada46075897 766 // Note: Display from GA628 shows 12 chars. This is actually the right half of a 24x1 display. The commons have been connected in reverse order.
Gabiuas 1:0ada46075897 767 _writeCommand(0x05); // Display Conf Set 0000 0, 1, P=0, Q=1 (Instr. Set 1)
Gabiuas 1:0ada46075897 768
Gabiuas 1:0ada46075897 769 _writeCommand(0x02); // Screen Config 0000 001, L=0 (Instr. Set 1)
Gabiuas 1:0ada46075897 770 _writeCommand(0x08); // ICON Conf 0000 1, IM=0 (Char mode), IB=0 (no Icon blink), 0 (Instr. Set 1)
Gabiuas 1:0ada46075897 771
Gabiuas 1:0ada46075897 772 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
Gabiuas 1:0ada46075897 773
Gabiuas 1:0ada46075897 774 #if(0)
Gabiuas 1:0ada46075897 775 // Select CG RAM
Gabiuas 1:0ada46075897 776 _writeCommand(0x40); //Set CG-RAM address, 8 sequential locations needed per UDC
Gabiuas 1:0ada46075897 777 // Store UDC/Icon pattern:
Gabiuas 1:0ada46075897 778 // 3 x 8 rows x 5 bits = 120 bits for Normal pattern (UDC 0..2) and
Gabiuas 1:0ada46075897 779 // 3 x 8 rows x 5 bits = 120 bits for Blink pattern (UDC 4..6)
Gabiuas 1:0ada46075897 780 for (int i=0; i<(8 * 8); i++) {
Gabiuas 1:0ada46075897 781 // _writeData(0x1F); // All On
Gabiuas 1:0ada46075897 782 _writeData(0x00); // All Off
Gabiuas 1:0ada46075897 783 }
Gabiuas 1:0ada46075897 784 #endif
Gabiuas 1:0ada46075897 785 break; // case PCF2103_3V3 Controller
Gabiuas 1:0ada46075897 786
Gabiuas 1:0ada46075897 787 case PCF2113_3V3:
Gabiuas 1:0ada46075897 788 // PCF2113 controller: Initialise Voltage booster for VLCD. VDD=3V3. VA and VB control contrast.
Gabiuas 1:0ada46075897 789 // Initialise Display configuration
Gabiuas 1:0ada46075897 790 switch (_type) {
Gabiuas 1:0ada46075897 791 // case LCD12x1:
Gabiuas 1:0ada46075897 792 // _function = 0x02; // FUNCTION SET 0 0 1 DL=0 4 bit, 0, M=0 1-line/12 chars display mode, SL=1, IS=0
Gabiuas 1:0ada46075897 793 // Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 794 case LCD24x1:
Gabiuas 1:0ada46075897 795 _function = 0x00; // FUNCTION SET 0 0 1 DL=0 4 bit, 0, M=0 1-line/24 chars display mode, SL=0, IS=0
Gabiuas 1:0ada46075897 796 // Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 797 break;
Gabiuas 1:0ada46075897 798
Gabiuas 1:0ada46075897 799 case LCD12x2:
Gabiuas 1:0ada46075897 800 _function = 0x04; // FUNCTION SET 0 0 1 DL=0 4 bit, 0, M=1 2-line/12 chars display mode, SL=0, IS=0
Gabiuas 1:0ada46075897 801 break;
Gabiuas 1:0ada46075897 802
Gabiuas 1:0ada46075897 803 default:
Gabiuas 1:0ada46075897 804 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 805 break;
Gabiuas 1:0ada46075897 806
Gabiuas 1:0ada46075897 807 } // switch type
Gabiuas 1:0ada46075897 808
Gabiuas 1:0ada46075897 809 // Init special features
Gabiuas 1:0ada46075897 810 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
Gabiuas 1:0ada46075897 811
Gabiuas 1:0ada46075897 812 _writeCommand(0x04); // Display Conf Set 0000 0, 1, P=0, Q=0 (Instr. Set 1)
Gabiuas 1:0ada46075897 813 _writeCommand(0x10); // Temp Compensation Set 0001 0, 0, TC1=0, TC2=0 (Instr. Set 1)
Gabiuas 1:0ada46075897 814 // _writeCommand(0x42); // HV GEN 0100 S1=1, S2=0 (2x multiplier) (Instr. Set 1)
Gabiuas 1:0ada46075897 815 _writeCommand(0x40 | (LCD_PCF2_S12 & 0x03)); // HV Gen 0100 S1=1, S2=0 (2x multiplier) (Instr. Set 1)
Gabiuas 1:0ada46075897 816
Gabiuas 1:0ada46075897 817 _contrast = LCD_PCF2_CONTRAST;
Gabiuas 1:0ada46075897 818 _writeCommand(0x80 | 0x00 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) 1, V=0, VA=contrast
Gabiuas 1:0ada46075897 819 _writeCommand(0x80 | 0x40 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) 1, V=1, VB=contrast
Gabiuas 1:0ada46075897 820 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 821
Gabiuas 1:0ada46075897 822 _writeCommand(0x02); // Screen Config 0000 001, L=0 (Instr. Set 1)
Gabiuas 1:0ada46075897 823 _writeCommand(0x08); // ICON Conf 0000 1, IM=0 (Char mode), IB=0 (no icon blink) DM=0 (no direct mode) (Instr. Set 1)
Gabiuas 1:0ada46075897 824
Gabiuas 1:0ada46075897 825 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
Gabiuas 1:0ada46075897 826
Gabiuas 1:0ada46075897 827 break; // case PCF2113_3V3 Controller
Gabiuas 1:0ada46075897 828
Gabiuas 1:0ada46075897 829
Gabiuas 1:0ada46075897 830 // case PCF2113_5V:
Gabiuas 1:0ada46075897 831 // PCF2113 controller: No Voltage generator for VLCD. VDD=5V. Contrast voltage controlled by VA or VB.
Gabiuas 1:0ada46075897 832 //@TODO
Gabiuas 1:0ada46075897 833
Gabiuas 1:0ada46075897 834
Gabiuas 1:0ada46075897 835 case PCF2116_3V3:
Gabiuas 1:0ada46075897 836 // PCF2116 controller: Voltage generator for VLCD. VDD=5V. V0 controls contrast voltage.
Gabiuas 1:0ada46075897 837 // Initialise Display configuration
Gabiuas 1:0ada46075897 838 switch (_type) {
Gabiuas 1:0ada46075897 839 // case LCD12x1:
Gabiuas 1:0ada46075897 840 // case LCD12x2:
Gabiuas 1:0ada46075897 841 case LCD24x1:
Gabiuas 1:0ada46075897 842 _writeCommand(0x22); //FUNCTION SET 0 0 1 DL=0 4-bit, N=0/M=0 1-line/24 chars display mode, G=1 Vgen on, 0
Gabiuas 1:0ada46075897 843 //Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 844 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 845 break;
Gabiuas 1:0ada46075897 846
Gabiuas 1:0ada46075897 847 case LCD12x3D: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 848 case LCD12x3D1: // Special mode for PCF21XX
Gabiuas 1:0ada46075897 849 case LCD12x4D: // Special mode for PCF21XX:
Gabiuas 1:0ada46075897 850 _writeCommand(0x2E); //FUNCTION SET 0 0 1 DL=0 4-bit, N=1/M=1 4-line/12 chars display mode, G=1 VGen on, 0
Gabiuas 1:0ada46075897 851 //Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 852 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 853 break;
Gabiuas 1:0ada46075897 854
Gabiuas 1:0ada46075897 855 case LCD24x2:
Gabiuas 1:0ada46075897 856 _writeCommand(0x2A); //FUNCTION SET 0 0 1 DL=0 4-bit, N=1/M=0 2-line/24 chars display mode, G=1 VGen on, 0
Gabiuas 1:0ada46075897 857 //Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 858 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 859 break;
Gabiuas 1:0ada46075897 860
Gabiuas 1:0ada46075897 861 default:
Gabiuas 1:0ada46075897 862 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 863 break;
Gabiuas 1:0ada46075897 864
Gabiuas 1:0ada46075897 865 } // switch type
Gabiuas 1:0ada46075897 866
Gabiuas 1:0ada46075897 867 break; // case PCF2116_3V3 Controller
Gabiuas 1:0ada46075897 868
Gabiuas 1:0ada46075897 869
Gabiuas 1:0ada46075897 870 //Experimental for cellphone 3-line display, SA=0x74, No Ack supported, Character set C or K, DL = 8 bit, N=0,M=1 (reserved mode !!), external VLCD -2V5
Gabiuas 1:0ada46075897 871 //@TODO
Gabiuas 1:0ada46075897 872 case PCF2116_5V:
Gabiuas 1:0ada46075897 873 // PCF2116 controller: No Voltage generator for VLCD. VDD=5V. V0 controls contrast voltage.
Gabiuas 1:0ada46075897 874 // Initialise Display configuration
Gabiuas 1:0ada46075897 875 switch (_type) {
Gabiuas 1:0ada46075897 876 // case LCD12x1:
Gabiuas 1:0ada46075897 877 // case LCD12x2:
Gabiuas 1:0ada46075897 878 // case LCD24x1:
Gabiuas 1:0ada46075897 879 // _writeCommand(0x20); //FUNCTION SET 0 0 1 DL=0 4-bit, N=0/M=0 1-line/24 chars display mode, G=0 no Vgen, 0
Gabiuas 1:0ada46075897 880 //Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 881 // wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 882 // break;
Gabiuas 1:0ada46075897 883
Gabiuas 1:0ada46075897 884 case LCD12x3D: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 885 case LCD12x3D1: // Special mode for PCF21XX
Gabiuas 1:0ada46075897 886 case LCD12x4D: // Special mode for PCF21XX:
Gabiuas 1:0ada46075897 887 // _writeCommand(0x34); //FUNCTION SET 8 bit, N=0/M=1 4-line/12 chars display mode OK
Gabiuas 1:0ada46075897 888 // _writeCommand(0x24); //FUNCTION SET 4 bit, N=0/M=1 4-line/12 chars display mode OK
Gabiuas 1:0ada46075897 889 _writeCommand(0x2C); //FUNCTION SET 0 0 1 DL=0 4-bit, N=1/M=1 4-line/12 chars display mode, G=0 no Vgen, 0 OK
Gabiuas 1:0ada46075897 890 //Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 891 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 892 break;
Gabiuas 1:0ada46075897 893
Gabiuas 1:0ada46075897 894 // case LCD24x2:
Gabiuas 1:0ada46075897 895 // _writeCommand(0x28); //FUNCTION SET 4 bit, N=1/M=0 2-line/24 chars display mode
Gabiuas 1:0ada46075897 896 //Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 897 // wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 898 // break;
Gabiuas 1:0ada46075897 899
Gabiuas 1:0ada46075897 900 default:
Gabiuas 1:0ada46075897 901 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 902 break;
Gabiuas 1:0ada46075897 903
Gabiuas 1:0ada46075897 904 } // switch type
Gabiuas 1:0ada46075897 905
Gabiuas 1:0ada46075897 906 break; // case PCF2116_5V Controller
Gabiuas 1:0ada46075897 907
Gabiuas 1:0ada46075897 908 case PCF2119_3V3:
Gabiuas 1:0ada46075897 909 case PCF2119R_3V3:
Gabiuas 1:0ada46075897 910 // PCF2119 controller: Initialise Voltage booster for VLCD. VDD=3V3. VA and VB control contrast.
Gabiuas 1:0ada46075897 911 // Note1: See datasheet, the PCF2119 supports icons and provides separate constrast control for Icons and characters.
Gabiuas 1:0ada46075897 912 // Note2: Vgen is switched off when the contrast voltage VA or VB is set to 0x00.
Gabiuas 1:0ada46075897 913
Gabiuas 1:0ada46075897 914 //POR or Hardware Reset should be applied
Gabiuas 1:0ada46075897 915 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 916
Gabiuas 1:0ada46075897 917 // Initialise Display configuration
Gabiuas 1:0ada46075897 918 switch (_type) {
Gabiuas 1:0ada46075897 919 case LCD8x1:
Gabiuas 1:0ada46075897 920 // case LCD12x1:
Gabiuas 1:0ada46075897 921 case LCD16x1:
Gabiuas 1:0ada46075897 922 _function = 0x02; // FUNCTION SET 0 0 1 DL=0 4-bit, 0 , M=0 1-line/16 chars display mode, SL=1
Gabiuas 1:0ada46075897 923 // Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 924 break;
Gabiuas 1:0ada46075897 925
Gabiuas 1:0ada46075897 926 case LCD24x1:
Gabiuas 1:0ada46075897 927 // case LCD32x1:
Gabiuas 1:0ada46075897 928 _function = 0x00; // FUNCTION SET 0 0 1 DL=0 4-bit, 0 , M=0 1-line/32 chars display mode, SL=0
Gabiuas 1:0ada46075897 929 // Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 930 break;
Gabiuas 1:0ada46075897 931
Gabiuas 1:0ada46075897 932 case LCD8x2:
Gabiuas 1:0ada46075897 933 // case LCD12x2:
Gabiuas 1:0ada46075897 934 case LCD16x2:
Gabiuas 1:0ada46075897 935 _function = 0x04; // FUNCTION SET 0 0 1 DL=0 4-bit, 0, M=1 2-line/16 chars display mode, SL=0
Gabiuas 1:0ada46075897 936 // Note: 4 bit mode is ignored for I2C mode
Gabiuas 1:0ada46075897 937 break;
Gabiuas 1:0ada46075897 938
Gabiuas 1:0ada46075897 939 default:
Gabiuas 1:0ada46075897 940 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 941 break;
Gabiuas 1:0ada46075897 942
Gabiuas 1:0ada46075897 943 } // switch type
Gabiuas 1:0ada46075897 944
Gabiuas 1:0ada46075897 945 // Init special features
Gabiuas 1:0ada46075897 946 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instruction Set = 1
Gabiuas 1:0ada46075897 947
Gabiuas 1:0ada46075897 948 // _writeCommand(0x04); // DISP CONF SET (Instr. Set 1) 0000, 0, 1, P=0, Q=0 (IC at Bottom)
Gabiuas 1:0ada46075897 949 // _writeCommand(0x05); // Display Conf Set 0000, 0, 1, P=0, Q=1
Gabiuas 1:0ada46075897 950 // _writeCommand(0x06); // Display Conf Set 0000, 0, 1, P=1, Q=0
Gabiuas 1:0ada46075897 951 _writeCommand(0x07); // Display Conf Set 0000, 0, 1, P=1, Q=1 (IC at Top)
Gabiuas 1:0ada46075897 952
Gabiuas 1:0ada46075897 953 _writeCommand(0x10); // TEMP CTRL SET (Instr. Set 1) 0001, 0, 0, TC1=0, TC2=0
Gabiuas 1:0ada46075897 954 // _writeCommand(0x42); // HV GEN (Instr. Set 1) 0100, 0, 0, S1=1, S2=0 (2x multiplier)
Gabiuas 1:0ada46075897 955 _writeCommand(0x40 | (LCD_PCF2_S12 & 0x03)); // HV GEN (Instr. Set 1) 0100, 0, 0, S1=1, S2=0 (2x multiplier)
Gabiuas 1:0ada46075897 956
Gabiuas 1:0ada46075897 957 _contrast = LCD_PCF2_CONTRAST;
Gabiuas 1:0ada46075897 958 _writeCommand(0x80 | 0x00 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=0, VA=contrast
Gabiuas 1:0ada46075897 959 _writeCommand(0x80 | 0x40 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=1, VB=contrast
Gabiuas 1:0ada46075897 960 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 961
Gabiuas 1:0ada46075897 962 _writeCommand(0x02); // SCRN CONF (Instr. Set 1) L=0
Gabiuas 1:0ada46075897 963 _writeCommand(0x08); // ICON CONF (Instr. Set 1) IM=0 (Char mode) IB=0 (no icon blink) DM=0 (no direct mode)
Gabiuas 1:0ada46075897 964
Gabiuas 1:0ada46075897 965 _writeCommand(0x20 | _function); // Select Instruction Set = 0
Gabiuas 1:0ada46075897 966
Gabiuas 1:0ada46075897 967 break; // case PCF2119_3V3 Controller
Gabiuas 1:0ada46075897 968
Gabiuas 1:0ada46075897 969 // case PCF2119_5V:
Gabiuas 1:0ada46075897 970 // PCF2119 controller: No Voltage booster for VLCD. VDD=3V3. VA and VB control contrast.
Gabiuas 1:0ada46075897 971 // Note1: See datasheet, the PCF2119 supports icons and provides separate constrast control for Icons and characters.
Gabiuas 1:0ada46075897 972 // Note2: Vgen is switched off when the contrast voltage VA or VB is set to 0x00.
Gabiuas 1:0ada46075897 973 //@TODO
Gabiuas 1:0ada46075897 974
Gabiuas 1:0ada46075897 975 case WS0010:
Gabiuas 1:0ada46075897 976 // WS0010 OLED controller: Initialise DC/DC Voltage converter for LEDs
Gabiuas 1:0ada46075897 977 // Note1: Identical to RS0010
Gabiuas 1:0ada46075897 978 // Note2: supports 1 or 2 lines (and 16x100 graphics)
Gabiuas 1:0ada46075897 979 // supports 4 fonts (English/Japanese (default), Western European-I, English/Russian, Western European-II)
Gabiuas 1:0ada46075897 980 // Cursor/Disp shift set 0001 SC RL 0 0
Gabiuas 1:0ada46075897 981 //
Gabiuas 1:0ada46075897 982 // Mode and Power set 0001 GC PWR 1 1
Gabiuas 1:0ada46075897 983 // GC = 0 (Graph Mode=1, Char Mode=0)
Gabiuas 1:0ada46075897 984 // PWR = 1 (DC/DC On/Off)
Gabiuas 1:0ada46075897 985
Gabiuas 1:0ada46075897 986 //@Todo: This may be needed to enable a warm reboot
Gabiuas 1:0ada46075897 987 //_writeCommand(0x13); // Char mode, DC/DC off
Gabiuas 1:0ada46075897 988 //wait_ms(10); // Wait 10ms to ensure powered down
Gabiuas 1:0ada46075897 989 _writeCommand(0x17); // Char mode, DC/DC on
Gabiuas 1:0ada46075897 990 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 991
Gabiuas 1:0ada46075897 992 // Initialise Display configuration
Gabiuas 1:0ada46075897 993 switch (_type) {
Gabiuas 1:0ada46075897 994 case LCD8x1: //8x1 is a regular 1 line display
Gabiuas 1:0ada46075897 995 case LCD8x2B: //8x2B is a special case of 16x1
Gabiuas 1:0ada46075897 996 // case LCD12x1:
Gabiuas 1:0ada46075897 997 case LCD16x1:
Gabiuas 1:0ada46075897 998 case LCD24x1:
Gabiuas 1:0ada46075897 999 _writeCommand(0x20); // Function set 001 DL N F FT1 FT0
Gabiuas 1:0ada46075897 1000 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 1001 // N=0 (1 line)
Gabiuas 1:0ada46075897 1002 // F=0 (5x7 dots font)
Gabiuas 1:0ada46075897 1003 // FT=00 (00 = Engl/Jap, 01 = WestEur1, 10 = Engl/Russian, 11 = WestEur2
Gabiuas 1:0ada46075897 1004 break;
Gabiuas 1:0ada46075897 1005
Gabiuas 1:0ada46075897 1006 case LCD12x3D: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 1007 case LCD12x3D1: // Special mode for PCF21XX
Gabiuas 1:0ada46075897 1008 case LCD12x4D: // Special mode for PCF21XX:
Gabiuas 1:0ada46075897 1009 case LCD16x3G: // Special mode for ST7036
Gabiuas 1:0ada46075897 1010 case LCD24x4D: // Special mode for KS0078
Gabiuas 1:0ada46075897 1011 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 1012 break;
Gabiuas 1:0ada46075897 1013
Gabiuas 1:0ada46075897 1014 default:
Gabiuas 1:0ada46075897 1015 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
Gabiuas 1:0ada46075897 1016 _writeCommand(0x28); // Function set 001 DL N F FT1 FT0
Gabiuas 1:0ada46075897 1017 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 1018 // N=1 (2 lines)
Gabiuas 1:0ada46075897 1019 // F=0 (5x7 dots font)
Gabiuas 1:0ada46075897 1020 // FT=00 (00 = Engl/Jap, 01 = WestEur1, 10 = Engl/Russian, 11 = WestEur2
Gabiuas 1:0ada46075897 1021
Gabiuas 1:0ada46075897 1022 break;
Gabiuas 1:0ada46075897 1023 } // switch type
Gabiuas 1:0ada46075897 1024
Gabiuas 1:0ada46075897 1025 break; // case WS0010 Controller
Gabiuas 1:0ada46075897 1026
Gabiuas 1:0ada46075897 1027
Gabiuas 1:0ada46075897 1028 case US2066_3V3:
Gabiuas 1:0ada46075897 1029 // US2066/SSD1311 OLED controller, Initialise for VDD=3V3
Gabiuas 1:0ada46075897 1030 // Note: supports 1,2, 3 or 4 lines
Gabiuas 1:0ada46075897 1031 // case USS2066_5V:
Gabiuas 1:0ada46075897 1032 // US2066 controller, VDD=5V
Gabiuas 1:0ada46075897 1033
Gabiuas 1:0ada46075897 1034 // Initialise Display configuration
Gabiuas 1:0ada46075897 1035 switch (_type) {
Gabiuas 1:0ada46075897 1036 case LCD8x1: //8x1 is a regular 1 line display
Gabiuas 1:0ada46075897 1037 case LCD8x2B: //8x2D is a special case of 16x1
Gabiuas 1:0ada46075897 1038 // case LCD12x1:
Gabiuas 1:0ada46075897 1039 case LCD16x1:
Gabiuas 1:0ada46075897 1040 // case LCD20x1:
Gabiuas 1:0ada46075897 1041 _function = 0x00; // Set function 0 0 1 X N DH RE(0) IS
Gabiuas 1:0ada46075897 1042 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 1043 // DL=X bit is ignored for US2066. Uses hardwired pins instead
Gabiuas 1:0ada46075897 1044 // N=0 1 Line / 3 Line
Gabiuas 1:0ada46075897 1045 // DH=0 Double Height disable
Gabiuas 1:0ada46075897 1046 // IS=0
Gabiuas 1:0ada46075897 1047
Gabiuas 1:0ada46075897 1048 _function_1 = 0x02; // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 1049 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 1050 // DL=X bit is ignored for US2066. Uses hardwired pins instead
Gabiuas 1:0ada46075897 1051 // N=0 1 Line / 3 Line
Gabiuas 1:0ada46075897 1052 // BE=0 Blink Enable off, special feature of SSD1803, US2066
Gabiuas 1:0ada46075897 1053 // REV=0 Reverse off, special feature of SSD1803, US2066
Gabiuas 1:0ada46075897 1054
Gabiuas 1:0ada46075897 1055 _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW
Gabiuas 1:0ada46075897 1056 // NW=0 1-Line LCD (N=0)
Gabiuas 1:0ada46075897 1057 break;
Gabiuas 1:0ada46075897 1058
Gabiuas 1:0ada46075897 1059 case LCD16x1C:
Gabiuas 1:0ada46075897 1060 case LCD8x2:
Gabiuas 1:0ada46075897 1061 case LCD16x2:
Gabiuas 1:0ada46075897 1062 case LCD20x2:
Gabiuas 1:0ada46075897 1063 _function = 0x08; // Set function 0 0 1 X N DH RE(0) IS
Gabiuas 1:0ada46075897 1064 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 1065 // DL=X bit is ignored for US2066. Uses hardwired pins instead
Gabiuas 1:0ada46075897 1066 // N=1 2 line / 4 Line
Gabiuas 1:0ada46075897 1067 // DH=0 Double Height disable
Gabiuas 1:0ada46075897 1068 // IS=0
Gabiuas 1:0ada46075897 1069
Gabiuas 1:0ada46075897 1070 _function_1 = 0x0A; // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 1071 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 1072 // DL=X bit is ignored for US2066. Uses hardwired pins instead
Gabiuas 1:0ada46075897 1073 // N=1 2 line / 4 Line
Gabiuas 1:0ada46075897 1074 // BE=0 Blink Enable off, special feature of SSD1803, US2066
Gabiuas 1:0ada46075897 1075 // REV=0 Reverse off, special feature of SSD1803, US2066
Gabiuas 1:0ada46075897 1076
Gabiuas 1:0ada46075897 1077 _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW
Gabiuas 1:0ada46075897 1078 // NW=0 2-Line LCD (N=1)
Gabiuas 1:0ada46075897 1079 break;
Gabiuas 1:0ada46075897 1080
Gabiuas 1:0ada46075897 1081 case LCD12x3D: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 1082 // case LCD12x3D1: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 1083 case LCD16x3D: // Special mode for KS0078, SSD1803 and US2066
Gabiuas 1:0ada46075897 1084 // case LCD16x3D1: // Special mode for SSD1803, US2066
Gabiuas 1:0ada46075897 1085 // case LCD20x3D: // Special mode for SSD1803, US2066
Gabiuas 1:0ada46075897 1086 _function = 0x00; // Set function 0 0 1 X N DH RE(0) IS
Gabiuas 1:0ada46075897 1087 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 1088 // DL=X bit is ignored for US2066. Uses hardwired pins instead
Gabiuas 1:0ada46075897 1089 // N=0 1 Line / 3 Line
Gabiuas 1:0ada46075897 1090 // DH=0 Double Height disable
Gabiuas 1:0ada46075897 1091 // IS=0
Gabiuas 1:0ada46075897 1092
Gabiuas 1:0ada46075897 1093 _function_1 = 0x02; // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 1094 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 1095 // DL=X bit is ignored for US2066. Uses hardwired pins instead
Gabiuas 1:0ada46075897 1096 // N=0 1 Line / 3 Line
Gabiuas 1:0ada46075897 1097 // BE=0 Blink Enable off, special feature of SSD1803, US2066
Gabiuas 1:0ada46075897 1098 // REV=0 Reverse off, special feature of SSD1803, US2066
Gabiuas 1:0ada46075897 1099
Gabiuas 1:0ada46075897 1100 _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW
Gabiuas 1:0ada46075897 1101 // NW=1 3-Line LCD (N=0)
Gabiuas 1:0ada46075897 1102 break;
Gabiuas 1:0ada46075897 1103
Gabiuas 1:0ada46075897 1104 case LCD20x4D: // Special mode for SSD1803, US2066
Gabiuas 1:0ada46075897 1105 _function = 0x08; // Set function 0 0 1 X N DH RE(0) IS
Gabiuas 1:0ada46075897 1106 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 1107 // DL=X bit is ignored for US2066. Uses hardwired pins instead
Gabiuas 1:0ada46075897 1108 // N=1 2 line / 4 Line
Gabiuas 1:0ada46075897 1109 // DH=0 Double Height disable
Gabiuas 1:0ada46075897 1110 // IS=0
Gabiuas 1:0ada46075897 1111
Gabiuas 1:0ada46075897 1112 _function_1 = 0x0A; // Set function, 0 0 1 DL N BE RE(1) REV
Gabiuas 1:0ada46075897 1113 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 1114 // DL=0 bit is ignored for US2066. Uses hardwired pins instead
Gabiuas 1:0ada46075897 1115 // N=1 2 line / 4 Line
Gabiuas 1:0ada46075897 1116 // BE=0 Blink Enable off, special feature of SSD1803, US2066
Gabiuas 1:0ada46075897 1117 // REV=0 Reverse off, special feature of SSD1803, US2066
Gabiuas 1:0ada46075897 1118
Gabiuas 1:0ada46075897 1119 _lines = 0x01; // Ext function set 0 0 0 0 1 FW BW NW
Gabiuas 1:0ada46075897 1120 // NW=1 4-Line LCD (N=1)
Gabiuas 1:0ada46075897 1121 break;
Gabiuas 1:0ada46075897 1122
Gabiuas 1:0ada46075897 1123 // case LCD24x1:
Gabiuas 1:0ada46075897 1124 // case LCD16x3G: // Special mode for ST7036
Gabiuas 1:0ada46075897 1125 // case LCD24x4D: // Special mode for KS0078
Gabiuas 1:0ada46075897 1126 default:
Gabiuas 1:0ada46075897 1127 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 1128 break;
Gabiuas 1:0ada46075897 1129
Gabiuas 1:0ada46075897 1130 } // switch type
Gabiuas 1:0ada46075897 1131
Gabiuas 1:0ada46075897 1132 _writeCommand(0x00); // NOP, make sure to sync SPI
Gabiuas 1:0ada46075897 1133
Gabiuas 1:0ada46075897 1134 // init special features
Gabiuas 1:0ada46075897 1135 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 1136 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 1137
Gabiuas 1:0ada46075897 1138 _writeCommand(0x71); // Function Select A: 0 1 1 1 0 0 0 1 (Ext Instr Set)
Gabiuas 1:0ada46075897 1139 _writeData(0x00); // Disable Internal VDD
Gabiuas 1:0ada46075897 1140
Gabiuas 1:0ada46075897 1141 _writeCommand(0x79); // Function Select OLED: 0 1 1 1 1 0 0 1 (Ext Instr Set)
Gabiuas 1:0ada46075897 1142
Gabiuas 1:0ada46075897 1143 _writeCommand(0xD5); // Display Clock Divide Ratio: 1 1 0 1 0 1 0 1 (Ext Instr Set, OLED Instr Set)
Gabiuas 1:0ada46075897 1144 _writeCommand(0x70); // Display Clock Divide Ratio value: 0 1 1 1 0 0 0 0 (Ext Instr Set, OLED Instr Set)
Gabiuas 1:0ada46075897 1145
Gabiuas 1:0ada46075897 1146 _writeCommand(0x78); // Function Disable OLED: 0 1 1 1 1 0 0 0 (Ext Instr Set)
Gabiuas 1:0ada46075897 1147
Gabiuas 1:0ada46075897 1148 // _writeCommand(0x06); // Set ext entry mode, 0 0 0 0 0 1 BDC=1 COM1-32, BDS=0 SEG100-1 "Bottom View" (Ext Instr Set)
Gabiuas 1:0ada46075897 1149 _writeCommand(0x05); // Set ext entry mode, 0 0 0 0 0 1 BDC=0 COM32-1, BDS=1 SEG1-100 "Top View" (Ext Instr Set)
Gabiuas 1:0ada46075897 1150
Gabiuas 1:0ada46075897 1151 _writeCommand(0x08 | _lines); // Set ext function 0 0 0 0 1 FW BW NW 1,2,3 or 4 lines (Ext Instr Set)
Gabiuas 1:0ada46075897 1152
Gabiuas 1:0ada46075897 1153 // _writeCommand(0x1C); // Double Height, 0 0 0 1 UD2=1, UD1=1, X, DH'=0 (Ext Instr Set)
Gabiuas 1:0ada46075897 1154 // // Default
Gabiuas 1:0ada46075897 1155
Gabiuas 1:0ada46075897 1156 _writeCommand(0x72); // Function Select B: 0 1 1 1 0 0 1 0 (Ext Instr Set)
Gabiuas 1:0ada46075897 1157 _writeData(0x01); // Select ROM A (CGRAM 8, CGROM 248)
Gabiuas 1:0ada46075897 1158
Gabiuas 1:0ada46075897 1159 _writeCommand(0x79); // Function Select OLED: 0 1 1 1 1 0 0 1 (Ext Instr Set)
Gabiuas 1:0ada46075897 1160
Gabiuas 1:0ada46075897 1161 _writeCommand(0xDA); // Set Segm Pins Config: 1 1 0 1 1 0 1 0 (Ext Instr Set, OLED)
Gabiuas 1:0ada46075897 1162 _writeCommand(0x10); // Set Segm Pins Config value: Altern Odd/Even, Disable Remap (Ext Instr Set, OLED)
Gabiuas 1:0ada46075897 1163
Gabiuas 1:0ada46075897 1164 _writeCommand(0xDC); // Function Select C: 1 1 0 1 1 1 0 0 (Ext Instr Set, OLED)
Gabiuas 1:0ada46075897 1165 // _writeCommand(0x00); // Set internal VSL, GPIO pin HiZ (always read low)
Gabiuas 1:0ada46075897 1166 _writeCommand(0x80); // Set external VSL, GPIO pin HiZ (always read low)
Gabiuas 1:0ada46075897 1167
Gabiuas 1:0ada46075897 1168 _contrast = LCD_US20_CONTRAST;
Gabiuas 1:0ada46075897 1169 _writeCommand(0x81); // Set Contrast Control: 1 0 0 0 0 0 0 1 (Ext Instr Set, OLED)
Gabiuas 1:0ada46075897 1170 _writeCommand((_contrast << 2) | 0x03); // Set Contrast Value: 8 bits, use 6 bits for compatibility
Gabiuas 1:0ada46075897 1171
Gabiuas 1:0ada46075897 1172 _writeCommand(0xD9); // Set Phase Length: 1 1 0 1 1 0 0 1 (Ext Instr Set, OLED)
Gabiuas 1:0ada46075897 1173 _writeCommand(0xF1); // Set Phase Length Value:
Gabiuas 1:0ada46075897 1174
Gabiuas 1:0ada46075897 1175 _writeCommand(0xDB); // Set VCOMH Deselect Lvl: 1 1 0 1 1 0 1 1 (Ext Instr Set, OLED)
Gabiuas 1:0ada46075897 1176 _writeCommand(0x30); // Set VCOMH Deselect Value: 0.83 x VCC
Gabiuas 1:0ada46075897 1177
Gabiuas 1:0ada46075897 1178 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 1179
Gabiuas 1:0ada46075897 1180 //Test Fade/Blinking. Hard Blink on/off, No fade in/out ??
Gabiuas 1:0ada46075897 1181 // _writeCommand(0x23); // Set (Ext Instr Set, OLED)
Gabiuas 1:0ada46075897 1182 // _writeCommand(0x3F); // Set interval 128 frames
Gabiuas 1:0ada46075897 1183 //End Test Blinking
Gabiuas 1:0ada46075897 1184
Gabiuas 1:0ada46075897 1185 _writeCommand(0x78); // Function Disable OLED: 0 1 1 1 1 0 0 0 (Ext Instr Set)
Gabiuas 1:0ada46075897 1186
Gabiuas 1:0ada46075897 1187 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 X N DH RE(0) IS=1 Select Instruction Set 1
Gabiuas 1:0ada46075897 1188 // Select Std Instr set, Select IS=1
Gabiuas 1:0ada46075897 1189
Gabiuas 1:0ada46075897 1190 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 1191 // Select Ext Instr Set, IS=1
Gabiuas 1:0ada46075897 1192 _writeCommand(0x10); // Shift/Scroll enable, 0 0 0 1 DS4/HS4 DS3/HS3 DS2/HS2 DS1/HS1 (Ext Instr Set, IS=1)
Gabiuas 1:0ada46075897 1193
Gabiuas 1:0ada46075897 1194 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 1195 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 1196 break; // case US2066/SSD1311 Controller
Gabiuas 1:0ada46075897 1197
Gabiuas 1:0ada46075897 1198 //not yet tested on hardware
Gabiuas 1:0ada46075897 1199 case PT6314 :
Gabiuas 1:0ada46075897 1200 // Initialise Display configuration
Gabiuas 1:0ada46075897 1201 switch (_type) {
Gabiuas 1:0ada46075897 1202 case LCD8x1: //8x1 is a regular 1 line display
Gabiuas 1:0ada46075897 1203 case LCD8x2B: //8x2B is a special case of 16x1
Gabiuas 1:0ada46075897 1204 // case LCD12x1:
Gabiuas 1:0ada46075897 1205 case LCD16x1:
Gabiuas 1:0ada46075897 1206 case LCD20x1:
Gabiuas 1:0ada46075897 1207 case LCD24x1:
Gabiuas 1:0ada46075897 1208 _function = 0x00; // Function set 001 DL N X BR1 BR0
Gabiuas 1:0ada46075897 1209 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 1210 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 1211 // N=0 (1 line)
Gabiuas 1:0ada46075897 1212 // X
Gabiuas 1:0ada46075897 1213 // BR1=0 (2 significant bits for brightness
Gabiuas 1:0ada46075897 1214 // BR0=0
Gabiuas 1:0ada46075897 1215 // 0x0 = 100%
Gabiuas 1:0ada46075897 1216 // 0x1 = 75%
Gabiuas 1:0ada46075897 1217 // 0x2 = 50%
Gabiuas 1:0ada46075897 1218 // 0x3 = 25%
Gabiuas 1:0ada46075897 1219
Gabiuas 1:0ada46075897 1220 break;
Gabiuas 1:0ada46075897 1221
Gabiuas 1:0ada46075897 1222 // All other valid LCD types are initialised as 2 Line displays
Gabiuas 1:0ada46075897 1223 case LCD8x2:
Gabiuas 1:0ada46075897 1224 case LCD16x2:
Gabiuas 1:0ada46075897 1225 case LCD20x2:
Gabiuas 1:0ada46075897 1226 case LCD24x2:
Gabiuas 1:0ada46075897 1227 _function = 0x08; // Function set 001 DL N X BR1 BR2
Gabiuas 1:0ada46075897 1228 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 1229 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 1230 // N=1 (2 lines)
Gabiuas 1:0ada46075897 1231 // X
Gabiuas 1:0ada46075897 1232 // BR1=0 (2 significant bits for brightness
Gabiuas 1:0ada46075897 1233 // BR0=0
Gabiuas 1:0ada46075897 1234 break;
Gabiuas 1:0ada46075897 1235
Gabiuas 1:0ada46075897 1236 default:
Gabiuas 1:0ada46075897 1237 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 1238 break;
Gabiuas 1:0ada46075897 1239 } // switch type
Gabiuas 1:0ada46075897 1240
Gabiuas 1:0ada46075897 1241 _contrast = LCD_PT63_CONTRAST;
Gabiuas 1:0ada46075897 1242 _writeCommand(0x20 | _function | ((~_contrast) >> 4)); // Invert and shift to use 2 MSBs
Gabiuas 1:0ada46075897 1243 break; // case PT6314 Controller (VFD)
Gabiuas 1:0ada46075897 1244
Gabiuas 1:0ada46075897 1245
Gabiuas 1:0ada46075897 1246 case HD66712:
Gabiuas 1:0ada46075897 1247 // Initialise Display configuration
Gabiuas 1:0ada46075897 1248 switch (_type) {
Gabiuas 1:0ada46075897 1249 case LCD8x1: //8x1 is a regular 1 line display
Gabiuas 1:0ada46075897 1250 case LCD12x1:
Gabiuas 1:0ada46075897 1251 case LCD16x1:
Gabiuas 1:0ada46075897 1252 case LCD20x1:
Gabiuas 1:0ada46075897 1253 case LCD24x1:
Gabiuas 1:0ada46075897 1254 // case LCD32x1: // EXT pin is High, extension driver needed
Gabiuas 1:0ada46075897 1255 _function = 0x02; // Function set 001 DL N RE(0) - - (Std Regs)
Gabiuas 1:0ada46075897 1256 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 1257 // N=0 (1-line mode, N=1 2-line mode)
Gabiuas 1:0ada46075897 1258 // RE=0 (Dis. Extended Regs, special mode for HD66712)
Gabiuas 1:0ada46075897 1259 //
Gabiuas 1:0ada46075897 1260
Gabiuas 1:0ada46075897 1261 _function_1 = 0x04; // Function set 001 DL N RE(1) BE LP (Ext Regs)
Gabiuas 1:0ada46075897 1262 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 1263 // N=0 (1-line mode, N=1 2-line mode)
Gabiuas 1:0ada46075897 1264 // RE=1 (Ena Extended Regs; special mode for HD66712)
Gabiuas 1:0ada46075897 1265 // BE=0 (Blink Enable, CG/SEG RAM; special mode for HD66712)
Gabiuas 1:0ada46075897 1266 // LP=0 (LP=1 Low power mode, LP=0 Normal; special mode for HD66712)
Gabiuas 1:0ada46075897 1267
Gabiuas 1:0ada46075897 1268 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
Gabiuas 1:0ada46075897 1269 // NW=0 (1,2 line), NW=1 (4 Line, special mode for HD66712)
Gabiuas 1:0ada46075897 1270 break;
Gabiuas 1:0ada46075897 1271
Gabiuas 1:0ada46075897 1272 // case LCD12x3D: // Special mode for KS0073, KS0078, PCF21XX and HD66712
Gabiuas 1:0ada46075897 1273 // case LCD12x3D1: // Special mode for KS0073, KS0078, PCF21XX and HD66712
Gabiuas 1:0ada46075897 1274 case LCD12x4D: // Special mode for KS0073, KS0078, PCF21XX and HD66712
Gabiuas 1:0ada46075897 1275 // case LCD16x3D: // Special mode for KS0073, KS0078 and HD66712
Gabiuas 1:0ada46075897 1276 // case LCD16x4D: // Special mode for KS0073, KS0078 and HD66712
Gabiuas 1:0ada46075897 1277 case LCD20x4D: // Special mode for KS0073, KS0078 and HD66712
Gabiuas 1:0ada46075897 1278 _function = 0x02; // Function set 001 DL N RE(0) - - (Std Regs)
Gabiuas 1:0ada46075897 1279 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 1280 // N=0 (1-line mode, N=1 2-line mode)
Gabiuas 1:0ada46075897 1281 // RE=0 (Dis. Extended Regs, special mode for HD66712)
Gabiuas 1:0ada46075897 1282 //
Gabiuas 1:0ada46075897 1283
Gabiuas 1:0ada46075897 1284 _function_1 = 0x04; // Function set 001 DL N RE(1) BE LP (Ext Regs)
Gabiuas 1:0ada46075897 1285 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 1286 // N=0 (1-line mode, N=1 2-line mode)
Gabiuas 1:0ada46075897 1287 // RE=1 (Ena Extended Regs; special mode for HD66712)
Gabiuas 1:0ada46075897 1288 // BE=0 (Blink Enable, CG/SEG RAM; special mode for HD66712)
Gabiuas 1:0ada46075897 1289 // LP=0 (LP=1 Low power mode, LP=0 Normal; special mode for HD66712)
Gabiuas 1:0ada46075897 1290
Gabiuas 1:0ada46075897 1291 _function_x = 0x01; // Ext Function set 0000 1 FW BW NW (Ext Regs)
Gabiuas 1:0ada46075897 1292 // NW=0 (1,2 line), NW=1 (4 Line, special mode for HD66712)
Gabiuas 1:0ada46075897 1293 break;
Gabiuas 1:0ada46075897 1294
Gabiuas 1:0ada46075897 1295 case LCD16x3G: // Special mode for ST7036
Gabiuas 1:0ada46075897 1296 // case LCD24x3D: // Special mode for KS0078
Gabiuas 1:0ada46075897 1297 // case LCD24x3D1: // Special mode for KS0078
Gabiuas 1:0ada46075897 1298 case LCD24x4D: // Special mode for KS0078
Gabiuas 1:0ada46075897 1299 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 1300 break;
Gabiuas 1:0ada46075897 1301
Gabiuas 1:0ada46075897 1302 default:
Gabiuas 1:0ada46075897 1303 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
Gabiuas 1:0ada46075897 1304 _function = 0x0A; // Function set 001 DL N RE(0) - - (Std Regs)
Gabiuas 1:0ada46075897 1305 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 1306 // N=1 (2-line mode), N=0 (1-line mode)
Gabiuas 1:0ada46075897 1307 // RE=0 (Dis. Extended Regs, special mode for HD66712)
Gabiuas 1:0ada46075897 1308
Gabiuas 1:0ada46075897 1309 _function_1 = 0x0C; // Function set 001 DL N RE(1) BE LP (Ext Regs)
Gabiuas 1:0ada46075897 1310 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 1311 // N=1 (2 line mode), N=0 (1-line mode)
Gabiuas 1:0ada46075897 1312 // RE=1 (Ena Extended Regs, special mode for HD66712)
Gabiuas 1:0ada46075897 1313 // BE=0 (Blink Enable, CG/SEG RAM, special mode for HD66712)
Gabiuas 1:0ada46075897 1314 // LP=0 (LP=1 Low power mode, LP=0 Normal)
Gabiuas 1:0ada46075897 1315
Gabiuas 1:0ada46075897 1316 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
Gabiuas 1:0ada46075897 1317 // NW=0 (1,2 line), NW=1 (4 Line, special mode for HD66712)
Gabiuas 1:0ada46075897 1318 break;
Gabiuas 1:0ada46075897 1319 } // switch type
Gabiuas 1:0ada46075897 1320
Gabiuas 1:0ada46075897 1321 // init special features
Gabiuas 1:0ada46075897 1322 _writeCommand(0x20 | _function_1);// Function set 001 DL N RE(1) BE LP (Ext Regs)
Gabiuas 1:0ada46075897 1323 // DL=0 (4 bits bus), DL=1 (8 bits mode)
Gabiuas 1:0ada46075897 1324 // N=0 (1 line mode), N=1 (2 line mode)
Gabiuas 1:0ada46075897 1325 // RE=1 (Ena Extended Regs, special mode for HD66712)
Gabiuas 1:0ada46075897 1326 // BE=0 (Blink Enable/Disable, CG/SEG RAM, special mode for HD66712)
Gabiuas 1:0ada46075897 1327 // LP=0 (LP=1 Low power mode, LP=0 Normal)
Gabiuas 1:0ada46075897 1328
Gabiuas 1:0ada46075897 1329 _writeCommand(0x08 | _function_x); // Ext Function set 0000 1 FW BW NW (Ext Regs)
Gabiuas 1:0ada46075897 1330 // FW=0 (5-dot font, special mode for HD66712)
Gabiuas 1:0ada46075897 1331 // BW=0 (Cur BW invert disable, special mode for HD66712)
Gabiuas 1:0ada46075897 1332 // NW=0 (1,2 Line), NW=1 (4 line, special mode for HD66712)
Gabiuas 1:0ada46075897 1333
Gabiuas 1:0ada46075897 1334 _writeCommand(0x10); // Scroll/Shift set 0001 HS4 HS3 HS2 HS1 (Ext Regs)
Gabiuas 1:0ada46075897 1335 // Dotscroll/Display shift enable (Special mode for HD66712)
Gabiuas 1:0ada46075897 1336
Gabiuas 1:0ada46075897 1337 _writeCommand(0x80); // Scroll Quantity set 1 0 HDS5 HDS4 HDS3 HDS2 HDS1 HDS0 (Ext Regs)
Gabiuas 1:0ada46075897 1338 // Scroll quantity (Special mode for HD66712)
Gabiuas 1:0ada46075897 1339
Gabiuas 1:0ada46075897 1340 _writeCommand(0x20 | _function); // Function set 001 DL N RE(0) DH REV (Std Regs)
Gabiuas 1:0ada46075897 1341 // DL=0 (4 bits bus), DL=1 (8 bits mode)
Gabiuas 1:0ada46075897 1342 // N=0 (1 line mode), N=1 (2 line mode)
Gabiuas 1:0ada46075897 1343 // RE=0 (Dis. Extended Regs, special mode for HD66712)
Gabiuas 1:0ada46075897 1344 // DH=1 (Disp shift enable/disable, special mode for HD66712)
Gabiuas 1:0ada46075897 1345 // REV=0 (Reverse/Normal, special mode for HD66712)
Gabiuas 1:0ada46075897 1346 break; // case HD66712 Controller
Gabiuas 1:0ada46075897 1347
Gabiuas 1:0ada46075897 1348 case SPLC792A_3V3:
Gabiuas 1:0ada46075897 1349 // SPLC792A controller: Initialise Voltage booster for VLCD. VDD=3V3
Gabiuas 1:0ada46075897 1350 // Note very similar to ST7032
Gabiuas 1:0ada46075897 1351
Gabiuas 1:0ada46075897 1352 // Initialise Display configuration
Gabiuas 1:0ada46075897 1353 switch (_type) {
Gabiuas 1:0ada46075897 1354 case LCD8x1: //8x1 is a regular 1 line display
Gabiuas 1:0ada46075897 1355 case LCD8x2B: //8x2B is a special case of 16x1
Gabiuas 1:0ada46075897 1356 // case LCD12x1:
Gabiuas 1:0ada46075897 1357 case LCD16x1:
Gabiuas 1:0ada46075897 1358 // case LCD20x1:
Gabiuas 1:0ada46075897 1359 case LCD24x1:
Gabiuas 1:0ada46075897 1360 _function = 0x00; // FUNCTION SET 0 0 1 DL=0 (4 bit), N=0 (1-line display mode), F=0 (5*7dot), 0, IS
Gabiuas 1:0ada46075897 1361 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 1362 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 1363 break;
Gabiuas 1:0ada46075897 1364
Gabiuas 1:0ada46075897 1365 case LCD12x3D: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 1366 case LCD12x3D1: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 1367 case LCD12x4D: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 1368 case LCD16x3G: // Special mode for ST7036
Gabiuas 1:0ada46075897 1369 case LCD24x4D: // Special mode for KS0078
Gabiuas 1:0ada46075897 1370 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 1371 break;
Gabiuas 1:0ada46075897 1372
Gabiuas 1:0ada46075897 1373 default:
Gabiuas 1:0ada46075897 1374 // All other LCD types are initialised as 2 Line displays
Gabiuas 1:0ada46075897 1375 _function = 0x08; // FUNCTION SET 0 0 1 DL=0 (4 bit), N=1 (2-line display mode), F=0 (5*7dot), 0, IS
Gabiuas 1:0ada46075897 1376 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 1377 // Saved to allow switch between Instruction sets at later time
Gabiuas 1:0ada46075897 1378 break;
Gabiuas 1:0ada46075897 1379 } // switch type
Gabiuas 1:0ada46075897 1380
Gabiuas 1:0ada46075897 1381 // init special features
Gabiuas 1:0ada46075897 1382 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N F 0 IS=1 Select Instr Set = 1
Gabiuas 1:0ada46075897 1383
Gabiuas 1:0ada46075897 1384 //SPLC792A Does not support Bias and Internal Osc register
Gabiuas 1:0ada46075897 1385 // _writeCommand(0x1C); // Internal OSC frequency adjustment Framefreq=183HZ, Bias will be 1/4 (Instr Set=1)
Gabiuas 1:0ada46075897 1386
Gabiuas 1:0ada46075897 1387 _contrast = LCD_SPLC792A_CONTRAST;
Gabiuas 1:0ada46075897 1388 _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast Low bits, 0 1 1 1 C3 C2 C1 C0 (IS=1)
Gabiuas 1:0ada46075897 1389
Gabiuas 1:0ada46075897 1390
Gabiuas 1:0ada46075897 1391 // _icon_power = 0x04; // Icon display off (Bit3=0), Booster circuit is turned on (Bit2=1) (IS=1)
Gabiuas 1:0ada46075897 1392 _icon_power = 0x0C; // Icon display on (Bit3=1), Booster circuit is turned on (Bit2=1) (IS=1)
Gabiuas 1:0ada46075897 1393 // Note: Booster circuit always on for SPLC792A, Bit2 is dont care
Gabiuas 1:0ada46075897 1394 // Saved to allow contrast change at later time
Gabiuas 1:0ada46075897 1395
Gabiuas 1:0ada46075897 1396 _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Set Icon, Booster and Contrast High bits, 0 1 0 1 Ion Bon C5 C4 (IS=1)
Gabiuas 1:0ada46075897 1397 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 1398
Gabiuas 1:0ada46075897 1399 _writeCommand(0x68 | (LCD_SPLC792A_RAB & 0x07)); // Voltage follower, 0 1 1 0 FOn=1, Ampl ratio Rab2=1, Rab1=0, Rab0=0 (IS=1)
Gabiuas 1:0ada46075897 1400 // Note: Follower circuit always on for SPLC792A, Bit3 is dont care
Gabiuas 1:0ada46075897 1401 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 1402
Gabiuas 1:0ada46075897 1403 _writeCommand(0x20 | _function); // Select Instruction Set = 0
Gabiuas 1:0ada46075897 1404
Gabiuas 1:0ada46075897 1405 break; // case SPLC792A_3V3 Controller
Gabiuas 1:0ada46075897 1406
Gabiuas 1:0ada46075897 1407 case ST7066_ACM: // ST7066 4/8 bit, I2C on ACM1602 using a PIC
Gabiuas 1:0ada46075897 1408 default:
Gabiuas 1:0ada46075897 1409 // Devices fully compatible to HD44780 that do not use any DC/DC Voltage converters but external VLCD, no icons etc
Gabiuas 1:0ada46075897 1410
Gabiuas 1:0ada46075897 1411 // Initialise Display configuration
Gabiuas 1:0ada46075897 1412 switch (_type) {
Gabiuas 1:0ada46075897 1413 case LCD8x1: //8x1 is a regular 1 line display
Gabiuas 1:0ada46075897 1414 case LCD8x2B: //8x2B is a special case of 16x1
Gabiuas 1:0ada46075897 1415 // case LCD12x1:
Gabiuas 1:0ada46075897 1416 case LCD16x1:
Gabiuas 1:0ada46075897 1417 // case LCD20x1:
Gabiuas 1:0ada46075897 1418 case LCD24x1:
Gabiuas 1:0ada46075897 1419 // case LCD40x1:
Gabiuas 1:0ada46075897 1420 _function = 0x00; // Function set 001 DL N F - -
Gabiuas 1:0ada46075897 1421 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 1422 // N=0 (1 line)
Gabiuas 1:0ada46075897 1423 // F=0 (5x7 dots font)
Gabiuas 1:0ada46075897 1424 break;
Gabiuas 1:0ada46075897 1425
Gabiuas 1:0ada46075897 1426 case LCD12x3D: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 1427 case LCD12x3D1: // Special mode for KS0078 and PCF21XX
Gabiuas 1:0ada46075897 1428 case LCD12x4D: // Special mode for KS0078 and PCF21XX:
Gabiuas 1:0ada46075897 1429 case LCD16x3D: // Special mode for KS0078
Gabiuas 1:0ada46075897 1430 // case LCD16x3D1: // Special mode for KS0078
Gabiuas 1:0ada46075897 1431 // case LCD24x3D: // Special mode for KS0078
Gabiuas 1:0ada46075897 1432 // case LCD24x3D1: // Special mode for KS0078
Gabiuas 1:0ada46075897 1433 case LCD24x4D: // Special mode for KS0078
Gabiuas 1:0ada46075897 1434 error("Error: LCD Controller type does not support this Display type\n\r");
Gabiuas 1:0ada46075897 1435 break;
Gabiuas 1:0ada46075897 1436
Gabiuas 1:0ada46075897 1437 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
Gabiuas 1:0ada46075897 1438 default:
Gabiuas 1:0ada46075897 1439 _function = 0x08; // Function set 001 DL N F - -
Gabiuas 1:0ada46075897 1440 // DL=0 (4 bits bus)
Gabiuas 1:0ada46075897 1441 // Note: 4 bit mode is ignored for native SPI and I2C devices
Gabiuas 1:0ada46075897 1442 // N=1 (2 lines)
Gabiuas 1:0ada46075897 1443 // F=0 (5x7 dots font, only option for 2 line display)
Gabiuas 1:0ada46075897 1444 // - (Don't care)
Gabiuas 1:0ada46075897 1445 break;
Gabiuas 1:0ada46075897 1446 } // switch type
Gabiuas 1:0ada46075897 1447
Gabiuas 1:0ada46075897 1448 _writeCommand(0x20 | _function);
Gabiuas 1:0ada46075897 1449 break; // case default Controller
Gabiuas 1:0ada46075897 1450
Gabiuas 1:0ada46075897 1451 } // switch Controller specific initialisations
Gabiuas 1:0ada46075897 1452
Gabiuas 1:0ada46075897 1453 // Controller general initialisations
Gabiuas 1:0ada46075897 1454 // _writeCommand(0x01); // Clear Display and set cursor to 0
Gabiuas 1:0ada46075897 1455 // wait_ms(10); // The CLS command takes 1.64 ms.
Gabiuas 1:0ada46075897 1456 // // Since we are not using the Busy flag, Lets be safe and take 10 ms
Gabiuas 1:0ada46075897 1457
Gabiuas 1:0ada46075897 1458 _writeCommand(0x02); // Cursor Home, DDRAM Address to Origin
Gabiuas 1:0ada46075897 1459 wait_ms(10); // The Return Home command takes 1.64 ms.
Gabiuas 1:0ada46075897 1460 // Since we are not using the Busy flag, Lets be safe and take 10 ms
Gabiuas 1:0ada46075897 1461
Gabiuas 1:0ada46075897 1462 _writeCommand(0x06); // Entry Mode 0000 0 1 I/D S
Gabiuas 1:0ada46075897 1463 // Cursor Direction and Display Shift
Gabiuas 1:0ada46075897 1464 // I/D=1 (Cur incr)
Gabiuas 1:0ada46075897 1465 // S=0 (No display shift)
Gabiuas 1:0ada46075897 1466
Gabiuas 1:0ada46075897 1467 _writeCommand(0x14); // Cursor or Display shift 0001 S/C R/L x x
Gabiuas 1:0ada46075897 1468 // S/C=0 Cursor moves
Gabiuas 1:0ada46075897 1469 // R/L=1 Right
Gabiuas 1:0ada46075897 1470 //
Gabiuas 1:0ada46075897 1471
Gabiuas 1:0ada46075897 1472 // _writeCommand(0x0C); // Display Ctrl 0000 1 D C B
Gabiuas 1:0ada46075897 1473 // // Display On, Cursor Off, Blink Off
Gabiuas 1:0ada46075897 1474
Gabiuas 1:0ada46075897 1475 // setCursor(CurOff_BlkOff);
Gabiuas 1:0ada46075897 1476 setCursor(CurOn_BlkOff);
Gabiuas 1:0ada46075897 1477 setMode(DispOn);
Gabiuas 1:0ada46075897 1478 }
Gabiuas 1:0ada46075897 1479
Gabiuas 1:0ada46075897 1480
Gabiuas 1:0ada46075897 1481 /** Clear the screen, Cursor home.
Gabiuas 1:0ada46075897 1482 * Note: The whole display is initialised to charcode 0x20, which may not be a 'space' on some controllers with a
Gabiuas 1:0ada46075897 1483 * different fontset such as the PCF2116C or PCF2119R. In this case you should fill the display with 'spaces'.
Gabiuas 1:0ada46075897 1484 */
Gabiuas 1:0ada46075897 1485 void TextLCD_Base::cls() {
Gabiuas 1:0ada46075897 1486
Gabiuas 1:0ada46075897 1487 #if (LCD_TWO_CTRL == 1)
Gabiuas 1:0ada46075897 1488 // Select and configure second LCD controller when needed
Gabiuas 1:0ada46075897 1489 if(_type==LCD40x4) {
Gabiuas 1:0ada46075897 1490 _ctrl_idx=_LCDCtrl_1; // Select 2nd controller
Gabiuas 1:0ada46075897 1491
Gabiuas 1:0ada46075897 1492 // Second LCD controller Cursor always Off
Gabiuas 1:0ada46075897 1493 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
Gabiuas 1:0ada46075897 1494
Gabiuas 1:0ada46075897 1495 // Second LCD controller Clearscreen
Gabiuas 1:0ada46075897 1496 _writeCommand(0x01); // cls, and set cursor to 0
Gabiuas 1:0ada46075897 1497 wait_ms(20); // The CLS command takes 1.64 ms.
Gabiuas 1:0ada46075897 1498 // Since we are not using the Busy flag, Lets be safe and take 10 ms
Gabiuas 1:0ada46075897 1499
Gabiuas 1:0ada46075897 1500 _ctrl_idx=_LCDCtrl_0; // Select primary controller
Gabiuas 1:0ada46075897 1501 }
Gabiuas 1:0ada46075897 1502
Gabiuas 1:0ada46075897 1503
Gabiuas 1:0ada46075897 1504 // Primary LCD controller Clearscreen
Gabiuas 1:0ada46075897 1505 _writeCommand(0x01); // cls, and set cursor to 0
Gabiuas 1:0ada46075897 1506 wait_ms(20); // The CLS command takes 1.64 ms.
Gabiuas 1:0ada46075897 1507 // Since we are not using the Busy flag, Lets be safe and take 10 ms
Gabiuas 1:0ada46075897 1508
Gabiuas 1:0ada46075897 1509 // Restore cursormode on primary LCD controller when needed
Gabiuas 1:0ada46075897 1510 if(_type==LCD40x4) {
Gabiuas 1:0ada46075897 1511 _setCursorAndDisplayMode(_currentMode,_currentCursor);
Gabiuas 1:0ada46075897 1512 }
Gabiuas 1:0ada46075897 1513
Gabiuas 1:0ada46075897 1514 #else
Gabiuas 1:0ada46075897 1515 // Support only one LCD controller
Gabiuas 1:0ada46075897 1516 _writeCommand(0x01); // cls, and set cursor to 0
Gabiuas 1:0ada46075897 1517 wait_ms(20); // The CLS command takes 1.64 ms.
Gabiuas 1:0ada46075897 1518 // Since we are not using the Busy flag, Lets be safe and take 10 ms
Gabiuas 1:0ada46075897 1519 #endif
Gabiuas 1:0ada46075897 1520
Gabiuas 1:0ada46075897 1521 setAddress(0, 0); // Reset Cursor location
Gabiuas 1:0ada46075897 1522 // Note: This is needed because some displays (eg PCF21XX) don't use line 0 in the '3 Line' mode.
Gabiuas 1:0ada46075897 1523 }
Gabiuas 1:0ada46075897 1524
Gabiuas 1:0ada46075897 1525 /** Locate cursor to a screen column and row
Gabiuas 1:0ada46075897 1526 *
Gabiuas 1:0ada46075897 1527 * @param column The horizontal position from the left, indexed from 0
Gabiuas 1:0ada46075897 1528 * @param row The vertical position from the top, indexed from 0
Gabiuas 1:0ada46075897 1529 */
Gabiuas 1:0ada46075897 1530 void TextLCD_Base::locate(int column, int row) {
Gabiuas 1:0ada46075897 1531
Gabiuas 1:0ada46075897 1532 // setAddress() does all the heavy lifting:
Gabiuas 1:0ada46075897 1533 // check column and row sanity,
Gabiuas 1:0ada46075897 1534 // switch controllers for LCD40x4 if needed
Gabiuas 1:0ada46075897 1535 // switch cursor for LCD40x4 if needed
Gabiuas 1:0ada46075897 1536 // set the new memory address to show cursor at correct location
Gabiuas 1:0ada46075897 1537 setAddress(column, row);
Gabiuas 1:0ada46075897 1538 }
Gabiuas 1:0ada46075897 1539
Gabiuas 1:0ada46075897 1540
Gabiuas 1:0ada46075897 1541 /** Write a single character (Stream implementation)
Gabiuas 1:0ada46075897 1542 */
Gabiuas 1:0ada46075897 1543 int TextLCD_Base::_putc(int value) {
Gabiuas 1:0ada46075897 1544 int addr;
Gabiuas 1:0ada46075897 1545
Gabiuas 1:0ada46075897 1546 if (value == '\n') {
Gabiuas 1:0ada46075897 1547 //No character to write
Gabiuas 1:0ada46075897 1548
Gabiuas 1:0ada46075897 1549 //Update Cursor
Gabiuas 1:0ada46075897 1550 _column = 0;
Gabiuas 1:0ada46075897 1551 _row++;
Gabiuas 1:0ada46075897 1552 if (_row >= rows()) {
Gabiuas 1:0ada46075897 1553 _row = 0;
Gabiuas 1:0ada46075897 1554 }
Gabiuas 1:0ada46075897 1555 }
Gabiuas 1:0ada46075897 1556 else {
Gabiuas 1:0ada46075897 1557 //Character to write
Gabiuas 1:0ada46075897 1558
Gabiuas 1:0ada46075897 1559 #if (LCD_DEF_FONT == 1) //Default HD44780 font
Gabiuas 1:0ada46075897 1560 _writeData(value);
Gabiuas 1:0ada46075897 1561 #elif (LCD_C_FONT == 1) || (LCD_R_FONT == 1) //PCF21xxC or PCF21xxR font
Gabiuas 1:0ada46075897 1562 _writeData(ASCII_2_LCD(value));
Gabiuas 1:0ada46075897 1563 #elif (LCD_UTF8_FONT == 1) // UTF8 2 byte font (eg Cyrillic)
Gabiuas 1:0ada46075897 1564 // value = UTF_2_LCD(value, utf_seq_rec_first_cyr, utf_seq_recode_cyr, &utf_rnd_recode_cyr[0][0]);
Gabiuas 1:0ada46075897 1565 value = UTF_2_LCD(value);
Gabiuas 1:0ada46075897 1566 if (value >= 0) {
Gabiuas 1:0ada46075897 1567 _writeData(value);
Gabiuas 1:0ada46075897 1568
Gabiuas 1:0ada46075897 1569 // Only increment cursor when there is something to write
Gabiuas 1:0ada46075897 1570 // Continue below to closing bracket...
Gabiuas 1:0ada46075897 1571 #else
Gabiuas 1:0ada46075897 1572 _writeData('?'); //Oops, no font defined
Gabiuas 1:0ada46075897 1573 #endif
Gabiuas 1:0ada46075897 1574
Gabiuas 1:0ada46075897 1575 //Update Cursor
Gabiuas 1:0ada46075897 1576 _column++;
Gabiuas 1:0ada46075897 1577 if (_column >= columns()) {
Gabiuas 1:0ada46075897 1578 _column = 0;
Gabiuas 1:0ada46075897 1579 _row++;
Gabiuas 1:0ada46075897 1580 if (_row >= rows()) {
Gabiuas 1:0ada46075897 1581 _row = 0;
Gabiuas 1:0ada46075897 1582 }
Gabiuas 1:0ada46075897 1583 }
Gabiuas 1:0ada46075897 1584
Gabiuas 1:0ada46075897 1585 #if (LCD_DEF_FONT == 1) //Default HD44780 font
Gabiuas 1:0ada46075897 1586
Gabiuas 1:0ada46075897 1587 #elif (LCD_C_FONT == 1) || (LCD_R_FONT == 1) //PCF21xxC or PCF21xxR font
Gabiuas 1:0ada46075897 1588
Gabiuas 1:0ada46075897 1589 #elif (LCD_UTF8_FONT == 1) //UTF8 2 byte font (eg Cyrillic)
Gabiuas 1:0ada46075897 1590 // Continue code above to close bracket...
Gabiuas 1:0ada46075897 1591 } // if (value >= 0) {..
Gabiuas 1:0ada46075897 1592 #else
Gabiuas 1:0ada46075897 1593
Gabiuas 1:0ada46075897 1594 #endif
Gabiuas 1:0ada46075897 1595
Gabiuas 1:0ada46075897 1596 } //else
Gabiuas 1:0ada46075897 1597
Gabiuas 1:0ada46075897 1598 //Set next memoryaddress, make sure cursor blinks at next location
Gabiuas 1:0ada46075897 1599 addr = getAddress(_column, _row);
Gabiuas 1:0ada46075897 1600 _writeCommand(0x80 | addr);
Gabiuas 1:0ada46075897 1601
Gabiuas 1:0ada46075897 1602 return value;
Gabiuas 1:0ada46075897 1603 }
Gabiuas 1:0ada46075897 1604
Gabiuas 1:0ada46075897 1605
Gabiuas 1:0ada46075897 1606 // get a single character (Stream implementation)
Gabiuas 1:0ada46075897 1607 int TextLCD_Base::_getc() {
Gabiuas 1:0ada46075897 1608 return -1;
Gabiuas 1:0ada46075897 1609 }
Gabiuas 1:0ada46075897 1610
Gabiuas 1:0ada46075897 1611
Gabiuas 1:0ada46075897 1612 #if ((LCD_C_FONT == 1) || (LCD_R_FONT == 1)) //PCF21xxC or PCF21xxR font
Gabiuas 1:0ada46075897 1613 /** Convert ASCII character code to the LCD fonttable code
Gabiuas 1:0ada46075897 1614 *
Gabiuas 1:0ada46075897 1615 * @param c The character to write to the display
Gabiuas 1:0ada46075897 1616 * @return The character code for the specific fonttable of the controller
Gabiuas 1:0ada46075897 1617 */
Gabiuas 1:0ada46075897 1618 int TextLCD_Base::ASCII_2_LCD (int c) {
Gabiuas 1:0ada46075897 1619
Gabiuas 1:0ada46075897 1620 //LCD_C_F0 is default for HD44780 and compatible series
Gabiuas 1:0ada46075897 1621 // if (_font == LCD_C_F0) return c;
Gabiuas 1:0ada46075897 1622
Gabiuas 1:0ada46075897 1623 //LCD_C_FC for PCF21XXC series
Gabiuas 1:0ada46075897 1624 //LCD_C_FR for PCF21XXR series
Gabiuas 1:0ada46075897 1625 //Used code from Suga koubou library for PCF2119K and PCF2119R
Gabiuas 1:0ada46075897 1626 if (((c >= ' ') && (c <= '?')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) {
Gabiuas 1:0ada46075897 1627 c |= 0x80;
Gabiuas 1:0ada46075897 1628 } else if (c >= 0xF0 && c <= 0xFF) {
Gabiuas 1:0ada46075897 1629 c &= 0x0F;
Gabiuas 1:0ada46075897 1630 }
Gabiuas 1:0ada46075897 1631 return c;
Gabiuas 1:0ada46075897 1632 }
Gabiuas 1:0ada46075897 1633 #endif
Gabiuas 1:0ada46075897 1634
Gabiuas 1:0ada46075897 1635 #if(LCD_UTF8_FONT == 1)
Gabiuas 1:0ada46075897 1636
Gabiuas 1:0ada46075897 1637 /** Convert UTF8 2-byte character code to the LCD fonttable code
Gabiuas 1:0ada46075897 1638 * @param c The character to write to the display
Gabiuas 1:0ada46075897 1639 * @return character code for the specific fonttable of the controller or -1 if UTF8 code is not yet complete or incorrect
Gabiuas 1:0ada46075897 1640 *
Gabiuas 1:0ada46075897 1641 * Orig by Andriy, Modified by WH
Gabiuas 1:0ada46075897 1642 *
Gabiuas 1:0ada46075897 1643 * Note: The UTF8 decoding table for a specific controller is defined and selected in file TextLCD_UTF8.inc
Gabiuas 1:0ada46075897 1644 * The table is accessed in this UTF_2_LCD() method through
Gabiuas 1:0ada46075897 1645 * #define UTF_FIRST, UTF_LAST, UTF_SEQ_REC_FIRST, UTF_SEQ_REC_LAST and
Gabiuas 1:0ada46075897 1646 * #define UTF_SEQ_RECODE and UTF_RND_RECODE
Gabiuas 1:0ada46075897 1647 */
Gabiuas 1:0ada46075897 1648 int TextLCD_Base::UTF_2_LCD (int c) {
Gabiuas 1:0ada46075897 1649 int utf_code;
Gabiuas 1:0ada46075897 1650 int utf_low_byte; // Low byte UTF8
Gabiuas 1:0ada46075897 1651 static int utf_hi_byte = 0; // High byte UTF8
Gabiuas 1:0ada46075897 1652
Gabiuas 1:0ada46075897 1653 if (c < 0x80) { // Regular ASCII code, no need to convert
Gabiuas 1:0ada46075897 1654 return c;
Gabiuas 1:0ada46075897 1655 }
Gabiuas 1:0ada46075897 1656 else { // UTF8 handling, See wikipedia.org/wiki/UTF-8 and www.utf8-chartable.de
Gabiuas 1:0ada46075897 1657 // printf("0x%X ", c);
Gabiuas 1:0ada46075897 1658
Gabiuas 1:0ada46075897 1659 if (c >= 0xC0) { // First UTF8 byte should be formatted as 110b bbaa, Do sanity check
Gabiuas 1:0ada46075897 1660 utf_hi_byte = c & 0x1F; // Mask out significant bits (0x1F) and save high byte
Gabiuas 1:0ada46075897 1661 return -1; // Nothing to display as yet, wait for second UTF8 byte
Gabiuas 1:0ada46075897 1662 }
Gabiuas 1:0ada46075897 1663
Gabiuas 1:0ada46075897 1664 if (c <= 0xBF) { // Second UTF8 byte should be formatted as 10aa aaaa, Do sanity check
Gabiuas 1:0ada46075897 1665 utf_low_byte = c & 0x3F; // Mask out significant bits (0x3F)
Gabiuas 1:0ada46075897 1666
Gabiuas 1:0ada46075897 1667 // Compose UTF character code from UTF8 bytes. The UTF codes will be between U+0080 and U+07FF
Gabiuas 1:0ada46075897 1668 utf_code = (utf_hi_byte << 6) | utf_low_byte; // 00000bbb aaaaaaaa
Gabiuas 1:0ada46075897 1669 // printf("0x%4X ", utf_code);
Gabiuas 1:0ada46075897 1670
Gabiuas 1:0ada46075897 1671 // Sanity check on UTF codes
Gabiuas 1:0ada46075897 1672 // For example Cyrillic characters are UTF encoded between 0x0400 and 0x04FF
Gabiuas 1:0ada46075897 1673 if ((utf_code < UTF_FIRST) || (utf_code > UTF_LAST)) {
Gabiuas 1:0ada46075897 1674 return -1; // Invalid UTF8 code
Gabiuas 1:0ada46075897 1675 };
Gabiuas 1:0ada46075897 1676
Gabiuas 1:0ada46075897 1677 //Map some specific UTF codes on a character in LCD fonttable using a special correcting lookup table
Gabiuas 1:0ada46075897 1678 for (char i=0; UTF_RND_RECODE[i][0]; i++) { // Step through table until endvalue 0 is found or until a match is found
Gabiuas 1:0ada46075897 1679 if (utf_code == UTF_RND_RECODE[i][0]) { // UTF8 code match is found
Gabiuas 1:0ada46075897 1680 c = UTF_RND_RECODE[1][1];
Gabiuas 1:0ada46075897 1681 return c; // found match in correcting random table
Gabiuas 1:0ada46075897 1682 }
Gabiuas 1:0ada46075897 1683 }
Gabiuas 1:0ada46075897 1684
Gabiuas 1:0ada46075897 1685 //Sanity check on table idx range
Gabiuas 1:0ada46075897 1686 if ((utf_code < UTF_SEQ_REC_FIRST) || (utf_code > UTF_SEQ_REC_LAST)) {
Gabiuas 1:0ada46075897 1687 return -1; // Invalid UTF8 code
Gabiuas 1:0ada46075897 1688 };
Gabiuas 1:0ada46075897 1689
Gabiuas 1:0ada46075897 1690 //Map all other UTF codes on a character in LCD fonttable using a sequential lookup table
Gabiuas 1:0ada46075897 1691 c = UTF_SEQ_RECODE[utf_code - UTF_SEQ_REC_FIRST];
Gabiuas 1:0ada46075897 1692 return c; // entry in sequential table
Gabiuas 1:0ada46075897 1693 }
Gabiuas 1:0ada46075897 1694 else {
Gabiuas 1:0ada46075897 1695 return -1; // Invalid UTF8 code for second byte
Gabiuas 1:0ada46075897 1696 }
Gabiuas 1:0ada46075897 1697 } // End UTF8 handling
Gabiuas 1:0ada46075897 1698 }
Gabiuas 1:0ada46075897 1699
Gabiuas 1:0ada46075897 1700 #endif
Gabiuas 1:0ada46075897 1701
Gabiuas 1:0ada46075897 1702
Gabiuas 1:0ada46075897 1703 #if(LCD_PRINTF != 1)
Gabiuas 1:0ada46075897 1704 /** Write a character to the LCD
Gabiuas 1:0ada46075897 1705 *
Gabiuas 1:0ada46075897 1706 * @param c The character to write to the display
Gabiuas 1:0ada46075897 1707 */
Gabiuas 1:0ada46075897 1708 int TextLCD_Base::putc(int c){
Gabiuas 1:0ada46075897 1709 return _putc(c);
Gabiuas 1:0ada46075897 1710 }
Gabiuas 1:0ada46075897 1711
Gabiuas 1:0ada46075897 1712
Gabiuas 1:0ada46075897 1713 /** Write a raw string to the LCD
Gabiuas 1:0ada46075897 1714 *
Gabiuas 1:0ada46075897 1715 * @param string text, may be followed by variables to emulate formatting the string.
Gabiuas 1:0ada46075897 1716 * However, printf formatting is NOT supported and variables will be ignored!
Gabiuas 1:0ada46075897 1717 */
Gabiuas 1:0ada46075897 1718 int TextLCD_Base::printf(const char* text, ...) {
Gabiuas 1:0ada46075897 1719
Gabiuas 1:0ada46075897 1720 while (*text !=0) {
Gabiuas 1:0ada46075897 1721 _putc(*text);
Gabiuas 1:0ada46075897 1722 text++;
Gabiuas 1:0ada46075897 1723 }
Gabiuas 1:0ada46075897 1724 return 0;
Gabiuas 1:0ada46075897 1725 }
Gabiuas 1:0ada46075897 1726 #endif
Gabiuas 1:0ada46075897 1727
Gabiuas 1:0ada46075897 1728
Gabiuas 1:0ada46075897 1729 // Write a nibble using the 4-bit interface
Gabiuas 1:0ada46075897 1730 void TextLCD_Base::_writeNibble(int value) {
Gabiuas 1:0ada46075897 1731
Gabiuas 1:0ada46075897 1732 // Enable is Low
Gabiuas 1:0ada46075897 1733 this->_setEnable(true);
Gabiuas 1:0ada46075897 1734 this->_setData(value); // Low nibble of value on D4..D7
Gabiuas 1:0ada46075897 1735 wait_us(1); // Data setup time
Gabiuas 1:0ada46075897 1736 this->_setEnable(false);
Gabiuas 1:0ada46075897 1737 wait_us(1); // Datahold time
Gabiuas 1:0ada46075897 1738 // Enable is Low
Gabiuas 1:0ada46075897 1739 }
Gabiuas 1:0ada46075897 1740
Gabiuas 1:0ada46075897 1741 // Write a byte using the 4-bit interface
Gabiuas 1:0ada46075897 1742 void TextLCD_Base::_writeByte(int value) {
Gabiuas 1:0ada46075897 1743
Gabiuas 1:0ada46075897 1744 // Enable is Low
Gabiuas 1:0ada46075897 1745 this->_setEnable(true);
Gabiuas 1:0ada46075897 1746 this->_setData(value >> 4); // High nibble
Gabiuas 1:0ada46075897 1747 wait_us(1); // Data setup time
Gabiuas 1:0ada46075897 1748 this->_setEnable(false);
Gabiuas 1:0ada46075897 1749 wait_us(1); // Data hold time
Gabiuas 1:0ada46075897 1750
Gabiuas 1:0ada46075897 1751 this->_setEnable(true);
Gabiuas 1:0ada46075897 1752 this->_setData(value); // Low nibble
Gabiuas 1:0ada46075897 1753 wait_us(1); // Data setup time
Gabiuas 1:0ada46075897 1754 this->_setEnable(false);
Gabiuas 1:0ada46075897 1755 wait_us(1); // Datahold time
Gabiuas 1:0ada46075897 1756
Gabiuas 1:0ada46075897 1757 // Enable is Low
Gabiuas 1:0ada46075897 1758 }
Gabiuas 1:0ada46075897 1759
Gabiuas 1:0ada46075897 1760 // Write a command byte to the LCD controller
Gabiuas 1:0ada46075897 1761 void TextLCD_Base::_writeCommand(int command) {
Gabiuas 1:0ada46075897 1762
Gabiuas 1:0ada46075897 1763 this->_setRS(false);
Gabiuas 1:0ada46075897 1764 wait_us(1); // Data setup time for RS
Gabiuas 1:0ada46075897 1765
Gabiuas 1:0ada46075897 1766 this->_writeByte(command);
Gabiuas 1:0ada46075897 1767 wait_us(40); // most instructions take 40us
Gabiuas 1:0ada46075897 1768 }
Gabiuas 1:0ada46075897 1769
Gabiuas 1:0ada46075897 1770 // Write a data byte to the LCD controller
Gabiuas 1:0ada46075897 1771 void TextLCD_Base::_writeData(int data) {
Gabiuas 1:0ada46075897 1772
Gabiuas 1:0ada46075897 1773 this->_setRS(true);
Gabiuas 1:0ada46075897 1774 wait_us(1); // Data setup time for RS
Gabiuas 1:0ada46075897 1775
Gabiuas 1:0ada46075897 1776 this->_writeByte(data);
Gabiuas 1:0ada46075897 1777 wait_us(40); // data writes take 40us
Gabiuas 1:0ada46075897 1778 }
Gabiuas 1:0ada46075897 1779
Gabiuas 1:0ada46075897 1780
Gabiuas 1:0ada46075897 1781 // This replaces the original _address() method.
Gabiuas 1:0ada46075897 1782 // It is confusing since it returns the memoryaddress or-ed with the set memorycommand 0x80.
Gabiuas 1:0ada46075897 1783 // Left it in here for compatibility with older code. New applications should use getAddress() instead.
Gabiuas 1:0ada46075897 1784 int TextLCD_Base::_address(int column, int row) {
Gabiuas 1:0ada46075897 1785 return 0x80 | getAddress(column, row);
Gabiuas 1:0ada46075897 1786 }
Gabiuas 1:0ada46075897 1787
Gabiuas 1:0ada46075897 1788
Gabiuas 1:0ada46075897 1789 // This is new method to return the memory address based on row, column and displaytype.
Gabiuas 1:0ada46075897 1790 //
Gabiuas 1:0ada46075897 1791 /** Return the memoryaddress of screen column and row location
Gabiuas 1:0ada46075897 1792 *
Gabiuas 1:0ada46075897 1793 * @param column The horizontal position from the left, indexed from 0
Gabiuas 1:0ada46075897 1794 * @param row The vertical position from the top, indexed from 0
Gabiuas 1:0ada46075897 1795 * @return The memoryaddress of screen column and row location
Gabiuas 1:0ada46075897 1796 *
Gabiuas 1:0ada46075897 1797 */
Gabiuas 1:0ada46075897 1798 int TextLCD_Base::getAddress(int column, int row) {
Gabiuas 1:0ada46075897 1799
Gabiuas 1:0ada46075897 1800 switch (_addr_mode) {
Gabiuas 1:0ada46075897 1801
Gabiuas 1:0ada46075897 1802 case LCD_T_A:
Gabiuas 1:0ada46075897 1803 //Default addressing mode for 1, 2 and 4 rows (except 40x4)
Gabiuas 1:0ada46075897 1804 //The two available rows are split and stacked on top of eachother. Addressing for 3rd and 4th line continues where lines 1 and 2 were split.
Gabiuas 1:0ada46075897 1805 //Displays top rows when less than four are used.
Gabiuas 1:0ada46075897 1806 switch (row) {
Gabiuas 1:0ada46075897 1807 case 0:
Gabiuas 1:0ada46075897 1808 return 0x00 + column;
Gabiuas 1:0ada46075897 1809 case 1:
Gabiuas 1:0ada46075897 1810 return 0x40 + column;
Gabiuas 1:0ada46075897 1811 case 2:
Gabiuas 1:0ada46075897 1812 return 0x00 + _nr_cols + column;
Gabiuas 1:0ada46075897 1813 case 3:
Gabiuas 1:0ada46075897 1814 return 0x40 + _nr_cols + column;
Gabiuas 1:0ada46075897 1815 // Should never get here.
Gabiuas 1:0ada46075897 1816 // default:
Gabiuas 1:0ada46075897 1817 // return 0x00;
Gabiuas 1:0ada46075897 1818 }
Gabiuas 1:0ada46075897 1819
Gabiuas 1:0ada46075897 1820 case LCD_T_B:
Gabiuas 1:0ada46075897 1821 // LCD8x2B is a special layout of LCD16x1
Gabiuas 1:0ada46075897 1822 if (row==0)
Gabiuas 1:0ada46075897 1823 return 0x00 + column;
Gabiuas 1:0ada46075897 1824 else
Gabiuas 1:0ada46075897 1825 // return _nr_cols + column;
Gabiuas 1:0ada46075897 1826 return 0x08 + column;
Gabiuas 1:0ada46075897 1827
Gabiuas 1:0ada46075897 1828 case LCD_T_C:
Gabiuas 1:0ada46075897 1829 // LCD16x1C is a special layout of LCD8x2
Gabiuas 1:0ada46075897 1830 // LCD32x1C is a special layout of LCD16x2
Gabiuas 1:0ada46075897 1831 // LCD40x1C is a special layout of LCD20x2
Gabiuas 1:0ada46075897 1832 #if(0)
Gabiuas 1:0ada46075897 1833 if (column < 8)
Gabiuas 1:0ada46075897 1834 return 0x00 + column;
Gabiuas 1:0ada46075897 1835 else
Gabiuas 1:0ada46075897 1836 return 0x40 + (column - 8);
Gabiuas 1:0ada46075897 1837 #else
Gabiuas 1:0ada46075897 1838 if (column < (_nr_cols >> 1))
Gabiuas 1:0ada46075897 1839 return 0x00 + column;
Gabiuas 1:0ada46075897 1840 else
Gabiuas 1:0ada46075897 1841 return 0x40 + (column - (_nr_cols >> 1));
Gabiuas 1:0ada46075897 1842 #endif
Gabiuas 1:0ada46075897 1843
Gabiuas 1:0ada46075897 1844 case LCD_T_D:
Gabiuas 1:0ada46075897 1845 //Alternate addressing mode for 3 and 4 row displays (except 40x4). Used by PCF21XX, KS0073, KS0078, SSD1803
Gabiuas 1:0ada46075897 1846 //The 4 available rows start at a hardcoded address.
Gabiuas 1:0ada46075897 1847 //Displays top rows when less than four are used.
Gabiuas 1:0ada46075897 1848 switch (row) {
Gabiuas 1:0ada46075897 1849 case 0:
Gabiuas 1:0ada46075897 1850 return 0x00 + column;
Gabiuas 1:0ada46075897 1851 case 1:
Gabiuas 1:0ada46075897 1852 return 0x20 + column;
Gabiuas 1:0ada46075897 1853 case 2:
Gabiuas 1:0ada46075897 1854 return 0x40 + column;
Gabiuas 1:0ada46075897 1855 case 3:
Gabiuas 1:0ada46075897 1856 return 0x60 + column;
Gabiuas 1:0ada46075897 1857 // Should never get here.
Gabiuas 1:0ada46075897 1858 // default:
Gabiuas 1:0ada46075897 1859 // return 0x00;
Gabiuas 1:0ada46075897 1860 }
Gabiuas 1:0ada46075897 1861
Gabiuas 1:0ada46075897 1862 case LCD_T_D1:
Gabiuas 1:0ada46075897 1863 //Alternate addressing mode for 3 row displays. Used by PCF21XX, KS0073, KS0078, SSD1803
Gabiuas 1:0ada46075897 1864 //The 4 available rows start at a hardcoded address.
Gabiuas 1:0ada46075897 1865 //Skips top row of 4 row display and starts display at row 1
Gabiuas 1:0ada46075897 1866 switch (row) {
Gabiuas 1:0ada46075897 1867 case 0:
Gabiuas 1:0ada46075897 1868 return 0x20 + column;
Gabiuas 1:0ada46075897 1869 case 1:
Gabiuas 1:0ada46075897 1870 return 0x40 + column;
Gabiuas 1:0ada46075897 1871 case 2:
Gabiuas 1:0ada46075897 1872 return 0x60 + column;
Gabiuas 1:0ada46075897 1873 // Should never get here.
Gabiuas 1:0ada46075897 1874 // default:
Gabiuas 1:0ada46075897 1875 // return 0x00;
Gabiuas 1:0ada46075897 1876 }
Gabiuas 1:0ada46075897 1877
Gabiuas 1:0ada46075897 1878 case LCD_T_E:
Gabiuas 1:0ada46075897 1879 // LCD40x4 is a special case since it has 2 controllers.
Gabiuas 1:0ada46075897 1880 // Each controller is configured as 40x2 (Type A)
Gabiuas 1:0ada46075897 1881 if (row<2) {
Gabiuas 1:0ada46075897 1882 // Test to see if we need to switch between controllers
Gabiuas 1:0ada46075897 1883 if (_ctrl_idx != _LCDCtrl_0) {
Gabiuas 1:0ada46075897 1884
Gabiuas 1:0ada46075897 1885 // Second LCD controller Cursor Off
Gabiuas 1:0ada46075897 1886 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
Gabiuas 1:0ada46075897 1887
Gabiuas 1:0ada46075897 1888 // Select primary controller
Gabiuas 1:0ada46075897 1889 _ctrl_idx = _LCDCtrl_0;
Gabiuas 1:0ada46075897 1890
Gabiuas 1:0ada46075897 1891 // Restore cursormode on primary LCD controller
Gabiuas 1:0ada46075897 1892 _setCursorAndDisplayMode(_currentMode, _currentCursor);
Gabiuas 1:0ada46075897 1893 }
Gabiuas 1:0ada46075897 1894
Gabiuas 1:0ada46075897 1895 return 0x00 + (row * 0x40) + column;
Gabiuas 1:0ada46075897 1896 }
Gabiuas 1:0ada46075897 1897 else {
Gabiuas 1:0ada46075897 1898
Gabiuas 1:0ada46075897 1899 // Test to see if we need to switch between controllers
Gabiuas 1:0ada46075897 1900 if (_ctrl_idx != _LCDCtrl_1) {
Gabiuas 1:0ada46075897 1901 // Primary LCD controller Cursor Off
Gabiuas 1:0ada46075897 1902 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
Gabiuas 1:0ada46075897 1903
Gabiuas 1:0ada46075897 1904 // Select secondary controller
Gabiuas 1:0ada46075897 1905 _ctrl_idx = _LCDCtrl_1;
Gabiuas 1:0ada46075897 1906
Gabiuas 1:0ada46075897 1907 // Restore cursormode on secondary LCD controller
Gabiuas 1:0ada46075897 1908 _setCursorAndDisplayMode(_currentMode, _currentCursor);
Gabiuas 1:0ada46075897 1909 }
Gabiuas 1:0ada46075897 1910
Gabiuas 1:0ada46075897 1911 return 0x00 + ((row-2) * 0x40) + column;
Gabiuas 1:0ada46075897 1912 }
Gabiuas 1:0ada46075897 1913
Gabiuas 1:0ada46075897 1914 case LCD_T_F:
Gabiuas 1:0ada46075897 1915 //Alternate addressing mode for 3 row displays.
Gabiuas 1:0ada46075897 1916 //The first half of 3rd row continues from 1st row, the second half continues from 2nd row.
Gabiuas 1:0ada46075897 1917 switch (row) {
Gabiuas 1:0ada46075897 1918 case 0:
Gabiuas 1:0ada46075897 1919 return 0x00 + column;
Gabiuas 1:0ada46075897 1920 case 1:
Gabiuas 1:0ada46075897 1921 return 0x40 + column;
Gabiuas 1:0ada46075897 1922 case 2:
Gabiuas 1:0ada46075897 1923 if (column < (_nr_cols >> 1)) // check first or second half of line
Gabiuas 1:0ada46075897 1924 return (0x00 + _nr_cols + column);
Gabiuas 1:0ada46075897 1925 else
Gabiuas 1:0ada46075897 1926 return (0x40 + _nr_cols + (column - (_nr_cols >> 1)));
Gabiuas 1:0ada46075897 1927 // Should never get here.
Gabiuas 1:0ada46075897 1928 // default:
Gabiuas 1:0ada46075897 1929 // return 0x00;
Gabiuas 1:0ada46075897 1930 }
Gabiuas 1:0ada46075897 1931
Gabiuas 1:0ada46075897 1932 case LCD_T_G:
Gabiuas 1:0ada46075897 1933 //Alternate addressing mode for 3 row displays. Used by ST7036
Gabiuas 1:0ada46075897 1934 switch (row) {
Gabiuas 1:0ada46075897 1935 case 0:
Gabiuas 1:0ada46075897 1936 return 0x00 + column;
Gabiuas 1:0ada46075897 1937 case 1:
Gabiuas 1:0ada46075897 1938 return 0x10 + column;
Gabiuas 1:0ada46075897 1939 case 2:
Gabiuas 1:0ada46075897 1940 return 0x20 + column;
Gabiuas 1:0ada46075897 1941 // Should never get here.
Gabiuas 1:0ada46075897 1942 // default:
Gabiuas 1:0ada46075897 1943 // return 0x00;
Gabiuas 1:0ada46075897 1944 }
Gabiuas 1:0ada46075897 1945
Gabiuas 1:0ada46075897 1946 // Should never get here.
Gabiuas 1:0ada46075897 1947 default:
Gabiuas 1:0ada46075897 1948 return 0x00;
Gabiuas 1:0ada46075897 1949
Gabiuas 1:0ada46075897 1950 } // switch _addr_mode
Gabiuas 1:0ada46075897 1951 }
Gabiuas 1:0ada46075897 1952
Gabiuas 1:0ada46075897 1953
Gabiuas 1:0ada46075897 1954 /** Set the memoryaddress of screen column and row location
Gabiuas 1:0ada46075897 1955 *
Gabiuas 1:0ada46075897 1956 * @param column The horizontal position from the left, indexed from 0
Gabiuas 1:0ada46075897 1957 * @param row The vertical position from the top, indexed from 0
Gabiuas 1:0ada46075897 1958 */
Gabiuas 1:0ada46075897 1959 void TextLCD_Base::setAddress(int column, int row) {
Gabiuas 1:0ada46075897 1960
Gabiuas 1:0ada46075897 1961 // Sanity Check column
Gabiuas 1:0ada46075897 1962 if (column < 0) {
Gabiuas 1:0ada46075897 1963 _column = 0;
Gabiuas 1:0ada46075897 1964 }
Gabiuas 1:0ada46075897 1965 else if (column >= _nr_cols) {
Gabiuas 1:0ada46075897 1966 _column = _nr_cols - 1;
Gabiuas 1:0ada46075897 1967 } else _column = column;
Gabiuas 1:0ada46075897 1968
Gabiuas 1:0ada46075897 1969 // Sanity Check row
Gabiuas 1:0ada46075897 1970 if (row < 0) {
Gabiuas 1:0ada46075897 1971 _row = 0;
Gabiuas 1:0ada46075897 1972 }
Gabiuas 1:0ada46075897 1973 else if (row >= _nr_rows) {
Gabiuas 1:0ada46075897 1974 _row = _nr_rows - 1;
Gabiuas 1:0ada46075897 1975 } else _row = row;
Gabiuas 1:0ada46075897 1976
Gabiuas 1:0ada46075897 1977
Gabiuas 1:0ada46075897 1978 // Compute the memory address
Gabiuas 1:0ada46075897 1979 // For LCD40x4: switch controllers if needed
Gabiuas 1:0ada46075897 1980 // switch cursor if needed
Gabiuas 1:0ada46075897 1981 int addr = getAddress(_column, _row);
Gabiuas 1:0ada46075897 1982
Gabiuas 1:0ada46075897 1983 _writeCommand(0x80 | addr);
Gabiuas 1:0ada46075897 1984 }
Gabiuas 1:0ada46075897 1985
Gabiuas 1:0ada46075897 1986
Gabiuas 1:0ada46075897 1987 /** Return the number of columns
Gabiuas 1:0ada46075897 1988 *
Gabiuas 1:0ada46075897 1989 * @return The number of columns
Gabiuas 1:0ada46075897 1990 *
Gabiuas 1:0ada46075897 1991 * Note: some configurations are commented out because they have not yet been tested due to lack of hardware
Gabiuas 1:0ada46075897 1992 */
Gabiuas 1:0ada46075897 1993 int TextLCD_Base::columns() {
Gabiuas 1:0ada46075897 1994
Gabiuas 1:0ada46075897 1995 // Columns encoded in b7..b0
Gabiuas 1:0ada46075897 1996 //return (_type & 0xFF);
Gabiuas 1:0ada46075897 1997 return _nr_cols;
Gabiuas 1:0ada46075897 1998 }
Gabiuas 1:0ada46075897 1999
Gabiuas 1:0ada46075897 2000 /** Return the number of rows
Gabiuas 1:0ada46075897 2001 *
Gabiuas 1:0ada46075897 2002 * @return The number of rows
Gabiuas 1:0ada46075897 2003 *
Gabiuas 1:0ada46075897 2004 * Note: some configurations are commented out because they have not yet been tested due to lack of hardware
Gabiuas 1:0ada46075897 2005 */
Gabiuas 1:0ada46075897 2006 int TextLCD_Base::rows() {
Gabiuas 1:0ada46075897 2007
Gabiuas 1:0ada46075897 2008 // Rows encoded in b15..b8
Gabiuas 1:0ada46075897 2009 //return ((_type >> 8) & 0xFF);
Gabiuas 1:0ada46075897 2010 return _nr_rows;
Gabiuas 1:0ada46075897 2011 }
Gabiuas 1:0ada46075897 2012
Gabiuas 1:0ada46075897 2013 /** Set the Cursormode
Gabiuas 1:0ada46075897 2014 *
Gabiuas 1:0ada46075897 2015 * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn)
Gabiuas 1:0ada46075897 2016 */
Gabiuas 1:0ada46075897 2017 void TextLCD_Base::setCursor(LCDCursor cursorMode) {
Gabiuas 1:0ada46075897 2018
Gabiuas 1:0ada46075897 2019 // Save new cursor mode, needed when 2 controllers are in use or when display is switched off/on
Gabiuas 1:0ada46075897 2020 _currentCursor = cursorMode;
Gabiuas 1:0ada46075897 2021
Gabiuas 1:0ada46075897 2022 // Configure only current LCD controller
Gabiuas 1:0ada46075897 2023 _setCursorAndDisplayMode(_currentMode, _currentCursor);
Gabiuas 1:0ada46075897 2024 }
Gabiuas 1:0ada46075897 2025
Gabiuas 1:0ada46075897 2026 /** Set the Displaymode
Gabiuas 1:0ada46075897 2027 *
Gabiuas 1:0ada46075897 2028 * @param displayMode The Display mode (DispOff, DispOn)
Gabiuas 1:0ada46075897 2029 */
Gabiuas 1:0ada46075897 2030 void TextLCD_Base::setMode(LCDMode displayMode) {
Gabiuas 1:0ada46075897 2031
Gabiuas 1:0ada46075897 2032 // Save new displayMode, needed when 2 controllers are in use or when cursor is changed
Gabiuas 1:0ada46075897 2033 _currentMode = displayMode;
Gabiuas 1:0ada46075897 2034
Gabiuas 1:0ada46075897 2035 #if (LCD_TWO_CTRL == 1)
Gabiuas 1:0ada46075897 2036 // Select and configure second LCD controller when needed
Gabiuas 1:0ada46075897 2037 if(_type==LCD40x4) {
Gabiuas 1:0ada46075897 2038 if (_ctrl_idx==_LCDCtrl_0) {
Gabiuas 1:0ada46075897 2039 // Configure primary LCD controller
Gabiuas 1:0ada46075897 2040 _setCursorAndDisplayMode(_currentMode, _currentCursor);
Gabiuas 1:0ada46075897 2041
Gabiuas 1:0ada46075897 2042 // Select 2nd controller
Gabiuas 1:0ada46075897 2043 _ctrl_idx=_LCDCtrl_1;
Gabiuas 1:0ada46075897 2044
Gabiuas 1:0ada46075897 2045 // Configure secondary LCD controller
Gabiuas 1:0ada46075897 2046 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
Gabiuas 1:0ada46075897 2047
Gabiuas 1:0ada46075897 2048 // Restore current controller
Gabiuas 1:0ada46075897 2049 _ctrl_idx=_LCDCtrl_0;
Gabiuas 1:0ada46075897 2050 }
Gabiuas 1:0ada46075897 2051 else {
Gabiuas 1:0ada46075897 2052 // Select primary controller
Gabiuas 1:0ada46075897 2053 _ctrl_idx=_LCDCtrl_0;
Gabiuas 1:0ada46075897 2054
Gabiuas 1:0ada46075897 2055 // Configure primary LCD controller
Gabiuas 1:0ada46075897 2056 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
Gabiuas 1:0ada46075897 2057
Gabiuas 1:0ada46075897 2058 // Restore current controller
Gabiuas 1:0ada46075897 2059 _ctrl_idx=_LCDCtrl_1;
Gabiuas 1:0ada46075897 2060
Gabiuas 1:0ada46075897 2061 // Configure secondary LCD controller
Gabiuas 1:0ada46075897 2062 _setCursorAndDisplayMode(_currentMode, _currentCursor);
Gabiuas 1:0ada46075897 2063 }
Gabiuas 1:0ada46075897 2064 }
Gabiuas 1:0ada46075897 2065 else {
Gabiuas 1:0ada46075897 2066 // Configure primary LCD controller
Gabiuas 1:0ada46075897 2067 _setCursorAndDisplayMode(_currentMode, _currentCursor);
Gabiuas 1:0ada46075897 2068 }
Gabiuas 1:0ada46075897 2069 #else
Gabiuas 1:0ada46075897 2070 // Support only one LCD controller
Gabiuas 1:0ada46075897 2071 _setCursorAndDisplayMode(_currentMode, _currentCursor);
Gabiuas 1:0ada46075897 2072
Gabiuas 1:0ada46075897 2073 #endif
Gabiuas 1:0ada46075897 2074 }
Gabiuas 1:0ada46075897 2075
Gabiuas 1:0ada46075897 2076 /** Low level method to restore the cursortype and display mode for current controller
Gabiuas 1:0ada46075897 2077 */
Gabiuas 1:0ada46075897 2078 void TextLCD_Base::_setCursorAndDisplayMode(LCDMode displayMode, LCDCursor cursorType) {
Gabiuas 1:0ada46075897 2079
Gabiuas 1:0ada46075897 2080 // Configure current LCD controller
Gabiuas 1:0ada46075897 2081 switch (_ctrl) {
Gabiuas 1:0ada46075897 2082 case ST7070:
Gabiuas 1:0ada46075897 2083 //ST7070 does not support Cursorblink. The P bit selects the font instead !
Gabiuas 1:0ada46075897 2084 _writeCommand(0x08 | displayMode | (cursorType & 0x02));
Gabiuas 1:0ada46075897 2085 break;
Gabiuas 1:0ada46075897 2086 default:
Gabiuas 1:0ada46075897 2087 _writeCommand(0x08 | displayMode | cursorType);
Gabiuas 1:0ada46075897 2088 break;
Gabiuas 1:0ada46075897 2089 } //switch
Gabiuas 1:0ada46075897 2090 }
Gabiuas 1:0ada46075897 2091
Gabiuas 1:0ada46075897 2092 /** Set the Backlight mode
Gabiuas 1:0ada46075897 2093 *
Gabiuas 1:0ada46075897 2094 * @param backlightMode The Backlight mode (LightOff, LightOn)
Gabiuas 1:0ada46075897 2095 */
Gabiuas 1:0ada46075897 2096 void TextLCD_Base::setBacklight(LCDBacklight backlightMode) {
Gabiuas 1:0ada46075897 2097
Gabiuas 1:0ada46075897 2098 #if (BACKLIGHT_INV==0)
Gabiuas 1:0ada46075897 2099 // Positive Backlight control pin logic
Gabiuas 1:0ada46075897 2100 if (backlightMode == LightOn) {
Gabiuas 1:0ada46075897 2101 this->_setBL(true);
Gabiuas 1:0ada46075897 2102 }
Gabiuas 1:0ada46075897 2103 else {
Gabiuas 1:0ada46075897 2104 this->_setBL(false);
Gabiuas 1:0ada46075897 2105 }
Gabiuas 1:0ada46075897 2106 #else
Gabiuas 1:0ada46075897 2107 // Inverted Backlight control pin logic
Gabiuas 1:0ada46075897 2108 if (backlightMode == LightOn) {
Gabiuas 1:0ada46075897 2109 this->_setBL(false);
Gabiuas 1:0ada46075897 2110 }
Gabiuas 1:0ada46075897 2111 else {
Gabiuas 1:0ada46075897 2112 this->_setBL(true);
Gabiuas 1:0ada46075897 2113 }
Gabiuas 1:0ada46075897 2114 #endif
Gabiuas 1:0ada46075897 2115 }
Gabiuas 1:0ada46075897 2116
Gabiuas 1:0ada46075897 2117 /** Set User Defined Characters
Gabiuas 1:0ada46075897 2118 *
Gabiuas 1:0ada46075897 2119 * @param unsigned char c The Index of the UDC (0..7) for HD44780 or clones and (0..15) for some more advanced controllers
Gabiuas 1:0ada46075897 2120 * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits for bitpattern and 3 bits for blinkmode (advanced types))
Gabiuas 1:0ada46075897 2121 */
Gabiuas 1:0ada46075897 2122 void TextLCD_Base::setUDC(unsigned char c, char *udc_data) {
Gabiuas 1:0ada46075897 2123
Gabiuas 1:0ada46075897 2124 #if (LCD_TWO_CTRL == 1)
Gabiuas 1:0ada46075897 2125 // Select and configure second LCD controller when needed
Gabiuas 1:0ada46075897 2126 if(_type==LCD40x4) {
Gabiuas 1:0ada46075897 2127 _LCDCtrl_Idx current_ctrl_idx = _ctrl_idx; // Temp save current controller
Gabiuas 1:0ada46075897 2128
Gabiuas 1:0ada46075897 2129 // Select primary controller
Gabiuas 1:0ada46075897 2130 _ctrl_idx=_LCDCtrl_0;
Gabiuas 1:0ada46075897 2131
Gabiuas 1:0ada46075897 2132 // Configure primary LCD controller
Gabiuas 1:0ada46075897 2133 _setUDC(c, udc_data);
Gabiuas 1:0ada46075897 2134
Gabiuas 1:0ada46075897 2135 // Select 2nd controller
Gabiuas 1:0ada46075897 2136 _ctrl_idx=_LCDCtrl_1;
Gabiuas 1:0ada46075897 2137
Gabiuas 1:0ada46075897 2138 // Configure secondary LCD controller
Gabiuas 1:0ada46075897 2139 _setUDC(c, udc_data);
Gabiuas 1:0ada46075897 2140
Gabiuas 1:0ada46075897 2141 // Restore current controller
Gabiuas 1:0ada46075897 2142 _ctrl_idx=current_ctrl_idx;
Gabiuas 1:0ada46075897 2143 }
Gabiuas 1:0ada46075897 2144 else {
Gabiuas 1:0ada46075897 2145 // Configure primary LCD controller
Gabiuas 1:0ada46075897 2146 _setUDC(c, udc_data);
Gabiuas 1:0ada46075897 2147 }
Gabiuas 1:0ada46075897 2148 #else
Gabiuas 1:0ada46075897 2149 // Support only one LCD controller
Gabiuas 1:0ada46075897 2150 _setUDC(c, udc_data);
Gabiuas 1:0ada46075897 2151 #endif
Gabiuas 1:0ada46075897 2152 }
Gabiuas 1:0ada46075897 2153
Gabiuas 1:0ada46075897 2154 /** Low level method to store user defined characters for current controller
Gabiuas 1:0ada46075897 2155 *
Gabiuas 1:0ada46075897 2156 * @param unsigned char c The Index of the UDC (0..7) for HD44780 clones and (0..15) for some more advanced controllers
Gabiuas 1:0ada46075897 2157 * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits for bitpattern and 3 bits for blinkmode (advanced types))
Gabiuas 1:0ada46075897 2158 */
Gabiuas 1:0ada46075897 2159 void TextLCD_Base::_setUDC(unsigned char c, char *udc_data) {
Gabiuas 1:0ada46075897 2160
Gabiuas 1:0ada46075897 2161 switch (_ctrl) {
Gabiuas 1:0ada46075897 2162 case PCF2103_3V3 : // Some UDCs may be used for Icons
Gabiuas 1:0ada46075897 2163 case PCF2113_3V3 : // Some UDCs may be used for Icons
Gabiuas 1:0ada46075897 2164 case PCF2116_3V3 :
Gabiuas 1:0ada46075897 2165 case PCF2116_5V :
Gabiuas 1:0ada46075897 2166 case PCF2119_3V3 : // Some UDCs may be used for Icons
Gabiuas 1:0ada46075897 2167 case PCF2119R_3V3: // Some UDCs may be used for Icons
Gabiuas 1:0ada46075897 2168 c = c & 0x0F; // mask down to valid range
Gabiuas 1:0ada46075897 2169 break;
Gabiuas 1:0ada46075897 2170
Gabiuas 1:0ada46075897 2171 default:
Gabiuas 1:0ada46075897 2172 c = c & 0x07; // mask down to valid range
Gabiuas 1:0ada46075897 2173 break;
Gabiuas 1:0ada46075897 2174 } //switch _ctrl
Gabiuas 1:0ada46075897 2175
Gabiuas 1:0ada46075897 2176 // Select DD RAM for current LCD controller
Gabiuas 1:0ada46075897 2177 // This is needed to correctly set Bit 6 of the addresspointer for controllers that support 16 UDCs
Gabiuas 1:0ada46075897 2178 _writeCommand(0x80 | ((c << 3) & 0x40)) ;
Gabiuas 1:0ada46075897 2179
Gabiuas 1:0ada46075897 2180 // Select CG RAM for current LCD controller
Gabiuas 1:0ada46075897 2181 _writeCommand(0x40 | ((c << 3) & 0x3F)); //Set CG-RAM address, (note that Bit 6 is retained and can not be set by this command !)
Gabiuas 1:0ada46075897 2182 //8 sequential locations needed per UDC
Gabiuas 1:0ada46075897 2183 // Store UDC pattern
Gabiuas 1:0ada46075897 2184 for (int i=0; i<8; i++) {
Gabiuas 1:0ada46075897 2185 _writeData(*udc_data++);
Gabiuas 1:0ada46075897 2186 }
Gabiuas 1:0ada46075897 2187
Gabiuas 1:0ada46075897 2188 //Select DD RAM again for current LCD controller and restore the addresspointer
Gabiuas 1:0ada46075897 2189 int addr = getAddress(_column, _row);
Gabiuas 1:0ada46075897 2190 _writeCommand(0x80 | addr);
Gabiuas 1:0ada46075897 2191 }
Gabiuas 1:0ada46075897 2192
Gabiuas 1:0ada46075897 2193 #if(LCD_BLINK == 1)
Gabiuas 1:0ada46075897 2194 /** Set UDC Blink and Icon blink
Gabiuas 1:0ada46075897 2195 * setUDCBlink method is supported by some compatible devices (eg SSD1803)
Gabiuas 1:0ada46075897 2196 *
Gabiuas 1:0ada46075897 2197 * @param blinkMode The Blink mode (BlinkOff, BlinkOn)
Gabiuas 1:0ada46075897 2198 */
Gabiuas 1:0ada46075897 2199 void TextLCD_Base::setUDCBlink(LCDBlink blinkMode){
Gabiuas 1:0ada46075897 2200 // Blinking UDCs (and icons) are enabled when a specific controlbit (BE) is set.
Gabiuas 1:0ada46075897 2201 // The blinking pixels in the UDC and icons can be controlled by setting additional bits in the UDC or icon bitpattern.
Gabiuas 1:0ada46075897 2202 // UDCs are defined by an 8 byte bitpattern. The P0..P4 form the character pattern.
Gabiuas 1:0ada46075897 2203 // P7 P6 P5 P4 P3 P2 P1 P0
Gabiuas 1:0ada46075897 2204 // 0 B1 B0 x 0 1 1 1 0
Gabiuas 1:0ada46075897 2205 // 1 B1 B0 x 1 0 0 0 1
Gabiuas 1:0ada46075897 2206 // .............
Gabiuas 1:0ada46075897 2207 // 7 B1 B0 x 1 0 0 0 1
Gabiuas 1:0ada46075897 2208 //
Gabiuas 1:0ada46075897 2209 // Bit 6 and Bit 7 in the pattern will control the blinking mode when Blink is enabled through BE.
Gabiuas 1:0ada46075897 2210 // B1 B0 Mode
Gabiuas 1:0ada46075897 2211 // 0 0 No Blinking in this row of the UDC
Gabiuas 1:0ada46075897 2212 // 0 1 Enabled pixels in P4 will blink
Gabiuas 1:0ada46075897 2213 // 1 x Enabled pixels in P0..P4 will blink
Gabiuas 1:0ada46075897 2214 //
Gabiuas 1:0ada46075897 2215 // Note: the PCF2103 and PCF2113 use UDCs to set Icons
Gabiuas 1:0ada46075897 2216 // 3 x 8 rows x 5 bits = 120 bits Icons for Normal pattern (UDC 0..2) and
Gabiuas 1:0ada46075897 2217 // 3 x 8 rows x 5 bits = 120 bits Icons for Blink pattern (UDC 4..6)
Gabiuas 1:0ada46075897 2218 // Note: the PCF2119 uses UDCs to set Icons
Gabiuas 1:0ada46075897 2219 // 4 x 8 rows x 5 bits = 160 bits Icons for Normal pattern (UDC 0..3) and
Gabiuas 1:0ada46075897 2220 // 4 x 8 rows x 5 bits = 160 bits Icons for Blink pattern (UDC 4..7)
Gabiuas 1:0ada46075897 2221 switch (blinkMode) {
Gabiuas 1:0ada46075897 2222 case BlinkOn:
Gabiuas 1:0ada46075897 2223 // Controllers that support UDC/Icon Blink
Gabiuas 1:0ada46075897 2224 switch (_ctrl) {
Gabiuas 1:0ada46075897 2225 case KS0073 :
Gabiuas 1:0ada46075897 2226 case KS0078 :
Gabiuas 1:0ada46075897 2227 case HD66712 :
Gabiuas 1:0ada46075897 2228 _function_1 |= 0x02; // Enable UDC/Icon Blink
Gabiuas 1:0ada46075897 2229 _writeCommand(0x20 | _function_1); // Function set 0 0 1 DL N RE(1) BE 0/LP (Ext Regs)
Gabiuas 1:0ada46075897 2230
Gabiuas 1:0ada46075897 2231 _writeCommand(0x20 | _function); // Function set 0 0 1 DL N RE(0) DH REV (Std Regs)
Gabiuas 1:0ada46075897 2232 break; // case KS0073, KS0078, HD66712 Controller
Gabiuas 1:0ada46075897 2233
Gabiuas 1:0ada46075897 2234 case US2066_3V3 :
Gabiuas 1:0ada46075897 2235 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2236 _function_1 |= 0x04; // Enable UDC/Icon Blink
Gabiuas 1:0ada46075897 2237 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
Gabiuas 1:0ada46075897 2238 // Select Ext Instr Set
Gabiuas 1:0ada46075897 2239
Gabiuas 1:0ada46075897 2240 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2241 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2242 break; // case SSD1803, US2066
Gabiuas 1:0ada46075897 2243
Gabiuas 1:0ada46075897 2244 case PCF2103_3V3 :
Gabiuas 1:0ada46075897 2245 case PCF2113_3V3 :
Gabiuas 1:0ada46075897 2246 case PCF2119_3V3 :
Gabiuas 1:0ada46075897 2247 case PCF2119R_3V3 :
Gabiuas 1:0ada46075897 2248 // Enable Icon Blink
Gabiuas 1:0ada46075897 2249 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
Gabiuas 1:0ada46075897 2250 _writeCommand(0x08 | 0x02); // ICON Conf 0000 1, IM=0 (Char mode), IB=1 (Icon blink), 0 (Instr. Set 1)
Gabiuas 1:0ada46075897 2251 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
Gabiuas 1:0ada46075897 2252
Gabiuas 1:0ada46075897 2253 break;
Gabiuas 1:0ada46075897 2254
Gabiuas 1:0ada46075897 2255 default:
Gabiuas 1:0ada46075897 2256 //Unsupported feature for other controllers
Gabiuas 1:0ada46075897 2257 break;
Gabiuas 1:0ada46075897 2258 } //switch _ctrl
Gabiuas 1:0ada46075897 2259
Gabiuas 1:0ada46075897 2260 break; // BlinkOn
Gabiuas 1:0ada46075897 2261
Gabiuas 1:0ada46075897 2262 case BlinkOff:
Gabiuas 1:0ada46075897 2263 // Controllers that support UDC Blink
Gabiuas 1:0ada46075897 2264 switch (_ctrl) {
Gabiuas 1:0ada46075897 2265 case KS0073 :
Gabiuas 1:0ada46075897 2266 case KS0078 :
Gabiuas 1:0ada46075897 2267 case HD66712:
Gabiuas 1:0ada46075897 2268 _function_1 &= ~0x02; // Disable UDC/Icon Blink
Gabiuas 1:0ada46075897 2269 _writeCommand(0x20 | _function_1); // Function set 0 0 1 DL N RE(1) BE 0/LP (Ext Regs)
Gabiuas 1:0ada46075897 2270
Gabiuas 1:0ada46075897 2271 _writeCommand(0x20 | _function); // Function set 0 0 1 DL N RE(0) DH REV (Std Regs)
Gabiuas 1:0ada46075897 2272 break; // case KS0073, KS0078, HD66712 Controller
Gabiuas 1:0ada46075897 2273
Gabiuas 1:0ada46075897 2274 case US2066_3V3 :
Gabiuas 1:0ada46075897 2275 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2276 _function_1 &= ~0x04; // Disable UDC/Icon Blink
Gabiuas 1:0ada46075897 2277 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
Gabiuas 1:0ada46075897 2278 // Select Ext Instr Set
Gabiuas 1:0ada46075897 2279
Gabiuas 1:0ada46075897 2280 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2281 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2282 break; // case SSD1803, US2066
Gabiuas 1:0ada46075897 2283
Gabiuas 1:0ada46075897 2284 case PCF2103_3V3 :
Gabiuas 1:0ada46075897 2285 case PCF2113_3V3 :
Gabiuas 1:0ada46075897 2286 case PCF2119_3V3 :
Gabiuas 1:0ada46075897 2287 case PCF2119R_3V3 :
Gabiuas 1:0ada46075897 2288 // Disable Icon Blink
Gabiuas 1:0ada46075897 2289 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
Gabiuas 1:0ada46075897 2290 _writeCommand(0x08); // ICON Conf 0000 1, IM=0 (Char mode), IB=1 (Icon blink), 0 (Instr. Set 1)
Gabiuas 1:0ada46075897 2291 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
Gabiuas 1:0ada46075897 2292
Gabiuas 1:0ada46075897 2293 break;
Gabiuas 1:0ada46075897 2294
Gabiuas 1:0ada46075897 2295 default:
Gabiuas 1:0ada46075897 2296 //Unsupported feature for other controllers
Gabiuas 1:0ada46075897 2297 break;
Gabiuas 1:0ada46075897 2298 } //switch _ctrl
Gabiuas 1:0ada46075897 2299
Gabiuas 1:0ada46075897 2300 break; //BlinkOff
Gabiuas 1:0ada46075897 2301
Gabiuas 1:0ada46075897 2302 default:
Gabiuas 1:0ada46075897 2303 break;
Gabiuas 1:0ada46075897 2304 } // blinkMode
Gabiuas 1:0ada46075897 2305
Gabiuas 1:0ada46075897 2306 } // setUDCBlink()
Gabiuas 1:0ada46075897 2307 #endif
Gabiuas 1:0ada46075897 2308
Gabiuas 1:0ada46075897 2309 #if(LCD_CONTRAST == 1)
Gabiuas 1:0ada46075897 2310 /** Set Contrast
Gabiuas 1:0ada46075897 2311 * setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation
Gabiuas 1:0ada46075897 2312 * Initial code for ST70XX imported from fork by JH1PJL
Gabiuas 1:0ada46075897 2313 *
Gabiuas 1:0ada46075897 2314 * @param unsigned char c contrast data (6 significant bits, valid range 0..63, Value 0 will disable the Vgen)
Gabiuas 1:0ada46075897 2315 * @return none
Gabiuas 1:0ada46075897 2316 */
Gabiuas 1:0ada46075897 2317 //@TODO Add support for 40x4 dual controller
Gabiuas 1:0ada46075897 2318 void TextLCD_Base::setContrast(unsigned char c) {
Gabiuas 1:0ada46075897 2319
Gabiuas 1:0ada46075897 2320 // Function set mode stored during Init. Make sure we dont accidentally switch between 1-line and 2-line mode!
Gabiuas 1:0ada46075897 2321 // Icon/Booster mode stored during Init. Make sure we dont accidentally change this!
Gabiuas 1:0ada46075897 2322
Gabiuas 1:0ada46075897 2323 _contrast = c & 0x3F; // Sanity check
Gabiuas 1:0ada46075897 2324
Gabiuas 1:0ada46075897 2325 switch (_ctrl) {
Gabiuas 1:0ada46075897 2326 case PCF2113_3V3 :
Gabiuas 1:0ada46075897 2327 case PCF2119_3V3 :
Gabiuas 1:0ada46075897 2328 case PCF2119R_3V3 :
Gabiuas 1:0ada46075897 2329 if (_contrast < 5) _contrast = 0; // See datasheet. Sanity check for PCF2113/PCF2119
Gabiuas 1:0ada46075897 2330 if (_contrast > 55) _contrast = 55;
Gabiuas 1:0ada46075897 2331
Gabiuas 1:0ada46075897 2332 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instruction Set = 1
Gabiuas 1:0ada46075897 2333 _writeCommand(0x80 | 0x00 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=0, VA=contrast
Gabiuas 1:0ada46075897 2334 _writeCommand(0x80 | 0x40 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=1, VB=contrast
Gabiuas 1:0ada46075897 2335 _writeCommand(0x20 | _function); // Select Instruction Set = 0
Gabiuas 1:0ada46075897 2336 break;
Gabiuas 1:0ada46075897 2337
Gabiuas 1:0ada46075897 2338 case ST7032_3V3 :
Gabiuas 1:0ada46075897 2339 case ST7032_5V :
Gabiuas 1:0ada46075897 2340 case ST7036_3V3 :
Gabiuas 1:0ada46075897 2341 // case ST7036_5V :
Gabiuas 1:0ada46075897 2342 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2343 case SPLC792A_3V3 :
Gabiuas 1:0ada46075897 2344 _writeCommand(0x20 | _function | 0x01); // Select Instruction Set = 1
Gabiuas 1:0ada46075897 2345 _writeCommand(0x70 | (_contrast & 0x0F)); // Contrast Low bits
Gabiuas 1:0ada46075897 2346 _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Contrast High bits
Gabiuas 1:0ada46075897 2347 _writeCommand(0x20 | _function); // Select Instruction Set = 0
Gabiuas 1:0ada46075897 2348 break;
Gabiuas 1:0ada46075897 2349
Gabiuas 1:0ada46075897 2350 case US2066_3V3 :
Gabiuas 1:0ada46075897 2351 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
Gabiuas 1:0ada46075897 2352 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2353
Gabiuas 1:0ada46075897 2354 _writeCommand(0x79); // Function Select OLED: 0 1 1 1 1 0 0 1 (Ext Instr Set)
Gabiuas 1:0ada46075897 2355
Gabiuas 1:0ada46075897 2356 _writeCommand(0x81); // Set Contrast Control: 1 0 0 0 0 0 0 1 (Ext Instr Set, OLED)
Gabiuas 1:0ada46075897 2357 _writeCommand((_contrast << 2) | 0x03); // Set Contrast Value: 8 bits. Use 6 bits for compatibility
Gabiuas 1:0ada46075897 2358
Gabiuas 1:0ada46075897 2359 _writeCommand(0x78); // Function Disable OLED: 0 1 1 1 1 0 0 0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2360
Gabiuas 1:0ada46075897 2361 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2362 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2363 break;
Gabiuas 1:0ada46075897 2364
Gabiuas 1:0ada46075897 2365 //not yet tested on hardware
Gabiuas 1:0ada46075897 2366 case PT6314 :
Gabiuas 1:0ada46075897 2367 // Only 2 significant bits
Gabiuas 1:0ada46075897 2368 // 0x00 = 100%
Gabiuas 1:0ada46075897 2369 // 0x01 = 75%
Gabiuas 1:0ada46075897 2370 // 0x02 = 50%
Gabiuas 1:0ada46075897 2371 // 0x03 = 25%
Gabiuas 1:0ada46075897 2372 _writeCommand(0x20 | _function | ((~_contrast) >> 4)); // Invert and shift to use 2 MSBs
Gabiuas 1:0ada46075897 2373 break;
Gabiuas 1:0ada46075897 2374
Gabiuas 1:0ada46075897 2375 default:
Gabiuas 1:0ada46075897 2376 //Unsupported feature for other controllers
Gabiuas 1:0ada46075897 2377 break;
Gabiuas 1:0ada46075897 2378 } // end switch
Gabiuas 1:0ada46075897 2379 } // end setContrast()
Gabiuas 1:0ada46075897 2380 #endif
Gabiuas 1:0ada46075897 2381
Gabiuas 1:0ada46075897 2382 #if(LCD_POWER == 1)
Gabiuas 1:0ada46075897 2383 /** Set Power
Gabiuas 1:0ada46075897 2384 * setPower method is supported by some compatible devices (eg SSD1803) that have power down modes
Gabiuas 1:0ada46075897 2385 *
Gabiuas 1:0ada46075897 2386 * @param bool powerOn Power on/off
Gabiuas 1:0ada46075897 2387 * @return none
Gabiuas 1:0ada46075897 2388 */
Gabiuas 1:0ada46075897 2389 //@TODO Add support for 40x4 dual controller
Gabiuas 1:0ada46075897 2390 void TextLCD_Base::setPower(bool powerOn) {
Gabiuas 1:0ada46075897 2391
Gabiuas 1:0ada46075897 2392 if (powerOn) {
Gabiuas 1:0ada46075897 2393 // Switch on
Gabiuas 1:0ada46075897 2394 setMode(DispOn);
Gabiuas 1:0ada46075897 2395
Gabiuas 1:0ada46075897 2396 // Controllers that supports specific Power Down mode
Gabiuas 1:0ada46075897 2397 switch (_ctrl) {
Gabiuas 1:0ada46075897 2398
Gabiuas 1:0ada46075897 2399 // case PCF2113_3V3 :
Gabiuas 1:0ada46075897 2400 // case PCF2119_3V3 :
Gabiuas 1:0ada46075897 2401 // case PCF2119R_3V3 :
Gabiuas 1:0ada46075897 2402 // case ST7032_3V3 :
Gabiuas 1:0ada46075897 2403 //@todo
Gabiuas 1:0ada46075897 2404 // enable Booster Bon
Gabiuas 1:0ada46075897 2405
Gabiuas 1:0ada46075897 2406 case WS0010:
Gabiuas 1:0ada46075897 2407 _writeCommand(0x17); // Char mode, DC/DC on
Gabiuas 1:0ada46075897 2408 wait_ms(10); // Wait 10ms to ensure powered up
Gabiuas 1:0ada46075897 2409 break;
Gabiuas 1:0ada46075897 2410
Gabiuas 1:0ada46075897 2411 case KS0073:
Gabiuas 1:0ada46075897 2412 case KS0078:
Gabiuas 1:0ada46075897 2413 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2414 // case SSD1803_5V :
Gabiuas 1:0ada46075897 2415 _writeCommand(0x20 | _function_1); // Select Ext Instr Set
Gabiuas 1:0ada46075897 2416 _writeCommand(0x02); // Power On
Gabiuas 1:0ada46075897 2417 _writeCommand(0x20 | _function); // Select Std Instr Set
Gabiuas 1:0ada46075897 2418 break;
Gabiuas 1:0ada46075897 2419
Gabiuas 1:0ada46075897 2420 default:
Gabiuas 1:0ada46075897 2421 //Unsupported feature for other controllers
Gabiuas 1:0ada46075897 2422 break;
Gabiuas 1:0ada46075897 2423 } // end switch
Gabiuas 1:0ada46075897 2424 }
Gabiuas 1:0ada46075897 2425 else {
Gabiuas 1:0ada46075897 2426 // Switch off
Gabiuas 1:0ada46075897 2427 setMode(DispOff);
Gabiuas 1:0ada46075897 2428
Gabiuas 1:0ada46075897 2429 // Controllers that support specific Power Down mode
Gabiuas 1:0ada46075897 2430 switch (_ctrl) {
Gabiuas 1:0ada46075897 2431
Gabiuas 1:0ada46075897 2432 // case PCF2113_3V3 :
Gabiuas 1:0ada46075897 2433 // case PCF2119_3V3 :
Gabiuas 1:0ada46075897 2434 // case PCF2119R_3V3 :
Gabiuas 1:0ada46075897 2435 // case ST7032_3V3 :
Gabiuas 1:0ada46075897 2436 //@todo
Gabiuas 1:0ada46075897 2437 // disable Booster Bon
Gabiuas 1:0ada46075897 2438
Gabiuas 1:0ada46075897 2439 case WS0010:
Gabiuas 1:0ada46075897 2440 _writeCommand(0x13); // Char mode, DC/DC off
Gabiuas 1:0ada46075897 2441 break;
Gabiuas 1:0ada46075897 2442
Gabiuas 1:0ada46075897 2443 case KS0073:
Gabiuas 1:0ada46075897 2444 case KS0078:
Gabiuas 1:0ada46075897 2445 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2446 // case SSD1803_5V :
Gabiuas 1:0ada46075897 2447 _writeCommand(0x20 | _function_1); // Select Ext Instr Set
Gabiuas 1:0ada46075897 2448 _writeCommand(0x03); // Power Down
Gabiuas 1:0ada46075897 2449 _writeCommand(0x20 | _function); // Select Std Instr Set
Gabiuas 1:0ada46075897 2450 break;
Gabiuas 1:0ada46075897 2451
Gabiuas 1:0ada46075897 2452 default:
Gabiuas 1:0ada46075897 2453 //Unsupported feature for other controllers
Gabiuas 1:0ada46075897 2454 break;
Gabiuas 1:0ada46075897 2455 } // end switch
Gabiuas 1:0ada46075897 2456 }
Gabiuas 1:0ada46075897 2457 } // end setPower()
Gabiuas 1:0ada46075897 2458 #endif
Gabiuas 1:0ada46075897 2459
Gabiuas 1:0ada46075897 2460 #if(LCD_ORIENT == 1)
Gabiuas 1:0ada46075897 2461 /** Set Orient
Gabiuas 1:0ada46075897 2462 * setOrient method is supported by some compatible devices (eg SSD1803, US2066) that have top/bottom view modes
Gabiuas 1:0ada46075897 2463 *
Gabiuas 1:0ada46075897 2464 * @param LCDOrient orient Orientation
Gabiuas 1:0ada46075897 2465 * @return none
Gabiuas 1:0ada46075897 2466 */
Gabiuas 1:0ada46075897 2467 void TextLCD_Base::setOrient(LCDOrient orient){
Gabiuas 1:0ada46075897 2468
Gabiuas 1:0ada46075897 2469 switch (orient) {
Gabiuas 1:0ada46075897 2470
Gabiuas 1:0ada46075897 2471 case Top:
Gabiuas 1:0ada46075897 2472 switch (_ctrl) {
Gabiuas 1:0ada46075897 2473 case PCF2103_3V3:
Gabiuas 1:0ada46075897 2474 case PCF2116_3V3:
Gabiuas 1:0ada46075897 2475 case PCF2116_5V:
Gabiuas 1:0ada46075897 2476 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
Gabiuas 1:0ada46075897 2477 _writeCommand(0x05); // Display Conf Set 0000 0, 1, P=0, Q=1 (Instr. Set 1)
Gabiuas 1:0ada46075897 2478 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
Gabiuas 1:0ada46075897 2479 break;
Gabiuas 1:0ada46075897 2480
Gabiuas 1:0ada46075897 2481 case PCF2119_3V3:
Gabiuas 1:0ada46075897 2482 case PCF2119R_3V3:
Gabiuas 1:0ada46075897 2483 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
Gabiuas 1:0ada46075897 2484 _writeCommand(0x07); // Display Conf Set 0000 0, 1, P=1, Q=1 (Instr. Set 1)
Gabiuas 1:0ada46075897 2485 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
Gabiuas 1:0ada46075897 2486 break;
Gabiuas 1:0ada46075897 2487
Gabiuas 1:0ada46075897 2488 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2489 // case SSD1803_5V :
Gabiuas 1:0ada46075897 2490 case US2066_3V3 :
Gabiuas 1:0ada46075897 2491 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 2492 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2493 // _writeCommand(0x06); // Set ext entry mode, 0 0 0 0 0 1 BDC=1 COM1-32, BDS=0 SEG100-1 "Bottom View" (Ext Instr Set)
Gabiuas 1:0ada46075897 2494 _writeCommand(0x05); // Set ext entry mode, 0 0 0 0 0 1 BDC=0 COM32-1, BDS=1 SEG1-100 "Top View" (Ext Instr Set)
Gabiuas 1:0ada46075897 2495
Gabiuas 1:0ada46075897 2496 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2497 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2498 break;
Gabiuas 1:0ada46075897 2499
Gabiuas 1:0ada46075897 2500 case ST7070:
Gabiuas 1:0ada46075897 2501 _writeCommand(0x20 | _function | 0x04); // Set function, 0 0 1 DL, N, EXT=1, x, x (Select Instr Set = 1)
Gabiuas 1:0ada46075897 2502
Gabiuas 1:0ada46075897 2503 _writeCommand(0x40 | 0x00); // COM/SEG directions 0 1 0 0 C1, C2, S1, S2 (Instr Set 1)
Gabiuas 1:0ada46075897 2504 // C1=1: Com1-8 -> Com8-1; C2=1: Com9-16 -> Com16-9
Gabiuas 1:0ada46075897 2505 // S1=1: Seg1-40 -> Seg40-1; S2=1: Seg41-80 -> Seg80-41
Gabiuas 1:0ada46075897 2506 wait_ms(5); // Wait to ensure completion or ST7070 fails to set Top/Bottom after reset..
Gabiuas 1:0ada46075897 2507
Gabiuas 1:0ada46075897 2508 _writeCommand(0x20 | _function); // Set function, EXT=0 (Select Instr Set = 0)
Gabiuas 1:0ada46075897 2509
Gabiuas 1:0ada46075897 2510 break; // case ST7070 Controller
Gabiuas 1:0ada46075897 2511
Gabiuas 1:0ada46075897 2512 default:
Gabiuas 1:0ada46075897 2513 //Unsupported feature for other controllers
Gabiuas 1:0ada46075897 2514 break;
Gabiuas 1:0ada46075897 2515
Gabiuas 1:0ada46075897 2516 } // end switch _ctrl
Gabiuas 1:0ada46075897 2517 break; // end Top
Gabiuas 1:0ada46075897 2518
Gabiuas 1:0ada46075897 2519 case Bottom:
Gabiuas 1:0ada46075897 2520 switch (_ctrl) {
Gabiuas 1:0ada46075897 2521 case PCF2103_3V3:
Gabiuas 1:0ada46075897 2522 case PCF2116_3V3:
Gabiuas 1:0ada46075897 2523 case PCF2116_5V:
Gabiuas 1:0ada46075897 2524 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
Gabiuas 1:0ada46075897 2525 _writeCommand(0x06); // Display Conf Set 0000 0, 1, P=1, Q=0 (Instr. Set 1)
Gabiuas 1:0ada46075897 2526 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
Gabiuas 1:0ada46075897 2527 break;
Gabiuas 1:0ada46075897 2528
Gabiuas 1:0ada46075897 2529 case PCF2119_3V3:
Gabiuas 1:0ada46075897 2530 case PCF2119R_3V3 :
Gabiuas 1:0ada46075897 2531 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
Gabiuas 1:0ada46075897 2532 _writeCommand(0x04); // Display Conf Set 0000 0, 1, P=0, Q=0 (Instr. Set 1)
Gabiuas 1:0ada46075897 2533 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
Gabiuas 1:0ada46075897 2534 break;
Gabiuas 1:0ada46075897 2535
Gabiuas 1:0ada46075897 2536 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2537 // case SSD1803_5V :
Gabiuas 1:0ada46075897 2538 case US2066_3V3 :
Gabiuas 1:0ada46075897 2539 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 2540 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2541 _writeCommand(0x06); // Set ext entry mode, 0 0 0 0 0 1 BDC=1 COM1-32, BDS=0 SEG100-1 "Bottom View" (Ext Instr Set)
Gabiuas 1:0ada46075897 2542 // _writeCommand(0x05); // Set ext entry mode, 0 0 0 0 0 1 BDC=0 COM32-1, BDS=1 SEG1-100 "Top View" (Ext Instr Set)
Gabiuas 1:0ada46075897 2543
Gabiuas 1:0ada46075897 2544 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2545 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2546 break;
Gabiuas 1:0ada46075897 2547
Gabiuas 1:0ada46075897 2548 case ST7070:
Gabiuas 1:0ada46075897 2549 //Note: this does not result in correct top/bottom view.
Gabiuas 1:0ada46075897 2550 //The left and right half of each row are reversed and the addressing of both rows is also incorrect:
Gabiuas 1:0ada46075897 2551 //Top/bottomline when orientation is flipped:
Gabiuas 1:0ada46075897 2552 // 0x48...0x4F 0x40...0x47
Gabiuas 1:0ada46075897 2553 // 0x08...0x0F 0x00...0x07
Gabiuas 1:0ada46075897 2554 _writeCommand(0x20 | _function | 0x04); // Set function, 0 0 1 DL N EXT=1 x x (Select Instr Set = 1)
Gabiuas 1:0ada46075897 2555
Gabiuas 1:0ada46075897 2556 _writeCommand(0x40 | 0x0F); // COM/SEG directions 0 1 0 0 C1, C2, S1, S2 (Instr Set 1)
Gabiuas 1:0ada46075897 2557 // C1=1: Com1-8 -> Com8-1; C2=1: Com9-16 -> Com16-9
Gabiuas 1:0ada46075897 2558 // S1=1: Seg1-40 -> Seg40-1; S2=1: Seg41-80 -> Seg80-41
Gabiuas 1:0ada46075897 2559 wait_ms(5); // Wait to ensure completion or ST7070 fails to set Top/Bottom after reset..
Gabiuas 1:0ada46075897 2560
Gabiuas 1:0ada46075897 2561 _writeCommand(0x20 | _function); // Set function, EXT=0 (Select Instr Set = 0)
Gabiuas 1:0ada46075897 2562
Gabiuas 1:0ada46075897 2563 break; // case ST7070 Controller
Gabiuas 1:0ada46075897 2564
Gabiuas 1:0ada46075897 2565 default:
Gabiuas 1:0ada46075897 2566 //Unsupported feature for other controllers
Gabiuas 1:0ada46075897 2567 break;
Gabiuas 1:0ada46075897 2568
Gabiuas 1:0ada46075897 2569 } // end switch _ctrl
Gabiuas 1:0ada46075897 2570
Gabiuas 1:0ada46075897 2571 break; // end Bottom
Gabiuas 1:0ada46075897 2572 } // end switch orient
Gabiuas 1:0ada46075897 2573 } // end setOrient()
Gabiuas 1:0ada46075897 2574 #endif
Gabiuas 1:0ada46075897 2575
Gabiuas 1:0ada46075897 2576 #if(LCD_BIGFONT == 1)
Gabiuas 1:0ada46075897 2577 /** Set Big Font
Gabiuas 1:0ada46075897 2578 * setBigFont method is supported by some compatible devices (eg SSD1803, US2066)
Gabiuas 1:0ada46075897 2579 *
Gabiuas 1:0ada46075897 2580 * @param lines The selected Big Font lines (None, TopLine, CenterLine, BottomLine, TopBottomLine)
Gabiuas 1:0ada46075897 2581 * Double height characters can be shown on lines 1+2, 2+3, 3+4 or 1+2 and 3+4
Gabiuas 1:0ada46075897 2582 * Valid double height lines depend on the LCDs number of rows.
Gabiuas 1:0ada46075897 2583 */
Gabiuas 1:0ada46075897 2584 void TextLCD_Base::setBigFont(LCDBigFont lines) {
Gabiuas 1:0ada46075897 2585
Gabiuas 1:0ada46075897 2586 switch (lines) {
Gabiuas 1:0ada46075897 2587 case None:
Gabiuas 1:0ada46075897 2588 switch (_ctrl) {
Gabiuas 1:0ada46075897 2589 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2590 case US2066_3V3 :
Gabiuas 1:0ada46075897 2591 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 2592 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2593 _writeCommand(0x1C); // Double Height, 0 0 0 1 UD2=1, UD1=1, X, DH'=0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2594 // Default
Gabiuas 1:0ada46075897 2595 _function = _function & ~0x04; // Set function, 0 0 1 DL N DH=0 RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2596 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2597 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2598 break; // end US2066
Gabiuas 1:0ada46075897 2599
Gabiuas 1:0ada46075897 2600 default:
Gabiuas 1:0ada46075897 2601 break; // end default
Gabiuas 1:0ada46075897 2602 } // end switch _ctrl
Gabiuas 1:0ada46075897 2603 break; // end None
Gabiuas 1:0ada46075897 2604
Gabiuas 1:0ada46075897 2605 case TopLine:
Gabiuas 1:0ada46075897 2606 if (_nr_rows < 2) return; //Sanity check
Gabiuas 1:0ada46075897 2607
Gabiuas 1:0ada46075897 2608 switch (_ctrl) {
Gabiuas 1:0ada46075897 2609 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2610 case US2066_3V3 :
Gabiuas 1:0ada46075897 2611 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 2612 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2613 _writeCommand(0x1C); // Double Height, 0 0 0 1 UD2=1, UD1=1, X, DH'=0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2614 // Default
Gabiuas 1:0ada46075897 2615 _function = _function | 0x04; // Set function, 0 0 1 DL N DH=1 RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2616 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2617 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2618 break; // end US2066, SSD1803
Gabiuas 1:0ada46075897 2619
Gabiuas 1:0ada46075897 2620 default:
Gabiuas 1:0ada46075897 2621 break; // end default
Gabiuas 1:0ada46075897 2622 } // end switch _ctrl
Gabiuas 1:0ada46075897 2623 break; // end TopLine
Gabiuas 1:0ada46075897 2624
Gabiuas 1:0ada46075897 2625 case CenterLine:
Gabiuas 1:0ada46075897 2626 if (_nr_rows != 4) return; //Sanity check
Gabiuas 1:0ada46075897 2627
Gabiuas 1:0ada46075897 2628 switch (_ctrl) {
Gabiuas 1:0ada46075897 2629 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2630 case US2066_3V3 :
Gabiuas 1:0ada46075897 2631 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 2632 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2633 _writeCommand(0x14); // Double Height, 0 0 0 1 UD2=0, UD1=1, X, DH'=0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2634 // Default
Gabiuas 1:0ada46075897 2635 _function = _function | 0x04; // Set function, 0 0 1 DL N DH=1 RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2636 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2637 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2638 break; // end US2066, SSD1803
Gabiuas 1:0ada46075897 2639
Gabiuas 1:0ada46075897 2640 default:
Gabiuas 1:0ada46075897 2641 break; // end default
Gabiuas 1:0ada46075897 2642 } // end switch _ctrl
Gabiuas 1:0ada46075897 2643 break; // end CenterLine
Gabiuas 1:0ada46075897 2644
Gabiuas 1:0ada46075897 2645 case BottomLine:
Gabiuas 1:0ada46075897 2646 if (_nr_rows < 3) return; //Sanity check
Gabiuas 1:0ada46075897 2647
Gabiuas 1:0ada46075897 2648 switch (_ctrl) {
Gabiuas 1:0ada46075897 2649 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2650 case US2066_3V3 :
Gabiuas 1:0ada46075897 2651 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 2652 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2653 if (_nr_rows == 3) {
Gabiuas 1:0ada46075897 2654 _writeCommand(0x14); // Double Height, 0 0 0 1 UD2=0, UD1=1, X, DH'=0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2655 }
Gabiuas 1:0ada46075897 2656 else {
Gabiuas 1:0ada46075897 2657 _writeCommand(0x10); // Double Height, 0 0 0 1 UD2=0, UD1=0, X, DH'=0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2658 }
Gabiuas 1:0ada46075897 2659 _function = _function | 0x04; // Set function, 0 0 1 DL N DH=1 RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2660 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2661 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2662 break; // end US2066, SSD1803
Gabiuas 1:0ada46075897 2663
Gabiuas 1:0ada46075897 2664 default:
Gabiuas 1:0ada46075897 2665 break; // end default
Gabiuas 1:0ada46075897 2666 } // end switch _ctrl
Gabiuas 1:0ada46075897 2667 break; // end BottomLine
Gabiuas 1:0ada46075897 2668
Gabiuas 1:0ada46075897 2669 case TopBottomLine:
Gabiuas 1:0ada46075897 2670 if (_nr_rows != 4) return; //Sanity check
Gabiuas 1:0ada46075897 2671
Gabiuas 1:0ada46075897 2672 switch (_ctrl) {
Gabiuas 1:0ada46075897 2673 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2674 case US2066_3V3 :
Gabiuas 1:0ada46075897 2675 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 2676 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2677 _writeCommand(0x18); // Double Height, 0 0 0 1 UD2=1, UD1=0, X, DH'=0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2678 // Default
Gabiuas 1:0ada46075897 2679 _function = _function | 0x04; // Set function, 0 0 1 DL N DH=1 RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2680 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
Gabiuas 1:0ada46075897 2681 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2682 break; // end US2066, SSD1803
Gabiuas 1:0ada46075897 2683
Gabiuas 1:0ada46075897 2684 default:
Gabiuas 1:0ada46075897 2685 break; // end default
Gabiuas 1:0ada46075897 2686 } // end switch _ctrl
Gabiuas 1:0ada46075897 2687 break; // end TopBottomLine
Gabiuas 1:0ada46075897 2688
Gabiuas 1:0ada46075897 2689 } // end switch lines
Gabiuas 1:0ada46075897 2690
Gabiuas 1:0ada46075897 2691 } // end setBigFont()
Gabiuas 1:0ada46075897 2692 #endif
Gabiuas 1:0ada46075897 2693
Gabiuas 1:0ada46075897 2694
Gabiuas 1:0ada46075897 2695 #if (LCD_FONTSEL == 1)
Gabiuas 1:0ada46075897 2696 /** Set Font
Gabiuas 1:0ada46075897 2697 * setFont method is supported by some compatible devices (eg SSD1803, US2066, ST7070)
Gabiuas 1:0ada46075897 2698 *
Gabiuas 1:0ada46075897 2699 * @param LCDFont font The selected Font
Gabiuas 1:0ada46075897 2700 * @return none
Gabiuas 1:0ada46075897 2701 *
Gabiuas 1:0ada46075897 2702 * Note: most controllers support only one font and the hardware specific
Gabiuas 1:0ada46075897 2703 * fonttable is encoded as part of the controller type number (eg PCF21XXC or PCF21XXR).
Gabiuas 1:0ada46075897 2704 * Some controllers support multiple tables that can only be selected by logic levels on a few pins.
Gabiuas 1:0ada46075897 2705 * Some controllers also support runtime fontable switching through a specific instruction
Gabiuas 1:0ada46075897 2706 */
Gabiuas 1:0ada46075897 2707 void TextLCD_Base::setFont(LCDFont font) {
Gabiuas 1:0ada46075897 2708
Gabiuas 1:0ada46075897 2709 switch (font) {
Gabiuas 1:0ada46075897 2710 case Font_RA: // UK/EU
Gabiuas 1:0ada46075897 2711 switch (_ctrl) {
Gabiuas 1:0ada46075897 2712 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2713 case US2066_3V3 :
Gabiuas 1:0ada46075897 2714 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 2715 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2716 _writeCommand(0x72); // ROM Select command, 0 1 1 1 0 0 1 0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2717 _writeData(0x00); // ROM_0 Select data, 0 0 0 0 ROM2 ROM1 0 0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2718
Gabiuas 1:0ada46075897 2719 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS (Std Instr Set)
Gabiuas 1:0ada46075897 2720
Gabiuas 1:0ada46075897 2721 _font = font; // Save active font
Gabiuas 1:0ada46075897 2722 break; // end SSD1803, US2066
Gabiuas 1:0ada46075897 2723
Gabiuas 1:0ada46075897 2724 case ST7070:
Gabiuas 1:0ada46075897 2725 //ST7070 does not support Cursorblink. The P bit selects the font instead !
Gabiuas 1:0ada46075897 2726 _writeCommand(0x08 | _currentMode | (_currentCursor & 0x02));
Gabiuas 1:0ada46075897 2727
Gabiuas 1:0ada46075897 2728 _font = font; // Save active font
Gabiuas 1:0ada46075897 2729 break; // end ST7070
Gabiuas 1:0ada46075897 2730
Gabiuas 1:0ada46075897 2731 default:
Gabiuas 1:0ada46075897 2732 break; // end default
Gabiuas 1:0ada46075897 2733 } // end switch _ctrl
Gabiuas 1:0ada46075897 2734 break; // end Font_RA
Gabiuas 1:0ada46075897 2735
Gabiuas 1:0ada46075897 2736 case Font_RB: // UK/CYR
Gabiuas 1:0ada46075897 2737 switch (_ctrl) {
Gabiuas 1:0ada46075897 2738 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2739 case US2066_3V3 :
Gabiuas 1:0ada46075897 2740 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 2741 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2742 _writeCommand(0x72); // ROM Select command, 0 1 1 1 0 0 1 0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2743 _writeData(0x04); // ROM_0 Select data, 0 0 0 0 ROM2 ROM1 0 0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2744
Gabiuas 1:0ada46075897 2745 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS (Std Instr Set)
Gabiuas 1:0ada46075897 2746
Gabiuas 1:0ada46075897 2747 _font = font; // Save active font
Gabiuas 1:0ada46075897 2748 break; // end SSD1803, US2066
Gabiuas 1:0ada46075897 2749
Gabiuas 1:0ada46075897 2750 case ST7070:
Gabiuas 1:0ada46075897 2751 //ST7070 does not support Cursorblink. The P bit selects the font instead !
Gabiuas 1:0ada46075897 2752 _writeCommand(0x08 | _currentMode | (_currentCursor & 0x02) | 0x01);
Gabiuas 1:0ada46075897 2753
Gabiuas 1:0ada46075897 2754 _font = font; // Save active font
Gabiuas 1:0ada46075897 2755 break; // end ST7070
Gabiuas 1:0ada46075897 2756
Gabiuas 1:0ada46075897 2757 default:
Gabiuas 1:0ada46075897 2758 break; // end default
Gabiuas 1:0ada46075897 2759 } // end switch _ctrl
Gabiuas 1:0ada46075897 2760 break; // end Font_RB
Gabiuas 1:0ada46075897 2761
Gabiuas 1:0ada46075897 2762 case Font_0: //Font_O is pretty similar to ROM_C
Gabiuas 1:0ada46075897 2763 case Font_RC: // UK/JAP
Gabiuas 1:0ada46075897 2764 switch (_ctrl) {
Gabiuas 1:0ada46075897 2765 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 2766 case US2066_3V3 :
Gabiuas 1:0ada46075897 2767 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
Gabiuas 1:0ada46075897 2768 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2769 _writeCommand(0x72); // ROM Select command, 0 1 1 1 0 0 1 0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2770 _writeData(0x08); // ROM_0 Select data, 0 0 0 0 ROM2 ROM1 0 0 (Ext Instr Set)
Gabiuas 1:0ada46075897 2771
Gabiuas 1:0ada46075897 2772 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS (Std Instr Set)
Gabiuas 1:0ada46075897 2773
Gabiuas 1:0ada46075897 2774 _font = font; // Save active font
Gabiuas 1:0ada46075897 2775 break; // end SSD1803, US2066
Gabiuas 1:0ada46075897 2776
Gabiuas 1:0ada46075897 2777 default:
Gabiuas 1:0ada46075897 2778 break; // end default
Gabiuas 1:0ada46075897 2779 } // end switch _ctrl
Gabiuas 1:0ada46075897 2780 break; // end Font_RC
Gabiuas 1:0ada46075897 2781 } // end switch font
Gabiuas 1:0ada46075897 2782
Gabiuas 1:0ada46075897 2783 //SSD1803 seems to screw up cursor position after selecting new font. Restore to make sure...
Gabiuas 1:0ada46075897 2784 //Set next memoryaddress, make sure cursor blinks at next location
Gabiuas 1:0ada46075897 2785 int addr = getAddress(_column, _row);
Gabiuas 1:0ada46075897 2786 _writeCommand(0x80 | addr);
Gabiuas 1:0ada46075897 2787
Gabiuas 1:0ada46075897 2788 }
Gabiuas 1:0ada46075897 2789 #endif
Gabiuas 1:0ada46075897 2790
Gabiuas 1:0ada46075897 2791
Gabiuas 1:0ada46075897 2792 #if(LCD_ICON==1)
Gabiuas 1:0ada46075897 2793 /** Set Icons
Gabiuas 1:0ada46075897 2794 *
Gabiuas 1:0ada46075897 2795 * @param unsigned char idx The Index of the icon pattern (0..15) for KS0073 and similar controllers
Gabiuas 1:0ada46075897 2796 * and Index (0..31) for PCF2103 and similar controllers
Gabiuas 1:0ada46075897 2797 * @param unsigned char data The bitpattern for the icons (6 lsb for KS0073 bitpattern (5 lsb for KS0078) and 2 msb for blinkmode)
Gabiuas 1:0ada46075897 2798 * The bitpattern for the PCF2103 icons is 5 lsb (UDC 0..2) and 5 lsb for blinkmode (UDC 4..6)
Gabiuas 1:0ada46075897 2799 */
Gabiuas 1:0ada46075897 2800 void TextLCD_Base::setIcon(unsigned char idx, unsigned char data) {
Gabiuas 1:0ada46075897 2801 // Blinking icons are enabled when a specific controlbit (BE) is set.
Gabiuas 1:0ada46075897 2802 // The blinking pixels in the icons can be controlled by setting additional bits in the icon bitpattern.
Gabiuas 1:0ada46075897 2803 // Icons are defined by a byte bitpattern. The P0..P5 form the Icon pattern for KS0073, and P0..P4 for KS0078
Gabiuas 1:0ada46075897 2804 // P7 P6 P5 P4 P3 P2 P1 P0
Gabiuas 1:0ada46075897 2805 // 0 B1 B0 0 0 1 1 1 0
Gabiuas 1:0ada46075897 2806 // 1 B1 B0 1 1 0 0 0 1
Gabiuas 1:0ada46075897 2807 // .............
Gabiuas 1:0ada46075897 2808 // 15 B1 B0 1 1 0 0 0 1
Gabiuas 1:0ada46075897 2809 //
Gabiuas 1:0ada46075897 2810 // Bit 6 and Bit 7 in the pattern will control the blinking mode when Blink is enabled through BE.
Gabiuas 1:0ada46075897 2811 // B1 B0 Mode
Gabiuas 1:0ada46075897 2812 // 0 0 No Blinking for this icon row
Gabiuas 1:0ada46075897 2813 // 0 1 Enabled pixels in P5 will blink
Gabiuas 1:0ada46075897 2814 // 1 x Enabled pixels in P0..P5 will blink
Gabiuas 1:0ada46075897 2815 //
Gabiuas 1:0ada46075897 2816 // Note: the PCF2103 and PCF2113 use UDCs to set Icons
Gabiuas 1:0ada46075897 2817 // 3 x 8 rows x 5 bits = 120 bits Icons for Normal pattern (UDC 0..2) and
Gabiuas 1:0ada46075897 2818 // 3 x 8 rows x 5 bits = 120 bits Icons for Blink pattern (UDC 4..6)
Gabiuas 1:0ada46075897 2819 // Note: the PCF2119 uses UDCs to set Icons
Gabiuas 1:0ada46075897 2820 // 4 x 8 rows x 5 bits = 160 bits Icons for Normal pattern (UDC 0..3) and
Gabiuas 1:0ada46075897 2821 // 4 x 8 rows x 5 bits = 160 bits Icons for Blink pattern (UDC 4..7)
Gabiuas 1:0ada46075897 2822
Gabiuas 1:0ada46075897 2823 switch (_ctrl) {
Gabiuas 1:0ada46075897 2824 case KS0073:
Gabiuas 1:0ada46075897 2825 case KS0078:
Gabiuas 1:0ada46075897 2826 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N RE(1) BE LP
Gabiuas 1:0ada46075897 2827 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2828 _writeCommand(0x40 | (idx & 0x0F)); // Set Icon Address, mask Address to valid range (Ext Instr Set)
Gabiuas 1:0ada46075897 2829
Gabiuas 1:0ada46075897 2830 _writeData(data); // Set Icon pattern (Ext Instr Set)
Gabiuas 1:0ada46075897 2831
Gabiuas 1:0ada46075897 2832 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N RE(0) DH REV Select Instruction Set 0
Gabiuas 1:0ada46075897 2833 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2834 break; // end KS0073, KS0078
Gabiuas 1:0ada46075897 2835
Gabiuas 1:0ada46075897 2836 case ST7032_3V3:
Gabiuas 1:0ada46075897 2837 case ST7032_5V:
Gabiuas 1:0ada46075897 2838 case SPLC792A_3V3:
Gabiuas 1:0ada46075897 2839 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N F 0 IS=1 Select Instr Set = 1
Gabiuas 1:0ada46075897 2840 _writeCommand(0x40 | (idx & 0x0F)); // Set Icon Address, mask Address to valid range (Instr Set 1)
Gabiuas 1:0ada46075897 2841
Gabiuas 1:0ada46075897 2842 _writeData(data & 0x1F); // Set Icon pattern, no blink support (Instr Set 1)
Gabiuas 1:0ada46075897 2843
Gabiuas 1:0ada46075897 2844 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N RE(0) DH REV Select Instruction Set 0
Gabiuas 1:0ada46075897 2845 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2846 break; // end ST7032
Gabiuas 1:0ada46075897 2847
Gabiuas 1:0ada46075897 2848 case ST7036_3V3:
Gabiuas 1:0ada46075897 2849 case ST7036_5V:
Gabiuas 1:0ada46075897 2850 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N DH IS2,IS1 = 01 (Select Instr Set = 1)
Gabiuas 1:0ada46075897 2851 _writeCommand(0x40 | (idx & 0x0F)); // Set Icon Address, mask Address to valid range (Instr Set 1)
Gabiuas 1:0ada46075897 2852
Gabiuas 1:0ada46075897 2853 _writeData(data & 0x1F); // Set Icon pattern, no blink support (Instr Set 1)
Gabiuas 1:0ada46075897 2854
Gabiuas 1:0ada46075897 2855 _writeCommand(0x20 | _function); // Set function, IS2,IS1 = 00 (Select Instr Set = 0)
Gabiuas 1:0ada46075897 2856 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2857 break; // end ST7036
Gabiuas 1:0ada46075897 2858
Gabiuas 1:0ada46075897 2859 case SSD1803_3V3:
Gabiuas 1:0ada46075897 2860 // case SSD1803_5V:
Gabiuas 1:0ada46075897 2861 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N DH RE(0) IS
Gabiuas 1:0ada46075897 2862 // Select Instruction Set 1
Gabiuas 1:0ada46075897 2863 _writeCommand(0x40 | (idx & 0x0F)); // Set Icon Address, mask Address to valid range (Instr Set = 1)
Gabiuas 1:0ada46075897 2864 _writeData(data); // Set Icon pattern (Instr Set = 1)
Gabiuas 1:0ada46075897 2865
Gabiuas 1:0ada46075897 2866 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS
Gabiuas 1:0ada46075897 2867 // Select IS=0
Gabiuas 1:0ada46075897 2868 break; // end SSD1803
Gabiuas 1:0ada46075897 2869
Gabiuas 1:0ada46075897 2870 case PCF2103_3V3:
Gabiuas 1:0ada46075897 2871 case PCF2113_3V3:
Gabiuas 1:0ada46075897 2872 case PCF2119_3V3:
Gabiuas 1:0ada46075897 2873 case PCF2119R_3V3:
Gabiuas 1:0ada46075897 2874 // Store UDC/Icon pattern for PCF2103 and PCF2113:
Gabiuas 1:0ada46075897 2875 // 3 x 8 rows x 5 bits = 120 bits for Normal pattern (UDC 0..2) and
Gabiuas 1:0ada46075897 2876 // 3 x 8 rows x 5 bits = 120 bits for Blink pattern (UDC 4..6)
Gabiuas 1:0ada46075897 2877 // Store UDC/Icon pattern for PCF2119:
Gabiuas 1:0ada46075897 2878 // 4 x 8 rows x 5 bits = 160 bits for Normal pattern (UDC 0..3) and
Gabiuas 1:0ada46075897 2879 // 4 x 8 rows x 5 bits = 160 bits for Blink pattern (UDC 4..7)
Gabiuas 1:0ada46075897 2880 _writeCommand(0x40 | (idx & 0x3F)); //Set CG-RAM address, 8 sequential locations needed per UDC
Gabiuas 1:0ada46075897 2881 _writeData(data); // Set Icon pattern (Instr Set = 1)
Gabiuas 1:0ada46075897 2882 break; // case PCF2103_3V3 Controller
Gabiuas 1:0ada46075897 2883
Gabiuas 1:0ada46075897 2884 default:
Gabiuas 1:0ada46075897 2885 break; // end default
Gabiuas 1:0ada46075897 2886 } // end switch _ctrl
Gabiuas 1:0ada46075897 2887
Gabiuas 1:0ada46075897 2888 //Select DD RAM again for current LCD controller and restore the addresspointer
Gabiuas 1:0ada46075897 2889 int addr = getAddress(_column, _row);
Gabiuas 1:0ada46075897 2890 _writeCommand(0x80 | addr);
Gabiuas 1:0ada46075897 2891
Gabiuas 1:0ada46075897 2892 } // end setIcon()
Gabiuas 1:0ada46075897 2893
Gabiuas 1:0ada46075897 2894 /** Clear Icons
Gabiuas 1:0ada46075897 2895 *
Gabiuas 1:0ada46075897 2896 * @param none
Gabiuas 1:0ada46075897 2897 * @return none
Gabiuas 1:0ada46075897 2898 */
Gabiuas 1:0ada46075897 2899 //@TODO Add support for 40x4 dual controller
Gabiuas 1:0ada46075897 2900 void TextLCD_Base::clrIcon() {
Gabiuas 1:0ada46075897 2901 // Icons are defined by a byte bitpattern. The P0..P5 form the Icon pattern for KS0073, and P0..P4 for KS0078
Gabiuas 1:0ada46075897 2902 // P7 P6 P5 P4 P3 P2 P1 P0
Gabiuas 1:0ada46075897 2903 // 0 B1 B0 0 0 0 0 0 0
Gabiuas 1:0ada46075897 2904 // 1 B1 B0 0 0 0 0 0 0
Gabiuas 1:0ada46075897 2905 // .............
Gabiuas 1:0ada46075897 2906 // 15 B1 B0 0 0 0 0 0 0
Gabiuas 1:0ada46075897 2907 //
Gabiuas 1:0ada46075897 2908 // Bit 6 and Bit 7 in the pattern will control the blinking mode when Blink is enabled through BE.
Gabiuas 1:0ada46075897 2909 // B1 B0 Mode
Gabiuas 1:0ada46075897 2910 // 0 0 No Blinking for this icon row
Gabiuas 1:0ada46075897 2911 // 0 1 Enabled pixels in P5 will blink
Gabiuas 1:0ada46075897 2912 // 1 x Enabled pixels in P0..P5 will blink
Gabiuas 1:0ada46075897 2913 //
Gabiuas 1:0ada46075897 2914 // Note: the PCF2103 and PCF2113 use UDCs to set Icons
Gabiuas 1:0ada46075897 2915 // 3 x 8 rows x 5 bits = 120 bits Icons for Normal pattern (UDC 0..2) and
Gabiuas 1:0ada46075897 2916 // 3 x 8 rows x 5 bits = 120 bits Icons for Blink pattern (UDC 4..6)
Gabiuas 1:0ada46075897 2917 // Note: the PCF2119 uses UDCs to set Icons
Gabiuas 1:0ada46075897 2918 // 4 x 8 rows x 5 bits = 160 bits Icons for Normal pattern (UDC 0..3) and
Gabiuas 1:0ada46075897 2919 // 4 x 8 rows x 5 bits = 160 bits Icons for Blink pattern (UDC 4..7)
Gabiuas 1:0ada46075897 2920 int idx;
Gabiuas 1:0ada46075897 2921
Gabiuas 1:0ada46075897 2922 switch (_ctrl) {
Gabiuas 1:0ada46075897 2923 case KS0073:
Gabiuas 1:0ada46075897 2924 case KS0078:
Gabiuas 1:0ada46075897 2925 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N RE(1) BE LP
Gabiuas 1:0ada46075897 2926 // Select Extended Instruction Set
Gabiuas 1:0ada46075897 2927 for (idx=0; idx<16; idx++) {
Gabiuas 1:0ada46075897 2928 _writeCommand(0x40 | idx); // Set Icon Address, mask Address to valid range (Ext Instr Set)
Gabiuas 1:0ada46075897 2929 _writeData(0x00); // Clear Icon pattern (Ext Instr Set)
Gabiuas 1:0ada46075897 2930 }
Gabiuas 1:0ada46075897 2931 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N RE(0) DH REV Select Std Instruction Set
Gabiuas 1:0ada46075897 2932 // Select Std Instr set
Gabiuas 1:0ada46075897 2933 break; // end KS0073, KS0078
Gabiuas 1:0ada46075897 2934
Gabiuas 1:0ada46075897 2935 case ST7032_3V3:
Gabiuas 1:0ada46075897 2936 case ST7032_5V:
Gabiuas 1:0ada46075897 2937 case SPLC792A_3V3:
Gabiuas 1:0ada46075897 2938 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N F 0 IS=1 Select Instr Set = 1
Gabiuas 1:0ada46075897 2939
Gabiuas 1:0ada46075897 2940 for (idx=0; idx<16; idx++) {
Gabiuas 1:0ada46075897 2941 _writeCommand(0x40 | idx); // Set Icon Address, mask Address to valid range (Instr Set 1)
Gabiuas 1:0ada46075897 2942 _writeData(0x00); // Clear Icon pattern (Instr Set 1)
Gabiuas 1:0ada46075897 2943 }
Gabiuas 1:0ada46075897 2944
Gabiuas 1:0ada46075897 2945 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N RE(0) DH REV Select Instruction Set 0
Gabiuas 1:0ada46075897 2946 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2947 break; // end ST7032
Gabiuas 1:0ada46075897 2948
Gabiuas 1:0ada46075897 2949 case ST7036_3V3:
Gabiuas 1:0ada46075897 2950 case ST7036_5V:
Gabiuas 1:0ada46075897 2951 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N DH IS2,IS1 = 01 (Select Instr Set = 1)
Gabiuas 1:0ada46075897 2952
Gabiuas 1:0ada46075897 2953 for (idx=0; idx<16; idx++) {
Gabiuas 1:0ada46075897 2954 _writeCommand(0x40 | idx); // Set Icon Address, mask Address to valid range (Instr Set 1)
Gabiuas 1:0ada46075897 2955 _writeData(0x00); // Clear Icon pattern (Instr Set 1)
Gabiuas 1:0ada46075897 2956 }
Gabiuas 1:0ada46075897 2957
Gabiuas 1:0ada46075897 2958 _writeCommand(0x20 | _function); // Set function, IS2,IS1 = 00 (Select Instr Set = 0)
Gabiuas 1:0ada46075897 2959 // Select Std Instr set, Select IS=0
Gabiuas 1:0ada46075897 2960 break; // end ST7036
Gabiuas 1:0ada46075897 2961
Gabiuas 1:0ada46075897 2962 case SSD1803_3V3:
Gabiuas 1:0ada46075897 2963 // case SSD1803_5V:
Gabiuas 1:0ada46075897 2964 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N DH RE(0) IS
Gabiuas 1:0ada46075897 2965 // Select Instruction Set 1
Gabiuas 1:0ada46075897 2966 for (idx=0; idx<16; idx++) {
Gabiuas 1:0ada46075897 2967 _writeCommand(0x40 | idx); // Set Icon Address, mask Address to valid range (Ext Instr Set)
Gabiuas 1:0ada46075897 2968 _writeData(0x00); // Clear Icon pattern (Ext Instr Set)
Gabiuas 1:0ada46075897 2969 }
Gabiuas 1:0ada46075897 2970 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS
Gabiuas 1:0ada46075897 2971 // Select IS=0
Gabiuas 1:0ada46075897 2972 break; // end SSD1803
Gabiuas 1:0ada46075897 2973
Gabiuas 1:0ada46075897 2974 case PCF2103_3V3:
Gabiuas 1:0ada46075897 2975 case PCF2113_3V3:
Gabiuas 1:0ada46075897 2976 // PCF2103 and PCF2113 use part of the UDC RAM to control Icons
Gabiuas 1:0ada46075897 2977 // Select CG RAM
Gabiuas 1:0ada46075897 2978
Gabiuas 1:0ada46075897 2979 _writeCommand(0x40 | (0 * 8)); //Set CG-RAM address, 8 sequential locations needed per UDC
Gabiuas 1:0ada46075897 2980 // Store UDC/Icon pattern:
Gabiuas 1:0ada46075897 2981 // 3 x 8 rows x 5 bits = 120 bits for Normal pattern (UDC 0..2) and
Gabiuas 1:0ada46075897 2982 for (int i=0; i<(3 * 8); i++) {
Gabiuas 1:0ada46075897 2983 // _writeData(0x1F); // All On
Gabiuas 1:0ada46075897 2984 _writeData(0x00); // All Off
Gabiuas 1:0ada46075897 2985 }
Gabiuas 1:0ada46075897 2986
Gabiuas 1:0ada46075897 2987 _writeCommand(0x40 | (4 * 8)); //Set CG-RAM address, 8 sequential locations needed per UDC
Gabiuas 1:0ada46075897 2988 // 3 x 8 rows x 5 bits = 120 bits for Blink pattern (UDC 4..6)
Gabiuas 1:0ada46075897 2989 for (int i=0; i<(3 * 8); i++) {
Gabiuas 1:0ada46075897 2990 // _writeData(0x1F); // All On
Gabiuas 1:0ada46075897 2991 _writeData(0x00); // All Off
Gabiuas 1:0ada46075897 2992 }
Gabiuas 1:0ada46075897 2993 break; // case PCF2103_3V3 Controller
Gabiuas 1:0ada46075897 2994
Gabiuas 1:0ada46075897 2995 case PCF2119_3V3:
Gabiuas 1:0ada46075897 2996 case PCF2119R_3V3:
Gabiuas 1:0ada46075897 2997 // PCF2119 uses part of the UDC RAM to control Icons
Gabiuas 1:0ada46075897 2998 // Select CG RAM
Gabiuas 1:0ada46075897 2999
Gabiuas 1:0ada46075897 3000 _writeCommand(0x40 | (0 * 8)); //Set CG-RAM address, 8 sequential locations needed per UDC
Gabiuas 1:0ada46075897 3001 // Store UDC/Icon pattern:
Gabiuas 1:0ada46075897 3002 // 4 x 8 rows x 5 bits = 160 bits for Normal pattern (UDC 0..3) and
Gabiuas 1:0ada46075897 3003 for (int i=0; i<(4 * 8); i++) {
Gabiuas 1:0ada46075897 3004 // _writeData(0x1F); // All On
Gabiuas 1:0ada46075897 3005 _writeData(0x00); // All Off
Gabiuas 1:0ada46075897 3006 }
Gabiuas 1:0ada46075897 3007
Gabiuas 1:0ada46075897 3008 _writeCommand(0x40 | (4 * 8)); //Set CG-RAM address, 8 sequential locations needed per UDC
Gabiuas 1:0ada46075897 3009 // 4 x 8 rows x 5 bits = 160 bits for Blink pattern (UDC 4..7)
Gabiuas 1:0ada46075897 3010 for (int i=0; i<(4 * 8); i++) {
Gabiuas 1:0ada46075897 3011 // _writeData(0x1F); // All On
Gabiuas 1:0ada46075897 3012 _writeData(0x00); // All Off
Gabiuas 1:0ada46075897 3013 }
Gabiuas 1:0ada46075897 3014 break; // case PCF2119_3V3 Controller
Gabiuas 1:0ada46075897 3015
Gabiuas 1:0ada46075897 3016 default:
Gabiuas 1:0ada46075897 3017 break; // end default
Gabiuas 1:0ada46075897 3018 } // end switch _ctrl
Gabiuas 1:0ada46075897 3019
Gabiuas 1:0ada46075897 3020 //Select DD RAM again for current LCD controller and restore the addresspointer
Gabiuas 1:0ada46075897 3021 int addr = getAddress(_column, _row);
Gabiuas 1:0ada46075897 3022 _writeCommand(0x80 | addr);
Gabiuas 1:0ada46075897 3023 } //end clrIcon()
Gabiuas 1:0ada46075897 3024 #endif
Gabiuas 1:0ada46075897 3025
Gabiuas 1:0ada46075897 3026 #if(LCD_INVERT == 1)
Gabiuas 1:0ada46075897 3027 /** Set Invert
Gabiuas 1:0ada46075897 3028 * setInvert method is supported by some compatible devices (eg KS0073) to swap between black and white
Gabiuas 1:0ada46075897 3029 *
Gabiuas 1:0ada46075897 3030 * @param bool invertOn Invert on/off
Gabiuas 1:0ada46075897 3031 * @return none
Gabiuas 1:0ada46075897 3032 */
Gabiuas 1:0ada46075897 3033 //@TODO Add support for 40x4 dual controller
Gabiuas 1:0ada46075897 3034 void TextLCD_Base::setInvert(bool invertOn) {
Gabiuas 1:0ada46075897 3035
Gabiuas 1:0ada46075897 3036 if (invertOn) {
Gabiuas 1:0ada46075897 3037 // Controllers that support Invert
Gabiuas 1:0ada46075897 3038 switch (_ctrl) {
Gabiuas 1:0ada46075897 3039 case KS0073:
Gabiuas 1:0ada46075897 3040 case KS0078:
Gabiuas 1:0ada46075897 3041 _function = _function | 0x01; // Enable Invert
Gabiuas 1:0ada46075897 3042 _writeCommand(0x20 | _function); // Activate Invert (Std Instr Set)
Gabiuas 1:0ada46075897 3043 break;
Gabiuas 1:0ada46075897 3044 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 3045 // case SSD1803_5V :
Gabiuas 1:0ada46075897 3046 case US2066_3V3:
Gabiuas 1:0ada46075897 3047 // case USS2066_5V:
Gabiuas 1:0ada46075897 3048 _function_1 = _function_1 | 0x01; // Enable Invert
Gabiuas 1:0ada46075897 3049 // Set function, 0 0 1 DL N BE RE(1) REV (SSD1803)
Gabiuas 1:0ada46075897 3050 // Set function, 0 0 1 X N BE RE(1) REV (US2066)
Gabiuas 1:0ada46075897 3051 _writeCommand(0x20 | _function_1); // Activate Invert (Ext Instr Set)
Gabiuas 1:0ada46075897 3052 _writeCommand(0x20 | _function); // Return to Std Instr Set
Gabiuas 1:0ada46075897 3053 break;
Gabiuas 1:0ada46075897 3054 default:
Gabiuas 1:0ada46075897 3055 //Unsupported feature for other controllers
Gabiuas 1:0ada46075897 3056 break;
Gabiuas 1:0ada46075897 3057 } // end switch
Gabiuas 1:0ada46075897 3058 }
Gabiuas 1:0ada46075897 3059 else {
Gabiuas 1:0ada46075897 3060 // Controllers that support Invert
Gabiuas 1:0ada46075897 3061 switch (_ctrl) {
Gabiuas 1:0ada46075897 3062 case KS0073:
Gabiuas 1:0ada46075897 3063 case KS0078:
Gabiuas 1:0ada46075897 3064 _function = _function & ~0x01; // Disable Invert
Gabiuas 1:0ada46075897 3065 _writeCommand(0x20 | _function); // Disable Invert (Std Instr Set)
Gabiuas 1:0ada46075897 3066 break;
Gabiuas 1:0ada46075897 3067 case SSD1803_3V3 :
Gabiuas 1:0ada46075897 3068 // case SSD1803_5V :
Gabiuas 1:0ada46075897 3069 case US2066_3V3:
Gabiuas 1:0ada46075897 3070 // case USS2066_5V:
Gabiuas 1:0ada46075897 3071 _function_1 = _function_1 & ~0x01; // Disable Invert
Gabiuas 1:0ada46075897 3072 // Set function, 0 0 1 DL N BE RE(1) REV (SSD1803)
Gabiuas 1:0ada46075897 3073 // Set function, 0 0 1 X N BE RE(1) REV (US2066)
Gabiuas 1:0ada46075897 3074 _writeCommand(0x20 | _function_1); // Activate Invert (Ext Instr Set)
Gabiuas 1:0ada46075897 3075 _writeCommand(0x20 | _function); // Return to Std Instr Set
Gabiuas 1:0ada46075897 3076 break;
Gabiuas 1:0ada46075897 3077
Gabiuas 1:0ada46075897 3078 default:
Gabiuas 1:0ada46075897 3079 //Unsupported feature for other controllers
Gabiuas 1:0ada46075897 3080 break;
Gabiuas 1:0ada46075897 3081 } // end switch
Gabiuas 1:0ada46075897 3082 }
Gabiuas 1:0ada46075897 3083 } // end setInvert()
Gabiuas 1:0ada46075897 3084 #endif
Gabiuas 1:0ada46075897 3085
Gabiuas 1:0ada46075897 3086 //--------- End TextLCD_Base -----------
Gabiuas 1:0ada46075897 3087
Gabiuas 1:0ada46075897 3088
Gabiuas 1:0ada46075897 3089 //--------- Start TextLCD Bus -----------
Gabiuas 1:0ada46075897 3090
Gabiuas 1:0ada46075897 3091 /* Create a TextLCD interface for using regular mbed pins
Gabiuas 1:0ada46075897 3092 *
Gabiuas 1:0ada46075897 3093 * @param rs Instruction/data control line
Gabiuas 1:0ada46075897 3094 * @param e Enable line (clock)
Gabiuas 1:0ada46075897 3095 * @param d4-d7 Data lines for using as a 4-bit interface
Gabiuas 1:0ada46075897 3096 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Gabiuas 1:0ada46075897 3097 * @param bl Backlight control line (optional, default = NC)
Gabiuas 1:0ada46075897 3098 * @param e2 Enable2 line (clock for second controller, LCD40x4 only)
Gabiuas 1:0ada46075897 3099 * @param ctrl LCD controller (default = HD44780)
Gabiuas 1:0ada46075897 3100 */
Gabiuas 1:0ada46075897 3101 TextLCD::TextLCD(PinName rs, PinName e,
Gabiuas 1:0ada46075897 3102 PinName d4, PinName d5, PinName d6, PinName d7,
Gabiuas 1:0ada46075897 3103 LCDType type, PinName bl, PinName e2, LCDCtrl ctrl) :
Gabiuas 1:0ada46075897 3104 TextLCD_Base(type, ctrl),
Gabiuas 1:0ada46075897 3105 _rs(rs), _e(e), _d(d4, d5, d6, d7) {
Gabiuas 1:0ada46075897 3106
Gabiuas 1:0ada46075897 3107 // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access.
Gabiuas 1:0ada46075897 3108 if (bl != NC) {
Gabiuas 1:0ada46075897 3109 _bl = new DigitalOut(bl); //Construct new pin
Gabiuas 1:0ada46075897 3110 _bl->write(0); //Deactivate
Gabiuas 1:0ada46075897 3111 }
Gabiuas 1:0ada46075897 3112 else {
Gabiuas 1:0ada46075897 3113 // No Hardware Backlight pin
Gabiuas 1:0ada46075897 3114 _bl = NULL; //Construct dummy pin
Gabiuas 1:0ada46075897 3115 }
Gabiuas 1:0ada46075897 3116
Gabiuas 1:0ada46075897 3117 // The hardware Enable2 pin is only needed for LCD40x4. Test and make sure whether it exists or not to prevent illegal access.
Gabiuas 1:0ada46075897 3118 if (e2 != NC) {
Gabiuas 1:0ada46075897 3119 _e2 = new DigitalOut(e2); //Construct new pin
Gabiuas 1:0ada46075897 3120 _e2->write(0); //Deactivate
Gabiuas 1:0ada46075897 3121 }
Gabiuas 1:0ada46075897 3122 else {
Gabiuas 1:0ada46075897 3123 // No Hardware Enable pin
Gabiuas 1:0ada46075897 3124 _e2 = NULL; //Construct dummy pin
Gabiuas 1:0ada46075897 3125 }
Gabiuas 1:0ada46075897 3126
Gabiuas 1:0ada46075897 3127 _init(_LCD_DL_4); // Set Datalength to 4 bit for mbed bus interfaces
Gabiuas 1:0ada46075897 3128 }
Gabiuas 1:0ada46075897 3129
Gabiuas 1:0ada46075897 3130 /** Destruct a TextLCD interface for using regular mbed pins
Gabiuas 1:0ada46075897 3131 *
Gabiuas 1:0ada46075897 3132 * @param none
Gabiuas 1:0ada46075897 3133 * @return none
Gabiuas 1:0ada46075897 3134 */
Gabiuas 1:0ada46075897 3135 TextLCD::~TextLCD() {
Gabiuas 1:0ada46075897 3136 if (_bl != NULL) {delete _bl;} // BL pin
Gabiuas 1:0ada46075897 3137 if (_e2 != NULL) {delete _e2;} // E2 pin
Gabiuas 1:0ada46075897 3138 }
Gabiuas 1:0ada46075897 3139
Gabiuas 1:0ada46075897 3140 /** Set E pin (or E2 pin)
Gabiuas 1:0ada46075897 3141 * Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 3142 * Default PinName value for E2 is NC, must be used as pointer to avoid issues with mbed lib and DigitalOut pins
Gabiuas 1:0ada46075897 3143 * @param value true or false
Gabiuas 1:0ada46075897 3144 * @return none
Gabiuas 1:0ada46075897 3145 */
Gabiuas 1:0ada46075897 3146 void TextLCD::_setEnable(bool value) {
Gabiuas 1:0ada46075897 3147
Gabiuas 1:0ada46075897 3148 if(_ctrl_idx==_LCDCtrl_0) {
Gabiuas 1:0ada46075897 3149 if (value) {
Gabiuas 1:0ada46075897 3150 _e = 1; // Set E bit
Gabiuas 1:0ada46075897 3151 }
Gabiuas 1:0ada46075897 3152 else {
Gabiuas 1:0ada46075897 3153 _e = 0; // Reset E bit
Gabiuas 1:0ada46075897 3154 }
Gabiuas 1:0ada46075897 3155 }
Gabiuas 1:0ada46075897 3156 else {
Gabiuas 1:0ada46075897 3157 if (value) {
Gabiuas 1:0ada46075897 3158 if (_e2 != NULL) {_e2->write(1);} //Set E2 bit
Gabiuas 1:0ada46075897 3159 }
Gabiuas 1:0ada46075897 3160 else {
Gabiuas 1:0ada46075897 3161 if (_e2 != NULL) {_e2->write(0);} //Reset E2 bit
Gabiuas 1:0ada46075897 3162 }
Gabiuas 1:0ada46075897 3163 }
Gabiuas 1:0ada46075897 3164 }
Gabiuas 1:0ada46075897 3165
Gabiuas 1:0ada46075897 3166 // Set RS pin
Gabiuas 1:0ada46075897 3167 // Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 3168 void TextLCD::_setRS(bool value) {
Gabiuas 1:0ada46075897 3169
Gabiuas 1:0ada46075897 3170 if (value) {
Gabiuas 1:0ada46075897 3171 _rs = 1; // Set RS bit
Gabiuas 1:0ada46075897 3172 }
Gabiuas 1:0ada46075897 3173 else {
Gabiuas 1:0ada46075897 3174 _rs = 0; // Reset RS bit
Gabiuas 1:0ada46075897 3175 }
Gabiuas 1:0ada46075897 3176 }
Gabiuas 1:0ada46075897 3177
Gabiuas 1:0ada46075897 3178 /** Set BL pin
Gabiuas 1:0ada46075897 3179 * Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 3180 * Default PinName value is NC, must be used as pointer to avoid issues with mbed lib and DigitalOut pins
Gabiuas 1:0ada46075897 3181 * @param value true or false
Gabiuas 1:0ada46075897 3182 * @return none
Gabiuas 1:0ada46075897 3183 */
Gabiuas 1:0ada46075897 3184 void TextLCD::_setBL(bool value) {
Gabiuas 1:0ada46075897 3185
Gabiuas 1:0ada46075897 3186 if (value) {
Gabiuas 1:0ada46075897 3187 if (_bl != NULL) {_bl->write(1);} //Set BL bit
Gabiuas 1:0ada46075897 3188 }
Gabiuas 1:0ada46075897 3189 else {
Gabiuas 1:0ada46075897 3190 if (_bl != NULL) {_bl->write(0);} //Reset BL bit
Gabiuas 1:0ada46075897 3191 }
Gabiuas 1:0ada46075897 3192 }
Gabiuas 1:0ada46075897 3193
Gabiuas 1:0ada46075897 3194 // Place the 4bit data on the databus
Gabiuas 1:0ada46075897 3195 // Used for mbed pins, I2C bus expander or SPI shifregister
Gabiuas 1:0ada46075897 3196 void TextLCD::_setData(int value) {
Gabiuas 1:0ada46075897 3197 _d = value & 0x0F; // Write Databits
Gabiuas 1:0ada46075897 3198 }
Gabiuas 1:0ada46075897 3199
Gabiuas 1:0ada46075897 3200 //----------- End TextLCD ---------------
Gabiuas 1:0ada46075897 3201
Gabiuas 1:0ada46075897 3202
Gabiuas 1:0ada46075897 3203 //--------- Start TextLCD_I2C -----------
Gabiuas 1:0ada46075897 3204 #if(LCD_I2C == 1) /* I2C Expander PCF8574/MCP23008 */
Gabiuas 1:0ada46075897 3205 /** Create a TextLCD interface using an I2C PC8574 (or PCF8574A) or MCP23008 portexpander
Gabiuas 1:0ada46075897 3206 *
Gabiuas 1:0ada46075897 3207 * @param i2c I2C Bus
Gabiuas 1:0ada46075897 3208 * @param deviceAddress I2C slave address (PCF8574, PCF8574A or MCP23008, default = 0x40)
Gabiuas 1:0ada46075897 3209 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Gabiuas 1:0ada46075897 3210 * @param ctrl LCD controller (default = HD44780)
Gabiuas 1:0ada46075897 3211 */
Gabiuas 1:0ada46075897 3212 TextLCD_I2C::TextLCD_I2C(I2C *i2c, char deviceAddress, LCDType type, LCDCtrl ctrl) :
Gabiuas 1:0ada46075897 3213 TextLCD_Base(type, ctrl),
Gabiuas 1:0ada46075897 3214 _i2c(i2c){
Gabiuas 1:0ada46075897 3215
Gabiuas 1:0ada46075897 3216 _slaveAddress = deviceAddress & 0xFE;
Gabiuas 1:0ada46075897 3217
Gabiuas 1:0ada46075897 3218 // Setup the I2C bus
Gabiuas 1:0ada46075897 3219 // The max bitrate for PCF8574 is 100kbit, the max bitrate for MCP23008 is 400kbit,
Gabiuas 1:0ada46075897 3220 _i2c->frequency(100000);
Gabiuas 1:0ada46075897 3221
Gabiuas 1:0ada46075897 3222 #if (MCP23008==1)
Gabiuas 1:0ada46075897 3223 // MCP23008 portexpander Init
Gabiuas 1:0ada46075897 3224 _writeRegister(IODIR, 0x00); // All pins are outputs
Gabiuas 1:0ada46075897 3225 _writeRegister(IPOL, 0x00); // No reverse polarity on inputs
Gabiuas 1:0ada46075897 3226 _writeRegister(GPINTEN, 0x00); // No interrupt on change of input pins
Gabiuas 1:0ada46075897 3227 _writeRegister(DEFVAL, 0x00); // Default value to compare against for interrupts
Gabiuas 1:0ada46075897 3228 _writeRegister(INTCON, 0x00); // No interrupt on changes, compare against previous pin value
Gabiuas 1:0ada46075897 3229 _writeRegister(IOCON, 0x20); // b1=0 - Interrupt polarity active low
Gabiuas 1:0ada46075897 3230 // b2=0 - Interrupt pin active driver output
Gabiuas 1:0ada46075897 3231 // b4=0 - Slew rate enable on SDA
Gabiuas 1:0ada46075897 3232 // b5=0 - Auto-increment on registeraddress
Gabiuas 1:0ada46075897 3233 // b5=1 - No auto-increment on registeraddress => needed for performance improved I2C expander mode
Gabiuas 1:0ada46075897 3234 _writeRegister(GPPU, 0x00); // No Pullup
Gabiuas 1:0ada46075897 3235 // INTF // Interrupt flags read (Read-Only)
Gabiuas 1:0ada46075897 3236 // INTCAP // Captured inputpins at time of interrupt (Read-Only)
Gabiuas 1:0ada46075897 3237 // _writeRegister(GPIO, 0x00); // Output/Input pins
Gabiuas 1:0ada46075897 3238 // _writeRegister(OLAT, 0x00); // Output Latch
Gabiuas 1:0ada46075897 3239
Gabiuas 1:0ada46075897 3240 // Init the portexpander bus
Gabiuas 1:0ada46075897 3241 _lcd_bus = LCD_BUS_I2C_DEF;
Gabiuas 1:0ada46075897 3242
Gabiuas 1:0ada46075897 3243 // write the new data to the portexpander
Gabiuas 1:0ada46075897 3244 _writeRegister(GPIO, _lcd_bus);
Gabiuas 1:0ada46075897 3245 #else
Gabiuas 1:0ada46075897 3246 // PCF8574 of PCF8574A portexpander
Gabiuas 1:0ada46075897 3247
Gabiuas 1:0ada46075897 3248 // Init the portexpander bus
Gabiuas 1:0ada46075897 3249 _lcd_bus = LCD_BUS_I2C_DEF;
Gabiuas 1:0ada46075897 3250
Gabiuas 1:0ada46075897 3251 // write the new data to the portexpander
Gabiuas 1:0ada46075897 3252 _i2c->write(_slaveAddress, &_lcd_bus, 1);
Gabiuas 1:0ada46075897 3253 #endif
Gabiuas 1:0ada46075897 3254
Gabiuas 1:0ada46075897 3255 _init(_LCD_DL_4); // Set Datalength to 4 bit for all serial expander interfaces
Gabiuas 1:0ada46075897 3256 }
Gabiuas 1:0ada46075897 3257
Gabiuas 1:0ada46075897 3258 // Set E bit (or E2 bit) in the databus shadowvalue
Gabiuas 1:0ada46075897 3259 // Used for mbed I2C bus expander
Gabiuas 1:0ada46075897 3260 void TextLCD_I2C::_setEnableBit(bool value) {
Gabiuas 1:0ada46075897 3261
Gabiuas 1:0ada46075897 3262 #if (LCD_TWO_CTRL == 1)
Gabiuas 1:0ada46075897 3263 if(_ctrl_idx==_LCDCtrl_0) {
Gabiuas 1:0ada46075897 3264 if (value) {
Gabiuas 1:0ada46075897 3265 _lcd_bus |= LCD_BUS_I2C_E; // Set E bit
Gabiuas 1:0ada46075897 3266 }
Gabiuas 1:0ada46075897 3267 else {
Gabiuas 1:0ada46075897 3268 _lcd_bus &= ~LCD_BUS_I2C_E; // Reset E bit
Gabiuas 1:0ada46075897 3269 }
Gabiuas 1:0ada46075897 3270 }
Gabiuas 1:0ada46075897 3271 else {
Gabiuas 1:0ada46075897 3272 if (value) {
Gabiuas 1:0ada46075897 3273 _lcd_bus |= LCD_BUS_I2C_E2; // Set E2 bit
Gabiuas 1:0ada46075897 3274 }
Gabiuas 1:0ada46075897 3275 else {
Gabiuas 1:0ada46075897 3276 _lcd_bus &= ~LCD_BUS_I2C_E2; // Reset E2bit
Gabiuas 1:0ada46075897 3277 }
Gabiuas 1:0ada46075897 3278 }
Gabiuas 1:0ada46075897 3279 #else
Gabiuas 1:0ada46075897 3280 // Support only one controller
Gabiuas 1:0ada46075897 3281 if (value) {
Gabiuas 1:0ada46075897 3282 _lcd_bus |= LCD_BUS_I2C_E; // Set E bit
Gabiuas 1:0ada46075897 3283 }
Gabiuas 1:0ada46075897 3284 else {
Gabiuas 1:0ada46075897 3285 _lcd_bus &= ~LCD_BUS_I2C_E; // Reset E bit
Gabiuas 1:0ada46075897 3286 }
Gabiuas 1:0ada46075897 3287
Gabiuas 1:0ada46075897 3288 #endif
Gabiuas 1:0ada46075897 3289 }
Gabiuas 1:0ada46075897 3290
Gabiuas 1:0ada46075897 3291 // Set E pin (or E2 pin)
Gabiuas 1:0ada46075897 3292 // Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 3293 void TextLCD_I2C::_setEnable(bool value) {
Gabiuas 1:0ada46075897 3294
Gabiuas 1:0ada46075897 3295 // Place the E or E2 bit data on the databus shadowvalue
Gabiuas 1:0ada46075897 3296 _setEnableBit(value);
Gabiuas 1:0ada46075897 3297
Gabiuas 1:0ada46075897 3298 #if (MCP23008==1)
Gabiuas 1:0ada46075897 3299 // MCP23008 portexpander
Gabiuas 1:0ada46075897 3300
Gabiuas 1:0ada46075897 3301 // write the new data to the portexpander
Gabiuas 1:0ada46075897 3302 _writeRegister(GPIO, _lcd_bus);
Gabiuas 1:0ada46075897 3303 #else
Gabiuas 1:0ada46075897 3304 // PCF8574 of PCF8574A portexpander
Gabiuas 1:0ada46075897 3305
Gabiuas 1:0ada46075897 3306 // write the new data to the I2C portexpander
Gabiuas 1:0ada46075897 3307 _i2c->write(_slaveAddress, &_lcd_bus, 1);
Gabiuas 1:0ada46075897 3308 #endif
Gabiuas 1:0ada46075897 3309 }
Gabiuas 1:0ada46075897 3310
Gabiuas 1:0ada46075897 3311
Gabiuas 1:0ada46075897 3312 // Set RS pin
Gabiuas 1:0ada46075897 3313 // Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 3314 void TextLCD_I2C::_setRS(bool value) {
Gabiuas 1:0ada46075897 3315
Gabiuas 1:0ada46075897 3316 if (value) {
Gabiuas 1:0ada46075897 3317 _lcd_bus |= LCD_BUS_I2C_RS; // Set RS bit
Gabiuas 1:0ada46075897 3318 }
Gabiuas 1:0ada46075897 3319 else {
Gabiuas 1:0ada46075897 3320 _lcd_bus &= ~LCD_BUS_I2C_RS; // Reset RS bit
Gabiuas 1:0ada46075897 3321 }
Gabiuas 1:0ada46075897 3322
Gabiuas 1:0ada46075897 3323 #if (MCP23008==1)
Gabiuas 1:0ada46075897 3324 // MCP23008 portexpander
Gabiuas 1:0ada46075897 3325
Gabiuas 1:0ada46075897 3326 // write the new data to the portexpander
Gabiuas 1:0ada46075897 3327 _writeRegister(GPIO, _lcd_bus);
Gabiuas 1:0ada46075897 3328 #else
Gabiuas 1:0ada46075897 3329 // PCF8574 of PCF8574A portexpander
Gabiuas 1:0ada46075897 3330
Gabiuas 1:0ada46075897 3331 // write the new data to the I2C portexpander
Gabiuas 1:0ada46075897 3332 _i2c->write(_slaveAddress, &_lcd_bus, 1);
Gabiuas 1:0ada46075897 3333 #endif
Gabiuas 1:0ada46075897 3334 }
Gabiuas 1:0ada46075897 3335
Gabiuas 1:0ada46075897 3336 // Set BL pin
Gabiuas 1:0ada46075897 3337 // Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 3338 void TextLCD_I2C::_setBL(bool value) {
Gabiuas 1:0ada46075897 3339
Gabiuas 1:0ada46075897 3340 if (value) {
Gabiuas 1:0ada46075897 3341 _lcd_bus |= LCD_BUS_I2C_BL; // Set BL bit
Gabiuas 1:0ada46075897 3342 }
Gabiuas 1:0ada46075897 3343 else {
Gabiuas 1:0ada46075897 3344 _lcd_bus &= ~LCD_BUS_I2C_BL; // Reset BL bit
Gabiuas 1:0ada46075897 3345 }
Gabiuas 1:0ada46075897 3346
Gabiuas 1:0ada46075897 3347 #if (MCP23008==1)
Gabiuas 1:0ada46075897 3348 // MCP23008 portexpander
Gabiuas 1:0ada46075897 3349
Gabiuas 1:0ada46075897 3350 // write the new data to the portexpander
Gabiuas 1:0ada46075897 3351 _writeRegister(GPIO, _lcd_bus);
Gabiuas 1:0ada46075897 3352 #else
Gabiuas 1:0ada46075897 3353 // PCF8574 of PCF8574A portexpander
Gabiuas 1:0ada46075897 3354
Gabiuas 1:0ada46075897 3355 // write the new data to the I2C portexpander
Gabiuas 1:0ada46075897 3356 _i2c->write(_slaveAddress, &_lcd_bus, 1);
Gabiuas 1:0ada46075897 3357 #endif
Gabiuas 1:0ada46075897 3358 }
Gabiuas 1:0ada46075897 3359
Gabiuas 1:0ada46075897 3360 #if(0)
Gabiuas 1:0ada46075897 3361 // New optimized v018
Gabiuas 1:0ada46075897 3362 // Test faster _writeByte 0.11s vs 0.27s for a 20x4 fillscreen (PCF8574), same as v018
Gabiuas 1:0ada46075897 3363 // Place the 4bit data in the databus shadowvalue
Gabiuas 1:0ada46075897 3364 // Used for mbed I2C bus expander
Gabiuas 1:0ada46075897 3365 const char _LCD_DATA_BITS[16] = {
Gabiuas 1:0ada46075897 3366 0x00,
Gabiuas 1:0ada46075897 3367 ( LCD_BUS_I2C_D4),
Gabiuas 1:0ada46075897 3368 ( LCD_BUS_I2C_D5 ),
Gabiuas 1:0ada46075897 3369 ( LCD_BUS_I2C_D5 | LCD_BUS_I2C_D4),
Gabiuas 1:0ada46075897 3370 ( LCD_BUS_I2C_D6 ),
Gabiuas 1:0ada46075897 3371 ( LCD_BUS_I2C_D6 | LCD_BUS_I2C_D4),
Gabiuas 1:0ada46075897 3372 ( LCD_BUS_I2C_D6 | LCD_BUS_I2C_D5 ),
Gabiuas 1:0ada46075897 3373 ( LCD_BUS_I2C_D6 | LCD_BUS_I2C_D5 | LCD_BUS_I2C_D4),
Gabiuas 1:0ada46075897 3374 (LCD_BUS_I2C_D7 ),
Gabiuas 1:0ada46075897 3375 (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D4),
Gabiuas 1:0ada46075897 3376 (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D5 ),
Gabiuas 1:0ada46075897 3377 (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D5 | LCD_BUS_I2C_D4),
Gabiuas 1:0ada46075897 3378 (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D6 ),
Gabiuas 1:0ada46075897 3379 (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D6 | LCD_BUS_I2C_D4),
Gabiuas 1:0ada46075897 3380 (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D6 | LCD_BUS_I2C_D5 ),
Gabiuas 1:0ada46075897 3381 (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D6 | LCD_BUS_I2C_D5 | LCD_BUS_I2C_D4)
Gabiuas 1:0ada46075897 3382 };
Gabiuas 1:0ada46075897 3383 void TextLCD_I2C::_setDataBits(int value) {
Gabiuas 1:0ada46075897 3384
Gabiuas 1:0ada46075897 3385 //Clear all databits
Gabiuas 1:0ada46075897 3386 _lcd_bus &= ~LCD_BUS_I2C_MSK;
Gabiuas 1:0ada46075897 3387
Gabiuas 1:0ada46075897 3388 // Set bit by bit to support any mapping of expander portpins to LCD pins
Gabiuas 1:0ada46075897 3389 _lcd_bus |= _LCD_DATA_BITS[value & 0x0F];
Gabiuas 1:0ada46075897 3390 }
Gabiuas 1:0ada46075897 3391 #endif
Gabiuas 1:0ada46075897 3392
Gabiuas 1:0ada46075897 3393 // Test faster _writeByte 0.11s vs 0.27s for a 20x4 fillscreen (PCF8574)
Gabiuas 1:0ada46075897 3394 // Place the 4bit data in the databus shadowvalue
Gabiuas 1:0ada46075897 3395 // Used for mbed I2C bus expander
Gabiuas 1:0ada46075897 3396 void TextLCD_I2C::_setDataBits(int value) {
Gabiuas 1:0ada46075897 3397
Gabiuas 1:0ada46075897 3398 //Clear all databits
Gabiuas 1:0ada46075897 3399 _lcd_bus &= ~LCD_BUS_I2C_MSK;
Gabiuas 1:0ada46075897 3400
Gabiuas 1:0ada46075897 3401 // Set bit by bit to support any mapping of expander portpins to LCD pins
Gabiuas 1:0ada46075897 3402 if (value & 0x01){
Gabiuas 1:0ada46075897 3403 _lcd_bus |= LCD_BUS_I2C_D4; // Set Databit
Gabiuas 1:0ada46075897 3404 }
Gabiuas 1:0ada46075897 3405
Gabiuas 1:0ada46075897 3406 if (value & 0x02){
Gabiuas 1:0ada46075897 3407 _lcd_bus |= LCD_BUS_I2C_D5; // Set Databit
Gabiuas 1:0ada46075897 3408 }
Gabiuas 1:0ada46075897 3409
Gabiuas 1:0ada46075897 3410 if (value & 0x04) {
Gabiuas 1:0ada46075897 3411 _lcd_bus |= LCD_BUS_I2C_D6; // Set Databit
Gabiuas 1:0ada46075897 3412 }
Gabiuas 1:0ada46075897 3413
Gabiuas 1:0ada46075897 3414 if (value & 0x08) {
Gabiuas 1:0ada46075897 3415 _lcd_bus |= LCD_BUS_I2C_D7; // Set Databit
Gabiuas 1:0ada46075897 3416 }
Gabiuas 1:0ada46075897 3417 }
Gabiuas 1:0ada46075897 3418
Gabiuas 1:0ada46075897 3419
Gabiuas 1:0ada46075897 3420 // Place the 4bit data on the databus
Gabiuas 1:0ada46075897 3421 // Used for mbed pins, I2C bus expander or SPI shifregister
Gabiuas 1:0ada46075897 3422 void TextLCD_I2C::_setData(int value) {
Gabiuas 1:0ada46075897 3423
Gabiuas 1:0ada46075897 3424 // Place the 4bit data on the databus shadowvalue
Gabiuas 1:0ada46075897 3425 _setDataBits(value);
Gabiuas 1:0ada46075897 3426
Gabiuas 1:0ada46075897 3427 // Place the 4bit data on the databus
Gabiuas 1:0ada46075897 3428 #if (MCP23008==1)
Gabiuas 1:0ada46075897 3429 // MCP23008 portexpander
Gabiuas 1:0ada46075897 3430
Gabiuas 1:0ada46075897 3431 // write the new data to the portexpander
Gabiuas 1:0ada46075897 3432 _writeRegister(GPIO, _lcd_bus);
Gabiuas 1:0ada46075897 3433 #else
Gabiuas 1:0ada46075897 3434 // PCF8574 of PCF8574A portexpander
Gabiuas 1:0ada46075897 3435
Gabiuas 1:0ada46075897 3436 // write the new data to the I2C portexpander
Gabiuas 1:0ada46075897 3437 _i2c->write(_slaveAddress, &_lcd_bus, 1);
Gabiuas 1:0ada46075897 3438 #endif
Gabiuas 1:0ada46075897 3439 }
Gabiuas 1:0ada46075897 3440
Gabiuas 1:0ada46075897 3441 // Write data to MCP23008 I2C portexpander
Gabiuas 1:0ada46075897 3442 // Used for mbed I2C bus expander
Gabiuas 1:0ada46075897 3443 void TextLCD_I2C::_writeRegister (int reg, int value) {
Gabiuas 1:0ada46075897 3444 char data[] = {reg, value};
Gabiuas 1:0ada46075897 3445
Gabiuas 1:0ada46075897 3446 _i2c->write(_slaveAddress, data, 2);
Gabiuas 1:0ada46075897 3447 }
Gabiuas 1:0ada46075897 3448
Gabiuas 1:0ada46075897 3449 //New optimized
Gabiuas 1:0ada46075897 3450 //Test faster _writeByte 0.11s vs 0.27s for a 20x4 fillscreen (PCF8574)
Gabiuas 1:0ada46075897 3451 //Test faster _writeByte 0.14s vs 0.34s for a 20x4 fillscreen (MCP23008)
Gabiuas 1:0ada46075897 3452
Gabiuas 1:0ada46075897 3453 // Write a byte using I2C
Gabiuas 1:0ada46075897 3454 void TextLCD_I2C::_writeByte(int value) {
Gabiuas 1:0ada46075897 3455 char data[6];
Gabiuas 1:0ada46075897 3456
Gabiuas 1:0ada46075897 3457 #if (MCP23008==1)
Gabiuas 1:0ada46075897 3458 // MCP23008 portexpander
Gabiuas 1:0ada46075897 3459
Gabiuas 1:0ada46075897 3460 data[0] = GPIO; // set registeraddres
Gabiuas 1:0ada46075897 3461 // Note: auto-increment is disabled so all data will go to GPIO register
Gabiuas 1:0ada46075897 3462
Gabiuas 1:0ada46075897 3463 _setEnableBit(true); // set E
Gabiuas 1:0ada46075897 3464 _setDataBits(value >> 4); // set data high
Gabiuas 1:0ada46075897 3465 data[1] = _lcd_bus;
Gabiuas 1:0ada46075897 3466
Gabiuas 1:0ada46075897 3467 _setEnableBit(false); // clear E
Gabiuas 1:0ada46075897 3468 data[2] = _lcd_bus;
Gabiuas 1:0ada46075897 3469
Gabiuas 1:0ada46075897 3470 _setEnableBit(true); // set E
Gabiuas 1:0ada46075897 3471 _setDataBits(value); // set data low
Gabiuas 1:0ada46075897 3472 data[3] = _lcd_bus;
Gabiuas 1:0ada46075897 3473
Gabiuas 1:0ada46075897 3474 _setEnableBit(false); // clear E
Gabiuas 1:0ada46075897 3475 data[4] = _lcd_bus;
Gabiuas 1:0ada46075897 3476
Gabiuas 1:0ada46075897 3477 // write the packed data to the I2C portexpander
Gabiuas 1:0ada46075897 3478 _i2c->write(_slaveAddress, data, 5);
Gabiuas 1:0ada46075897 3479 #else
Gabiuas 1:0ada46075897 3480 // PCF8574 of PCF8574A portexpander
Gabiuas 1:0ada46075897 3481
Gabiuas 1:0ada46075897 3482 _setEnableBit(true); // set E
Gabiuas 1:0ada46075897 3483 _setDataBits(value >> 4); // set data high
Gabiuas 1:0ada46075897 3484 data[0] = _lcd_bus;
Gabiuas 1:0ada46075897 3485
Gabiuas 1:0ada46075897 3486 _setEnableBit(false); // clear E
Gabiuas 1:0ada46075897 3487 data[1] = _lcd_bus;
Gabiuas 1:0ada46075897 3488
Gabiuas 1:0ada46075897 3489 _setEnableBit(true); // set E
Gabiuas 1:0ada46075897 3490 _setDataBits(value); // set data low
Gabiuas 1:0ada46075897 3491 data[2] = _lcd_bus;
Gabiuas 1:0ada46075897 3492
Gabiuas 1:0ada46075897 3493 _setEnableBit(false); // clear E
Gabiuas 1:0ada46075897 3494 data[3] = _lcd_bus;
Gabiuas 1:0ada46075897 3495
Gabiuas 1:0ada46075897 3496 // write the packed data to the I2C portexpander
Gabiuas 1:0ada46075897 3497 _i2c->write(_slaveAddress, data, 4);
Gabiuas 1:0ada46075897 3498 #endif
Gabiuas 1:0ada46075897 3499 }
Gabiuas 1:0ada46075897 3500
Gabiuas 1:0ada46075897 3501 #endif /* I2C Expander PCF8574/MCP23008 */
Gabiuas 1:0ada46075897 3502 //---------- End TextLCD_I2C ------------
Gabiuas 1:0ada46075897 3503
Gabiuas 1:0ada46075897 3504
Gabiuas 1:0ada46075897 3505 //--------- Start TextLCD_SPI -----------
Gabiuas 1:0ada46075897 3506 #if(LCD_SPI == 1) /* SPI Expander SN74595 */
Gabiuas 1:0ada46075897 3507
Gabiuas 1:0ada46075897 3508 /** Create a TextLCD interface using an SPI 74595 portexpander
Gabiuas 1:0ada46075897 3509 *
Gabiuas 1:0ada46075897 3510 * @param spi SPI Bus
Gabiuas 1:0ada46075897 3511 * @param cs chip select pin (active low)
Gabiuas 1:0ada46075897 3512 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Gabiuas 1:0ada46075897 3513 * @param ctrl LCD controller (default = HD44780)
Gabiuas 1:0ada46075897 3514 */
Gabiuas 1:0ada46075897 3515 TextLCD_SPI::TextLCD_SPI(SPI *spi, PinName cs, LCDType type, LCDCtrl ctrl) :
Gabiuas 1:0ada46075897 3516 TextLCD_Base(type, ctrl),
Gabiuas 1:0ada46075897 3517 _spi(spi),
Gabiuas 1:0ada46075897 3518 _cs(cs) {
Gabiuas 1:0ada46075897 3519 // Init cs
Gabiuas 1:0ada46075897 3520 _cs = 1;
Gabiuas 1:0ada46075897 3521
Gabiuas 1:0ada46075897 3522 // Setup the spi for 8 bit data, low steady state clock,
Gabiuas 1:0ada46075897 3523 // rising edge capture, with a 500KHz or 1MHz clock rate
Gabiuas 1:0ada46075897 3524 _spi->format(8,0);
Gabiuas 1:0ada46075897 3525 _spi->frequency(500000);
Gabiuas 1:0ada46075897 3526 //_spi.frequency(1000000);
Gabiuas 1:0ada46075897 3527
Gabiuas 1:0ada46075897 3528 wait_ms(100); // Wait 100ms to ensure LCD powered up
Gabiuas 1:0ada46075897 3529
Gabiuas 1:0ada46075897 3530 // Init the portexpander bus
Gabiuas 1:0ada46075897 3531 _lcd_bus = LCD_BUS_SPI_DEF;
Gabiuas 1:0ada46075897 3532
Gabiuas 1:0ada46075897 3533 // write the new data to the portexpander
Gabiuas 1:0ada46075897 3534 _cs = 0;
Gabiuas 1:0ada46075897 3535 _spi->write(_lcd_bus);
Gabiuas 1:0ada46075897 3536 _cs = 1;
Gabiuas 1:0ada46075897 3537
Gabiuas 1:0ada46075897 3538 _init(_LCD_DL_4); // Set Datalength to 4 bit for all serial expander interfaces
Gabiuas 1:0ada46075897 3539 }
Gabiuas 1:0ada46075897 3540
Gabiuas 1:0ada46075897 3541 // Set E pin (or E2 pin)
Gabiuas 1:0ada46075897 3542 // Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 3543 void TextLCD_SPI::_setEnable(bool value) {
Gabiuas 1:0ada46075897 3544
Gabiuas 1:0ada46075897 3545 if(_ctrl_idx==_LCDCtrl_0) {
Gabiuas 1:0ada46075897 3546 if (value) {
Gabiuas 1:0ada46075897 3547 _lcd_bus |= LCD_BUS_SPI_E; // Set E bit
Gabiuas 1:0ada46075897 3548 }
Gabiuas 1:0ada46075897 3549 else {
Gabiuas 1:0ada46075897 3550 _lcd_bus &= ~LCD_BUS_SPI_E; // Reset E bit
Gabiuas 1:0ada46075897 3551 }
Gabiuas 1:0ada46075897 3552 }
Gabiuas 1:0ada46075897 3553 else {
Gabiuas 1:0ada46075897 3554 if (value) {
Gabiuas 1:0ada46075897 3555 _lcd_bus |= LCD_BUS_SPI_E2; // Set E2 bit
Gabiuas 1:0ada46075897 3556 }
Gabiuas 1:0ada46075897 3557 else {
Gabiuas 1:0ada46075897 3558 _lcd_bus &= ~LCD_BUS_SPI_E2; // Reset E2 bit
Gabiuas 1:0ada46075897 3559 }
Gabiuas 1:0ada46075897 3560 }
Gabiuas 1:0ada46075897 3561
Gabiuas 1:0ada46075897 3562 // write the new data to the SPI portexpander
Gabiuas 1:0ada46075897 3563 _cs = 0;
Gabiuas 1:0ada46075897 3564 _spi->write(_lcd_bus);
Gabiuas 1:0ada46075897 3565 _cs = 1;
Gabiuas 1:0ada46075897 3566 }
Gabiuas 1:0ada46075897 3567
Gabiuas 1:0ada46075897 3568 // Set RS pin
Gabiuas 1:0ada46075897 3569 // Used for mbed pins, I2C bus expander or SPI shiftregister and SPI_N
Gabiuas 1:0ada46075897 3570 void TextLCD_SPI::_setRS(bool value) {
Gabiuas 1:0ada46075897 3571
Gabiuas 1:0ada46075897 3572 if (value) {
Gabiuas 1:0ada46075897 3573 _lcd_bus |= LCD_BUS_SPI_RS; // Set RS bit
Gabiuas 1:0ada46075897 3574 }
Gabiuas 1:0ada46075897 3575 else {
Gabiuas 1:0ada46075897 3576 _lcd_bus &= ~LCD_BUS_SPI_RS; // Reset RS bit
Gabiuas 1:0ada46075897 3577 }
Gabiuas 1:0ada46075897 3578
Gabiuas 1:0ada46075897 3579 // write the new data to the SPI portexpander
Gabiuas 1:0ada46075897 3580 _cs = 0;
Gabiuas 1:0ada46075897 3581 _spi->write(_lcd_bus);
Gabiuas 1:0ada46075897 3582 _cs = 1;
Gabiuas 1:0ada46075897 3583 }
Gabiuas 1:0ada46075897 3584
Gabiuas 1:0ada46075897 3585 // Set BL pin
Gabiuas 1:0ada46075897 3586 // Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 3587 void TextLCD_SPI::_setBL(bool value) {
Gabiuas 1:0ada46075897 3588
Gabiuas 1:0ada46075897 3589 if (value) {
Gabiuas 1:0ada46075897 3590 _lcd_bus |= LCD_BUS_SPI_BL; // Set BL bit
Gabiuas 1:0ada46075897 3591 }
Gabiuas 1:0ada46075897 3592 else {
Gabiuas 1:0ada46075897 3593 _lcd_bus &= ~LCD_BUS_SPI_BL; // Reset BL bit
Gabiuas 1:0ada46075897 3594 }
Gabiuas 1:0ada46075897 3595
Gabiuas 1:0ada46075897 3596 // write the new data to the SPI portexpander
Gabiuas 1:0ada46075897 3597 _cs = 0;
Gabiuas 1:0ada46075897 3598 _spi->write(_lcd_bus);
Gabiuas 1:0ada46075897 3599 _cs = 1;
Gabiuas 1:0ada46075897 3600 }
Gabiuas 1:0ada46075897 3601
Gabiuas 1:0ada46075897 3602 // Place the 4bit data on the databus
Gabiuas 1:0ada46075897 3603 // Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 3604 void TextLCD_SPI::_setData(int value) {
Gabiuas 1:0ada46075897 3605
Gabiuas 1:0ada46075897 3606 // Set bit by bit to support any mapping of expander portpins to LCD pins
Gabiuas 1:0ada46075897 3607 if (value & 0x01) {
Gabiuas 1:0ada46075897 3608 _lcd_bus |= LCD_BUS_SPI_D4; // Set Databit
Gabiuas 1:0ada46075897 3609 }
Gabiuas 1:0ada46075897 3610 else {
Gabiuas 1:0ada46075897 3611 _lcd_bus &= ~LCD_BUS_SPI_D4; // Reset Databit
Gabiuas 1:0ada46075897 3612 }
Gabiuas 1:0ada46075897 3613
Gabiuas 1:0ada46075897 3614 if (value & 0x02) {
Gabiuas 1:0ada46075897 3615 _lcd_bus |= LCD_BUS_SPI_D5; // Set Databit
Gabiuas 1:0ada46075897 3616 }
Gabiuas 1:0ada46075897 3617 else {
Gabiuas 1:0ada46075897 3618 _lcd_bus &= ~LCD_BUS_SPI_D5; // Reset Databit
Gabiuas 1:0ada46075897 3619 }
Gabiuas 1:0ada46075897 3620
Gabiuas 1:0ada46075897 3621 if (value & 0x04) {
Gabiuas 1:0ada46075897 3622 _lcd_bus |= LCD_BUS_SPI_D6; // Set Databit
Gabiuas 1:0ada46075897 3623 }
Gabiuas 1:0ada46075897 3624 else {
Gabiuas 1:0ada46075897 3625 _lcd_bus &= ~LCD_BUS_SPI_D6; // Reset Databit
Gabiuas 1:0ada46075897 3626 }
Gabiuas 1:0ada46075897 3627
Gabiuas 1:0ada46075897 3628 if (value & 0x08) {
Gabiuas 1:0ada46075897 3629 _lcd_bus |= LCD_BUS_SPI_D7; // Set Databit
Gabiuas 1:0ada46075897 3630 }
Gabiuas 1:0ada46075897 3631 else {
Gabiuas 1:0ada46075897 3632 _lcd_bus &= ~LCD_BUS_SPI_D7; // Reset Databit
Gabiuas 1:0ada46075897 3633 }
Gabiuas 1:0ada46075897 3634
Gabiuas 1:0ada46075897 3635 // write the new data to the SPI portexpander
Gabiuas 1:0ada46075897 3636 _cs = 0;
Gabiuas 1:0ada46075897 3637 _spi->write(_lcd_bus);
Gabiuas 1:0ada46075897 3638 _cs = 1;
Gabiuas 1:0ada46075897 3639 }
Gabiuas 1:0ada46075897 3640
Gabiuas 1:0ada46075897 3641 #endif /* SPI Expander SN74595 */
Gabiuas 1:0ada46075897 3642 //---------- End TextLCD_SPI ------------
Gabiuas 1:0ada46075897 3643
Gabiuas 1:0ada46075897 3644
Gabiuas 1:0ada46075897 3645 //--------- Start TextLCD_I2C_N ---------
Gabiuas 1:0ada46075897 3646 #if(LCD_I2C_N == 1) /* Native I2C */
Gabiuas 1:0ada46075897 3647
Gabiuas 1:0ada46075897 3648 /** Create a TextLCD interface using a controller with native I2C interface
Gabiuas 1:0ada46075897 3649 *
Gabiuas 1:0ada46075897 3650 * @param i2c I2C Bus
Gabiuas 1:0ada46075897 3651 * @param deviceAddress I2C slave address (default = 0x7C)
Gabiuas 1:0ada46075897 3652 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Gabiuas 1:0ada46075897 3653 * @param bl Backlight control line (optional, default = NC)
Gabiuas 1:0ada46075897 3654 * @param ctrl LCD controller (default = ST7032_3V3)
Gabiuas 1:0ada46075897 3655 */
Gabiuas 1:0ada46075897 3656 TextLCD_I2C_N::TextLCD_I2C_N(I2C *i2c, char deviceAddress, LCDType type, PinName bl, LCDCtrl ctrl) :
Gabiuas 1:0ada46075897 3657 TextLCD_Base(type, ctrl),
Gabiuas 1:0ada46075897 3658
Gabiuas 1:0ada46075897 3659 _i2c(i2c){
Gabiuas 1:0ada46075897 3660
Gabiuas 1:0ada46075897 3661 _slaveAddress = deviceAddress & 0xFE;
Gabiuas 1:0ada46075897 3662
Gabiuas 1:0ada46075897 3663 // Setup the I2C bus
Gabiuas 1:0ada46075897 3664 // The max bitrate for ST7032i is 400kbit, lets stick to default here
Gabiuas 1:0ada46075897 3665 _i2c->frequency(100000);
Gabiuas 1:0ada46075897 3666
Gabiuas 1:0ada46075897 3667
Gabiuas 1:0ada46075897 3668 // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access.
Gabiuas 1:0ada46075897 3669 if (bl != NC) {
Gabiuas 1:0ada46075897 3670 _bl = new DigitalOut(bl); //Construct new pin
Gabiuas 1:0ada46075897 3671 _bl->write(0); //Deactivate
Gabiuas 1:0ada46075897 3672 }
Gabiuas 1:0ada46075897 3673 else {
Gabiuas 1:0ada46075897 3674 // No Hardware Backlight pin
Gabiuas 1:0ada46075897 3675 _bl = NULL; //Construct dummy pin
Gabiuas 1:0ada46075897 3676 }
Gabiuas 1:0ada46075897 3677
Gabiuas 1:0ada46075897 3678 //Sanity check
Gabiuas 1:0ada46075897 3679 if (_ctrl & LCD_C_I2C) {
Gabiuas 1:0ada46075897 3680 _init(_LCD_DL_8); // Set Datalength to 8 bit for all native serial interfaces
Gabiuas 1:0ada46075897 3681 }
Gabiuas 1:0ada46075897 3682 else {
Gabiuas 1:0ada46075897 3683 error("Error: LCD Controller type does not support native I2C interface\n\r");
Gabiuas 1:0ada46075897 3684 }
Gabiuas 1:0ada46075897 3685 }
Gabiuas 1:0ada46075897 3686
Gabiuas 1:0ada46075897 3687 TextLCD_I2C_N::~TextLCD_I2C_N() {
Gabiuas 1:0ada46075897 3688 if (_bl != NULL) {delete _bl;} // BL pin
Gabiuas 1:0ada46075897 3689 }
Gabiuas 1:0ada46075897 3690
Gabiuas 1:0ada46075897 3691 // Not used in this mode
Gabiuas 1:0ada46075897 3692 void TextLCD_I2C_N::_setEnable(bool value) {
Gabiuas 1:0ada46075897 3693 }
Gabiuas 1:0ada46075897 3694
Gabiuas 1:0ada46075897 3695 // Set RS pin
Gabiuas 1:0ada46075897 3696 // Used for mbed pins, I2C bus expander or SPI shiftregister and native I2C or SPI
Gabiuas 1:0ada46075897 3697 void TextLCD_I2C_N::_setRS(bool value) {
Gabiuas 1:0ada46075897 3698 // The controlbyte defines the meaning of the next byte. This next byte can either be data or command.
Gabiuas 1:0ada46075897 3699 // Start Slaveaddress+RW b7 b6 b5 b4 b3 b2 b1 b0 b7...........b0 Stop
Gabiuas 1:0ada46075897 3700 // Co RS RW 0 0 0 0 0 command or data
Gabiuas 1:0ada46075897 3701 //
Gabiuas 1:0ada46075897 3702 // C0=1 indicates that another controlbyte will follow after the next data or command byte
Gabiuas 1:0ada46075897 3703 // RS=1 means that next byte is data, RS=0 means that next byte is command
Gabiuas 1:0ada46075897 3704 // RW=0 means write to controller. RW=1 means that controller will be read from after the next command.
Gabiuas 1:0ada46075897 3705 // Many native I2C controllers dont support this option and it is not used by this lib.
Gabiuas 1:0ada46075897 3706 //
Gabiuas 1:0ada46075897 3707
Gabiuas 1:0ada46075897 3708 if (value) {
Gabiuas 1:0ada46075897 3709 _controlbyte = 0x40; // Next byte is data, No more control bytes will follow
Gabiuas 1:0ada46075897 3710 }
Gabiuas 1:0ada46075897 3711 else {
Gabiuas 1:0ada46075897 3712 _controlbyte = 0x00; // Next byte is command, No more control bytes will follow
Gabiuas 1:0ada46075897 3713 }
Gabiuas 1:0ada46075897 3714 }
Gabiuas 1:0ada46075897 3715
Gabiuas 1:0ada46075897 3716 // Set BL pin
Gabiuas 1:0ada46075897 3717 void TextLCD_I2C_N::_setBL(bool value) {
Gabiuas 1:0ada46075897 3718 if (_bl) {
Gabiuas 1:0ada46075897 3719 _bl->write(value);
Gabiuas 1:0ada46075897 3720 }
Gabiuas 1:0ada46075897 3721 }
Gabiuas 1:0ada46075897 3722
Gabiuas 1:0ada46075897 3723 // Not used in this mode
Gabiuas 1:0ada46075897 3724 void TextLCD_I2C_N::_setData(int value) {
Gabiuas 1:0ada46075897 3725 }
Gabiuas 1:0ada46075897 3726
Gabiuas 1:0ada46075897 3727 // Write a byte using I2C
Gabiuas 1:0ada46075897 3728 void TextLCD_I2C_N::_writeByte(int value) {
Gabiuas 1:0ada46075897 3729 // The controlbyte defines the meaning of the next byte. This next byte can either be data or command.
Gabiuas 1:0ada46075897 3730 // Start Slaveaddress+RW b7 b6 b5 b4 b3 b2 b1 b0 b7...........b0 Stop
Gabiuas 1:0ada46075897 3731 // Co RS RW 0 0 0 0 0 command or data
Gabiuas 1:0ada46075897 3732 //
Gabiuas 1:0ada46075897 3733 // C0=1 indicates that another controlbyte will follow after the next data or command byte
Gabiuas 1:0ada46075897 3734 // RS=1 means that next byte is data, RS=0 means that next byte is command
Gabiuas 1:0ada46075897 3735 // RW=0 means write to controller. RW=1 means that controller will be read from after the next command.
Gabiuas 1:0ada46075897 3736 // Many native I2C controllers dont support this option and it is not used by this lib.
Gabiuas 1:0ada46075897 3737 //
Gabiuas 1:0ada46075897 3738 char data[] = {_controlbyte, value};
Gabiuas 1:0ada46075897 3739
Gabiuas 1:0ada46075897 3740 #if(LCD_I2C_ACK==1)
Gabiuas 1:0ada46075897 3741 //Controllers that support ACK
Gabiuas 1:0ada46075897 3742 _i2c->write(_slaveAddress, data, 2);
Gabiuas 1:0ada46075897 3743 #else
Gabiuas 1:0ada46075897 3744 //Controllers that dont support ACK
Gabiuas 1:0ada46075897 3745 //Note: This may be issue with some mbed platforms that dont fully/correctly support I2C byte operations.
Gabiuas 1:0ada46075897 3746 _i2c->start();
Gabiuas 1:0ada46075897 3747 _i2c->write(_slaveAddress);
Gabiuas 1:0ada46075897 3748 _i2c->write(data[0]);
Gabiuas 1:0ada46075897 3749 _i2c->write(data[1]);
Gabiuas 1:0ada46075897 3750 _i2c->stop();
Gabiuas 1:0ada46075897 3751 #endif
Gabiuas 1:0ada46075897 3752 }
Gabiuas 1:0ada46075897 3753 #endif /* Native I2C */
Gabiuas 1:0ada46075897 3754 //-------- End TextLCD_I2C_N ------------
Gabiuas 1:0ada46075897 3755
Gabiuas 1:0ada46075897 3756
Gabiuas 1:0ada46075897 3757 //--------- Start TextLCD_SPI_N ---------
Gabiuas 1:0ada46075897 3758 #if(LCD_SPI_N == 1) /* Native SPI bus */
Gabiuas 1:0ada46075897 3759 /** Create a TextLCD interface using a controller with a native SPI4 interface
Gabiuas 1:0ada46075897 3760 *
Gabiuas 1:0ada46075897 3761 * @param spi SPI Bus
Gabiuas 1:0ada46075897 3762 * @param cs chip select pin (active low)
Gabiuas 1:0ada46075897 3763 * @param rs Instruction/data control line
Gabiuas 1:0ada46075897 3764 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Gabiuas 1:0ada46075897 3765 * @param bl Backlight control line (optional, default = NC)
Gabiuas 1:0ada46075897 3766 * @param ctrl LCD controller (default = ST7032_3V3)
Gabiuas 1:0ada46075897 3767 */
Gabiuas 1:0ada46075897 3768 TextLCD_SPI_N::TextLCD_SPI_N(SPI *spi, PinName cs, PinName rs, LCDType type, PinName bl, LCDCtrl ctrl) :
Gabiuas 1:0ada46075897 3769 TextLCD_Base(type, ctrl),
Gabiuas 1:0ada46075897 3770 _spi(spi),
Gabiuas 1:0ada46075897 3771 _cs(cs),
Gabiuas 1:0ada46075897 3772 _rs(rs) {
Gabiuas 1:0ada46075897 3773
Gabiuas 1:0ada46075897 3774 // Init CS
Gabiuas 1:0ada46075897 3775 _cs = 1;
Gabiuas 1:0ada46075897 3776
Gabiuas 1:0ada46075897 3777 // Setup the spi for 8 bit data, high steady state clock,
Gabiuas 1:0ada46075897 3778 // rising edge capture, with a 500KHz or 1MHz clock rate
Gabiuas 1:0ada46075897 3779 // _spi->format(8,3);
Gabiuas 1:0ada46075897 3780 // _spi->frequency(500000);
Gabiuas 1:0ada46075897 3781 // _spi->frequency(1000000);
Gabiuas 1:0ada46075897 3782
Gabiuas 1:0ada46075897 3783 // Setup the spi for 8 bit data, low steady state clock,
Gabiuas 1:0ada46075897 3784 // rising edge capture, with a 500KHz or 1MHz clock rate
Gabiuas 1:0ada46075897 3785 _spi->format(8,0);
Gabiuas 1:0ada46075897 3786 // _spi->frequency(500000);
Gabiuas 1:0ada46075897 3787 _spi->frequency(1000000);
Gabiuas 1:0ada46075897 3788
Gabiuas 1:0ada46075897 3789 // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access.
Gabiuas 1:0ada46075897 3790 if (bl != NC) {
Gabiuas 1:0ada46075897 3791 _bl = new DigitalOut(bl); //Construct new pin
Gabiuas 1:0ada46075897 3792 _bl->write(0); //Deactivate
Gabiuas 1:0ada46075897 3793 }
Gabiuas 1:0ada46075897 3794 else {
Gabiuas 1:0ada46075897 3795 // No Hardware Backlight pin
Gabiuas 1:0ada46075897 3796 _bl = NULL; //Construct dummy pin
Gabiuas 1:0ada46075897 3797 }
Gabiuas 1:0ada46075897 3798
Gabiuas 1:0ada46075897 3799 //Sanity check
Gabiuas 1:0ada46075897 3800 if (_ctrl & LCD_C_SPI4) {
Gabiuas 1:0ada46075897 3801 _init(_LCD_DL_8); // Set Datalength to 8 bit for all native serial interfaces
Gabiuas 1:0ada46075897 3802 // ST7070 must set datalength to 8 bits!
Gabiuas 1:0ada46075897 3803 }
Gabiuas 1:0ada46075897 3804 else {
Gabiuas 1:0ada46075897 3805 error("Error: LCD Controller type does not support native SPI4 interface\n\r");
Gabiuas 1:0ada46075897 3806 }
Gabiuas 1:0ada46075897 3807 }
Gabiuas 1:0ada46075897 3808
Gabiuas 1:0ada46075897 3809 TextLCD_SPI_N::~TextLCD_SPI_N() {
Gabiuas 1:0ada46075897 3810 if (_bl != NULL) {delete _bl;} // BL pin
Gabiuas 1:0ada46075897 3811 }
Gabiuas 1:0ada46075897 3812
Gabiuas 1:0ada46075897 3813 // Not used in this mode
Gabiuas 1:0ada46075897 3814 void TextLCD_SPI_N::_setEnable(bool value) {
Gabiuas 1:0ada46075897 3815 }
Gabiuas 1:0ada46075897 3816
Gabiuas 1:0ada46075897 3817 // Set RS pin
Gabiuas 1:0ada46075897 3818 // Used for mbed pins, I2C bus expander or SPI shiftregister, SPI_N
Gabiuas 1:0ada46075897 3819 void TextLCD_SPI_N::_setRS(bool value) {
Gabiuas 1:0ada46075897 3820 _rs = value;
Gabiuas 1:0ada46075897 3821 }
Gabiuas 1:0ada46075897 3822
Gabiuas 1:0ada46075897 3823 // Set BL pin
Gabiuas 1:0ada46075897 3824 void TextLCD_SPI_N::_setBL(bool value) {
Gabiuas 1:0ada46075897 3825 if (_bl) {
Gabiuas 1:0ada46075897 3826 _bl->write(value);
Gabiuas 1:0ada46075897 3827 }
Gabiuas 1:0ada46075897 3828 }
Gabiuas 1:0ada46075897 3829
Gabiuas 1:0ada46075897 3830 // Not used in this mode
Gabiuas 1:0ada46075897 3831 void TextLCD_SPI_N::_setData(int value) {
Gabiuas 1:0ada46075897 3832 }
Gabiuas 1:0ada46075897 3833
Gabiuas 1:0ada46075897 3834 // Write a byte using SPI
Gabiuas 1:0ada46075897 3835 void TextLCD_SPI_N::_writeByte(int value) {
Gabiuas 1:0ada46075897 3836 _cs = 0;
Gabiuas 1:0ada46075897 3837 wait_us(1);
Gabiuas 1:0ada46075897 3838 _spi->write(value);
Gabiuas 1:0ada46075897 3839 wait_us(1);
Gabiuas 1:0ada46075897 3840 _cs = 1;
Gabiuas 1:0ada46075897 3841 }
Gabiuas 1:0ada46075897 3842 #endif /* Native SPI bus */
Gabiuas 1:0ada46075897 3843 //-------- End TextLCD_SPI_N ------------
Gabiuas 1:0ada46075897 3844
Gabiuas 1:0ada46075897 3845
Gabiuas 1:0ada46075897 3846 //-------- Start TextLCD_SPI_N_3_8 --------
Gabiuas 1:0ada46075897 3847 #if(LCD_SPI_N_3_8 == 1) /* Native SPI bus */
Gabiuas 1:0ada46075897 3848
Gabiuas 1:0ada46075897 3849 /** Create a TextLCD interface using a controller with a native SPI3 8 bits interface
Gabiuas 1:0ada46075897 3850 * This mode is supported by ST7070. Note that implementation in TexTLCD is not very efficient due to
Gabiuas 1:0ada46075897 3851 * structure of the TextLCD library: each databyte is written separately and requires a separate 'count command' set to 1 byte.
Gabiuas 1:0ada46075897 3852 *
Gabiuas 1:0ada46075897 3853 * @param spi SPI Bus
Gabiuas 1:0ada46075897 3854 * @param cs chip select pin (active low)
Gabiuas 1:0ada46075897 3855 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Gabiuas 1:0ada46075897 3856 * @param bl Backlight control line (optional, default = NC)
Gabiuas 1:0ada46075897 3857 * @param ctrl LCD controller (default = ST7070)
Gabiuas 1:0ada46075897 3858 */
Gabiuas 1:0ada46075897 3859 TextLCD_SPI_N_3_8::TextLCD_SPI_N_3_8(SPI *spi, PinName cs, LCDType type, PinName bl, LCDCtrl ctrl) :
Gabiuas 1:0ada46075897 3860 TextLCD_Base(type, ctrl),
Gabiuas 1:0ada46075897 3861 _spi(spi),
Gabiuas 1:0ada46075897 3862 _cs(cs) {
Gabiuas 1:0ada46075897 3863
Gabiuas 1:0ada46075897 3864 // Init CS
Gabiuas 1:0ada46075897 3865 _cs = 1;
Gabiuas 1:0ada46075897 3866
Gabiuas 1:0ada46075897 3867 // Setup the spi for 8 bit data, high steady state clock,
Gabiuas 1:0ada46075897 3868 // rising edge capture, with a 500KHz or 1MHz clock rate
Gabiuas 1:0ada46075897 3869 // _spi->format(8,3);
Gabiuas 1:0ada46075897 3870 // _spi->frequency(500000);
Gabiuas 1:0ada46075897 3871 // _spi->frequency(1000000);
Gabiuas 1:0ada46075897 3872
Gabiuas 1:0ada46075897 3873 // Setup the spi for 8 bit data, low steady state clock,
Gabiuas 1:0ada46075897 3874 // rising edge capture, with a 500KHz or 1MHz clock rate
Gabiuas 1:0ada46075897 3875 _spi->format(8,0);
Gabiuas 1:0ada46075897 3876 // _spi->frequency(500000);
Gabiuas 1:0ada46075897 3877 _spi->frequency(1000000);
Gabiuas 1:0ada46075897 3878
Gabiuas 1:0ada46075897 3879
Gabiuas 1:0ada46075897 3880 // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access.
Gabiuas 1:0ada46075897 3881 if (bl != NC) {
Gabiuas 1:0ada46075897 3882 _bl = new DigitalOut(bl); //Construct new pin
Gabiuas 1:0ada46075897 3883 _bl->write(0); //Deactivate
Gabiuas 1:0ada46075897 3884 }
Gabiuas 1:0ada46075897 3885 else {
Gabiuas 1:0ada46075897 3886 // No Hardware Backlight pin
Gabiuas 1:0ada46075897 3887 _bl = NULL; //Construct dummy pin
Gabiuas 1:0ada46075897 3888 }
Gabiuas 1:0ada46075897 3889
Gabiuas 1:0ada46075897 3890 //Sanity check
Gabiuas 1:0ada46075897 3891 if (_ctrl & LCD_C_SPI3_8) {
Gabiuas 1:0ada46075897 3892 _init(_LCD_DL_8); // Set Datalength to 8 bit for all native serial interfaces
Gabiuas 1:0ada46075897 3893 }
Gabiuas 1:0ada46075897 3894 else {
Gabiuas 1:0ada46075897 3895 error("Error: LCD Controller type does not support native SPI3 8 bits interface\n\r");
Gabiuas 1:0ada46075897 3896 }
Gabiuas 1:0ada46075897 3897 }
Gabiuas 1:0ada46075897 3898
Gabiuas 1:0ada46075897 3899 TextLCD_SPI_N_3_8::~TextLCD_SPI_N_3_8() {
Gabiuas 1:0ada46075897 3900 if (_bl != NULL) {delete _bl;} // BL pin
Gabiuas 1:0ada46075897 3901 }
Gabiuas 1:0ada46075897 3902
Gabiuas 1:0ada46075897 3903 // Not used in this mode
Gabiuas 1:0ada46075897 3904 void TextLCD_SPI_N_3_8::_setEnable(bool value) {
Gabiuas 1:0ada46075897 3905 }
Gabiuas 1:0ada46075897 3906
Gabiuas 1:0ada46075897 3907 // Used for mbed pins, I2C bus expander or SPI shiftregister, SPI_N
Gabiuas 1:0ada46075897 3908 // RS=1 means that next byte is data, RS=0 means that next byte is command
Gabiuas 1:0ada46075897 3909 void TextLCD_SPI_N_3_8::_setRS(bool value) {
Gabiuas 1:0ada46075897 3910
Gabiuas 1:0ada46075897 3911 if (value) {
Gabiuas 1:0ada46075897 3912 _controlbyte = 0x01; // Next byte is data, No more control bytes will follow
Gabiuas 1:0ada46075897 3913 }
Gabiuas 1:0ada46075897 3914 else {
Gabiuas 1:0ada46075897 3915 _controlbyte = 0x00; // Next byte is command, No more control bytes will follow
Gabiuas 1:0ada46075897 3916 }
Gabiuas 1:0ada46075897 3917 }
Gabiuas 1:0ada46075897 3918
Gabiuas 1:0ada46075897 3919 // Set BL pin
Gabiuas 1:0ada46075897 3920 void TextLCD_SPI_N_3_8::_setBL(bool value) {
Gabiuas 1:0ada46075897 3921 if (_bl) {
Gabiuas 1:0ada46075897 3922 _bl->write(value);
Gabiuas 1:0ada46075897 3923 }
Gabiuas 1:0ada46075897 3924 }
Gabiuas 1:0ada46075897 3925
Gabiuas 1:0ada46075897 3926 // Not used in this mode
Gabiuas 1:0ada46075897 3927 void TextLCD_SPI_N_3_8::_setData(int value) {
Gabiuas 1:0ada46075897 3928 }
Gabiuas 1:0ada46075897 3929
Gabiuas 1:0ada46075897 3930 // Write a byte using SPI3 8 bits mode (ST7070)
Gabiuas 1:0ada46075897 3931 void TextLCD_SPI_N_3_8::_writeByte(int value) {
Gabiuas 1:0ada46075897 3932
Gabiuas 1:0ada46075897 3933 if (_controlbyte == 0x00) { // Byte is command
Gabiuas 1:0ada46075897 3934 _cs = 0;
Gabiuas 1:0ada46075897 3935 wait_us(1);
Gabiuas 1:0ada46075897 3936 _spi->write(value);
Gabiuas 1:0ada46075897 3937 wait_us(1);
Gabiuas 1:0ada46075897 3938 _cs = 1;
Gabiuas 1:0ada46075897 3939 }
Gabiuas 1:0ada46075897 3940 else { // Byte is data
Gabiuas 1:0ada46075897 3941 // Select Extended Instr Set
Gabiuas 1:0ada46075897 3942 _cs = 0;
Gabiuas 1:0ada46075897 3943 wait_us(1);
Gabiuas 1:0ada46075897 3944 _spi->write(0x20 | _function | 0x04); // Set function, 0 0 1 DL N EXT=1 x x (Select Instr Set = 1));
Gabiuas 1:0ada46075897 3945 wait_us(1);
Gabiuas 1:0ada46075897 3946 _cs = 1;
Gabiuas 1:0ada46075897 3947
Gabiuas 1:0ada46075897 3948 wait_us(40); // Wait until command has finished...
Gabiuas 1:0ada46075897 3949
Gabiuas 1:0ada46075897 3950 // Set Count to 1 databyte
Gabiuas 1:0ada46075897 3951 _cs = 0;
Gabiuas 1:0ada46075897 3952 wait_us(1);
Gabiuas 1:0ada46075897 3953 _spi->write(0x80); // Set display data length, 1 L6 L5 L4 L3 L2 L1 L0 (Instr Set = 1)
Gabiuas 1:0ada46075897 3954 wait_us(1);
Gabiuas 1:0ada46075897 3955 _cs = 1;
Gabiuas 1:0ada46075897 3956
Gabiuas 1:0ada46075897 3957 wait_us(40);
Gabiuas 1:0ada46075897 3958
Gabiuas 1:0ada46075897 3959 // Write 1 databyte
Gabiuas 1:0ada46075897 3960 _cs = 0;
Gabiuas 1:0ada46075897 3961 wait_us(1);
Gabiuas 1:0ada46075897 3962 _spi->write(value); // Write data (Instr Set = 1)
Gabiuas 1:0ada46075897 3963 wait_us(1);
Gabiuas 1:0ada46075897 3964 _cs = 1;
Gabiuas 1:0ada46075897 3965
Gabiuas 1:0ada46075897 3966 wait_us(40);
Gabiuas 1:0ada46075897 3967
Gabiuas 1:0ada46075897 3968 // Select Standard Instr Set
Gabiuas 1:0ada46075897 3969 _cs = 0;
Gabiuas 1:0ada46075897 3970 wait_us(1);
Gabiuas 1:0ada46075897 3971 _spi->write(0x20 | _function); // Set function, 0 0 1 DL N EXT=0 x x (Select Instr Set = 0));
Gabiuas 1:0ada46075897 3972 wait_us(1);
Gabiuas 1:0ada46075897 3973 _cs = 1;
Gabiuas 1:0ada46075897 3974 }
Gabiuas 1:0ada46075897 3975 }
Gabiuas 1:0ada46075897 3976 #endif /* Native SPI bus */
Gabiuas 1:0ada46075897 3977 //------- End TextLCD_SPI_N_3_8 -----------
Gabiuas 1:0ada46075897 3978
Gabiuas 1:0ada46075897 3979
Gabiuas 1:0ada46075897 3980 //-------- Start TextLCD_SPI_N_3_9 --------
Gabiuas 1:0ada46075897 3981 #if(LCD_SPI_N_3_9 == 1) /* Native SPI bus */
Gabiuas 1:0ada46075897 3982 //Code checked out on logic analyser. Not yet tested on hardware..
Gabiuas 1:0ada46075897 3983
Gabiuas 1:0ada46075897 3984 /** Create a TextLCD interface using a controller with a native SPI3 9 bits interface
Gabiuas 1:0ada46075897 3985 *
Gabiuas 1:0ada46075897 3986 * @param spi SPI Bus
Gabiuas 1:0ada46075897 3987 * @param cs chip select pin (active low)
Gabiuas 1:0ada46075897 3988 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Gabiuas 1:0ada46075897 3989 * @param bl Backlight control line (optional, default = NC)
Gabiuas 1:0ada46075897 3990 * @param ctrl LCD controller (default = AIP31068)
Gabiuas 1:0ada46075897 3991 */
Gabiuas 1:0ada46075897 3992 TextLCD_SPI_N_3_9::TextLCD_SPI_N_3_9(SPI *spi, PinName cs, LCDType type, PinName bl, LCDCtrl ctrl) :
Gabiuas 1:0ada46075897 3993 TextLCD_Base(type, ctrl),
Gabiuas 1:0ada46075897 3994 _spi(spi),
Gabiuas 1:0ada46075897 3995 _cs(cs) {
Gabiuas 1:0ada46075897 3996
Gabiuas 1:0ada46075897 3997 // Init CS
Gabiuas 1:0ada46075897 3998 _cs = 1;
Gabiuas 1:0ada46075897 3999
Gabiuas 1:0ada46075897 4000 // Setup the spi for 9 bit data, high steady state clock,
Gabiuas 1:0ada46075897 4001 // rising edge capture, with a 500KHz or 1MHz clock rate
Gabiuas 1:0ada46075897 4002 _spi->format(9,3);
Gabiuas 1:0ada46075897 4003 _spi->frequency(1000000);
Gabiuas 1:0ada46075897 4004
Gabiuas 1:0ada46075897 4005 // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access.
Gabiuas 1:0ada46075897 4006 if (bl != NC) {
Gabiuas 1:0ada46075897 4007 _bl = new DigitalOut(bl); //Construct new pin
Gabiuas 1:0ada46075897 4008 _bl->write(0); //Deactivate
Gabiuas 1:0ada46075897 4009 }
Gabiuas 1:0ada46075897 4010 else {
Gabiuas 1:0ada46075897 4011 // No Hardware Backlight pin
Gabiuas 1:0ada46075897 4012 _bl = NULL; //Construct dummy pin
Gabiuas 1:0ada46075897 4013 }
Gabiuas 1:0ada46075897 4014
Gabiuas 1:0ada46075897 4015 //Sanity check
Gabiuas 1:0ada46075897 4016 if (_ctrl & LCD_C_SPI3_9) {
Gabiuas 1:0ada46075897 4017 _init(_LCD_DL_8); // Set Datalength to 8 bit for all native serial interfaces
Gabiuas 1:0ada46075897 4018 }
Gabiuas 1:0ada46075897 4019 else {
Gabiuas 1:0ada46075897 4020 error("Error: LCD Controller type does not support native SPI3 9 bits interface\n\r");
Gabiuas 1:0ada46075897 4021 }
Gabiuas 1:0ada46075897 4022 }
Gabiuas 1:0ada46075897 4023
Gabiuas 1:0ada46075897 4024 TextLCD_SPI_N_3_9::~TextLCD_SPI_N_3_9() {
Gabiuas 1:0ada46075897 4025 if (_bl != NULL) {delete _bl;} // BL pin
Gabiuas 1:0ada46075897 4026 }
Gabiuas 1:0ada46075897 4027
Gabiuas 1:0ada46075897 4028 // Not used in this mode
Gabiuas 1:0ada46075897 4029 void TextLCD_SPI_N_3_9::_setEnable(bool value) {
Gabiuas 1:0ada46075897 4030 }
Gabiuas 1:0ada46075897 4031
Gabiuas 1:0ada46075897 4032 // Set RS pin
Gabiuas 1:0ada46075897 4033 // Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 4034 void TextLCD_SPI_N_3_9::_setRS(bool value) {
Gabiuas 1:0ada46075897 4035 // The controlbits define the meaning of the next byte. This next byte can either be data or command.
Gabiuas 1:0ada46075897 4036 // b8 b7...........b0
Gabiuas 1:0ada46075897 4037 // RS command or data
Gabiuas 1:0ada46075897 4038 //
Gabiuas 1:0ada46075897 4039 // RS=1 means that next byte is data, RS=0 means that next byte is command
Gabiuas 1:0ada46075897 4040 //
Gabiuas 1:0ada46075897 4041
Gabiuas 1:0ada46075897 4042 if (value) {
Gabiuas 1:0ada46075897 4043 _controlbyte = 0x01; // Next byte is data
Gabiuas 1:0ada46075897 4044 }
Gabiuas 1:0ada46075897 4045 else {
Gabiuas 1:0ada46075897 4046 _controlbyte = 0x00; // Next byte is command
Gabiuas 1:0ada46075897 4047 }
Gabiuas 1:0ada46075897 4048 }
Gabiuas 1:0ada46075897 4049
Gabiuas 1:0ada46075897 4050 // Set BL pin
Gabiuas 1:0ada46075897 4051 void TextLCD_SPI_N_3_9::_setBL(bool value) {
Gabiuas 1:0ada46075897 4052 if (_bl) {
Gabiuas 1:0ada46075897 4053 _bl->write(value);
Gabiuas 1:0ada46075897 4054 }
Gabiuas 1:0ada46075897 4055 }
Gabiuas 1:0ada46075897 4056
Gabiuas 1:0ada46075897 4057 // Not used in this mode
Gabiuas 1:0ada46075897 4058 void TextLCD_SPI_N_3_9::_setData(int value) {
Gabiuas 1:0ada46075897 4059 }
Gabiuas 1:0ada46075897 4060
Gabiuas 1:0ada46075897 4061 // Write a byte using SPI3 9 bits mode
Gabiuas 1:0ada46075897 4062 void TextLCD_SPI_N_3_9::_writeByte(int value) {
Gabiuas 1:0ada46075897 4063 _cs = 0;
Gabiuas 1:0ada46075897 4064 wait_us(1);
Gabiuas 1:0ada46075897 4065 _spi->write( (_controlbyte << 8) | (value & 0xFF));
Gabiuas 1:0ada46075897 4066 wait_us(1);
Gabiuas 1:0ada46075897 4067 _cs = 1;
Gabiuas 1:0ada46075897 4068 }
Gabiuas 1:0ada46075897 4069 #endif /* Native SPI bus */
Gabiuas 1:0ada46075897 4070 //------- End TextLCD_SPI_N_3_9 -----------
Gabiuas 1:0ada46075897 4071
Gabiuas 1:0ada46075897 4072
Gabiuas 1:0ada46075897 4073 //------- Start TextLCD_SPI_N_3_10 --------
Gabiuas 1:0ada46075897 4074 #if(LCD_SPI_N_3_10 == 1) /* Native SPI bus */
Gabiuas 1:0ada46075897 4075
Gabiuas 1:0ada46075897 4076 /** Create a TextLCD interface using a controller with a native SPI3 10 bits interface
Gabiuas 1:0ada46075897 4077 *
Gabiuas 1:0ada46075897 4078 * @param spi SPI Bus
Gabiuas 1:0ada46075897 4079 * @param cs chip select pin (active low)
Gabiuas 1:0ada46075897 4080 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Gabiuas 1:0ada46075897 4081 * @param bl Backlight control line (optional, default = NC)
Gabiuas 1:0ada46075897 4082 * @param ctrl LCD controller (default = AIP31068)
Gabiuas 1:0ada46075897 4083 */
Gabiuas 1:0ada46075897 4084 TextLCD_SPI_N_3_10::TextLCD_SPI_N_3_10(SPI *spi, PinName cs, LCDType type, PinName bl, LCDCtrl ctrl) :
Gabiuas 1:0ada46075897 4085 TextLCD_Base(type, ctrl),
Gabiuas 1:0ada46075897 4086 _spi(spi),
Gabiuas 1:0ada46075897 4087 _cs(cs) {
Gabiuas 1:0ada46075897 4088
Gabiuas 1:0ada46075897 4089 // Init CS
Gabiuas 1:0ada46075897 4090 _cs = 1;
Gabiuas 1:0ada46075897 4091
Gabiuas 1:0ada46075897 4092 // Setup the spi for 10 bit data, low steady state clock,
Gabiuas 1:0ada46075897 4093 // rising edge capture, with a 500KHz or 1MHz clock rate
Gabiuas 1:0ada46075897 4094 _spi->format(10,0);
Gabiuas 1:0ada46075897 4095 _spi->frequency(1000000);
Gabiuas 1:0ada46075897 4096
Gabiuas 1:0ada46075897 4097 // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access.
Gabiuas 1:0ada46075897 4098 if (bl != NC) {
Gabiuas 1:0ada46075897 4099 _bl = new DigitalOut(bl); //Construct new pin
Gabiuas 1:0ada46075897 4100 _bl->write(0); //Deactivate
Gabiuas 1:0ada46075897 4101 }
Gabiuas 1:0ada46075897 4102 else {
Gabiuas 1:0ada46075897 4103 // No Hardware Backlight pin
Gabiuas 1:0ada46075897 4104 _bl = NULL; //Construct dummy pin
Gabiuas 1:0ada46075897 4105 }
Gabiuas 1:0ada46075897 4106
Gabiuas 1:0ada46075897 4107 //Sanity check
Gabiuas 1:0ada46075897 4108 if (_ctrl & LCD_C_SPI3_10) {
Gabiuas 1:0ada46075897 4109 _init(_LCD_DL_8); // Set Datalength to 8 bit for all native serial interfaces
Gabiuas 1:0ada46075897 4110 }
Gabiuas 1:0ada46075897 4111 else {
Gabiuas 1:0ada46075897 4112 error("Error: LCD Controller type does not support native SPI3 10 bits interface\n\r");
Gabiuas 1:0ada46075897 4113 }
Gabiuas 1:0ada46075897 4114 }
Gabiuas 1:0ada46075897 4115
Gabiuas 1:0ada46075897 4116 TextLCD_SPI_N_3_10::~TextLCD_SPI_N_3_10() {
Gabiuas 1:0ada46075897 4117 if (_bl != NULL) {delete _bl;} // BL pin
Gabiuas 1:0ada46075897 4118 }
Gabiuas 1:0ada46075897 4119
Gabiuas 1:0ada46075897 4120 // Not used in this mode
Gabiuas 1:0ada46075897 4121 void TextLCD_SPI_N_3_10::_setEnable(bool value) {
Gabiuas 1:0ada46075897 4122 }
Gabiuas 1:0ada46075897 4123
Gabiuas 1:0ada46075897 4124 // Set RS pin
Gabiuas 1:0ada46075897 4125 // Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 4126 void TextLCD_SPI_N_3_10::_setRS(bool value) {
Gabiuas 1:0ada46075897 4127 // The controlbits define the meaning of the next byte. This next byte can either be data or command.
Gabiuas 1:0ada46075897 4128 // b9 b8 b7...........b0
Gabiuas 1:0ada46075897 4129 // RS RW command or data
Gabiuas 1:0ada46075897 4130 //
Gabiuas 1:0ada46075897 4131 // RS=1 means that next byte is data, RS=0 means that next byte is command
Gabiuas 1:0ada46075897 4132 // RW=0 means that next byte is writen, RW=1 means that next byte is read (not used in this lib)
Gabiuas 1:0ada46075897 4133 //
Gabiuas 1:0ada46075897 4134
Gabiuas 1:0ada46075897 4135 if (value) {
Gabiuas 1:0ada46075897 4136 _controlbyte = 0x02; // Next byte is data
Gabiuas 1:0ada46075897 4137 }
Gabiuas 1:0ada46075897 4138 else {
Gabiuas 1:0ada46075897 4139 _controlbyte = 0x00; // Next byte is command
Gabiuas 1:0ada46075897 4140 }
Gabiuas 1:0ada46075897 4141 }
Gabiuas 1:0ada46075897 4142
Gabiuas 1:0ada46075897 4143 // Set BL pin
Gabiuas 1:0ada46075897 4144 void TextLCD_SPI_N_3_10::_setBL(bool value) {
Gabiuas 1:0ada46075897 4145 if (_bl) {
Gabiuas 1:0ada46075897 4146 _bl->write(value);
Gabiuas 1:0ada46075897 4147 }
Gabiuas 1:0ada46075897 4148 }
Gabiuas 1:0ada46075897 4149
Gabiuas 1:0ada46075897 4150 // Not used in this mode
Gabiuas 1:0ada46075897 4151 void TextLCD_SPI_N_3_10::_setData(int value) {
Gabiuas 1:0ada46075897 4152 }
Gabiuas 1:0ada46075897 4153
Gabiuas 1:0ada46075897 4154 // Write a byte using SPI3 10 bits mode
Gabiuas 1:0ada46075897 4155 void TextLCD_SPI_N_3_10::_writeByte(int value) {
Gabiuas 1:0ada46075897 4156 _cs = 0;
Gabiuas 1:0ada46075897 4157 wait_us(1);
Gabiuas 1:0ada46075897 4158 _spi->write( (_controlbyte << 8) | (value & 0xFF));
Gabiuas 1:0ada46075897 4159 wait_us(1);
Gabiuas 1:0ada46075897 4160 _cs = 1;
Gabiuas 1:0ada46075897 4161 }
Gabiuas 1:0ada46075897 4162 #endif /* Native SPI bus */
Gabiuas 1:0ada46075897 4163 //------- End TextLCD_SPI_N_3_10 ----------
Gabiuas 1:0ada46075897 4164
Gabiuas 1:0ada46075897 4165
Gabiuas 1:0ada46075897 4166 //------- Start TextLCD_SPI_N_3_16 --------
Gabiuas 1:0ada46075897 4167 #if(LCD_SPI_N_3_16 == 1) /* Native SPI bus */
Gabiuas 1:0ada46075897 4168
Gabiuas 1:0ada46075897 4169 /** Create a TextLCD interface using a controller with a native SPI3 16 bits interface
Gabiuas 1:0ada46075897 4170 *
Gabiuas 1:0ada46075897 4171 * @param spi SPI Bus
Gabiuas 1:0ada46075897 4172 * @param cs chip select pin (active low)
Gabiuas 1:0ada46075897 4173 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Gabiuas 1:0ada46075897 4174 * @param bl Backlight control line (optional, default = NC)
Gabiuas 1:0ada46075897 4175 * @param ctrl LCD controller (default = PT6314)
Gabiuas 1:0ada46075897 4176 */
Gabiuas 1:0ada46075897 4177 TextLCD_SPI_N_3_16::TextLCD_SPI_N_3_16(SPI *spi, PinName cs, LCDType type, PinName bl, LCDCtrl ctrl) :
Gabiuas 1:0ada46075897 4178 TextLCD_Base(type, ctrl),
Gabiuas 1:0ada46075897 4179 _spi(spi),
Gabiuas 1:0ada46075897 4180 _cs(cs) {
Gabiuas 1:0ada46075897 4181
Gabiuas 1:0ada46075897 4182 // Init CS
Gabiuas 1:0ada46075897 4183 _cs = 1;
Gabiuas 1:0ada46075897 4184
Gabiuas 1:0ada46075897 4185 // Setup the spi for 8 bit data, low steady state clock,
Gabiuas 1:0ada46075897 4186 // rising edge capture, with a 500KHz or 1MHz clock rate
Gabiuas 1:0ada46075897 4187 _spi->format(8,0);
Gabiuas 1:0ada46075897 4188 _spi->frequency(1000000);
Gabiuas 1:0ada46075897 4189
Gabiuas 1:0ada46075897 4190 // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access.
Gabiuas 1:0ada46075897 4191 if (bl != NC) {
Gabiuas 1:0ada46075897 4192 _bl = new DigitalOut(bl); //Construct new pin
Gabiuas 1:0ada46075897 4193 _bl->write(0); //Deactivate
Gabiuas 1:0ada46075897 4194 }
Gabiuas 1:0ada46075897 4195 else {
Gabiuas 1:0ada46075897 4196 // No Hardware Backlight pin
Gabiuas 1:0ada46075897 4197 _bl = NULL; //Construct dummy pin
Gabiuas 1:0ada46075897 4198 }
Gabiuas 1:0ada46075897 4199
Gabiuas 1:0ada46075897 4200 //Sanity check
Gabiuas 1:0ada46075897 4201 if (_ctrl & LCD_C_SPI3_16) {
Gabiuas 1:0ada46075897 4202 _init(_LCD_DL_8); // Set Datalength to 8 bit for all native serial interfaces
Gabiuas 1:0ada46075897 4203 }
Gabiuas 1:0ada46075897 4204 else {
Gabiuas 1:0ada46075897 4205 error("Error: LCD Controller type does not support native SPI3 16 bits interface\n\r");
Gabiuas 1:0ada46075897 4206 }
Gabiuas 1:0ada46075897 4207 }
Gabiuas 1:0ada46075897 4208
Gabiuas 1:0ada46075897 4209 TextLCD_SPI_N_3_16::~TextLCD_SPI_N_3_16() {
Gabiuas 1:0ada46075897 4210 if (_bl != NULL) {delete _bl;} // BL pin
Gabiuas 1:0ada46075897 4211 }
Gabiuas 1:0ada46075897 4212
Gabiuas 1:0ada46075897 4213 // Not used in this mode
Gabiuas 1:0ada46075897 4214 void TextLCD_SPI_N_3_16::_setEnable(bool value) {
Gabiuas 1:0ada46075897 4215 }
Gabiuas 1:0ada46075897 4216
Gabiuas 1:0ada46075897 4217 // Set RS pin
Gabiuas 1:0ada46075897 4218 // Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 4219 void TextLCD_SPI_N_3_16::_setRS(bool value) {
Gabiuas 1:0ada46075897 4220 // The 16bit mode is split in 2 bytes. The first byte is for synchronisation and controlbits. The controlbits define the meaning of the next byte.
Gabiuas 1:0ada46075897 4221 // The 8 actual bits represent either a data or a command byte.
Gabiuas 1:0ada46075897 4222 // b15 b14 b13 b12 b11 b10 b9 b8 - b7 b6 b5 b4 b3 b2 b1 b0
Gabiuas 1:0ada46075897 4223 // 1 1 1 1 1 RW RS 0 d7 d6 d5 d4 d3 d2 d1 d0
Gabiuas 1:0ada46075897 4224 //
Gabiuas 1:0ada46075897 4225 // RS=1 means that next byte is data, RS=0 means that next byte is command
Gabiuas 1:0ada46075897 4226 // RW=0 means that next byte is writen, RW=1 means that next byte is read (not used in this lib)
Gabiuas 1:0ada46075897 4227 //
Gabiuas 1:0ada46075897 4228
Gabiuas 1:0ada46075897 4229 if (value) {
Gabiuas 1:0ada46075897 4230 _controlbyte = 0xFA; // Next byte is data
Gabiuas 1:0ada46075897 4231 }
Gabiuas 1:0ada46075897 4232 else {
Gabiuas 1:0ada46075897 4233 _controlbyte = 0xF8; // Next byte is command
Gabiuas 1:0ada46075897 4234 }
Gabiuas 1:0ada46075897 4235 }
Gabiuas 1:0ada46075897 4236
Gabiuas 1:0ada46075897 4237 // Set BL pin
Gabiuas 1:0ada46075897 4238 void TextLCD_SPI_N_3_16::_setBL(bool value) {
Gabiuas 1:0ada46075897 4239 if (_bl) {
Gabiuas 1:0ada46075897 4240 _bl->write(value);
Gabiuas 1:0ada46075897 4241 }
Gabiuas 1:0ada46075897 4242 }
Gabiuas 1:0ada46075897 4243
Gabiuas 1:0ada46075897 4244 // Not used in this mode
Gabiuas 1:0ada46075897 4245 void TextLCD_SPI_N_3_16::_setData(int value) {
Gabiuas 1:0ada46075897 4246 }
Gabiuas 1:0ada46075897 4247
Gabiuas 1:0ada46075897 4248 // Write a byte using SPI3 16 bits mode
Gabiuas 1:0ada46075897 4249 void TextLCD_SPI_N_3_16::_writeByte(int value) {
Gabiuas 1:0ada46075897 4250 _cs = 0;
Gabiuas 1:0ada46075897 4251 wait_us(1);
Gabiuas 1:0ada46075897 4252
Gabiuas 1:0ada46075897 4253 _spi->write(_controlbyte);
Gabiuas 1:0ada46075897 4254
Gabiuas 1:0ada46075897 4255 _spi->write(value);
Gabiuas 1:0ada46075897 4256
Gabiuas 1:0ada46075897 4257 wait_us(1);
Gabiuas 1:0ada46075897 4258 _cs = 1;
Gabiuas 1:0ada46075897 4259 }
Gabiuas 1:0ada46075897 4260 #endif /* Native SPI bus */
Gabiuas 1:0ada46075897 4261 //------- End TextLCD_SPI_N_3_16 ----------
Gabiuas 1:0ada46075897 4262
Gabiuas 1:0ada46075897 4263
Gabiuas 1:0ada46075897 4264 //------- Start TextLCD_SPI_N_3_24 --------
Gabiuas 1:0ada46075897 4265 #if(LCD_SPI_N_3_24 == 1) /* Native SPI bus */
Gabiuas 1:0ada46075897 4266
Gabiuas 1:0ada46075897 4267 /** Create a TextLCD interface using a controller with a native SPI3 24 bits interface
Gabiuas 1:0ada46075897 4268 *
Gabiuas 1:0ada46075897 4269 * @param spi SPI Bus
Gabiuas 1:0ada46075897 4270 * @param cs chip select pin (active low)
Gabiuas 1:0ada46075897 4271 * @param type Sets the panel size/addressing mode (default = LCD16x2)
Gabiuas 1:0ada46075897 4272 * @param bl Backlight control line (optional, default = NC)
Gabiuas 1:0ada46075897 4273 * @param ctrl LCD controller (default = SSD1803)
Gabiuas 1:0ada46075897 4274 */
Gabiuas 1:0ada46075897 4275 TextLCD_SPI_N_3_24::TextLCD_SPI_N_3_24(SPI *spi, PinName cs, LCDType type, PinName bl, LCDCtrl ctrl) :
Gabiuas 1:0ada46075897 4276 TextLCD_Base(type, ctrl),
Gabiuas 1:0ada46075897 4277 _spi(spi),
Gabiuas 1:0ada46075897 4278 _cs(cs) {
Gabiuas 1:0ada46075897 4279
Gabiuas 1:0ada46075897 4280 // Init CS
Gabiuas 1:0ada46075897 4281 _cs = 1;
Gabiuas 1:0ada46075897 4282
Gabiuas 1:0ada46075897 4283 // Setup the spi for 8 bit data, high steady state clock,
Gabiuas 1:0ada46075897 4284 // rising edge capture, with a 500KHz or 1MHz clock rate
Gabiuas 1:0ada46075897 4285 _spi->format(8,3);
Gabiuas 1:0ada46075897 4286 _spi->frequency(1000000);
Gabiuas 1:0ada46075897 4287
Gabiuas 1:0ada46075897 4288 // The hardware Backlight pin is optional. Test and make sure whether it exists or not to prevent illegal access.
Gabiuas 1:0ada46075897 4289 if (bl != NC) {
Gabiuas 1:0ada46075897 4290 _bl = new DigitalOut(bl); //Construct new pin
Gabiuas 1:0ada46075897 4291 _bl->write(0); //Deactivate
Gabiuas 1:0ada46075897 4292 }
Gabiuas 1:0ada46075897 4293 else {
Gabiuas 1:0ada46075897 4294 // No Hardware Backlight pin
Gabiuas 1:0ada46075897 4295 _bl = NULL; //Construct dummy pin
Gabiuas 1:0ada46075897 4296 }
Gabiuas 1:0ada46075897 4297
Gabiuas 1:0ada46075897 4298 //Sanity check
Gabiuas 1:0ada46075897 4299 if (_ctrl & LCD_C_SPI3_24) {
Gabiuas 1:0ada46075897 4300 _init(_LCD_DL_8); // Set Datalength to 8 bit for all native serial interfaces
Gabiuas 1:0ada46075897 4301 }
Gabiuas 1:0ada46075897 4302 else {
Gabiuas 1:0ada46075897 4303 error("Error: LCD Controller type does not support native SPI3 24 bits interface\n\r");
Gabiuas 1:0ada46075897 4304 }
Gabiuas 1:0ada46075897 4305 }
Gabiuas 1:0ada46075897 4306
Gabiuas 1:0ada46075897 4307 TextLCD_SPI_N_3_24::~TextLCD_SPI_N_3_24() {
Gabiuas 1:0ada46075897 4308 if (_bl != NULL) {delete _bl;} // BL pin
Gabiuas 1:0ada46075897 4309 }
Gabiuas 1:0ada46075897 4310
Gabiuas 1:0ada46075897 4311 // Not used in this mode
Gabiuas 1:0ada46075897 4312 void TextLCD_SPI_N_3_24::_setEnable(bool value) {
Gabiuas 1:0ada46075897 4313 }
Gabiuas 1:0ada46075897 4314
Gabiuas 1:0ada46075897 4315 // Set RS pin
Gabiuas 1:0ada46075897 4316 // Used for mbed pins, I2C bus expander or SPI shiftregister
Gabiuas 1:0ada46075897 4317 void TextLCD_SPI_N_3_24::_setRS(bool value) {
Gabiuas 1:0ada46075897 4318 // The 24bit mode is split in 3 bytes. The first byte is for synchronisation and controlbits. The controlbits define the meaning of the next two bytes.
Gabiuas 1:0ada46075897 4319 // Each byte encodes 4 actual bits. The 8 actual bits represent either a data or a command byte.
Gabiuas 1:0ada46075897 4320 // b23 b22 b21 b20 b19 b18 b17 b16 - b15 b14 b13 b12 b11 b10 b9 b8 - b7 b6 b5 b4 b3 b2 b1 b0
Gabiuas 1:0ada46075897 4321 // 1 1 1 1 1 RW RS 0 d0 d1 d2 d3 0 0 0 0 d4 d5 d6 d7 0 0 0 0
Gabiuas 1:0ada46075897 4322 //
Gabiuas 1:0ada46075897 4323 // RS=1 means that next byte is data, RS=0 means that next byte is command
Gabiuas 1:0ada46075897 4324 // RW=0 means that next byte is writen, RW=1 means that next byte is read (not used in this lib)
Gabiuas 1:0ada46075897 4325 //
Gabiuas 1:0ada46075897 4326 // Note: SPI3_24 expects LSB first. This is inconsistent with regular SPI convention (and hardware) that sends MSB first.
Gabiuas 1:0ada46075897 4327
Gabiuas 1:0ada46075897 4328 if (value) {
Gabiuas 1:0ada46075897 4329 _controlbyte = 0xFA; // Next byte is data
Gabiuas 1:0ada46075897 4330 }
Gabiuas 1:0ada46075897 4331 else {
Gabiuas 1:0ada46075897 4332 _controlbyte = 0xF8; // Next byte is command
Gabiuas 1:0ada46075897 4333 }
Gabiuas 1:0ada46075897 4334 }
Gabiuas 1:0ada46075897 4335
Gabiuas 1:0ada46075897 4336 // Set BL pin
Gabiuas 1:0ada46075897 4337 void TextLCD_SPI_N_3_24::_setBL(bool value) {
Gabiuas 1:0ada46075897 4338 if (_bl) {
Gabiuas 1:0ada46075897 4339 _bl->write(value);
Gabiuas 1:0ada46075897 4340 }
Gabiuas 1:0ada46075897 4341 }
Gabiuas 1:0ada46075897 4342
Gabiuas 1:0ada46075897 4343 // Not used in this mode
Gabiuas 1:0ada46075897 4344 void TextLCD_SPI_N_3_24::_setData(int value) {
Gabiuas 1:0ada46075897 4345 }
Gabiuas 1:0ada46075897 4346
Gabiuas 1:0ada46075897 4347 //Mapping table to flip the bits around cause SPI3_24 expects LSB first.
Gabiuas 1:0ada46075897 4348 const uint8_t map3_24[16] = {0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0, 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0};
Gabiuas 1:0ada46075897 4349
Gabiuas 1:0ada46075897 4350 // Write a byte using SPI3 24 bits mode
Gabiuas 1:0ada46075897 4351 void TextLCD_SPI_N_3_24::_writeByte(int value) {
Gabiuas 1:0ada46075897 4352 _cs = 0;
Gabiuas 1:0ada46075897 4353 wait_us(1);
Gabiuas 1:0ada46075897 4354 _spi->write(_controlbyte);
Gabiuas 1:0ada46075897 4355
Gabiuas 1:0ada46075897 4356 //Map and send the LSB nibble
Gabiuas 1:0ada46075897 4357 _spi->write( map3_24[value & 0x0F]);
Gabiuas 1:0ada46075897 4358
Gabiuas 1:0ada46075897 4359 //Map and send the MSB nibble
Gabiuas 1:0ada46075897 4360 _spi->write( map3_24[(value >> 4) & 0x0F]);
Gabiuas 1:0ada46075897 4361
Gabiuas 1:0ada46075897 4362 wait_us(1);
Gabiuas 1:0ada46075897 4363 _cs = 1;
Gabiuas 1:0ada46075897 4364 }
Gabiuas 1:0ada46075897 4365 #endif /* Native SPI bus */
Gabiuas 1:0ada46075897 4366 //------- End TextLCD_SPI_N_3_24 ----------
Gabiuas 1:0ada46075897 4367