Pantalla LCD

Dependencies:   mbed TextLCD

Committer:
jhonlopez
Date:
Sun May 26 17:55:58 2019 +0000
Revision:
0:531dcadb7c20
Programa pantalla LCD

Who changed what in which revision?

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