In TextLCD_I2C_N Class, added void setContrast(unsigned char c) function as temporary. This is for ST7032i non-volume type contrast control.

Dependents:   LPC1114_data_logger RTC_w_COM Frequency_Counter_w_GPS_1PPS CW_Decoder_using_FFT_on_F446 ... more

Fork of TextLCD by Wim Huiskamp

In TextLCD_I2C_N Class, added void setContrast(unsigned char c) function as temporary.

Committer:
kenjiArai
Date:
Tue Aug 04 03:55:44 2020 +0000
Revision:
31:f8e67a681560
Parent:
30:4c57a022a56c
added #include "Stream.h" (need to run on mbed-os6.2.0)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kenjiArai 30:4c57a022a56c 1 /* mbed TextLCD Library, for LCDs based on HD44780 controllers
simon 6:e4cb7ddee0d3 2 * Copyright (c) 2007-2010, sford, http://mbed.org
wim 14:0c32b66b14b8 3 * 2013, v01: WH, Added LCD types, fixed LCD address issues, added Cursor and UDCs
wim 14:0c32b66b14b8 4 * 2013, v02: WH, Added I2C and SPI bus interfaces
wim 15:b70ebfffb258 5 * 2013, v03: WH, Added support for LCD40x4 which uses 2 controllers
wim 18:bd65dc10f27f 6 * 2013, v04: WH, Added support for Display On/Off, improved 4bit bootprocess
wim 18:bd65dc10f27f 7 * 2013, v05: WH, Added support for 8x2B, added some UDCs
wim 19:c747b9e2e7b8 8 * 2013, v06: WH, Added support for devices that use internal DC/DC converters
wim 20:e0da005a777f 9 * 2013, v07: WH, Added support for backlight and include portdefinitions for LCD2004 Module from DFROBOT
wim 22:35742ec80c24 10 * 2014, v08: WH, Refactored in Base and Derived Classes to deal with mbed lib change regarding 'NC' defined pins
wim 25:6162b31128c9 11 * 2014, v09: WH/EO, Added Class for Native SPI controllers such as ST7032
kenjiArai 30:4c57a022a56c 12 * 2014, v10: WH, Added Class for Native I2C controllers such as ST7032i, Added support for MCP23008 I2C portexpander, Added support for Adafruit module
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 15 * 2014, v13: WH, Added support for controllers US2066/SSD1311 (OLED), added setUDCBlink() method for supported devices (eg SSD1803), fixed issue in setPower()
kenjiArai 30:4c57a022a56c 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,
kenjiArai 30:4c57a022a56c 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.
kenjiArai 30:4c57a022a56c 18 * 2014, v15: WH, Added AC780 support, added I2C expander modules, fixed setBacklight() for inverted logic modules. Fixed bug in LCD_SPI_N define
kenjiArai 30:4c57a022a56c 19 * 2014, v16: WH, Added ST7070 and KS0073 support, added setIcon(), clrIcon() and setInvert() method for supported devices
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 21 * 2015, v18: WH, Performance improvement I2C portexpander
kenjiArai 30:4c57a022a56c 22 * 2015, v19: WH, Fixed Adafruit I2C/SPI portexpander pinmappings, fixed SYDZ Backlight
kenjiArai 30:4c57a022a56c 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),
kenjiArai 30:4c57a022a56c 24 * Fixed and Added more fonttable support for PCF2119R_3V3, Added HD66712 controller.
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 26 * Added SPLC792A controller, Added UTF8_2_LCD decode for Cyrilic font (By Andriy Ribalko). Added setFont()
simon 1:ac48b187213c 27 *
simon 1:ac48b187213c 28 * Permission is hereby granted, free of charge, to any person obtaining a copy
simon 1:ac48b187213c 29 * of this software and associated documentation files (the "Software"), to deal
simon 1:ac48b187213c 30 * in the Software without restriction, including without limitation the rights
simon 1:ac48b187213c 31 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
simon 1:ac48b187213c 32 * copies of the Software, and to permit persons to whom the Software is
simon 1:ac48b187213c 33 * furnished to do so, subject to the following conditions:
simon 1:ac48b187213c 34 *
simon 1:ac48b187213c 35 * The above copyright notice and this permission notice shall be included in
simon 1:ac48b187213c 36 * all copies or substantial portions of the Software.
simon 1:ac48b187213c 37 *
simon 1:ac48b187213c 38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
simon 1:ac48b187213c 39 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
simon 1:ac48b187213c 40 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
simon 1:ac48b187213c 41 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
simon 1:ac48b187213c 42 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
simon 1:ac48b187213c 43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
simon 1:ac48b187213c 44 * THE SOFTWARE.
simon 1:ac48b187213c 45 */
kenjiArai 30:4c57a022a56c 46 #include "mbed.h"
simon 1:ac48b187213c 47 #include "TextLCD.h"
kenjiArai 30:4c57a022a56c 48 #include "TextLCD_UDC.inc"
kenjiArai 30:4c57a022a56c 49 #include "TextLCD_UTF8.inc"
kenjiArai 30:4c57a022a56c 50
wim 21:9eb628d9e164 51 /** Create a TextLCD_Base interface
wim 15:b70ebfffb258 52 *
wim 21:9eb628d9e164 53 * @param type Sets the panel size/addressing mode (default = LCD16x2)
wim 21:9eb628d9e164 54 * @param ctrl LCD controller (default = HD44780)
wim 15:b70ebfffb258 55 */
wim 21:9eb628d9e164 56 TextLCD_Base::TextLCD_Base(LCDType type, LCDCtrl ctrl) : _type(type), _ctrl(ctrl) {
kenjiArai 30:4c57a022a56c 57
kenjiArai 30:4c57a022a56c 58 // Extract LCDType data
kenjiArai 30:4c57a022a56c 59
kenjiArai 30:4c57a022a56c 60 // Columns encoded in b15..b8
kenjiArai 30:4c57a022a56c 61 _nr_cols = (_type & LCD_T_COL_MSK) >> LCD_T_COL_SHFT;
kenjiArai 30:4c57a022a56c 62
kenjiArai 30:4c57a022a56c 63 // Rows encoded in b23..b16
kenjiArai 30:4c57a022a56c 64 _nr_rows = (_type & LCD_T_ROW_MSK) >> LCD_T_ROW_SHFT;
kenjiArai 30:4c57a022a56c 65
kenjiArai 30:4c57a022a56c 66 // Addressing mode encoded in b27..b24
kenjiArai 30:4c57a022a56c 67 _addr_mode = _type & LCD_T_ADR_MSK;
kenjiArai 30:4c57a022a56c 68
kenjiArai 30:4c57a022a56c 69 // Font table, encoded in LCDCtrl
kenjiArai 30:4c57a022a56c 70 _font = _ctrl & LCD_C_FNT_MSK;
wim 14:0c32b66b14b8 71 }
wim 14:0c32b66b14b8 72
wim 21:9eb628d9e164 73 /** Init the LCD Controller(s)
wim 21:9eb628d9e164 74 * Clear display
kenjiArai 30:4c57a022a56c 75 * @param _LCDDatalength dl sets the datalength of data/commands
kenjiArai 30:4c57a022a56c 76 * @return none
wim 21:9eb628d9e164 77 */
kenjiArai 30:4c57a022a56c 78 void TextLCD_Base::_init(_LCDDatalength dl) {
kenjiArai 30:4c57a022a56c 79
kenjiArai 30:4c57a022a56c 80 WAIT_MS(100); // Wait 100ms to ensure powered up
wim 15:b70ebfffb258 81
kenjiArai 30:4c57a022a56c 82 #if (LCD_TWO_CTRL == 1)
wim 15:b70ebfffb258 83 // Select and configure second LCD controller when needed
wim 15:b70ebfffb258 84 if(_type==LCD40x4) {
kenjiArai 30:4c57a022a56c 85 _ctrl_idx=_LCDCtrl_1; // Select 2nd controller
kenjiArai 30:4c57a022a56c 86 _initCtrl(dl); // Init 2nd controller
wim 15:b70ebfffb258 87 }
kenjiArai 30:4c57a022a56c 88 #endif
wim 15:b70ebfffb258 89
wim 15:b70ebfffb258 90 // Select and configure primary LCD controller
wim 27:22d5086f6ba6 91 _ctrl_idx=_LCDCtrl_0; // Select primary controller
kenjiArai 30:4c57a022a56c 92 _initCtrl(dl); // Init primary controller
kenjiArai 30:4c57a022a56c 93
kenjiArai 30:4c57a022a56c 94 // Clear whole display and Reset Cursor location
kenjiArai 30:4c57a022a56c 95 // Note: This will make sure that some 3-line displays that skip topline of a 4-line configuration
kenjiArai 30:4c57a022a56c 96 // are cleared and init cursor correctly.
kenjiArai 30:4c57a022a56c 97 cls();
wim 15:b70ebfffb258 98 }
wim 15:b70ebfffb258 99
wim 21:9eb628d9e164 100 /** Init the LCD controller
kenjiArai 30:4c57a022a56c 101 * Set number of lines, fonttype, no cursor etc
kenjiArai 30:4c57a022a56c 102 * The controller is accessed in 4-bit parallel mode either directly via mbed pins or through I2C or SPI expander.
kenjiArai 30:4c57a022a56c 103 * Some controllers also support native I2C or SPI interfaces.
kenjiArai 30:4c57a022a56c 104 *
kenjiArai 30:4c57a022a56c 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.
kenjiArai 30:4c57a022a56c 106 * @return none
kenjiArai 30:4c57a022a56c 107 *
kenjiArai 30:4c57a022a56c 108 * Note: some configurations are commented out because they have not yet been tested due to lack of hardware
wim 21:9eb628d9e164 109 */
kenjiArai 30:4c57a022a56c 110 void TextLCD_Base::_initCtrl(_LCDDatalength dl) {
kenjiArai 30:4c57a022a56c 111 int _bias_lines=0; // Set Bias and lines (Instr Set 1), temporary variable.
kenjiArai 30:4c57a022a56c 112 int _lines=0; // Set lines (Ext Instr Set), temporary variable.
wim 15:b70ebfffb258 113
wim 26:bd897a001012 114 this->_setRS(false); // command mode
kenjiArai 30:4c57a022a56c 115
kenjiArai 30:4c57a022a56c 116 if (dl == _LCD_DL_4) {
kenjiArai 30:4c57a022a56c 117 // The Controller could be in 8 bit mode (power-on reset) or in 4 bit mode (warm reboot) at this point.
kenjiArai 30:4c57a022a56c 118 // Follow this procedure to make sure the Controller enters the correct state. The hardware interface
kenjiArai 30:4c57a022a56c 119 // between the uP and the LCD can only write the 4 most significant bits (Most Significant Nibble, MSN).
kenjiArai 30:4c57a022a56c 120 // In 4 bit mode the LCD expects the MSN first, followed by the LSN.
kenjiArai 30:4c57a022a56c 121 //
kenjiArai 30:4c57a022a56c 122 // Current state: 8 bit mode | 4 bit mode, MSN is next | 4 bit mode, LSN is next
kenjiArai 30:4c57a022a56c 123 //-------------------------------------------------------------------------------------------------
kenjiArai 30:4c57a022a56c 124 _writeNibble(0x3); // set 8 bit mode (MSN) and dummy LSN, | set 8 bit mode (MSN), | set dummy LSN,
kenjiArai 30:4c57a022a56c 125 // remains in 8 bit mode | remains in 4 bit mode | remains in 4 bit mode
kenjiArai 30:4c57a022a56c 126 WAIT_MS(15); //
kenjiArai 30:4c57a022a56c 127
kenjiArai 30:4c57a022a56c 128 _writeNibble(0x3); // set 8 bit mode (MSN) and dummy LSN, | set dummy LSN, | set 8bit mode (MSN),
kenjiArai 30:4c57a022a56c 129 // remains in 8 bit mode | change to 8 bit mode | remains in 4 bit mode
kenjiArai 30:4c57a022a56c 130 WAIT_MS(15); //
wim 13:24506ba22480 131
kenjiArai 30:4c57a022a56c 132 _writeNibble(0x3); // set 8 bit mode (MSN) and dummy LSN, | set 8 bit mode (MSN) and dummy LSN, | set dummy LSN,
kenjiArai 30:4c57a022a56c 133 // remains in 8 bit mode | remains in 8 bit mode | change to 8 bit mode
kenjiArai 30:4c57a022a56c 134 WAIT_MS(15); //
kenjiArai 30:4c57a022a56c 135
kenjiArai 30:4c57a022a56c 136 // Controller is now in 8 bit mode
kenjiArai 30:4c57a022a56c 137
kenjiArai 30:4c57a022a56c 138 _writeNibble(0x2); // Change to 4-bit mode (MSN), the LSN is undefined dummy
kenjiArai 30:4c57a022a56c 139 wait_us(40); // most instructions take 40us
kenjiArai 30:4c57a022a56c 140
kenjiArai 30:4c57a022a56c 141 // Controller is now in 4-bit mode
kenjiArai 30:4c57a022a56c 142 // Note: 4/8 bit mode is ignored for most native SPI and I2C devices. They dont use the parallel bus.
kenjiArai 30:4c57a022a56c 143 // However, _writeNibble() method is void anyway for native SPI and I2C devices.
wim 17:652ab113bc2e 144 }
kenjiArai 30:4c57a022a56c 145 else {
kenjiArai 30:4c57a022a56c 146 // Reset in 8 bit mode, final Function set will follow
kenjiArai 30:4c57a022a56c 147 _writeCommand(0x30); // Function set 0 0 1 DL=1 N F x x
kenjiArai 30:4c57a022a56c 148 WAIT_MS(1); // most instructions take 40us
kenjiArai 30:4c57a022a56c 149 }
wim 25:6162b31128c9 150
kenjiArai 30:4c57a022a56c 151 // Device specific initialisations: DC/DC converter to generate VLCD or VLED, number of lines etc
wim 19:c747b9e2e7b8 152 switch (_ctrl) {
kenjiArai 30:4c57a022a56c 153
kenjiArai 30:4c57a022a56c 154 case KS0073:
kenjiArai 30:4c57a022a56c 155 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 156 switch (_type) {
kenjiArai 30:4c57a022a56c 157 // case LCD6x1:
kenjiArai 30:4c57a022a56c 158 case LCD8x1: //8x1 is a regular 1 line display
kenjiArai 30:4c57a022a56c 159 // case LCD8x2B: //8x1 is a 16x1 line display
kenjiArai 30:4c57a022a56c 160 case LCD12x1:
kenjiArai 30:4c57a022a56c 161 case LCD16x1:
kenjiArai 30:4c57a022a56c 162 case LCD20x1:
kenjiArai 30:4c57a022a56c 163 case LCD24x1:
kenjiArai 30:4c57a022a56c 164 // case LCD32x1: // EXT pin is High, extension driver needed
kenjiArai 30:4c57a022a56c 165 // case LCD40x1: // EXT pin is High, extension driver needed
kenjiArai 30:4c57a022a56c 166 // case LCD52x1: // EXT pin is High, extension driver needed
kenjiArai 30:4c57a022a56c 167 _function = dl | 0x02; // Set function, 0 0 1 DL, N, RE(0), DH, REV
kenjiArai 30:4c57a022a56c 168 // Note: 4 bit mode is NOT ignored for native SPI !
kenjiArai 30:4c57a022a56c 169 // DL=1 (8 bits bus), DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 170 // N=0 (1-line mode), N=1 (2-line mode), dont care for 4 line mode
kenjiArai 30:4c57a022a56c 171 // RE=0 (Dis. Extended Regs, special mode for KS0073)
kenjiArai 30:4c57a022a56c 172 // DH=1 (Disp shift enable, special mode for KS0073)
kenjiArai 30:4c57a022a56c 173 // REV=0 (Reverse normal, special mode for KS0073)
kenjiArai 30:4c57a022a56c 174
kenjiArai 30:4c57a022a56c 175 _function_1 = dl | 0x04; // Set function, 0 0 1 DL, N, RE(1), BE, LP (Ext Regs)
kenjiArai 30:4c57a022a56c 176 // Note: 4 bit mode is NOT ignored for native SPI !
kenjiArai 30:4c57a022a56c 177 // DL=1 (8 bits bus), DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 178 // N=0 (1-line mode), N=1 (2-line mode), dont care for 4 line mode
kenjiArai 30:4c57a022a56c 179 // RE=1 (Ena Extended Regs, special mode for KS0073)
kenjiArai 30:4c57a022a56c 180 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073)
kenjiArai 30:4c57a022a56c 181 // LP=0 (LP=1 Low power mode, LP=0 Normal)
kenjiArai 30:4c57a022a56c 182
kenjiArai 30:4c57a022a56c 183 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
kenjiArai 30:4c57a022a56c 184 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073)
kenjiArai 30:4c57a022a56c 185 break;
kenjiArai 30:4c57a022a56c 186
kenjiArai 30:4c57a022a56c 187 // case LCD12x3D: // Special mode for KS0073, KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 188 // case LCD12x3D1: // Special mode for KS0073, KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 189 case LCD12x4D: // Special mode for KS0073, KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 190 // case LCD16x3D: // Special mode for KS0073, KS0078
kenjiArai 30:4c57a022a56c 191 // case LCD16x3D1: // Special mode for KS0073, KS0078
kenjiArai 30:4c57a022a56c 192 // case LCD16x4D: // Special mode for KS0073, KS0078
kenjiArai 30:4c57a022a56c 193 case LCD20x4D: // Special mode for KS0073, KS0078
kenjiArai 30:4c57a022a56c 194 _function = dl | 0x02; // Set function, 0 0 1 DL, N, RE(0), DH, REV
kenjiArai 30:4c57a022a56c 195 // Note: 4 bit mode is NOT ignored for native SPI !
kenjiArai 30:4c57a022a56c 196 // DL=1 (8 bits bus), DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 197 // N=0 (1-line mode), N=1 (2-line mode), dont care for 4 line mode
kenjiArai 30:4c57a022a56c 198 // RE=0 (Dis. Extended Regs, special mode for KS0073)
kenjiArai 30:4c57a022a56c 199 // DH=1 (Disp shift enable, special mode for KS0073)
kenjiArai 30:4c57a022a56c 200 // REV=0 (Reverse normal, special mode for KS0073)
kenjiArai 30:4c57a022a56c 201
kenjiArai 30:4c57a022a56c 202 _function_1 = dl | 0x04; // Set function, 0 0 1 DL, N, RE(1), BE, LP (Ext Regs)
kenjiArai 30:4c57a022a56c 203 // Note: 4 bit mode is NOT ignored for native SPI !
kenjiArai 30:4c57a022a56c 204 // DL=1 (8 bits bus), DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 205 // N=0 (1-line mode), N=1 (2-line mode), dont care for 4 line mode
kenjiArai 30:4c57a022a56c 206 // RE=1 (Ena Extended Regs, special mode for KS0073)
kenjiArai 30:4c57a022a56c 207 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073)
kenjiArai 30:4c57a022a56c 208 // LP=0 (LP=1 Low power mode, LP=0 Normal)
kenjiArai 30:4c57a022a56c 209
kenjiArai 30:4c57a022a56c 210 _function_x = 0x01; // Ext Function set 0000 1 FW BW NW (Ext Regs)
kenjiArai 30:4c57a022a56c 211 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073)
kenjiArai 30:4c57a022a56c 212 break;
kenjiArai 30:4c57a022a56c 213
kenjiArai 30:4c57a022a56c 214 // case LCD6x2:
kenjiArai 30:4c57a022a56c 215 case LCD8x2:
kenjiArai 30:4c57a022a56c 216 case LCD16x2:
kenjiArai 30:4c57a022a56c 217 // case LCD16x1C:
kenjiArai 30:4c57a022a56c 218 case LCD20x2:
kenjiArai 30:4c57a022a56c 219 case LCD24x2:
kenjiArai 30:4c57a022a56c 220 case LCD32x2:
kenjiArai 30:4c57a022a56c 221 // All other LCD types are initialised as 2 Line displays
kenjiArai 30:4c57a022a56c 222 _function = dl | 0x0A; // Set function, 0 0 1 DL, N, RE(0), DH, REV
kenjiArai 30:4c57a022a56c 223 // Note: 4 bit mode is NOT ignored for native SPI !
kenjiArai 30:4c57a022a56c 224 // DL=1 (8 bits bus), DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 225 // N=1 (2-line mode), N=0 (1-line mode)
kenjiArai 30:4c57a022a56c 226 // RE=0 (Dis. Extended Regs, special mode for KS0073)
kenjiArai 30:4c57a022a56c 227 // DH=1 (Disp shift enable, special mode for KS0073)
kenjiArai 30:4c57a022a56c 228 // REV=0 (Reverse normal, special mode for KS0073)
kenjiArai 30:4c57a022a56c 229
kenjiArai 30:4c57a022a56c 230 _function_1 = dl | 0x0C; // Set function, 0 0 1 DL, N, RE(1), BE, LP (Ext Regs)
kenjiArai 30:4c57a022a56c 231 // Note: 4 bit mode is NOT ignored for native SPI !
kenjiArai 30:4c57a022a56c 232 // DL=1 (8 bits bus), DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 233 // N=1 (2 line mode), N=0 (1-line mode)
kenjiArai 30:4c57a022a56c 234 // RE=1 (Ena Extended Regs, special mode for KS0073)
kenjiArai 30:4c57a022a56c 235 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073)
kenjiArai 30:4c57a022a56c 236 // LP=0 (LP=1 Low power mode, LP=0 Normal)
kenjiArai 30:4c57a022a56c 237
kenjiArai 30:4c57a022a56c 238 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
kenjiArai 30:4c57a022a56c 239 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073)
kenjiArai 30:4c57a022a56c 240 break;
kenjiArai 30:4c57a022a56c 241
kenjiArai 30:4c57a022a56c 242 default:
kenjiArai 30:4c57a022a56c 243 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 244 break;
kenjiArai 30:4c57a022a56c 245 } // switch type
kenjiArai 30:4c57a022a56c 246
kenjiArai 30:4c57a022a56c 247 // init special features
kenjiArai 30:4c57a022a56c 248 _writeCommand(0x20 | _function_1);// Function set 001 DL N RE(1) BE LP (Ext Regs)
kenjiArai 30:4c57a022a56c 249 // DL=0 (4 bits bus), DL=1 (8 bits mode)
kenjiArai 30:4c57a022a56c 250 // N=0 (1 line mode), N=1 (2 line mode)
kenjiArai 30:4c57a022a56c 251 // RE=1 (Ena Extended Regs, special mode for KS0073)
kenjiArai 30:4c57a022a56c 252 // BE=0 (Blink Enable/Disable, CG/SEG RAM, special mode for KS0073)
kenjiArai 30:4c57a022a56c 253 // LP=0 (LP=1 Low power mode, LP=0 Normal)
kenjiArai 30:4c57a022a56c 254
kenjiArai 30:4c57a022a56c 255 _writeCommand(0x08 | _function_x); // Ext Function set 0000 1 FW BW NW (Ext Regs)
kenjiArai 30:4c57a022a56c 256 // FW=0 (5-dot font, special mode for KS0073)
kenjiArai 30:4c57a022a56c 257 // BW=0 (Cur BW invert disable, special mode for KS0073)
kenjiArai 30:4c57a022a56c 258 // NW=0 (1,2 Line), NW=1 (4 line, special mode for KS0073)
kenjiArai 30:4c57a022a56c 259
kenjiArai 30:4c57a022a56c 260 _writeCommand(0x10); // Scroll/Shift set 0001 DS/HS4 DS/HS3 DS/HS2 DS/HS1 (Ext Regs)
kenjiArai 30:4c57a022a56c 261 // Dotscroll/Display shift enable (Special mode for KS0073)
kenjiArai 30:4c57a022a56c 262
kenjiArai 30:4c57a022a56c 263 _writeCommand(0x80); // Scroll Quantity set 1 0 SQ5 SQ4 SQ3 SQ2 SQ1 SQ0 (Ext Regs)
kenjiArai 30:4c57a022a56c 264 // Scroll quantity (Special mode for KS0073)
kenjiArai 30:4c57a022a56c 265
kenjiArai 30:4c57a022a56c 266 _writeCommand(0x20 | _function); // Function set 001 DL N RE(0) DH REV (Std Regs)
kenjiArai 30:4c57a022a56c 267 // DL=0 (4 bits bus), DL=1 (8 bits mode)
kenjiArai 30:4c57a022a56c 268 // N=0 (1 line mode), N=1 (2 line mode)
kenjiArai 30:4c57a022a56c 269 // RE=0 (Dis. Extended Regs, special mode for KS0073)
kenjiArai 30:4c57a022a56c 270 // DH=1 (Disp shift enable/disable, special mode for KS0073)
kenjiArai 30:4c57a022a56c 271 // REV=0 (Reverse/Normal, special mode for KS0073)
kenjiArai 30:4c57a022a56c 272 break; // case KS0073 Controller
kenjiArai 30:4c57a022a56c 273
kenjiArai 30:4c57a022a56c 274
kenjiArai 30:4c57a022a56c 275 case KS0078:
kenjiArai 30:4c57a022a56c 276 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 277 switch (_type) {
kenjiArai 30:4c57a022a56c 278 case LCD8x1: //8x1 is a regular 1 line display
kenjiArai 30:4c57a022a56c 279 case LCD8x2B: //8x2B is a special case of 16x1
kenjiArai 30:4c57a022a56c 280 // case LCD12x1:
kenjiArai 30:4c57a022a56c 281 case LCD16x1:
kenjiArai 30:4c57a022a56c 282 // case LCD20x1:
kenjiArai 30:4c57a022a56c 283 case LCD24x1:
kenjiArai 30:4c57a022a56c 284 _function = dl | 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs)
kenjiArai 30:4c57a022a56c 285 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 286 // N=0 (1 line mode), N=1 (2 line mode)
kenjiArai 30:4c57a022a56c 287 // RE=0 (Dis. Extended Regs, special mode for KS0078)
kenjiArai 30:4c57a022a56c 288 // DH=1 (Disp shift enable, special mode for KS0078)
kenjiArai 30:4c57a022a56c 289 // REV=0 (Reverse normal, special mode for KS0078)
kenjiArai 30:4c57a022a56c 290
kenjiArai 30:4c57a022a56c 291 _function_1 = dl | 0x04; // Function set 001 DL N RE(1) BE 0 (Ext Regs)
kenjiArai 30:4c57a022a56c 292 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 293 // N=0 (1 line mode), N=1 (2 line mode)
kenjiArai 30:4c57a022a56c 294 // RE=1 (Ena Extended Regs, special mode for KS0078)
kenjiArai 30:4c57a022a56c 295 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0078)
kenjiArai 30:4c57a022a56c 296 // 0
kenjiArai 30:4c57a022a56c 297
kenjiArai 30:4c57a022a56c 298 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
kenjiArai 30:4c57a022a56c 299 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0078)
kenjiArai 30:4c57a022a56c 300 break;
kenjiArai 30:4c57a022a56c 301
kenjiArai 30:4c57a022a56c 302 // case LCD12x3D: // Special mode for KS0073, KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 303 // case LCD12x3D1: // Special mode for KS0073, KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 304 // case LCD12x4D: // Special mode for KS0073, KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 305 // case LCD16x3D: // Special mode for KS0073, KS0078
kenjiArai 30:4c57a022a56c 306 // case LCD16x4D: // Special mode for KS0073, KS0078
kenjiArai 30:4c57a022a56c 307 // case LCD20x4D: // Special mode for KS0073, KS0078
kenjiArai 30:4c57a022a56c 308 // case LCD24x3D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 309 // case LCD24x3D1: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 310 case LCD24x4D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 311 _function = dl | 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs)
kenjiArai 30:4c57a022a56c 312 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 313 // N=0 (dont care for 4 line mode)
kenjiArai 30:4c57a022a56c 314 // RE=0 (Dis. Extended Regs, special mode for KS0078)
kenjiArai 30:4c57a022a56c 315 // DH=1 (Disp shift enable, special mode for KS0078)
kenjiArai 30:4c57a022a56c 316 // REV=0 (Reverse normal, special mode for KS0078)
kenjiArai 30:4c57a022a56c 317
kenjiArai 30:4c57a022a56c 318 _function_1 = dl | 0x04; // Function set 001 DL N RE(1) BE 0 (Ext Regs)
kenjiArai 30:4c57a022a56c 319 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 320 // N=0 (1 line mode), N=1 (2 line mode)
kenjiArai 30:4c57a022a56c 321 // RE=1 (Ena Extended Regs, special mode for KS0078)
kenjiArai 30:4c57a022a56c 322 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0078)
kenjiArai 30:4c57a022a56c 323 // 0
kenjiArai 30:4c57a022a56c 324
kenjiArai 30:4c57a022a56c 325 _function_x = 0x01; // Ext Function set 0000 1 FW BW NW (Ext Regs)
kenjiArai 30:4c57a022a56c 326 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0078)
kenjiArai 30:4c57a022a56c 327 break;
kenjiArai 30:4c57a022a56c 328
kenjiArai 30:4c57a022a56c 329 // case LCD6x2:
kenjiArai 30:4c57a022a56c 330 case LCD8x2:
kenjiArai 30:4c57a022a56c 331 case LCD16x2:
kenjiArai 30:4c57a022a56c 332 // case LCD16x1C:
kenjiArai 30:4c57a022a56c 333 case LCD20x2:
kenjiArai 30:4c57a022a56c 334 case LCD24x2:
kenjiArai 30:4c57a022a56c 335 case LCD32x2:
kenjiArai 30:4c57a022a56c 336 case LCD40x2:
kenjiArai 30:4c57a022a56c 337 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
kenjiArai 30:4c57a022a56c 338 _function = dl | 0x0A; // Function set 001 DL N RE(0) DH REV (Std Regs)
kenjiArai 30:4c57a022a56c 339 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 340 // N=1 (1 line mode), N=1 (2 line mode)
kenjiArai 30:4c57a022a56c 341 // RE=0 (Dis. Extended Regs, special mode for KS0078)
kenjiArai 30:4c57a022a56c 342 // DH=1 (Disp shift enable, special mode for KS0078)
kenjiArai 30:4c57a022a56c 343 // REV=0 (Reverse normal, special mode for KS0078)
kenjiArai 30:4c57a022a56c 344
kenjiArai 30:4c57a022a56c 345 _function_1 = dl | 0x0C; // Function set 001 DL N RE(1) BE 0 (Ext Regs)
kenjiArai 30:4c57a022a56c 346 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 347 // N=1 (1 line mode), N=1 (2 line mode)
kenjiArai 30:4c57a022a56c 348 // RE=1 (Ena Extended Regs, special mode for KS0078)
kenjiArai 30:4c57a022a56c 349 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0078)
kenjiArai 30:4c57a022a56c 350 // 0
kenjiArai 30:4c57a022a56c 351
kenjiArai 30:4c57a022a56c 352 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
kenjiArai 30:4c57a022a56c 353 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0078)
kenjiArai 30:4c57a022a56c 354 break;
kenjiArai 30:4c57a022a56c 355
kenjiArai 30:4c57a022a56c 356 default:
kenjiArai 30:4c57a022a56c 357 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 358 break;
kenjiArai 30:4c57a022a56c 359 } // switch type
kenjiArai 30:4c57a022a56c 360
kenjiArai 30:4c57a022a56c 361 // init special features
kenjiArai 30:4c57a022a56c 362 _writeCommand(0x20 | _function_1);// Function set 001 DL N RE(1) BE 0 (Ext Regs)
kenjiArai 30:4c57a022a56c 363 // DL=0 (4 bits bus), DL=1 (8 bits mode)
kenjiArai 30:4c57a022a56c 364 // N=0 (1 line mode), N=1 (2 line mode)
kenjiArai 30:4c57a022a56c 365 // RE=1 (Ena Extended Regs, special mode for KS0078)
kenjiArai 30:4c57a022a56c 366 // BE=0 (Blink Enable/Disable, CG/SEG RAM, special mode for KS0078)
kenjiArai 30:4c57a022a56c 367 // 0
kenjiArai 30:4c57a022a56c 368
kenjiArai 30:4c57a022a56c 369 _writeCommand(0x08 | _function_x); // Ext Function set 0000 1 FW BW NW (Ext Regs)
kenjiArai 30:4c57a022a56c 370 // FW=0 (5-dot font, special mode for KS0078)
kenjiArai 30:4c57a022a56c 371 // BW=0 (Cur BW invert disable, special mode for KS0078)
kenjiArai 30:4c57a022a56c 372 // NW=0 (1,2 Line), NW=1 (4 line, special mode for KS0078)
kenjiArai 30:4c57a022a56c 373
kenjiArai 30:4c57a022a56c 374 _writeCommand(0x10); // Scroll/Shift set 0001 DS/HS4 DS/HS3 DS/HS2 DS/HS1 (Ext Regs)
kenjiArai 30:4c57a022a56c 375 // Dotscroll/Display shift enable (Special mode for KS0078)
kenjiArai 30:4c57a022a56c 376
kenjiArai 30:4c57a022a56c 377 _writeCommand(0x80); // Scroll Quantity set 1 0 SQ5 SQ4 SQ3 SQ2 SQ1 SQ0 (Ext Regs)
kenjiArai 30:4c57a022a56c 378 // Scroll quantity (Special mode for KS0078)
kenjiArai 30:4c57a022a56c 379
kenjiArai 30:4c57a022a56c 380 _writeCommand(0x20 | _function); // Function set 001 DL N RE(0) DH REV (Std Regs)
kenjiArai 30:4c57a022a56c 381 // DL=0 (4 bits bus), DL=1 (8 bits mode)
kenjiArai 30:4c57a022a56c 382 // N=0 (1 line mode), N=1 (2 line mode)
kenjiArai 30:4c57a022a56c 383 // RE=0 (Dis. Extended Regs, special mode for KS0078)
kenjiArai 30:4c57a022a56c 384 // DH=1 (Disp shift enable/disable, special mode for KS0078)
kenjiArai 30:4c57a022a56c 385 // REV=0 (Reverse/Normal, special mode for KS0078)
kenjiArai 30:4c57a022a56c 386 break; // case KS0078 Controller
kenjiArai 30:4c57a022a56c 387
wim 26:bd897a001012 388 case ST7032_3V3:
wim 26:bd897a001012 389 // ST7032 controller: Initialise Voltage booster for VLCD. VDD=3V3
kenjiArai 30:4c57a022a56c 390 // Note: very similar to SPLC792A
kenjiArai 30:4c57a022a56c 391 case ST7032_5V:
kenjiArai 30:4c57a022a56c 392 // ST7032 controller: Disable Voltage booster for VLCD. VDD=5V
kenjiArai 30:4c57a022a56c 393
kenjiArai 30:4c57a022a56c 394 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 395 switch (_type) {
kenjiArai 30:4c57a022a56c 396 case LCD8x1: //8x1 is a regular 1 line display
kenjiArai 30:4c57a022a56c 397 case LCD8x2B: //8x2B is a special case of 16x1
kenjiArai 30:4c57a022a56c 398 // case LCD12x1:
kenjiArai 30:4c57a022a56c 399 case LCD16x1:
kenjiArai 30:4c57a022a56c 400 // case LCD20x1:
kenjiArai 30:4c57a022a56c 401 case LCD24x1:
kenjiArai 30:4c57a022a56c 402 _function = 0x00; // FUNCTION SET 0 0 1 DL=0 (4 bit), N=0 (1-line display mode), F=0 (5*7dot), 0, IS
kenjiArai 30:4c57a022a56c 403 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 404 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 405 break;
kenjiArai 30:4c57a022a56c 406
kenjiArai 30:4c57a022a56c 407 case LCD12x3D: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 408 case LCD12x3D1: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 409 case LCD12x4D: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 410 case LCD16x3G: // Special mode for ST7036
kenjiArai 30:4c57a022a56c 411 case LCD24x4D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 412 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 413 break;
kenjiArai 30:4c57a022a56c 414
kenjiArai 30:4c57a022a56c 415 default:
kenjiArai 30:4c57a022a56c 416 // All other LCD types are initialised as 2 Line displays
kenjiArai 30:4c57a022a56c 417 _function = 0x08; // FUNCTION SET 0 0 1 DL=0 (4 bit), N=1 (2-line display mode), F=0 (5*7dot), 0, IS
kenjiArai 30:4c57a022a56c 418 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 419 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 420 break;
kenjiArai 30:4c57a022a56c 421 } // switch type
kenjiArai 30:4c57a022a56c 422
kenjiArai 30:4c57a022a56c 423 // init special features
kenjiArai 30:4c57a022a56c 424 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N F 0 IS=1 Select Instr Set = 1
kenjiArai 30:4c57a022a56c 425
kenjiArai 30:4c57a022a56c 426 _writeCommand(0x1C); // Internal OSC frequency adjustment Framefreq=183HZ, Bias will be 1/4 (Instr Set=1)
kenjiArai 30:4c57a022a56c 427 // Note: Bias and Osc register not available on SPLC792A
kenjiArai 30:4c57a022a56c 428
kenjiArai 30:4c57a022a56c 429 _contrast = LCD_ST7032_CONTRAST;
kenjiArai 30:4c57a022a56c 430 _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast Low bits, 0 1 1 1 C3 C2 C1 C0 (IS=1)
kenjiArai 30:4c57a022a56c 431
kenjiArai 30:4c57a022a56c 432
kenjiArai 30:4c57a022a56c 433 if (_ctrl == ST7032_3V3) {
kenjiArai 30:4c57a022a56c 434 // _icon_power = 0x04; // Icon display off (Bit3=0), Booster circuit is turned on (Bit2=1) (IS=1)
kenjiArai 30:4c57a022a56c 435 _icon_power = 0x0C; // Icon display on (Bit3=1), Booster circuit is turned on (Bit2=1) (IS=1)
kenjiArai 30:4c57a022a56c 436 // Note: Booster circuit always on for SPLC792A, Bit2 is dont care
kenjiArai 30:4c57a022a56c 437 // Saved to allow contrast change at later time
kenjiArai 30:4c57a022a56c 438 }
kenjiArai 30:4c57a022a56c 439 else {
kenjiArai 30:4c57a022a56c 440 // _icon_power = 0x00; // Icon display off, Booster circuit is turned off (IS=1)
kenjiArai 30:4c57a022a56c 441 _icon_power = 0x08; // Icon display on, Booster circuit is turned off (IS=1)
kenjiArai 30:4c57a022a56c 442 // Saved to allow contrast change at later time
kenjiArai 30:4c57a022a56c 443 }
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 445 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 446
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 448 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 449
kenjiArai 30:4c57a022a56c 450 _writeCommand(0x20 | _function); // Select Instruction Set = 0
kenjiArai 30:4c57a022a56c 451
kenjiArai 30:4c57a022a56c 452 break; // case ST7032_3V3 Controller
kenjiArai 30:4c57a022a56c 453 // case ST7032_5V Controller
kenjiArai 30:4c57a022a56c 454
kenjiArai 30:4c57a022a56c 455 case ST7036_3V3:
kenjiArai 30:4c57a022a56c 456 // ST7036 controller: Initialise Voltage booster for VLCD. VDD=3V3
kenjiArai 30:4c57a022a56c 457 // Note: supports 1,2 (LCD_T_A) or 3 lines (LCD_T_G)
kenjiArai 30:4c57a022a56c 458 case ST7036_5V:
kenjiArai 30:4c57a022a56c 459 // ST7036 controller: Disable Voltage booster for VLCD. VDD=5V
kenjiArai 30:4c57a022a56c 460 // Note: supports 1,2 (LCD_T_A) or 3 lines (LCD_T_G)
kenjiArai 30:4c57a022a56c 461
kenjiArai 30:4c57a022a56c 462 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 463 switch (_type) {
kenjiArai 30:4c57a022a56c 464 case LCD8x1: //8x1 is a regular 1 line display
kenjiArai 30:4c57a022a56c 465 case LCD8x2B: //8x2D is a special case of 16x1
kenjiArai 30:4c57a022a56c 466 // case LCD12x1:
kenjiArai 30:4c57a022a56c 467 case LCD16x1:
kenjiArai 30:4c57a022a56c 468 case LCD24x1:
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 470 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 471 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 472
kenjiArai 30:4c57a022a56c 473 _bias_lines = 0x04; // Bias: 1/5, 1 or 2-Lines LCD
kenjiArai 30:4c57a022a56c 474 break;
kenjiArai 30:4c57a022a56c 475
kenjiArai 30:4c57a022a56c 476 // case LCD12x3G: // Special mode for ST7036
kenjiArai 30:4c57a022a56c 477 case LCD16x3G: // Special mode for ST7036
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 479 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 480 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 481
kenjiArai 30:4c57a022a56c 482 _bias_lines = 0x05; // Bias: 1/5, 3-Lines LCD
kenjiArai 30:4c57a022a56c 483 break;
kenjiArai 30:4c57a022a56c 484
kenjiArai 30:4c57a022a56c 485 // case LCD12x3D1: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 486 // case LCD16x3D1: // Special mode for SSD1803
kenjiArai 30:4c57a022a56c 487 case LCD12x4D: // Special mode for PCF2116
kenjiArai 30:4c57a022a56c 488 case LCD24x4D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 489 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 490 break;
kenjiArai 30:4c57a022a56c 491
kenjiArai 30:4c57a022a56c 492 default:
kenjiArai 30:4c57a022a56c 493 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 495 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 496 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 497
kenjiArai 30:4c57a022a56c 498 _bias_lines = 0x04; // Bias: 1/5, 1 or 2-Lines LCD
kenjiArai 30:4c57a022a56c 499 break;
kenjiArai 30:4c57a022a56c 500 } // switch type
kenjiArai 30:4c57a022a56c 501
kenjiArai 30:4c57a022a56c 502
kenjiArai 30:4c57a022a56c 503 // init special features
kenjiArai 30:4c57a022a56c 504 _writeCommand(0x20 | _function | 0x01); // Set function, IS2,IS1 = 01 (Select Instr Set = 1)
kenjiArai 30:4c57a022a56c 505 _writeCommand(0x10 | _bias_lines); // Set Bias and 1,2 or 3 lines (Instr Set 1)
kenjiArai 30:4c57a022a56c 506
kenjiArai 30:4c57a022a56c 507 _contrast = LCD_ST7036_CONTRAST;
kenjiArai 30:4c57a022a56c 508 _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast, 0 1 1 1 C3 C2 C1 C0 (Instr Set 1)
kenjiArai 30:4c57a022a56c 509
kenjiArai 30:4c57a022a56c 510 if (_ctrl == ST7036_3V3) {
kenjiArai 30:4c57a022a56c 511 _icon_power = 0x0C; // Set Icon, Booster, Contrast High bits, 0 1 0 1 Ion=1 Bon=1 C5 C4 (Instr Set 1)
kenjiArai 30:4c57a022a56c 512 // _icon_power = 0x04; // Set Icon, Booster, Contrast High bits, 0 1 0 1 Ion=0 Bon=1 C5 C4 (Instr Set 1)
kenjiArai 30:4c57a022a56c 513 // Saved to allow contrast change at later time
kenjiArai 30:4c57a022a56c 514 }
kenjiArai 30:4c57a022a56c 515 else {
kenjiArai 30:4c57a022a56c 516 _icon_power = 0x08; // Set Icon, Booster, Contrast High bits, 0 1 0 1 Ion=1 Bon=0 C5 C4 (Instr Set 1)
kenjiArai 30:4c57a022a56c 517 // _icon_power = 0x00; // Set Icon, Booster, Contrast High bits, 0 1 0 1 Ion=0 Bon=0 C5 C4 (Instr Set 1)
kenjiArai 30:4c57a022a56c 518 }
wim 28:30fa94f7341c 519
kenjiArai 30:4c57a022a56c 520 _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Set Contrast C5, C4 (Instr Set 1)
kenjiArai 30:4c57a022a56c 521 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 522
kenjiArai 30:4c57a022a56c 523 _writeCommand(0x68 | (LCD_ST7036_RAB & 0x07)); // Voltagefollower On = 1, Ampl ratio Rab2, Rab1, Rab0 = 1 0 1 (Instr Set 1)
kenjiArai 30:4c57a022a56c 524 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 525
kenjiArai 30:4c57a022a56c 526 _writeCommand(0x20 | _function); // Set function, IS2,IS1 = 00 (Select Instruction Set = 0)
kenjiArai 30:4c57a022a56c 527
kenjiArai 30:4c57a022a56c 528 break; // case ST7036_3V3 Controller
kenjiArai 30:4c57a022a56c 529 // case ST7036_5V Controller
kenjiArai 30:4c57a022a56c 530
kenjiArai 30:4c57a022a56c 531 case ST7070:
kenjiArai 30:4c57a022a56c 532 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 533 switch (_type) {
kenjiArai 30:4c57a022a56c 534 case LCD8x1: //8x1 is a regular 1 line display
kenjiArai 30:4c57a022a56c 535 case LCD8x2B: //8x2D is a special case of 16x1
kenjiArai 30:4c57a022a56c 536 // case LCD12x1:
kenjiArai 30:4c57a022a56c 537 case LCD16x1:
kenjiArai 30:4c57a022a56c 538 case LCD24x1:
kenjiArai 30:4c57a022a56c 539 _function = dl | 0x00; // Set function, 0 0 1 DL=0 (4-bit Databus), N=0 (1 Line), EXT=0, x, x
kenjiArai 30:4c57a022a56c 540 // Note: 4 bit mode is NOT ignored for native SPI !
kenjiArai 30:4c57a022a56c 541 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 542 break;
kenjiArai 30:4c57a022a56c 543
kenjiArai 30:4c57a022a56c 544 // case LCD12x3D1: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 545 // case LCD16x3D1: // Special mode for SSD1803
kenjiArai 30:4c57a022a56c 546 case LCD12x4D: // Special mode for PCF2116
kenjiArai 30:4c57a022a56c 547 case LCD24x4D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 548 // case LCD12x3G: // Special mode for ST7036
kenjiArai 30:4c57a022a56c 549 case LCD16x3G: // Special mode for ST7036
kenjiArai 30:4c57a022a56c 550 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 551 break;
kenjiArai 30:4c57a022a56c 552
kenjiArai 30:4c57a022a56c 553 default:
kenjiArai 30:4c57a022a56c 554 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
kenjiArai 30:4c57a022a56c 555 _function = dl | 0x08; // Set function, 0 0 1 DL, N=1 (2 Line), EXT=0, x, x
kenjiArai 30:4c57a022a56c 556 // Note: 4 bit mode is NOT ignored for native SPI !
kenjiArai 30:4c57a022a56c 557 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 558 break;
kenjiArai 30:4c57a022a56c 559 } // switch type
kenjiArai 30:4c57a022a56c 560
kenjiArai 30:4c57a022a56c 561 // _writeCommand(0x00); // NOP, make sure to sync SPI
kenjiArai 30:4c57a022a56c 562
kenjiArai 30:4c57a022a56c 563 // init special features
kenjiArai 30:4c57a022a56c 564 _writeCommand(0x20 | _function | 0x04); // Set function, 0 0 1 DL N EXT=1 x x (Select Instr Set = 1)
kenjiArai 30:4c57a022a56c 565
kenjiArai 30:4c57a022a56c 566 _writeCommand(0x04 | 0x00); // Set Bias resistors 0 0 0 0 0 1 Rb1,Rb0= 0 0 (Extern Res) (Instr Set 1)
kenjiArai 30:4c57a022a56c 567
kenjiArai 30:4c57a022a56c 568 _writeCommand(0x40 | 0x00); // COM/SEG directions 0 1 0 0 C1, C2, S1, S2 (Instr Set 1)
kenjiArai 30:4c57a022a56c 569 // C1=1: Com1-8 -> Com8-1; C2=1: Com9-16 -> Com16-9
kenjiArai 30:4c57a022a56c 570 // S1=1: Seg1-40 -> Seg40-1; S2=1: Seg41-80 -> Seg80-41
kenjiArai 30:4c57a022a56c 571
kenjiArai 30:4c57a022a56c 572 _writeCommand(0x20 | _function); // Set function, EXT=0 (Select Instr Set = 0)
kenjiArai 30:4c57a022a56c 573
kenjiArai 30:4c57a022a56c 574 break; // case ST7070 Controller
kenjiArai 30:4c57a022a56c 575
kenjiArai 30:4c57a022a56c 576 case SSD1803_3V3:
kenjiArai 30:4c57a022a56c 577 // SSD1803 controller: Initialise Voltage booster for VLCD. VDD=3V3
kenjiArai 30:4c57a022a56c 578 // Note: supports 1,2, 3 or 4 lines
kenjiArai 30:4c57a022a56c 579 // case SSD1803_5V:
kenjiArai 30:4c57a022a56c 580 // SSD1803 controller: No Voltage booster for VLCD. VDD=5V
kenjiArai 30:4c57a022a56c 581
kenjiArai 30:4c57a022a56c 582 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 583 switch (_type) {
kenjiArai 30:4c57a022a56c 584 case LCD8x1: //8x1 is a regular 1 line display
kenjiArai 30:4c57a022a56c 585 case LCD8x2B: //8x2D is a special case of 16x1
kenjiArai 30:4c57a022a56c 586 // case LCD12x1:
kenjiArai 30:4c57a022a56c 587 case LCD16x1:
kenjiArai 30:4c57a022a56c 588 case LCD24x1:
kenjiArai 30:4c57a022a56c 589 _function = 0x00; // Set function 0 0 1 DL N DH RE(0) IS
kenjiArai 30:4c57a022a56c 590 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 591 // DL=0 4-bit Databus,
kenjiArai 30:4c57a022a56c 592 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 593 // N=0 1 Line / 3 Line
kenjiArai 30:4c57a022a56c 594 // DH=0 Double Height disable
kenjiArai 30:4c57a022a56c 595 // IS=0
kenjiArai 30:4c57a022a56c 596
kenjiArai 30:4c57a022a56c 597 _function_1 = 0x02; // Set function, 0 0 1 DL N BE RE(1) REV
kenjiArai 30:4c57a022a56c 598 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 599 // DL=0 4-bit Databus,
kenjiArai 30:4c57a022a56c 600 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 601 // N=0 1 Line / 3 Line
kenjiArai 30:4c57a022a56c 602 // BE=0 Blink Enable off, special feature of SSD1803
kenjiArai 30:4c57a022a56c 603 // REV=0 Reverse off, special feature of SSD1803
kenjiArai 30:4c57a022a56c 604
kenjiArai 30:4c57a022a56c 605 _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW
kenjiArai 30:4c57a022a56c 606 // NW=0 1-Line LCD (N=0)
kenjiArai 30:4c57a022a56c 607 break;
kenjiArai 30:4c57a022a56c 608
kenjiArai 30:4c57a022a56c 609 case LCD12x3D: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 610 // case LCD12x3D1: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 611 case LCD16x3D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 612 // case LCD16x3D1: // Special mode for SSD1803
kenjiArai 30:4c57a022a56c 613 // case LCD20x3D: // Special mode for SSD1803
kenjiArai 30:4c57a022a56c 614 _function = 0x00; // Set function 0 0 1 DL N DH RE(0) IS
kenjiArai 30:4c57a022a56c 615 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 616 // DL=0 4-bit Databus,
kenjiArai 30:4c57a022a56c 617 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 618 // N=0 1 Line / 3 Line
kenjiArai 30:4c57a022a56c 619 // DH=0 Double Height disable
kenjiArai 30:4c57a022a56c 620 // IS=0
kenjiArai 30:4c57a022a56c 621
kenjiArai 30:4c57a022a56c 622 _function_1 = 0x02; // Set function, 0 0 1 DL N BE RE(1) REV
kenjiArai 30:4c57a022a56c 623 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 624 // DL=0 4-bit Databus,
kenjiArai 30:4c57a022a56c 625 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 626 // N=0 1 Line / 3 Line
kenjiArai 30:4c57a022a56c 627 // BE=0 Blink Enable off, special feature of SSD1803
kenjiArai 30:4c57a022a56c 628 // REV=0 Reverse off, special feature of SSD1803
kenjiArai 30:4c57a022a56c 629
kenjiArai 30:4c57a022a56c 630 _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW
kenjiArai 30:4c57a022a56c 631 // NW=1 3-Line LCD (N=0)
kenjiArai 30:4c57a022a56c 632 break;
kenjiArai 30:4c57a022a56c 633
kenjiArai 30:4c57a022a56c 634 // case LCD10x2D: // Special mode for SSD1803, 4-line mode but switch to double height font
kenjiArai 30:4c57a022a56c 635 case LCD10x4D: // Special mode for SSD1803
kenjiArai 30:4c57a022a56c 636 case LCD20x4D: // Special mode for SSD1803
kenjiArai 30:4c57a022a56c 637 _function = 0x08; // Set function 0 0 1 DL N DH RE(0) IS
kenjiArai 30:4c57a022a56c 638 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 639 // DL=0 4-bit Databus,
kenjiArai 30:4c57a022a56c 640 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 641 // N=1 4 Line
kenjiArai 30:4c57a022a56c 642 // DH=0 Double Height disable
kenjiArai 30:4c57a022a56c 643 // IS=0
kenjiArai 30:4c57a022a56c 644
kenjiArai 30:4c57a022a56c 645 _function_1 = 0x0A; // Set function, 0 0 1 DL N BE RE(1) REV
kenjiArai 30:4c57a022a56c 646 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 647 // DL=0 4-bit Databus,
kenjiArai 30:4c57a022a56c 648 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 649 // N=1 4 Line
kenjiArai 30:4c57a022a56c 650 // BE=0 Blink Enable off, special feature of SSD1803
kenjiArai 30:4c57a022a56c 651 // REV=0 Reverse off, special feature of SSD1803
kenjiArai 30:4c57a022a56c 652
kenjiArai 30:4c57a022a56c 653 _lines = 0x01; // Ext function set 0 0 0 0 1 FW BW NW
kenjiArai 30:4c57a022a56c 654 // NW=1 4-Line LCD (N=1)
kenjiArai 30:4c57a022a56c 655 break;
kenjiArai 30:4c57a022a56c 656
kenjiArai 30:4c57a022a56c 657 case LCD16x3G: // Special mode for ST7036
kenjiArai 30:4c57a022a56c 658 case LCD24x4D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 659 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 660 break;
kenjiArai 30:4c57a022a56c 661
kenjiArai 30:4c57a022a56c 662 default:
kenjiArai 30:4c57a022a56c 663 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
kenjiArai 30:4c57a022a56c 664 _function = 0x08; // Set function 0 0 1 DL N DH RE(0) IS
kenjiArai 30:4c57a022a56c 665 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 666 // DL=0 4-bit Databus,
kenjiArai 30:4c57a022a56c 667 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 668 // N=1 2 line / 4 Line
kenjiArai 30:4c57a022a56c 669 // DH=0 Double Height disable
kenjiArai 30:4c57a022a56c 670 // RE=0
kenjiArai 30:4c57a022a56c 671 // IS=0
wim 28:30fa94f7341c 672
kenjiArai 30:4c57a022a56c 673 _function_1 = 0x0A; // Set function, 0 0 1 DL N BE RE(1) REV
kenjiArai 30:4c57a022a56c 674 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 675 // DL=0 4-bit Databus,
kenjiArai 30:4c57a022a56c 676 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 677 // N=1 2 line / 4 Line
kenjiArai 30:4c57a022a56c 678 // BE=0 Blink Enable off, special feature of SSD1803
kenjiArai 30:4c57a022a56c 679 // RE=1
kenjiArai 30:4c57a022a56c 680 // REV=0 Reverse off, special feature of SSD1803
kenjiArai 30:4c57a022a56c 681
kenjiArai 30:4c57a022a56c 682 _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW
kenjiArai 30:4c57a022a56c 683 // NW=0 2-Line LCD (N=1)
kenjiArai 30:4c57a022a56c 684 break;
kenjiArai 30:4c57a022a56c 685 } // switch type
kenjiArai 30:4c57a022a56c 686
kenjiArai 30:4c57a022a56c 687
kenjiArai 30:4c57a022a56c 688 // init special features
kenjiArai 30:4c57a022a56c 689 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
kenjiArai 30:4c57a022a56c 690 // Select Extended Instruction Set
kenjiArai 30:4c57a022a56c 691
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 694 WAIT_MS(5); // Wait to ensure completion or SSD1803 fails to set Top/Bottom after reset..
kenjiArai 30:4c57a022a56c 695
kenjiArai 30:4c57a022a56c 696 _writeCommand(0x08 | _lines); // Set ext function 0 0 0 0 1 FW BW NW 1,2,3 or 4 lines (Ext Instr Set)
kenjiArai 30:4c57a022a56c 697
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 699
kenjiArai 30:4c57a022a56c 700 // _writeCommand(0x76); // Set TC Control, 0 1 1 1 0 1 1 0 (Ext Instr Set)
kenjiArai 30:4c57a022a56c 701 // _writeData(0x02); // Set TC data, 0 0 0 0 0 TC2,TC1,TC0 = 0 1 0 (Ext Instr Set)
kenjiArai 30:4c57a022a56c 702
kenjiArai 30:4c57a022a56c 703 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N DH RE(0) IS=1 Select Instruction Set 1
kenjiArai 30:4c57a022a56c 704 // Select Std Instr set, Select IS=1
kenjiArai 30:4c57a022a56c 705
kenjiArai 30:4c57a022a56c 706 _contrast = LCD_SSD1_CONTRAST;
kenjiArai 30:4c57a022a56c 707 _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast 0 1 1 1 C3, C2, C1, C0 (Instr Set 1)
kenjiArai 30:4c57a022a56c 708
kenjiArai 30:4c57a022a56c 709 // _icon_power = 0x04; // Icon off, Booster on (Instr Set 1)
kenjiArai 30:4c57a022a56c 710 _icon_power = 0x0C; // Icon on, Booster on (Instr Set 1)
kenjiArai 30:4c57a022a56c 711 // Saved to allow contrast change at later time
kenjiArai 30:4c57a022a56c 712 _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Set Power, Icon and Contrast, 0 1 0 1 Ion Bon C5 C4 (Instr Set 1)
kenjiArai 30:4c57a022a56c 713 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 714
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 716 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 717
kenjiArai 30:4c57a022a56c 718 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
kenjiArai 30:4c57a022a56c 719 // Select Extended Instruction Set 1
kenjiArai 30:4c57a022a56c 720 _writeCommand(0x10); // Shift/Scroll enable, 0 0 0 1 DS4/HS4 DS3/HS3 DS2/HS2 DS1/HS1 (Ext Instr Set 1)
kenjiArai 30:4c57a022a56c 721
kenjiArai 30:4c57a022a56c 722
kenjiArai 30:4c57a022a56c 723 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
kenjiArai 30:4c57a022a56c 724 // Select Std Instr set, Select IS=0
kenjiArai 30:4c57a022a56c 725
kenjiArai 30:4c57a022a56c 726 break; // case SSD1803 Controller
kenjiArai 30:4c57a022a56c 727
kenjiArai 30:4c57a022a56c 728
kenjiArai 30:4c57a022a56c 729 // Note1: The PCF21XX family of controllers has several types that dont have an onboard voltage generator for V-LCD.
kenjiArai 30:4c57a022a56c 730 // You must supply this LCD voltage externally and not try to enable VGen.
kenjiArai 30:4c57a022a56c 731 // Note2: The early versions of PCF2116 controllers (eg PCF2116C) can not generate sufficiently negative voltage for the LCD at a VDD of 3V3.
kenjiArai 30:4c57a022a56c 732 // You must supply this voltage externally and not enable VGen or you must use a higher VDD (e.g. 5V) and enable VGen.
kenjiArai 30:4c57a022a56c 733 // More recent versions of the controller (eg PCF2116K) have an improved VGen that will work with 3V3.
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 735 // contrast control similar to that of pin 3 on the standard 14pin LCD module connector.
kenjiArai 30:4c57a022a56c 736 // You can disable VGen by connecting Vo to VDD. VLCD will then be used directly as LCD voltage.
kenjiArai 30:4c57a022a56c 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.
kenjiArai 30:4c57a022a56c 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.
kenjiArai 30:4c57a022a56c 739 // Note5: See datasheet, members of the PCF21XX family support different numbers of rows/columns. Not all can support 3 or 4 rows.
kenjiArai 30:4c57a022a56c 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..
kenjiArai 30:4c57a022a56c 741
kenjiArai 30:4c57a022a56c 742 case PCF2103_3V3:
kenjiArai 30:4c57a022a56c 743 // PCF2103 controller: No Voltage generator for VLCD, VDD=3V3..5V, VLCD input controls contrast voltage.
kenjiArai 30:4c57a022a56c 744 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 745 switch (_type) {
kenjiArai 30:4c57a022a56c 746 case LCD24x1:
kenjiArai 30:4c57a022a56c 747 _function = 0x00; //FUNCTION SET 0 0 1 DL=0 4-bit, 0, M=0 1-line/24 chars display mode, 0, H=0
kenjiArai 30:4c57a022a56c 748 //Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 749 break;
kenjiArai 30:4c57a022a56c 750
kenjiArai 30:4c57a022a56c 751 // case LCD12x1D: //Special mode for PCF21XX, Only top line used
kenjiArai 30:4c57a022a56c 752 case LCD12x2:
kenjiArai 30:4c57a022a56c 753 _function = 0x04; //FUNCTION SET 0 0 1 DL=0 4-bit, 0, M=1 2-line/12 chars display mode, 0, H=0
kenjiArai 30:4c57a022a56c 754 //Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 755 break;
kenjiArai 30:4c57a022a56c 756
kenjiArai 30:4c57a022a56c 757 default:
kenjiArai 30:4c57a022a56c 758 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 759 break;
kenjiArai 30:4c57a022a56c 760
kenjiArai 30:4c57a022a56c 761 } // switch type
kenjiArai 30:4c57a022a56c 762
kenjiArai 30:4c57a022a56c 763 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
kenjiArai 30:4c57a022a56c 764 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 765
kenjiArai 30:4c57a022a56c 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.
kenjiArai 30:4c57a022a56c 767 _writeCommand(0x05); // Display Conf Set 0000 0, 1, P=0, Q=1 (Instr. Set 1)
kenjiArai 30:4c57a022a56c 768
kenjiArai 30:4c57a022a56c 769 _writeCommand(0x02); // Screen Config 0000 001, L=0 (Instr. Set 1)
kenjiArai 30:4c57a022a56c 770 _writeCommand(0x08); // ICON Conf 0000 1, IM=0 (Char mode), IB=0 (no Icon blink), 0 (Instr. Set 1)
kenjiArai 30:4c57a022a56c 771
kenjiArai 30:4c57a022a56c 772 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
kenjiArai 30:4c57a022a56c 773
kenjiArai 30:4c57a022a56c 774 #if(0)
kenjiArai 30:4c57a022a56c 775 // Select CG RAM
kenjiArai 30:4c57a022a56c 776 _writeCommand(0x40); //Set CG-RAM address, 8 sequential locations needed per UDC
kenjiArai 30:4c57a022a56c 777 // Store UDC/Icon pattern:
kenjiArai 30:4c57a022a56c 778 // 3 x 8 rows x 5 bits = 120 bits for Normal pattern (UDC 0..2) and
kenjiArai 30:4c57a022a56c 779 // 3 x 8 rows x 5 bits = 120 bits for Blink pattern (UDC 4..6)
kenjiArai 30:4c57a022a56c 780 for (int i=0; i<(8 * 8); i++) {
kenjiArai 30:4c57a022a56c 781 // _writeData(0x1F); // All On
kenjiArai 30:4c57a022a56c 782 _writeData(0x00); // All Off
kenjiArai 30:4c57a022a56c 783 }
kenjiArai 30:4c57a022a56c 784 #endif
kenjiArai 30:4c57a022a56c 785 break; // case PCF2103_3V3 Controller
kenjiArai 30:4c57a022a56c 786
kenjiArai 30:4c57a022a56c 787 case PCF2113_3V3:
kenjiArai 30:4c57a022a56c 788 // PCF2113 controller: Initialise Voltage booster for VLCD. VDD=3V3. VA and VB control contrast.
kenjiArai 30:4c57a022a56c 789 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 790 switch (_type) {
kenjiArai 30:4c57a022a56c 791 // case LCD12x1:
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 793 // Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 794 case LCD24x1:
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 796 // Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 797 break;
kenjiArai 30:4c57a022a56c 798
kenjiArai 30:4c57a022a56c 799 case LCD12x2:
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 801 break;
kenjiArai 30:4c57a022a56c 802
kenjiArai 30:4c57a022a56c 803 default:
kenjiArai 30:4c57a022a56c 804 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 805 break;
kenjiArai 30:4c57a022a56c 806
kenjiArai 30:4c57a022a56c 807 } // switch type
kenjiArai 30:4c57a022a56c 808
kenjiArai 30:4c57a022a56c 809 // Init special features
kenjiArai 30:4c57a022a56c 810 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
kenjiArai 30:4c57a022a56c 811
kenjiArai 30:4c57a022a56c 812 _writeCommand(0x04); // Display Conf Set 0000 0, 1, P=0, Q=0 (Instr. Set 1)
kenjiArai 30:4c57a022a56c 813 _writeCommand(0x10); // Temp Compensation Set 0001 0, 0, TC1=0, TC2=0 (Instr. Set 1)
kenjiArai 30:4c57a022a56c 814 // _writeCommand(0x42); // HV GEN 0100 S1=1, S2=0 (2x multiplier) (Instr. Set 1)
kenjiArai 30:4c57a022a56c 815 _writeCommand(0x40 | (LCD_PCF2_S12 & 0x03)); // HV Gen 0100 S1=1, S2=0 (2x multiplier) (Instr. Set 1)
kenjiArai 30:4c57a022a56c 816
kenjiArai 30:4c57a022a56c 817 _contrast = LCD_PCF2_CONTRAST;
kenjiArai 30:4c57a022a56c 818 _writeCommand(0x80 | 0x00 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) 1, V=0, VA=contrast
kenjiArai 30:4c57a022a56c 819 _writeCommand(0x80 | 0x40 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) 1, V=1, VB=contrast
kenjiArai 30:4c57a022a56c 820 WAIT_MS(10); // Wait 10ms to ensure powered up
wim 28:30fa94f7341c 821
kenjiArai 30:4c57a022a56c 822 _writeCommand(0x02); // Screen Config 0000 001, L=0 (Instr. Set 1)
kenjiArai 30:4c57a022a56c 823 _writeCommand(0x08); // ICON Conf 0000 1, IM=0 (Char mode), IB=0 (no icon blink) DM=0 (no direct mode) (Instr. Set 1)
kenjiArai 30:4c57a022a56c 824
kenjiArai 30:4c57a022a56c 825 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
kenjiArai 30:4c57a022a56c 826
kenjiArai 30:4c57a022a56c 827 break; // case PCF2113_3V3 Controller
kenjiArai 30:4c57a022a56c 828
kenjiArai 30:4c57a022a56c 829
kenjiArai 30:4c57a022a56c 830 // case PCF2113_5V:
kenjiArai 30:4c57a022a56c 831 // PCF2113 controller: No Voltage generator for VLCD. VDD=5V. Contrast voltage controlled by VA or VB.
kenjiArai 30:4c57a022a56c 832 //@TODO
kenjiArai 30:4c57a022a56c 833
kenjiArai 30:4c57a022a56c 834
kenjiArai 30:4c57a022a56c 835 case PCF2116_3V3:
kenjiArai 30:4c57a022a56c 836 // PCF2116 controller: Voltage generator for VLCD. VDD=5V. V0 controls contrast voltage.
kenjiArai 30:4c57a022a56c 837 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 838 switch (_type) {
kenjiArai 30:4c57a022a56c 839 // case LCD12x1:
kenjiArai 30:4c57a022a56c 840 // case LCD12x2:
kenjiArai 30:4c57a022a56c 841 case LCD24x1:
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 843 //Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 844 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 845 break;
kenjiArai 30:4c57a022a56c 846
kenjiArai 30:4c57a022a56c 847 case LCD12x3D: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 848 case LCD12x3D1: // Special mode for PCF21XX
kenjiArai 30:4c57a022a56c 849 case LCD12x4D: // Special mode for PCF21XX:
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 851 //Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 852 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 853 break;
kenjiArai 30:4c57a022a56c 854
kenjiArai 30:4c57a022a56c 855 case LCD24x2:
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 857 //Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 858 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 859 break;
kenjiArai 30:4c57a022a56c 860
kenjiArai 30:4c57a022a56c 861 default:
kenjiArai 30:4c57a022a56c 862 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 863 break;
kenjiArai 30:4c57a022a56c 864
kenjiArai 30:4c57a022a56c 865 } // switch type
kenjiArai 30:4c57a022a56c 866
kenjiArai 30:4c57a022a56c 867 break; // case PCF2116_3V3 Controller
kenjiArai 30:4c57a022a56c 868
kenjiArai 30:4c57a022a56c 869
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 871 //@TODO
kenjiArai 30:4c57a022a56c 872 case PCF2116_5V:
kenjiArai 30:4c57a022a56c 873 // PCF2116 controller: No Voltage generator for VLCD. VDD=5V. V0 controls contrast voltage.
kenjiArai 30:4c57a022a56c 874 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 875 switch (_type) {
kenjiArai 30:4c57a022a56c 876 // case LCD12x1:
kenjiArai 30:4c57a022a56c 877 // case LCD12x2:
kenjiArai 30:4c57a022a56c 878 // case LCD24x1:
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 880 //Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 881 // WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 882 // break;
kenjiArai 30:4c57a022a56c 883
kenjiArai 30:4c57a022a56c 884 case LCD12x3D: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 885 case LCD12x3D1: // Special mode for PCF21XX
kenjiArai 30:4c57a022a56c 886 case LCD12x4D: // Special mode for PCF21XX:
kenjiArai 30:4c57a022a56c 887 // _writeCommand(0x34); //FUNCTION SET 8 bit, N=0/M=1 4-line/12 chars display mode OK
kenjiArai 30:4c57a022a56c 888 // _writeCommand(0x24); //FUNCTION SET 4 bit, N=0/M=1 4-line/12 chars display mode OK
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 890 //Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 891 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 892 break;
kenjiArai 30:4c57a022a56c 893
kenjiArai 30:4c57a022a56c 894 // case LCD24x2:
kenjiArai 30:4c57a022a56c 895 // _writeCommand(0x28); //FUNCTION SET 4 bit, N=1/M=0 2-line/24 chars display mode
kenjiArai 30:4c57a022a56c 896 //Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 897 // WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 898 // break;
kenjiArai 30:4c57a022a56c 899
kenjiArai 30:4c57a022a56c 900 default:
kenjiArai 30:4c57a022a56c 901 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 902 break;
kenjiArai 30:4c57a022a56c 903
kenjiArai 30:4c57a022a56c 904 } // switch type
kenjiArai 30:4c57a022a56c 905
kenjiArai 30:4c57a022a56c 906 break; // case PCF2116_5V Controller
kenjiArai 30:4c57a022a56c 907
kenjiArai 30:4c57a022a56c 908 case PCF2119_3V3:
kenjiArai 30:4c57a022a56c 909 case PCF2119R_3V3:
kenjiArai 30:4c57a022a56c 910 // PCF2119 controller: Initialise Voltage booster for VLCD. VDD=3V3. VA and VB control contrast.
kenjiArai 30:4c57a022a56c 911 // Note1: See datasheet, the PCF2119 supports icons and provides separate constrast control for Icons and characters.
kenjiArai 30:4c57a022a56c 912 // Note2: Vgen is switched off when the contrast voltage VA or VB is set to 0x00.
kenjiArai 30:4c57a022a56c 913
kenjiArai 30:4c57a022a56c 914 //POR or Hardware Reset should be applied
kenjiArai 30:4c57a022a56c 915 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 916
kenjiArai 30:4c57a022a56c 917 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 918 switch (_type) {
kenjiArai 30:4c57a022a56c 919 case LCD8x1:
kenjiArai 30:4c57a022a56c 920 // case LCD12x1:
kenjiArai 30:4c57a022a56c 921 case LCD16x1:
kenjiArai 30:4c57a022a56c 922 _function = 0x02; // FUNCTION SET 0 0 1 DL=0 4-bit, 0 , M=0 1-line/16 chars display mode, SL=1
kenjiArai 30:4c57a022a56c 923 // Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 924 break;
kenjiArai 30:4c57a022a56c 925
kenjiArai 30:4c57a022a56c 926 case LCD24x1:
kenjiArai 30:4c57a022a56c 927 // case LCD32x1:
kenjiArai 30:4c57a022a56c 928 _function = 0x00; // FUNCTION SET 0 0 1 DL=0 4-bit, 0 , M=0 1-line/32 chars display mode, SL=0
kenjiArai 30:4c57a022a56c 929 // Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 930 break;
kenjiArai 30:4c57a022a56c 931
kenjiArai 30:4c57a022a56c 932 case LCD8x2:
kenjiArai 30:4c57a022a56c 933 // case LCD12x2:
kenjiArai 30:4c57a022a56c 934 case LCD16x2:
kenjiArai 30:4c57a022a56c 935 _function = 0x04; // FUNCTION SET 0 0 1 DL=0 4-bit, 0, M=1 2-line/16 chars display mode, SL=0
kenjiArai 30:4c57a022a56c 936 // Note: 4 bit mode is ignored for I2C mode
kenjiArai 30:4c57a022a56c 937 break;
kenjiArai 30:4c57a022a56c 938
kenjiArai 30:4c57a022a56c 939 default:
kenjiArai 30:4c57a022a56c 940 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 941 break;
kenjiArai 30:4c57a022a56c 942
kenjiArai 30:4c57a022a56c 943 } // switch type
kenjiArai 30:4c57a022a56c 944
kenjiArai 30:4c57a022a56c 945 // Init special features
kenjiArai 30:4c57a022a56c 946 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instruction Set = 1
kenjiArai 30:4c57a022a56c 947
kenjiArai 30:4c57a022a56c 948 // _writeCommand(0x04); // DISP CONF SET (Instr. Set 1) 0000, 0, 1, P=0, Q=0 (IC at Bottom)
kenjiArai 30:4c57a022a56c 949 // _writeCommand(0x05); // Display Conf Set 0000, 0, 1, P=0, Q=1
kenjiArai 30:4c57a022a56c 950 // _writeCommand(0x06); // Display Conf Set 0000, 0, 1, P=1, Q=0
kenjiArai 30:4c57a022a56c 951 _writeCommand(0x07); // Display Conf Set 0000, 0, 1, P=1, Q=1 (IC at Top)
kenjiArai 30:4c57a022a56c 952
kenjiArai 30:4c57a022a56c 953 _writeCommand(0x10); // TEMP CTRL SET (Instr. Set 1) 0001, 0, 0, TC1=0, TC2=0
kenjiArai 30:4c57a022a56c 954 // _writeCommand(0x42); // HV GEN (Instr. Set 1) 0100, 0, 0, S1=1, S2=0 (2x multiplier)
kenjiArai 30:4c57a022a56c 955 _writeCommand(0x40 | (LCD_PCF2_S12 & 0x03)); // HV GEN (Instr. Set 1) 0100, 0, 0, S1=1, S2=0 (2x multiplier)
kenjiArai 30:4c57a022a56c 956
kenjiArai 30:4c57a022a56c 957 _contrast = LCD_PCF2_CONTRAST;
kenjiArai 30:4c57a022a56c 958 _writeCommand(0x80 | 0x00 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=0, VA=contrast
kenjiArai 30:4c57a022a56c 959 _writeCommand(0x80 | 0x40 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=1, VB=contrast
kenjiArai 30:4c57a022a56c 960 WAIT_MS(10); // Wait 10ms to ensure powered up
wim 28:30fa94f7341c 961
kenjiArai 30:4c57a022a56c 962 _writeCommand(0x02); // SCRN CONF (Instr. Set 1) L=0
kenjiArai 30:4c57a022a56c 963 _writeCommand(0x08); // ICON CONF (Instr. Set 1) IM=0 (Char mode) IB=0 (no icon blink) DM=0 (no direct mode)
kenjiArai 30:4c57a022a56c 964
kenjiArai 30:4c57a022a56c 965 _writeCommand(0x20 | _function); // Select Instruction Set = 0
kenjiArai 30:4c57a022a56c 966
kenjiArai 30:4c57a022a56c 967 break; // case PCF2119_3V3 Controller
kenjiArai 30:4c57a022a56c 968
kenjiArai 30:4c57a022a56c 969 // case PCF2119_5V:
kenjiArai 30:4c57a022a56c 970 // PCF2119 controller: No Voltage booster for VLCD. VDD=3V3. VA and VB control contrast.
kenjiArai 30:4c57a022a56c 971 // Note1: See datasheet, the PCF2119 supports icons and provides separate constrast control for Icons and characters.
kenjiArai 30:4c57a022a56c 972 // Note2: Vgen is switched off when the contrast voltage VA or VB is set to 0x00.
kenjiArai 30:4c57a022a56c 973 //@TODO
kenjiArai 30:4c57a022a56c 974
wim 19:c747b9e2e7b8 975 case WS0010:
wim 19:c747b9e2e7b8 976 // WS0010 OLED controller: Initialise DC/DC Voltage converter for LEDs
kenjiArai 30:4c57a022a56c 977 // Note1: Identical to RS0010
kenjiArai 30:4c57a022a56c 978 // Note2: supports 1 or 2 lines (and 16x100 graphics)
kenjiArai 30:4c57a022a56c 979 // supports 4 fonts (English/Japanese (default), Western European-I, English/Russian, Western European-II)
wim 19:c747b9e2e7b8 980 // Cursor/Disp shift set 0001 SC RL 0 0
wim 19:c747b9e2e7b8 981 //
kenjiArai 30:4c57a022a56c 982 // Mode and Power set 0001 GC PWR 1 1
wim 19:c747b9e2e7b8 983 // GC = 0 (Graph Mode=1, Char Mode=0)
kenjiArai 30:4c57a022a56c 984 // PWR = 1 (DC/DC On/Off)
kenjiArai 30:4c57a022a56c 985
kenjiArai 30:4c57a022a56c 986 //@Todo: This may be needed to enable a warm reboot
kenjiArai 30:4c57a022a56c 987 //_writeCommand(0x13); // Char mode, DC/DC off
kenjiArai 30:4c57a022a56c 988 //WAIT_MS(10); // Wait 10ms to ensure powered down
kenjiArai 30:4c57a022a56c 989 _writeCommand(0x17); // Char mode, DC/DC on
kenjiArai 30:4c57a022a56c 990 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 991
kenjiArai 30:4c57a022a56c 992 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 993 switch (_type) {
kenjiArai 30:4c57a022a56c 994 case LCD8x1: //8x1 is a regular 1 line display
kenjiArai 30:4c57a022a56c 995 case LCD8x2B: //8x2B is a special case of 16x1
kenjiArai 30:4c57a022a56c 996 // case LCD12x1:
kenjiArai 30:4c57a022a56c 997 case LCD16x1:
kenjiArai 30:4c57a022a56c 998 case LCD24x1:
kenjiArai 30:4c57a022a56c 999 _writeCommand(0x20); // Function set 001 DL N F FT1 FT0
kenjiArai 30:4c57a022a56c 1000 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 1001 // N=0 (1 line)
kenjiArai 30:4c57a022a56c 1002 // F=0 (5x7 dots font)
kenjiArai 30:4c57a022a56c 1003 // FT=00 (00 = Engl/Jap, 01 = WestEur1, 10 = Engl/Russian, 11 = WestEur2
kenjiArai 30:4c57a022a56c 1004 break;
kenjiArai 30:4c57a022a56c 1005
kenjiArai 30:4c57a022a56c 1006 case LCD12x3D: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 1007 case LCD12x3D1: // Special mode for PCF21XX
kenjiArai 30:4c57a022a56c 1008 case LCD12x4D: // Special mode for PCF21XX:
kenjiArai 30:4c57a022a56c 1009 case LCD16x3G: // Special mode for ST7036
kenjiArai 30:4c57a022a56c 1010 case LCD24x4D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 1011 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 1012 break;
kenjiArai 30:4c57a022a56c 1013
kenjiArai 30:4c57a022a56c 1014 default:
kenjiArai 30:4c57a022a56c 1015 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
kenjiArai 30:4c57a022a56c 1016 _writeCommand(0x28); // Function set 001 DL N F FT1 FT0
kenjiArai 30:4c57a022a56c 1017 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 1018 // N=1 (2 lines)
kenjiArai 30:4c57a022a56c 1019 // F=0 (5x7 dots font)
kenjiArai 30:4c57a022a56c 1020 // FT=00 (00 = Engl/Jap, 01 = WestEur1, 10 = Engl/Russian, 11 = WestEur2
kenjiArai 30:4c57a022a56c 1021
kenjiArai 30:4c57a022a56c 1022 break;
kenjiArai 30:4c57a022a56c 1023 } // switch type
kenjiArai 30:4c57a022a56c 1024
kenjiArai 30:4c57a022a56c 1025 break; // case WS0010 Controller
kenjiArai 30:4c57a022a56c 1026
kenjiArai 30:4c57a022a56c 1027
kenjiArai 30:4c57a022a56c 1028 case US2066_3V3:
kenjiArai 30:4c57a022a56c 1029 // US2066/SSD1311 OLED controller, Initialise for VDD=3V3
kenjiArai 30:4c57a022a56c 1030 // Note: supports 1,2, 3 or 4 lines
kenjiArai 30:4c57a022a56c 1031 // case USS2066_5V:
kenjiArai 30:4c57a022a56c 1032 // US2066 controller, VDD=5V
kenjiArai 30:4c57a022a56c 1033
kenjiArai 30:4c57a022a56c 1034 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 1035 switch (_type) {
kenjiArai 30:4c57a022a56c 1036 case LCD8x1: //8x1 is a regular 1 line display
kenjiArai 30:4c57a022a56c 1037 case LCD8x2B: //8x2D is a special case of 16x1
kenjiArai 30:4c57a022a56c 1038 // case LCD12x1:
kenjiArai 30:4c57a022a56c 1039 case LCD16x1:
kenjiArai 30:4c57a022a56c 1040 // case LCD20x1:
kenjiArai 30:4c57a022a56c 1041 _function = 0x00; // Set function 0 0 1 X N DH RE(0) IS
kenjiArai 30:4c57a022a56c 1042 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 1043 // DL=X bit is ignored for US2066. Uses hardwired pins instead
kenjiArai 30:4c57a022a56c 1044 // N=0 1 Line / 3 Line
kenjiArai 30:4c57a022a56c 1045 // DH=0 Double Height disable
kenjiArai 30:4c57a022a56c 1046 // IS=0
kenjiArai 30:4c57a022a56c 1047
kenjiArai 30:4c57a022a56c 1048 _function_1 = 0x02; // Set function, 0 0 1 X N BE RE(1) REV
kenjiArai 30:4c57a022a56c 1049 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 1050 // DL=X bit is ignored for US2066. Uses hardwired pins instead
kenjiArai 30:4c57a022a56c 1051 // N=0 1 Line / 3 Line
kenjiArai 30:4c57a022a56c 1052 // BE=0 Blink Enable off, special feature of SSD1803, US2066
kenjiArai 30:4c57a022a56c 1053 // REV=0 Reverse off, special feature of SSD1803, US2066
kenjiArai 30:4c57a022a56c 1054
kenjiArai 30:4c57a022a56c 1055 _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW
kenjiArai 30:4c57a022a56c 1056 // NW=0 1-Line LCD (N=0)
kenjiArai 30:4c57a022a56c 1057 break;
kenjiArai 30:4c57a022a56c 1058
kenjiArai 30:4c57a022a56c 1059 case LCD16x1C:
kenjiArai 30:4c57a022a56c 1060 case LCD8x2:
kenjiArai 30:4c57a022a56c 1061 case LCD16x2:
kenjiArai 30:4c57a022a56c 1062 case LCD20x2:
kenjiArai 30:4c57a022a56c 1063 _function = 0x08; // Set function 0 0 1 X N DH RE(0) IS
kenjiArai 30:4c57a022a56c 1064 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 1065 // DL=X bit is ignored for US2066. Uses hardwired pins instead
kenjiArai 30:4c57a022a56c 1066 // N=1 2 line / 4 Line
kenjiArai 30:4c57a022a56c 1067 // DH=0 Double Height disable
kenjiArai 30:4c57a022a56c 1068 // IS=0
kenjiArai 30:4c57a022a56c 1069
kenjiArai 30:4c57a022a56c 1070 _function_1 = 0x0A; // Set function, 0 0 1 X N BE RE(1) REV
kenjiArai 30:4c57a022a56c 1071 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 1072 // DL=X bit is ignored for US2066. Uses hardwired pins instead
kenjiArai 30:4c57a022a56c 1073 // N=1 2 line / 4 Line
kenjiArai 30:4c57a022a56c 1074 // BE=0 Blink Enable off, special feature of SSD1803, US2066
kenjiArai 30:4c57a022a56c 1075 // REV=0 Reverse off, special feature of SSD1803, US2066
kenjiArai 30:4c57a022a56c 1076
kenjiArai 30:4c57a022a56c 1077 _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW
kenjiArai 30:4c57a022a56c 1078 // NW=0 2-Line LCD (N=1)
kenjiArai 30:4c57a022a56c 1079 break;
kenjiArai 30:4c57a022a56c 1080
kenjiArai 30:4c57a022a56c 1081 case LCD12x3D: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 1082 // case LCD12x3D1: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 1083 case LCD16x3D: // Special mode for KS0078, SSD1803 and US2066
kenjiArai 30:4c57a022a56c 1084 // case LCD16x3D1: // Special mode for SSD1803, US2066
kenjiArai 30:4c57a022a56c 1085 // case LCD20x3D: // Special mode for SSD1803, US2066
kenjiArai 30:4c57a022a56c 1086 _function = 0x00; // Set function 0 0 1 X N DH RE(0) IS
kenjiArai 30:4c57a022a56c 1087 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 1088 // DL=X bit is ignored for US2066. Uses hardwired pins instead
kenjiArai 30:4c57a022a56c 1089 // N=0 1 Line / 3 Line
kenjiArai 30:4c57a022a56c 1090 // DH=0 Double Height disable
kenjiArai 30:4c57a022a56c 1091 // IS=0
kenjiArai 30:4c57a022a56c 1092
kenjiArai 30:4c57a022a56c 1093 _function_1 = 0x02; // Set function, 0 0 1 X N BE RE(1) REV
kenjiArai 30:4c57a022a56c 1094 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 1095 // DL=X bit is ignored for US2066. Uses hardwired pins instead
kenjiArai 30:4c57a022a56c 1096 // N=0 1 Line / 3 Line
kenjiArai 30:4c57a022a56c 1097 // BE=0 Blink Enable off, special feature of SSD1803, US2066
kenjiArai 30:4c57a022a56c 1098 // REV=0 Reverse off, special feature of SSD1803, US2066
kenjiArai 30:4c57a022a56c 1099
kenjiArai 30:4c57a022a56c 1100 _lines = 0x00; // Ext function set 0 0 0 0 1 FW BW NW
kenjiArai 30:4c57a022a56c 1101 // NW=1 3-Line LCD (N=0)
kenjiArai 30:4c57a022a56c 1102 break;
kenjiArai 30:4c57a022a56c 1103
kenjiArai 30:4c57a022a56c 1104 case LCD20x4D: // Special mode for SSD1803, US2066
kenjiArai 30:4c57a022a56c 1105 _function = 0x08; // Set function 0 0 1 X N DH RE(0) IS
kenjiArai 30:4c57a022a56c 1106 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 1107 // DL=X bit is ignored for US2066. Uses hardwired pins instead
kenjiArai 30:4c57a022a56c 1108 // N=1 2 line / 4 Line
kenjiArai 30:4c57a022a56c 1109 // DH=0 Double Height disable
kenjiArai 30:4c57a022a56c 1110 // IS=0
kenjiArai 30:4c57a022a56c 1111
kenjiArai 30:4c57a022a56c 1112 _function_1 = 0x0A; // Set function, 0 0 1 DL N BE RE(1) REV
kenjiArai 30:4c57a022a56c 1113 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 1114 // DL=0 bit is ignored for US2066. Uses hardwired pins instead
kenjiArai 30:4c57a022a56c 1115 // N=1 2 line / 4 Line
kenjiArai 30:4c57a022a56c 1116 // BE=0 Blink Enable off, special feature of SSD1803, US2066
kenjiArai 30:4c57a022a56c 1117 // REV=0 Reverse off, special feature of SSD1803, US2066
kenjiArai 30:4c57a022a56c 1118
kenjiArai 30:4c57a022a56c 1119 _lines = 0x01; // Ext function set 0 0 0 0 1 FW BW NW
kenjiArai 30:4c57a022a56c 1120 // NW=1 4-Line LCD (N=1)
kenjiArai 30:4c57a022a56c 1121 break;
kenjiArai 30:4c57a022a56c 1122
kenjiArai 30:4c57a022a56c 1123 // case LCD24x1:
kenjiArai 30:4c57a022a56c 1124 // case LCD16x3G: // Special mode for ST7036
kenjiArai 30:4c57a022a56c 1125 // case LCD24x4D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 1126 default:
kenjiArai 30:4c57a022a56c 1127 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 1128 break;
kenjiArai 30:4c57a022a56c 1129
kenjiArai 30:4c57a022a56c 1130 } // switch type
kenjiArai 30:4c57a022a56c 1131
kenjiArai 30:4c57a022a56c 1132 _writeCommand(0x00); // NOP, make sure to sync SPI
kenjiArai 30:4c57a022a56c 1133
kenjiArai 30:4c57a022a56c 1134 // init special features
kenjiArai 30:4c57a022a56c 1135 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
kenjiArai 30:4c57a022a56c 1136 // Select Extended Instruction Set
kenjiArai 30:4c57a022a56c 1137
kenjiArai 30:4c57a022a56c 1138 _writeCommand(0x71); // Function Select A: 0 1 1 1 0 0 0 1 (Ext Instr Set)
kenjiArai 30:4c57a022a56c 1139 _writeData(0x00); // Disable Internal VDD
kenjiArai 30:4c57a022a56c 1140
kenjiArai 30:4c57a022a56c 1141 _writeCommand(0x79); // Function Select OLED: 0 1 1 1 1 0 0 1 (Ext Instr Set)
kenjiArai 30:4c57a022a56c 1142
kenjiArai 30:4c57a022a56c 1143 _writeCommand(0xD5); // Display Clock Divide Ratio: 1 1 0 1 0 1 0 1 (Ext Instr Set, OLED Instr Set)
kenjiArai 30:4c57a022a56c 1144 _writeCommand(0x70); // Display Clock Divide Ratio value: 0 1 1 1 0 0 0 0 (Ext Instr Set, OLED Instr Set)
kenjiArai 30:4c57a022a56c 1145
kenjiArai 30:4c57a022a56c 1146 _writeCommand(0x78); // Function Disable OLED: 0 1 1 1 1 0 0 0 (Ext Instr Set)
kenjiArai 30:4c57a022a56c 1147
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 1150
kenjiArai 30:4c57a022a56c 1151 _writeCommand(0x08 | _lines); // Set ext function 0 0 0 0 1 FW BW NW 1,2,3 or 4 lines (Ext Instr Set)
kenjiArai 30:4c57a022a56c 1152
kenjiArai 30:4c57a022a56c 1153 // _writeCommand(0x1C); // Double Height, 0 0 0 1 UD2=1, UD1=1, X, DH'=0 (Ext Instr Set)
kenjiArai 30:4c57a022a56c 1154 // // Default
kenjiArai 30:4c57a022a56c 1155
kenjiArai 30:4c57a022a56c 1156 _writeCommand(0x72); // Function Select B: 0 1 1 1 0 0 1 0 (Ext Instr Set)
kenjiArai 30:4c57a022a56c 1157 _writeData(0x01); // Select ROM A (CGRAM 8, CGROM 248)
kenjiArai 30:4c57a022a56c 1158
kenjiArai 30:4c57a022a56c 1159 _writeCommand(0x79); // Function Select OLED: 0 1 1 1 1 0 0 1 (Ext Instr Set)
kenjiArai 30:4c57a022a56c 1160
kenjiArai 30:4c57a022a56c 1161 _writeCommand(0xDA); // Set Segm Pins Config: 1 1 0 1 1 0 1 0 (Ext Instr Set, OLED)
kenjiArai 30:4c57a022a56c 1162 _writeCommand(0x10); // Set Segm Pins Config value: Altern Odd/Even, Disable Remap (Ext Instr Set, OLED)
kenjiArai 30:4c57a022a56c 1163
kenjiArai 30:4c57a022a56c 1164 _writeCommand(0xDC); // Function Select C: 1 1 0 1 1 1 0 0 (Ext Instr Set, OLED)
kenjiArai 30:4c57a022a56c 1165 // _writeCommand(0x00); // Set internal VSL, GPIO pin HiZ (always read low)
kenjiArai 30:4c57a022a56c 1166 _writeCommand(0x80); // Set external VSL, GPIO pin HiZ (always read low)
kenjiArai 30:4c57a022a56c 1167
kenjiArai 30:4c57a022a56c 1168 _contrast = LCD_US20_CONTRAST;
kenjiArai 30:4c57a022a56c 1169 _writeCommand(0x81); // Set Contrast Control: 1 0 0 0 0 0 0 1 (Ext Instr Set, OLED)
kenjiArai 30:4c57a022a56c 1170 _writeCommand((_contrast << 2) | 0x03); // Set Contrast Value: 8 bits, use 6 bits for compatibility
kenjiArai 30:4c57a022a56c 1171
kenjiArai 30:4c57a022a56c 1172 _writeCommand(0xD9); // Set Phase Length: 1 1 0 1 1 0 0 1 (Ext Instr Set, OLED)
kenjiArai 30:4c57a022a56c 1173 _writeCommand(0xF1); // Set Phase Length Value:
kenjiArai 30:4c57a022a56c 1174
kenjiArai 30:4c57a022a56c 1175 _writeCommand(0xDB); // Set VCOMH Deselect Lvl: 1 1 0 1 1 0 1 1 (Ext Instr Set, OLED)
kenjiArai 30:4c57a022a56c 1176 _writeCommand(0x30); // Set VCOMH Deselect Value: 0.83 x VCC
kenjiArai 30:4c57a022a56c 1177
kenjiArai 30:4c57a022a56c 1178 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 1179
kenjiArai 30:4c57a022a56c 1180 //Test Fade/Blinking. Hard Blink on/off, No fade in/out ??
kenjiArai 30:4c57a022a56c 1181 // _writeCommand(0x23); // Set (Ext Instr Set, OLED)
kenjiArai 30:4c57a022a56c 1182 // _writeCommand(0x3F); // Set interval 128 frames
kenjiArai 30:4c57a022a56c 1183 //End Test Blinking
kenjiArai 30:4c57a022a56c 1184
kenjiArai 30:4c57a022a56c 1185 _writeCommand(0x78); // Function Disable OLED: 0 1 1 1 1 0 0 0 (Ext Instr Set)
wim 25:6162b31128c9 1186
kenjiArai 30:4c57a022a56c 1187 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 X N DH RE(0) IS=1 Select Instruction Set 1
kenjiArai 30:4c57a022a56c 1188 // Select Std Instr set, Select IS=1
kenjiArai 30:4c57a022a56c 1189
kenjiArai 30:4c57a022a56c 1190 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
kenjiArai 30:4c57a022a56c 1191 // Select Ext Instr Set, IS=1
kenjiArai 30:4c57a022a56c 1192 _writeCommand(0x10); // Shift/Scroll enable, 0 0 0 1 DS4/HS4 DS3/HS3 DS2/HS2 DS1/HS1 (Ext Instr Set, IS=1)
kenjiArai 30:4c57a022a56c 1193
kenjiArai 30:4c57a022a56c 1194 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
kenjiArai 30:4c57a022a56c 1195 // Select Std Instr set, Select IS=0
kenjiArai 30:4c57a022a56c 1196 break; // case US2066/SSD1311 Controller
kenjiArai 30:4c57a022a56c 1197
kenjiArai 30:4c57a022a56c 1198 //not yet tested on hardware
kenjiArai 30:4c57a022a56c 1199 case PT6314 :
kenjiArai 30:4c57a022a56c 1200 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 1201 switch (_type) {
kenjiArai 30:4c57a022a56c 1202 case LCD8x1: //8x1 is a regular 1 line display
kenjiArai 30:4c57a022a56c 1203 case LCD8x2B: //8x2B is a special case of 16x1
kenjiArai 30:4c57a022a56c 1204 // case LCD12x1:
kenjiArai 30:4c57a022a56c 1205 case LCD16x1:
kenjiArai 30:4c57a022a56c 1206 case LCD20x1:
kenjiArai 30:4c57a022a56c 1207 case LCD24x1:
kenjiArai 30:4c57a022a56c 1208 _function = 0x00; // Function set 001 DL N X BR1 BR0
kenjiArai 30:4c57a022a56c 1209 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 1210 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 1211 // N=0 (1 line)
kenjiArai 30:4c57a022a56c 1212 // X
kenjiArai 30:4c57a022a56c 1213 // BR1=0 (2 significant bits for brightness
kenjiArai 30:4c57a022a56c 1214 // BR0=0
kenjiArai 30:4c57a022a56c 1215 // 0x0 = 100%
kenjiArai 30:4c57a022a56c 1216 // 0x1 = 75%
kenjiArai 30:4c57a022a56c 1217 // 0x2 = 50%
kenjiArai 30:4c57a022a56c 1218 // 0x3 = 25%
kenjiArai 30:4c57a022a56c 1219
kenjiArai 30:4c57a022a56c 1220 break;
kenjiArai 30:4c57a022a56c 1221
kenjiArai 30:4c57a022a56c 1222 // All other valid LCD types are initialised as 2 Line displays
kenjiArai 30:4c57a022a56c 1223 case LCD8x2:
kenjiArai 30:4c57a022a56c 1224 case LCD16x2:
kenjiArai 30:4c57a022a56c 1225 case LCD20x2:
kenjiArai 30:4c57a022a56c 1226 case LCD24x2:
kenjiArai 30:4c57a022a56c 1227 _function = 0x08; // Function set 001 DL N X BR1 BR2
kenjiArai 30:4c57a022a56c 1228 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 1229 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 1230 // N=1 (2 lines)
kenjiArai 30:4c57a022a56c 1231 // X
kenjiArai 30:4c57a022a56c 1232 // BR1=0 (2 significant bits for brightness
kenjiArai 30:4c57a022a56c 1233 // BR0=0
kenjiArai 30:4c57a022a56c 1234 break;
kenjiArai 30:4c57a022a56c 1235
kenjiArai 30:4c57a022a56c 1236 default:
kenjiArai 30:4c57a022a56c 1237 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 1238 break;
kenjiArai 30:4c57a022a56c 1239 } // switch type
kenjiArai 30:4c57a022a56c 1240
kenjiArai 30:4c57a022a56c 1241 _contrast = LCD_PT63_CONTRAST;
kenjiArai 30:4c57a022a56c 1242 _writeCommand(0x20 | _function | ((~_contrast) >> 4)); // Invert and shift to use 2 MSBs
kenjiArai 30:4c57a022a56c 1243 break; // case PT6314 Controller (VFD)
kenjiArai 30:4c57a022a56c 1244
kenjiArai 30:4c57a022a56c 1245
kenjiArai 30:4c57a022a56c 1246 case HD66712:
kenjiArai 30:4c57a022a56c 1247 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 1248 switch (_type) {
kenjiArai 30:4c57a022a56c 1249 case LCD8x1: //8x1 is a regular 1 line display
kenjiArai 30:4c57a022a56c 1250 case LCD12x1:
kenjiArai 30:4c57a022a56c 1251 case LCD16x1:
kenjiArai 30:4c57a022a56c 1252 case LCD20x1:
kenjiArai 30:4c57a022a56c 1253 case LCD24x1:
kenjiArai 30:4c57a022a56c 1254 // case LCD32x1: // EXT pin is High, extension driver needed
kenjiArai 30:4c57a022a56c 1255 _function = 0x02; // Function set 001 DL N RE(0) - - (Std Regs)
kenjiArai 30:4c57a022a56c 1256 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 1257 // N=0 (1-line mode, N=1 2-line mode)
kenjiArai 30:4c57a022a56c 1258 // RE=0 (Dis. Extended Regs, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1259 //
kenjiArai 30:4c57a022a56c 1260
kenjiArai 30:4c57a022a56c 1261 _function_1 = 0x04; // Function set 001 DL N RE(1) BE LP (Ext Regs)
kenjiArai 30:4c57a022a56c 1262 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 1263 // N=0 (1-line mode, N=1 2-line mode)
kenjiArai 30:4c57a022a56c 1264 // RE=1 (Ena Extended Regs; special mode for HD66712)
kenjiArai 30:4c57a022a56c 1265 // BE=0 (Blink Enable, CG/SEG RAM; special mode for HD66712)
kenjiArai 30:4c57a022a56c 1266 // LP=0 (LP=1 Low power mode, LP=0 Normal; special mode for HD66712)
kenjiArai 30:4c57a022a56c 1267
kenjiArai 30:4c57a022a56c 1268 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
kenjiArai 30:4c57a022a56c 1269 // NW=0 (1,2 line), NW=1 (4 Line, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1270 break;
kenjiArai 30:4c57a022a56c 1271
kenjiArai 30:4c57a022a56c 1272 // case LCD12x3D: // Special mode for KS0073, KS0078, PCF21XX and HD66712
kenjiArai 30:4c57a022a56c 1273 // case LCD12x3D1: // Special mode for KS0073, KS0078, PCF21XX and HD66712
kenjiArai 30:4c57a022a56c 1274 case LCD12x4D: // Special mode for KS0073, KS0078, PCF21XX and HD66712
kenjiArai 30:4c57a022a56c 1275 // case LCD16x3D: // Special mode for KS0073, KS0078 and HD66712
kenjiArai 30:4c57a022a56c 1276 // case LCD16x4D: // Special mode for KS0073, KS0078 and HD66712
kenjiArai 30:4c57a022a56c 1277 case LCD20x4D: // Special mode for KS0073, KS0078 and HD66712
kenjiArai 30:4c57a022a56c 1278 _function = 0x02; // Function set 001 DL N RE(0) - - (Std Regs)
kenjiArai 30:4c57a022a56c 1279 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 1280 // N=0 (1-line mode, N=1 2-line mode)
kenjiArai 30:4c57a022a56c 1281 // RE=0 (Dis. Extended Regs, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1282 //
kenjiArai 30:4c57a022a56c 1283
kenjiArai 30:4c57a022a56c 1284 _function_1 = 0x04; // Function set 001 DL N RE(1) BE LP (Ext Regs)
kenjiArai 30:4c57a022a56c 1285 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 1286 // N=0 (1-line mode, N=1 2-line mode)
kenjiArai 30:4c57a022a56c 1287 // RE=1 (Ena Extended Regs; special mode for HD66712)
kenjiArai 30:4c57a022a56c 1288 // BE=0 (Blink Enable, CG/SEG RAM; special mode for HD66712)
kenjiArai 30:4c57a022a56c 1289 // LP=0 (LP=1 Low power mode, LP=0 Normal; special mode for HD66712)
kenjiArai 30:4c57a022a56c 1290
kenjiArai 30:4c57a022a56c 1291 _function_x = 0x01; // Ext Function set 0000 1 FW BW NW (Ext Regs)
kenjiArai 30:4c57a022a56c 1292 // NW=0 (1,2 line), NW=1 (4 Line, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1293 break;
kenjiArai 30:4c57a022a56c 1294
kenjiArai 30:4c57a022a56c 1295 case LCD16x3G: // Special mode for ST7036
kenjiArai 30:4c57a022a56c 1296 // case LCD24x3D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 1297 // case LCD24x3D1: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 1298 case LCD24x4D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 1299 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 1300 break;
kenjiArai 30:4c57a022a56c 1301
kenjiArai 30:4c57a022a56c 1302 default:
kenjiArai 30:4c57a022a56c 1303 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
kenjiArai 30:4c57a022a56c 1304 _function = 0x0A; // Function set 001 DL N RE(0) - - (Std Regs)
kenjiArai 30:4c57a022a56c 1305 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 1306 // N=1 (2-line mode), N=0 (1-line mode)
kenjiArai 30:4c57a022a56c 1307 // RE=0 (Dis. Extended Regs, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1308
kenjiArai 30:4c57a022a56c 1309 _function_1 = 0x0C; // Function set 001 DL N RE(1) BE LP (Ext Regs)
kenjiArai 30:4c57a022a56c 1310 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 1311 // N=1 (2 line mode), N=0 (1-line mode)
kenjiArai 30:4c57a022a56c 1312 // RE=1 (Ena Extended Regs, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1313 // BE=0 (Blink Enable, CG/SEG RAM, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1314 // LP=0 (LP=1 Low power mode, LP=0 Normal)
kenjiArai 30:4c57a022a56c 1315
kenjiArai 30:4c57a022a56c 1316 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
kenjiArai 30:4c57a022a56c 1317 // NW=0 (1,2 line), NW=1 (4 Line, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1318 break;
kenjiArai 30:4c57a022a56c 1319 } // switch type
kenjiArai 30:4c57a022a56c 1320
kenjiArai 30:4c57a022a56c 1321 // init special features
kenjiArai 30:4c57a022a56c 1322 _writeCommand(0x20 | _function_1);// Function set 001 DL N RE(1) BE LP (Ext Regs)
kenjiArai 30:4c57a022a56c 1323 // DL=0 (4 bits bus), DL=1 (8 bits mode)
kenjiArai 30:4c57a022a56c 1324 // N=0 (1 line mode), N=1 (2 line mode)
kenjiArai 30:4c57a022a56c 1325 // RE=1 (Ena Extended Regs, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1326 // BE=0 (Blink Enable/Disable, CG/SEG RAM, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1327 // LP=0 (LP=1 Low power mode, LP=0 Normal)
kenjiArai 30:4c57a022a56c 1328
kenjiArai 30:4c57a022a56c 1329 _writeCommand(0x08 | _function_x); // Ext Function set 0000 1 FW BW NW (Ext Regs)
kenjiArai 30:4c57a022a56c 1330 // FW=0 (5-dot font, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1331 // BW=0 (Cur BW invert disable, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1332 // NW=0 (1,2 Line), NW=1 (4 line, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1333
kenjiArai 30:4c57a022a56c 1334 _writeCommand(0x10); // Scroll/Shift set 0001 HS4 HS3 HS2 HS1 (Ext Regs)
kenjiArai 30:4c57a022a56c 1335 // Dotscroll/Display shift enable (Special mode for HD66712)
kenjiArai 30:4c57a022a56c 1336
kenjiArai 30:4c57a022a56c 1337 _writeCommand(0x80); // Scroll Quantity set 1 0 HDS5 HDS4 HDS3 HDS2 HDS1 HDS0 (Ext Regs)
kenjiArai 30:4c57a022a56c 1338 // Scroll quantity (Special mode for HD66712)
kenjiArai 30:4c57a022a56c 1339
kenjiArai 30:4c57a022a56c 1340 _writeCommand(0x20 | _function); // Function set 001 DL N RE(0) DH REV (Std Regs)
kenjiArai 30:4c57a022a56c 1341 // DL=0 (4 bits bus), DL=1 (8 bits mode)
kenjiArai 30:4c57a022a56c 1342 // N=0 (1 line mode), N=1 (2 line mode)
kenjiArai 30:4c57a022a56c 1343 // RE=0 (Dis. Extended Regs, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1344 // DH=1 (Disp shift enable/disable, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1345 // REV=0 (Reverse/Normal, special mode for HD66712)
kenjiArai 30:4c57a022a56c 1346 break; // case HD66712 Controller
kenjiArai 30:4c57a022a56c 1347
kenjiArai 30:4c57a022a56c 1348 case SPLC792A_3V3:
kenjiArai 30:4c57a022a56c 1349 // SPLC792A controller: Initialise Voltage booster for VLCD. VDD=3V3
kenjiArai 30:4c57a022a56c 1350 // Note very similar to ST7032
kenjiArai 30:4c57a022a56c 1351
kenjiArai 30:4c57a022a56c 1352 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 1353 switch (_type) {
kenjiArai 30:4c57a022a56c 1354 case LCD8x1: //8x1 is a regular 1 line display
kenjiArai 30:4c57a022a56c 1355 case LCD8x2B: //8x2B is a special case of 16x1
kenjiArai 30:4c57a022a56c 1356 // case LCD12x1:
kenjiArai 30:4c57a022a56c 1357 case LCD16x1:
kenjiArai 30:4c57a022a56c 1358 // case LCD20x1:
kenjiArai 30:4c57a022a56c 1359 case LCD24x1:
kenjiArai 30:4c57a022a56c 1360 _function = 0x00; // FUNCTION SET 0 0 1 DL=0 (4 bit), N=0 (1-line display mode), F=0 (5*7dot), 0, IS
kenjiArai 30:4c57a022a56c 1361 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 1362 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 1363 break;
kenjiArai 30:4c57a022a56c 1364
kenjiArai 30:4c57a022a56c 1365 case LCD12x3D: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 1366 case LCD12x3D1: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 1367 case LCD12x4D: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 1368 case LCD16x3G: // Special mode for ST7036
kenjiArai 30:4c57a022a56c 1369 case LCD24x4D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 1370 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 1371 break;
kenjiArai 30:4c57a022a56c 1372
kenjiArai 30:4c57a022a56c 1373 default:
kenjiArai 30:4c57a022a56c 1374 // All other LCD types are initialised as 2 Line displays
kenjiArai 30:4c57a022a56c 1375 _function = 0x08; // FUNCTION SET 0 0 1 DL=0 (4 bit), N=1 (2-line display mode), F=0 (5*7dot), 0, IS
kenjiArai 30:4c57a022a56c 1376 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 1377 // Saved to allow switch between Instruction sets at later time
kenjiArai 30:4c57a022a56c 1378 break;
kenjiArai 30:4c57a022a56c 1379 } // switch type
kenjiArai 30:4c57a022a56c 1380
kenjiArai 30:4c57a022a56c 1381 // init special features
kenjiArai 30:4c57a022a56c 1382 _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N F 0 IS=1 Select Instr Set = 1
kenjiArai 30:4c57a022a56c 1383
kenjiArai 30:4c57a022a56c 1384 //SPLC792A Does not support Bias and Internal Osc register
kenjiArai 30:4c57a022a56c 1385 // _writeCommand(0x1C); // Internal OSC frequency adjustment Framefreq=183HZ, Bias will be 1/4 (Instr Set=1)
kenjiArai 30:4c57a022a56c 1386
kenjiArai 30:4c57a022a56c 1387 _contrast = LCD_SPLC792A_CONTRAST;
kenjiArai 30:4c57a022a56c 1388 _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast Low bits, 0 1 1 1 C3 C2 C1 C0 (IS=1)
kenjiArai 30:4c57a022a56c 1389
kenjiArai 30:4c57a022a56c 1390
kenjiArai 30:4c57a022a56c 1391 // _icon_power = 0x04; // Icon display off (Bit3=0), Booster circuit is turned on (Bit2=1) (IS=1)
kenjiArai 30:4c57a022a56c 1392 _icon_power = 0x0C; // Icon display on (Bit3=1), Booster circuit is turned on (Bit2=1) (IS=1)
kenjiArai 30:4c57a022a56c 1393 // Note: Booster circuit always on for SPLC792A, Bit2 is dont care
kenjiArai 30:4c57a022a56c 1394 // Saved to allow contrast change at later time
kenjiArai 30:4c57a022a56c 1395
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 1397 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 1398
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 1400 // Note: Follower circuit always on for SPLC792A, Bit3 is dont care
kenjiArai 30:4c57a022a56c 1401 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 1402
kenjiArai 30:4c57a022a56c 1403 _writeCommand(0x20 | _function); // Select Instruction Set = 0
kenjiArai 30:4c57a022a56c 1404
kenjiArai 30:4c57a022a56c 1405 break; // case SPLC792A_3V3 Controller
kenjiArai 30:4c57a022a56c 1406
kenjiArai 30:4c57a022a56c 1407 case ST7066_ACM: // ST7066 4/8 bit, I2C on ACM1602 using a PIC
wim 19:c747b9e2e7b8 1408 default:
kenjiArai 30:4c57a022a56c 1409 // Devices fully compatible to HD44780 that do not use any DC/DC Voltage converters but external VLCD, no icons etc
kenjiArai 30:4c57a022a56c 1410
kenjiArai 30:4c57a022a56c 1411 // Initialise Display configuration
kenjiArai 30:4c57a022a56c 1412 switch (_type) {
kenjiArai 30:4c57a022a56c 1413 case LCD8x1: //8x1 is a regular 1 line display
kenjiArai 30:4c57a022a56c 1414 case LCD8x2B: //8x2B is a special case of 16x1
kenjiArai 30:4c57a022a56c 1415 // case LCD12x1:
kenjiArai 30:4c57a022a56c 1416 case LCD16x1:
kenjiArai 30:4c57a022a56c 1417 // case LCD20x1:
kenjiArai 30:4c57a022a56c 1418 case LCD24x1:
kenjiArai 30:4c57a022a56c 1419 // case LCD40x1:
kenjiArai 30:4c57a022a56c 1420 _function = 0x00; // Function set 001 DL N F - -
kenjiArai 30:4c57a022a56c 1421 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 1422 // N=0 (1 line)
kenjiArai 30:4c57a022a56c 1423 // F=0 (5x7 dots font)
kenjiArai 30:4c57a022a56c 1424 break;
kenjiArai 30:4c57a022a56c 1425
kenjiArai 30:4c57a022a56c 1426 case LCD12x3D: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 1427 case LCD12x3D1: // Special mode for KS0078 and PCF21XX
kenjiArai 30:4c57a022a56c 1428 case LCD12x4D: // Special mode for KS0078 and PCF21XX:
kenjiArai 30:4c57a022a56c 1429 case LCD16x3D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 1430 // case LCD16x3D1: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 1431 // case LCD24x3D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 1432 // case LCD24x3D1: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 1433 case LCD24x4D: // Special mode for KS0078
kenjiArai 30:4c57a022a56c 1434 error("Error: LCD Controller type does not support this Display type\n\r");
kenjiArai 30:4c57a022a56c 1435 break;
kenjiArai 30:4c57a022a56c 1436
kenjiArai 30:4c57a022a56c 1437 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
kenjiArai 30:4c57a022a56c 1438 default:
kenjiArai 30:4c57a022a56c 1439 _function = 0x08; // Function set 001 DL N F - -
kenjiArai 30:4c57a022a56c 1440 // DL=0 (4 bits bus)
kenjiArai 30:4c57a022a56c 1441 // Note: 4 bit mode is ignored for native SPI and I2C devices
kenjiArai 30:4c57a022a56c 1442 // N=1 (2 lines)
kenjiArai 30:4c57a022a56c 1443 // F=0 (5x7 dots font, only option for 2 line display)
kenjiArai 30:4c57a022a56c 1444 // - (Don't care)
kenjiArai 30:4c57a022a56c 1445 break;
kenjiArai 30:4c57a022a56c 1446 } // switch type
kenjiArai 30:4c57a022a56c 1447
kenjiArai 30:4c57a022a56c 1448 _writeCommand(0x20 | _function);
kenjiArai 30:4c57a022a56c 1449 break; // case default Controller
kenjiArai 30:4c57a022a56c 1450
kenjiArai 30:4c57a022a56c 1451 } // switch Controller specific initialisations
kenjiArai 30:4c57a022a56c 1452
kenjiArai 30:4c57a022a56c 1453 // Controller general initialisations
kenjiArai 30:4c57a022a56c 1454 // _writeCommand(0x01); // Clear Display and set cursor to 0
kenjiArai 30:4c57a022a56c 1455 // WAIT_MS(10); // The CLS command takes 1.64 ms.
kenjiArai 30:4c57a022a56c 1456 // // Since we are not using the Busy flag, Lets be safe and take 10 ms
kenjiArai 30:4c57a022a56c 1457
kenjiArai 30:4c57a022a56c 1458 _writeCommand(0x02); // Cursor Home, DDRAM Address to Origin
kenjiArai 30:4c57a022a56c 1459 WAIT_MS(10); // The Return Home command takes 1.64 ms.
kenjiArai 30:4c57a022a56c 1460 // Since we are not using the Busy flag, Lets be safe and take 10 ms
wim 28:30fa94f7341c 1461
wim 28:30fa94f7341c 1462 _writeCommand(0x06); // Entry Mode 0000 0 1 I/D S
wim 13:24506ba22480 1463 // Cursor Direction and Display Shift
wim 28:30fa94f7341c 1464 // I/D=1 (Cur incr)
wim 28:30fa94f7341c 1465 // S=0 (No display shift)
wim 10:dd9b3a696acd 1466
kenjiArai 30:4c57a022a56c 1467 _writeCommand(0x14); // Cursor or Display shift 0001 S/C R/L x x
kenjiArai 30:4c57a022a56c 1468 // S/C=0 Cursor moves
kenjiArai 30:4c57a022a56c 1469 // R/L=1 Right
kenjiArai 30:4c57a022a56c 1470 //
kenjiArai 30:4c57a022a56c 1471
wim 13:24506ba22480 1472 // _writeCommand(0x0C); // Display Ctrl 0000 1 D C B
wim 17:652ab113bc2e 1473 // // Display On, Cursor Off, Blink Off
kenjiArai 30:4c57a022a56c 1474
kenjiArai 30:4c57a022a56c 1475 // setCursor(CurOff_BlkOff);
kenjiArai 30:4c57a022a56c 1476 setCursor(CurOn_BlkOff);
wim 21:9eb628d9e164 1477 setMode(DispOn);
simon 1:ac48b187213c 1478 }
simon 1:ac48b187213c 1479
wim 8:03116f75b66e 1480
wim 21:9eb628d9e164 1481 /** Clear the screen, Cursor home.
kenjiArai 30:4c57a022a56c 1482 * Note: The whole display is initialised to charcode 0x20, which may not be a 'space' on some controllers with a
kenjiArai 30:4c57a022a56c 1483 * different fontset such as the PCF2116C or PCF2119R. In this case you should fill the display with 'spaces'.
wim 21:9eb628d9e164 1484 */
wim 21:9eb628d9e164 1485 void TextLCD_Base::cls() {
wim 15:b70ebfffb258 1486
kenjiArai 30:4c57a022a56c 1487 #if (LCD_TWO_CTRL == 1)
wim 15:b70ebfffb258 1488 // Select and configure second LCD controller when needed
wim 15:b70ebfffb258 1489 if(_type==LCD40x4) {
wim 21:9eb628d9e164 1490 _ctrl_idx=_LCDCtrl_1; // Select 2nd controller
wim 15:b70ebfffb258 1491
wim 15:b70ebfffb258 1492 // Second LCD controller Cursor always Off
wim 21:9eb628d9e164 1493 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
wim 15:b70ebfffb258 1494
wim 15:b70ebfffb258 1495 // Second LCD controller Clearscreen
wim 27:22d5086f6ba6 1496 _writeCommand(0x01); // cls, and set cursor to 0
kenjiArai 30:4c57a022a56c 1497 WAIT_MS(20); // The CLS command takes 1.64 ms.
kenjiArai 30:4c57a022a56c 1498 // Since we are not using the Busy flag, Lets be safe and take 10 ms
wim 15:b70ebfffb258 1499
wim 21:9eb628d9e164 1500 _ctrl_idx=_LCDCtrl_0; // Select primary controller
wim 15:b70ebfffb258 1501 }
kenjiArai 30:4c57a022a56c 1502
wim 15:b70ebfffb258 1503
wim 15:b70ebfffb258 1504 // Primary LCD controller Clearscreen
wim 27:22d5086f6ba6 1505 _writeCommand(0x01); // cls, and set cursor to 0
kenjiArai 30:4c57a022a56c 1506 WAIT_MS(20); // The CLS command takes 1.64 ms.
kenjiArai 30:4c57a022a56c 1507 // Since we are not using the Busy flag, Lets be safe and take 10 ms
wim 15:b70ebfffb258 1508
wim 15:b70ebfffb258 1509 // Restore cursormode on primary LCD controller when needed
wim 15:b70ebfffb258 1510 if(_type==LCD40x4) {
wim 17:652ab113bc2e 1511 _setCursorAndDisplayMode(_currentMode,_currentCursor);
wim 15:b70ebfffb258 1512 }
kenjiArai 30:4c57a022a56c 1513
kenjiArai 30:4c57a022a56c 1514 #else
kenjiArai 30:4c57a022a56c 1515 // Support only one LCD controller
kenjiArai 30:4c57a022a56c 1516 _writeCommand(0x01); // cls, and set cursor to 0
kenjiArai 30:4c57a022a56c 1517 WAIT_MS(20); // The CLS command takes 1.64 ms.
kenjiArai 30:4c57a022a56c 1518 // Since we are not using the Busy flag, Lets be safe and take 10 ms
kenjiArai 30:4c57a022a56c 1519 #endif
wim 15:b70ebfffb258 1520
kenjiArai 30:4c57a022a56c 1521 setAddress(0, 0); // Reset Cursor location
kenjiArai 30:4c57a022a56c 1522 // Note: This is needed because some displays (eg PCF21XX) don't use line 0 in the '3 Line' mode.
simon 1:ac48b187213c 1523 }
simon 1:ac48b187213c 1524
kenjiArai 30:4c57a022a56c 1525 /** Locate cursor to a screen column and row
kenjiArai 30:4c57a022a56c 1526 *
kenjiArai 30:4c57a022a56c 1527 * @param column The horizontal position from the left, indexed from 0
kenjiArai 30:4c57a022a56c 1528 * @param row The vertical position from the top, indexed from 0
kenjiArai 30:4c57a022a56c 1529 */
wim 21:9eb628d9e164 1530 void TextLCD_Base::locate(int column, int row) {
wim 15:b70ebfffb258 1531
wim 15:b70ebfffb258 1532 // setAddress() does all the heavy lifting:
wim 15:b70ebfffb258 1533 // check column and row sanity,
wim 15:b70ebfffb258 1534 // switch controllers for LCD40x4 if needed
wim 15:b70ebfffb258 1535 // switch cursor for LCD40x4 if needed
wim 15:b70ebfffb258 1536 // set the new memory address to show cursor at correct location
kenjiArai 30:4c57a022a56c 1537 setAddress(column, row);
wim 15:b70ebfffb258 1538 }
kenjiArai 30:4c57a022a56c 1539
wim 15:b70ebfffb258 1540
wim 21:9eb628d9e164 1541 /** Write a single character (Stream implementation)
wim 21:9eb628d9e164 1542 */
wim 21:9eb628d9e164 1543 int TextLCD_Base::_putc(int value) {
wim 15:b70ebfffb258 1544 int addr;
wim 15:b70ebfffb258 1545
wim 15:b70ebfffb258 1546 if (value == '\n') {
wim 15:b70ebfffb258 1547 //No character to write
wim 15:b70ebfffb258 1548
wim 15:b70ebfffb258 1549 //Update Cursor
wim 15:b70ebfffb258 1550 _column = 0;
wim 15:b70ebfffb258 1551 _row++;
wim 15:b70ebfffb258 1552 if (_row >= rows()) {
wim 15:b70ebfffb258 1553 _row = 0;
wim 15:b70ebfffb258 1554 }
wim 15:b70ebfffb258 1555 }
wim 15:b70ebfffb258 1556 else {
kenjiArai 30:4c57a022a56c 1557 //Character to write
kenjiArai 30:4c57a022a56c 1558
kenjiArai 30:4c57a022a56c 1559 #if (LCD_DEF_FONT == 1) //Default HD44780 font
kenjiArai 30:4c57a022a56c 1560 _writeData(value);
kenjiArai 30:4c57a022a56c 1561 #elif (LCD_C_FONT == 1) || (LCD_R_FONT == 1) //PCF21xxC or PCF21xxR font
kenjiArai 30:4c57a022a56c 1562 _writeData(ASCII_2_LCD(value));
kenjiArai 30:4c57a022a56c 1563 #elif (LCD_UTF8_FONT == 1) // UTF8 2 byte font (eg Cyrillic)
kenjiArai 30:4c57a022a56c 1564 // value = UTF_2_LCD(value, utf_seq_rec_first_cyr, utf_seq_recode_cyr, &utf_rnd_recode_cyr[0][0]);
kenjiArai 30:4c57a022a56c 1565 value = UTF_2_LCD(value);
kenjiArai 30:4c57a022a56c 1566 if (value >= 0) {
kenjiArai 30:4c57a022a56c 1567 _writeData(value);
kenjiArai 30:4c57a022a56c 1568
kenjiArai 30:4c57a022a56c 1569 // Only increment cursor when there is something to write
kenjiArai 30:4c57a022a56c 1570 // Continue below to closing bracket...
kenjiArai 30:4c57a022a56c 1571 #else
kenjiArai 30:4c57a022a56c 1572 _writeData('?'); //Oops, no font defined
kenjiArai 30:4c57a022a56c 1573 #endif
kenjiArai 30:4c57a022a56c 1574
wim 15:b70ebfffb258 1575 //Update Cursor
wim 15:b70ebfffb258 1576 _column++;
wim 15:b70ebfffb258 1577 if (_column >= columns()) {
wim 15:b70ebfffb258 1578 _column = 0;
wim 15:b70ebfffb258 1579 _row++;
wim 15:b70ebfffb258 1580 if (_row >= rows()) {
wim 15:b70ebfffb258 1581 _row = 0;
wim 15:b70ebfffb258 1582 }
kenjiArai 30:4c57a022a56c 1583 }
kenjiArai 30:4c57a022a56c 1584
kenjiArai 30:4c57a022a56c 1585 #if (LCD_DEF_FONT == 1) //Default HD44780 font
kenjiArai 30:4c57a022a56c 1586
kenjiArai 30:4c57a022a56c 1587 #elif (LCD_C_FONT == 1) || (LCD_R_FONT == 1) //PCF21xxC or PCF21xxR font
kenjiArai 30:4c57a022a56c 1588
kenjiArai 30:4c57a022a56c 1589 #elif (LCD_UTF8_FONT == 1) //UTF8 2 byte font (eg Cyrillic)
kenjiArai 30:4c57a022a56c 1590 // Continue code above to close bracket...
kenjiArai 30:4c57a022a56c 1591 } // if (value >= 0) {..
kenjiArai 30:4c57a022a56c 1592 #else
kenjiArai 30:4c57a022a56c 1593
kenjiArai 30:4c57a022a56c 1594 #endif
kenjiArai 30:4c57a022a56c 1595
wim 15:b70ebfffb258 1596 } //else
wim 15:b70ebfffb258 1597
wim 15:b70ebfffb258 1598 //Set next memoryaddress, make sure cursor blinks at next location
wim 15:b70ebfffb258 1599 addr = getAddress(_column, _row);
wim 15:b70ebfffb258 1600 _writeCommand(0x80 | addr);
wim 15:b70ebfffb258 1601
wim 15:b70ebfffb258 1602 return value;
wim 15:b70ebfffb258 1603 }
wim 15:b70ebfffb258 1604
wim 15:b70ebfffb258 1605
wim 16:c276b75e6585 1606 // get a single character (Stream implementation)
wim 21:9eb628d9e164 1607 int TextLCD_Base::_getc() {
simon 1:ac48b187213c 1608 return -1;
simon 1:ac48b187213c 1609 }
simon 1:ac48b187213c 1610
wim 14:0c32b66b14b8 1611
kenjiArai 30:4c57a022a56c 1612 #if ((LCD_C_FONT == 1) || (LCD_R_FONT == 1)) //PCF21xxC or PCF21xxR font
kenjiArai 30:4c57a022a56c 1613 /** Convert ASCII character code to the LCD fonttable code
kenjiArai 30:4c57a022a56c 1614 *
kenjiArai 30:4c57a022a56c 1615 * @param c The character to write to the display
kenjiArai 30:4c57a022a56c 1616 * @return The character code for the specific fonttable of the controller
kenjiArai 30:4c57a022a56c 1617 */
kenjiArai 30:4c57a022a56c 1618 int TextLCD_Base::ASCII_2_LCD (int c) {
kenjiArai 30:4c57a022a56c 1619
kenjiArai 30:4c57a022a56c 1620 //LCD_C_F0 is default for HD44780 and compatible series
kenjiArai 30:4c57a022a56c 1621 // if (_font == LCD_C_F0) return c;
kenjiArai 30:4c57a022a56c 1622
kenjiArai 30:4c57a022a56c 1623 //LCD_C_FC for PCF21XXC series
kenjiArai 30:4c57a022a56c 1624 //LCD_C_FR for PCF21XXR series
kenjiArai 30:4c57a022a56c 1625 //Used code from Suga koubou library for PCF2119K and PCF2119R
kenjiArai 30:4c57a022a56c 1626 if (((c >= ' ') && (c <= '?')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) {
kenjiArai 30:4c57a022a56c 1627 c |= 0x80;
kenjiArai 30:4c57a022a56c 1628 } else if (c >= 0xF0 && c <= 0xFF) {
kenjiArai 30:4c57a022a56c 1629 c &= 0x0F;
kenjiArai 30:4c57a022a56c 1630 }
kenjiArai 30:4c57a022a56c 1631 return c;
kenjiArai 30:4c57a022a56c 1632 }
kenjiArai 30:4c57a022a56c 1633 #endif
kenjiArai 30:4c57a022a56c 1634
kenjiArai 30:4c57a022a56c 1635 #if(LCD_UTF8_FONT == 1)
kenjiArai 30:4c57a022a56c 1636
kenjiArai 30:4c57a022a56c 1637 /** Convert UTF8 2-byte character code to the LCD fonttable code
kenjiArai 30:4c57a022a56c 1638 * @param c The character to write to the display
kenjiArai 30:4c57a022a56c 1639 * @return character code for the specific fonttable of the controller or -1 if UTF8 code is not yet complete or incorrect
kenjiArai 30:4c57a022a56c 1640 *
kenjiArai 30:4c57a022a56c 1641 * Orig by Andriy, Modified by WH
kenjiArai 30:4c57a022a56c 1642 *
kenjiArai 30:4c57a022a56c 1643 * Note: The UTF8 decoding table for a specific controller is defined and selected in file TextLCD_UTF8.inc
kenjiArai 30:4c57a022a56c 1644 * The table is accessed in this UTF_2_LCD() method through
kenjiArai 30:4c57a022a56c 1645 * #define UTF_FIRST, UTF_LAST, UTF_SEQ_REC_FIRST, UTF_SEQ_REC_LAST and
kenjiArai 30:4c57a022a56c 1646 * #define UTF_SEQ_RECODE and UTF_RND_RECODE
kenjiArai 30:4c57a022a56c 1647 */
kenjiArai 30:4c57a022a56c 1648 int TextLCD_Base::UTF_2_LCD (int c) {
kenjiArai 30:4c57a022a56c 1649 int utf_code;
kenjiArai 30:4c57a022a56c 1650 int utf_low_byte; // Low byte UTF8
kenjiArai 30:4c57a022a56c 1651 static int utf_hi_byte = 0; // High byte UTF8
kenjiArai 30:4c57a022a56c 1652
kenjiArai 30:4c57a022a56c 1653 if (c < 0x80) { // Regular ASCII code, no need to convert
kenjiArai 30:4c57a022a56c 1654 return c;
kenjiArai 30:4c57a022a56c 1655 }
kenjiArai 30:4c57a022a56c 1656 else { // UTF8 handling, See wikipedia.org/wiki/UTF-8 and www.utf8-chartable.de
kenjiArai 30:4c57a022a56c 1657 // printf("0x%X ", c);
kenjiArai 30:4c57a022a56c 1658
kenjiArai 30:4c57a022a56c 1659 if (c >= 0xC0) { // First UTF8 byte should be formatted as 110b bbaa, Do sanity check
kenjiArai 30:4c57a022a56c 1660 utf_hi_byte = c & 0x1F; // Mask out significant bits (0x1F) and save high byte
kenjiArai 30:4c57a022a56c 1661 return -1; // Nothing to display as yet, wait for second UTF8 byte
kenjiArai 30:4c57a022a56c 1662 }
kenjiArai 30:4c57a022a56c 1663
kenjiArai 30:4c57a022a56c 1664 if (c <= 0xBF) { // Second UTF8 byte should be formatted as 10aa aaaa, Do sanity check
kenjiArai 30:4c57a022a56c 1665 utf_low_byte = c & 0x3F; // Mask out significant bits (0x3F)
kenjiArai 30:4c57a022a56c 1666
kenjiArai 30:4c57a022a56c 1667 // Compose UTF character code from UTF8 bytes. The UTF codes will be between U+0080 and U+07FF
kenjiArai 30:4c57a022a56c 1668 utf_code = (utf_hi_byte << 6) | utf_low_byte; // 00000bbb aaaaaaaa
kenjiArai 30:4c57a022a56c 1669 // printf("0x%4X ", utf_code);
kenjiArai 30:4c57a022a56c 1670
kenjiArai 30:4c57a022a56c 1671 // Sanity check on UTF codes
kenjiArai 30:4c57a022a56c 1672 // For example Cyrillic characters are UTF encoded between 0x0400 and 0x04FF
kenjiArai 30:4c57a022a56c 1673 if ((utf_code < UTF_FIRST) || (utf_code > UTF_LAST)) {
kenjiArai 30:4c57a022a56c 1674 return -1; // Invalid UTF8 code
kenjiArai 30:4c57a022a56c 1675 };
kenjiArai 30:4c57a022a56c 1676
kenjiArai 30:4c57a022a56c 1677 //Map some specific UTF codes on a character in LCD fonttable using a special correcting lookup table
kenjiArai 30:4c57a022a56c 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
kenjiArai 30:4c57a022a56c 1679 if (utf_code == UTF_RND_RECODE[i][0]) { // UTF8 code match is found
kenjiArai 30:4c57a022a56c 1680 c = UTF_RND_RECODE[1][1];
kenjiArai 30:4c57a022a56c 1681 return c; // found match in correcting random table
kenjiArai 30:4c57a022a56c 1682 }
kenjiArai 30:4c57a022a56c 1683 }
kenjiArai 30:4c57a022a56c 1684
kenjiArai 30:4c57a022a56c 1685 //Sanity check on table idx range
kenjiArai 30:4c57a022a56c 1686 if ((utf_code < UTF_SEQ_REC_FIRST) || (utf_code > UTF_SEQ_REC_LAST)) {
kenjiArai 30:4c57a022a56c 1687 return -1; // Invalid UTF8 code
kenjiArai 30:4c57a022a56c 1688 };
kenjiArai 30:4c57a022a56c 1689
kenjiArai 30:4c57a022a56c 1690 //Map all other UTF codes on a character in LCD fonttable using a sequential lookup table
kenjiArai 30:4c57a022a56c 1691 c = UTF_SEQ_RECODE[utf_code - UTF_SEQ_REC_FIRST];
kenjiArai 30:4c57a022a56c 1692 return c; // entry in sequential table
kenjiArai 30:4c57a022a56c 1693 }
kenjiArai 30:4c57a022a56c 1694 else {
kenjiArai 30:4c57a022a56c 1695 return -1; // Invalid UTF8 code for second byte
kenjiArai 30:4c57a022a56c 1696 }
kenjiArai 30:4c57a022a56c 1697 } // End UTF8 handling
kenjiArai 30:4c57a022a56c 1698 }
kenjiArai 30:4c57a022a56c 1699
kenjiArai 30:4c57a022a56c 1700 #endif
kenjiArai 30:4c57a022a56c 1701
kenjiArai 30:4c57a022a56c 1702
kenjiArai 30:4c57a022a56c 1703 #if(LCD_PRINTF != 1)
kenjiArai 30:4c57a022a56c 1704 /** Write a character to the LCD
kenjiArai 30:4c57a022a56c 1705 *
kenjiArai 30:4c57a022a56c 1706 * @param c The character to write to the display
kenjiArai 30:4c57a022a56c 1707 */
kenjiArai 30:4c57a022a56c 1708 int TextLCD_Base::putc(int c){
kenjiArai 30:4c57a022a56c 1709 return _putc(c);
kenjiArai 30:4c57a022a56c 1710 }
kenjiArai 30:4c57a022a56c 1711
kenjiArai 30:4c57a022a56c 1712
kenjiArai 30:4c57a022a56c 1713 /** Write a raw string to the LCD
kenjiArai 30:4c57a022a56c 1714 *
kenjiArai 30:4c57a022a56c 1715 * @param string text, may be followed by variables to emulate formatting the string.
kenjiArai 30:4c57a022a56c 1716 * However, printf formatting is NOT supported and variables will be ignored!
kenjiArai 30:4c57a022a56c 1717 */
kenjiArai 30:4c57a022a56c 1718 int TextLCD_Base::printf(const char* text, ...) {
kenjiArai 30:4c57a022a56c 1719
kenjiArai 30:4c57a022a56c 1720 while (*text !=0) {
kenjiArai 30:4c57a022a56c 1721 _putc(*text);
kenjiArai 30:4c57a022a56c 1722 text++;
kenjiArai 30:4c57a022a56c 1723 }
kenjiArai 30:4c57a022a56c 1724 return 0;
kenjiArai 30:4c57a022a56c 1725 }
kenjiArai 30:4c57a022a56c 1726 #endif
kenjiArai 30:4c57a022a56c 1727
kenjiArai 30:4c57a022a56c 1728
wim 17:652ab113bc2e 1729 // Write a nibble using the 4-bit interface
wim 21:9eb628d9e164 1730 void TextLCD_Base::_writeNibble(int value) {
wim 17:652ab113bc2e 1731
wim 17:652ab113bc2e 1732 // Enable is Low
wim 21:9eb628d9e164 1733 this->_setEnable(true);
kenjiArai 30:4c57a022a56c 1734 this->_setData(value); // Low nibble of value on D4..D7
wim 17:652ab113bc2e 1735 wait_us(1); // Data setup time
wim 21:9eb628d9e164 1736 this->_setEnable(false);
wim 17:652ab113bc2e 1737 wait_us(1); // Datahold time
wim 17:652ab113bc2e 1738 // Enable is Low
wim 17:652ab113bc2e 1739 }
wim 17:652ab113bc2e 1740
wim 16:c276b75e6585 1741 // Write a byte using the 4-bit interface
wim 21:9eb628d9e164 1742 void TextLCD_Base::_writeByte(int value) {
wim 15:b70ebfffb258 1743
wim 15:b70ebfffb258 1744 // Enable is Low
wim 21:9eb628d9e164 1745 this->_setEnable(true);
wim 21:9eb628d9e164 1746 this->_setData(value >> 4); // High nibble
wim 15:b70ebfffb258 1747 wait_us(1); // Data setup time
wim 21:9eb628d9e164 1748 this->_setEnable(false);
wim 15:b70ebfffb258 1749 wait_us(1); // Data hold time
wim 15:b70ebfffb258 1750
wim 21:9eb628d9e164 1751 this->_setEnable(true);
kenjiArai 30:4c57a022a56c 1752 this->_setData(value); // Low nibble
wim 15:b70ebfffb258 1753 wait_us(1); // Data setup time
wim 21:9eb628d9e164 1754 this->_setEnable(false);
wim 15:b70ebfffb258 1755 wait_us(1); // Datahold time
wim 15:b70ebfffb258 1756
wim 15:b70ebfffb258 1757 // Enable is Low
simon 1:ac48b187213c 1758 }
simon 1:ac48b187213c 1759
wim 21:9eb628d9e164 1760 // Write a command byte to the LCD controller
wim 21:9eb628d9e164 1761 void TextLCD_Base::_writeCommand(int command) {
wim 15:b70ebfffb258 1762
wim 21:9eb628d9e164 1763 this->_setRS(false);
wim 16:c276b75e6585 1764 wait_us(1); // Data setup time for RS
wim 15:b70ebfffb258 1765
wim 21:9eb628d9e164 1766 this->_writeByte(command);
wim 15:b70ebfffb258 1767 wait_us(40); // most instructions take 40us
simon 1:ac48b187213c 1768 }
simon 1:ac48b187213c 1769
wim 21:9eb628d9e164 1770 // Write a data byte to the LCD controller
wim 21:9eb628d9e164 1771 void TextLCD_Base::_writeData(int data) {
wim 15:b70ebfffb258 1772
wim 21:9eb628d9e164 1773 this->_setRS(true);
wim 16:c276b75e6585 1774 wait_us(1); // Data setup time for RS
wim 15:b70ebfffb258 1775
wim 21:9eb628d9e164 1776 this->_writeByte(data);
wim 15:b70ebfffb258 1777 wait_us(40); // data writes take 40us
simon 1:ac48b187213c 1778 }
simon 1:ac48b187213c 1779
wim 8:03116f75b66e 1780
kenjiArai 30:4c57a022a56c 1781 // This replaces the original _address() method.
wim 8:03116f75b66e 1782 // It is confusing since it returns the memoryaddress or-ed with the set memorycommand 0x80.
wim 8:03116f75b66e 1783 // Left it in here for compatibility with older code. New applications should use getAddress() instead.
wim 21:9eb628d9e164 1784 int TextLCD_Base::_address(int column, int row) {
wim 8:03116f75b66e 1785 return 0x80 | getAddress(column, row);
wim 8:03116f75b66e 1786 }
wim 8:03116f75b66e 1787
kenjiArai 30:4c57a022a56c 1788
wim 8:03116f75b66e 1789 // This is new method to return the memory address based on row, column and displaytype.
wim 8:03116f75b66e 1790 //
kenjiArai 30:4c57a022a56c 1791 /** Return the memoryaddress of screen column and row location
kenjiArai 30:4c57a022a56c 1792 *
kenjiArai 30:4c57a022a56c 1793 * @param column The horizontal position from the left, indexed from 0
kenjiArai 30:4c57a022a56c 1794 * @param row The vertical position from the top, indexed from 0
kenjiArai 30:4c57a022a56c 1795 * @return The memoryaddress of screen column and row location
kenjiArai 30:4c57a022a56c 1796 *
kenjiArai 30:4c57a022a56c 1797 */
wim 21:9eb628d9e164 1798 int TextLCD_Base::getAddress(int column, int row) {
wim 8:03116f75b66e 1799
kenjiArai 30:4c57a022a56c 1800 switch (_addr_mode) {
kenjiArai 30:4c57a022a56c 1801
kenjiArai 30:4c57a022a56c 1802 case LCD_T_A:
kenjiArai 30:4c57a022a56c 1803 //Default addressing mode for 1, 2 and 4 rows (except 40x4)
kenjiArai 30:4c57a022a56c 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.
kenjiArai 30:4c57a022a56c 1805 //Displays top rows when less than four are used.
kenjiArai 30:4c57a022a56c 1806 switch (row) {
kenjiArai 30:4c57a022a56c 1807 case 0:
kenjiArai 30:4c57a022a56c 1808 return 0x00 + column;
kenjiArai 30:4c57a022a56c 1809 case 1:
kenjiArai 30:4c57a022a56c 1810 return 0x40 + column;
kenjiArai 30:4c57a022a56c 1811 case 2:
kenjiArai 30:4c57a022a56c 1812 return 0x00 + _nr_cols + column;
kenjiArai 30:4c57a022a56c 1813 case 3:
kenjiArai 30:4c57a022a56c 1814 return 0x40 + _nr_cols + column;
kenjiArai 30:4c57a022a56c 1815 // Should never get here.
kenjiArai 30:4c57a022a56c 1816 // default:
kenjiArai 30:4c57a022a56c 1817 // return 0x00;
kenjiArai 30:4c57a022a56c 1818 }
kenjiArai 30:4c57a022a56c 1819
kenjiArai 30:4c57a022a56c 1820 case LCD_T_B:
kenjiArai 30:4c57a022a56c 1821 // LCD8x2B is a special layout of LCD16x1
kenjiArai 30:4c57a022a56c 1822 if (row==0)
wim 8:03116f75b66e 1823 return 0x00 + column;
kenjiArai 30:4c57a022a56c 1824 else
kenjiArai 30:4c57a022a56c 1825 // return _nr_cols + column;
kenjiArai 30:4c57a022a56c 1826 return 0x08 + column;
kenjiArai 30:4c57a022a56c 1827
kenjiArai 30:4c57a022a56c 1828 case LCD_T_C:
kenjiArai 30:4c57a022a56c 1829 // LCD16x1C is a special layout of LCD8x2
kenjiArai 30:4c57a022a56c 1830 // LCD32x1C is a special layout of LCD16x2
kenjiArai 30:4c57a022a56c 1831 // LCD40x1C is a special layout of LCD20x2
wim 28:30fa94f7341c 1832 #if(0)
kenjiArai 30:4c57a022a56c 1833 if (column < 8)
kenjiArai 30:4c57a022a56c 1834 return 0x00 + column;
kenjiArai 30:4c57a022a56c 1835 else
kenjiArai 30:4c57a022a56c 1836 return 0x40 + (column - 8);
kenjiArai 30:4c57a022a56c 1837 #else
kenjiArai 30:4c57a022a56c 1838 if (column < (_nr_cols >> 1))
kenjiArai 30:4c57a022a56c 1839 return 0x00 + column;
kenjiArai 30:4c57a022a56c 1840 else
kenjiArai 30:4c57a022a56c 1841 return 0x40 + (column - (_nr_cols >> 1));
wim 28:30fa94f7341c 1842 #endif
wim 28:30fa94f7341c 1843
kenjiArai 30:4c57a022a56c 1844 case LCD_T_D:
kenjiArai 30:4c57a022a56c 1845 //Alternate addressing mode for 3 and 4 row displays (except 40x4). Used by PCF21XX, KS0073, KS0078, SSD1803
kenjiArai 30:4c57a022a56c 1846 //The 4 available rows start at a hardcoded address.
kenjiArai 30:4c57a022a56c 1847 //Displays top rows when less than four are used.
kenjiArai 30:4c57a022a56c 1848 switch (row) {
kenjiArai 30:4c57a022a56c 1849 case 0:
kenjiArai 30:4c57a022a56c 1850 return 0x00 + column;
kenjiArai 30:4c57a022a56c 1851 case 1:
kenjiArai 30:4c57a022a56c 1852 return 0x20 + column;
kenjiArai 30:4c57a022a56c 1853 case 2:
kenjiArai 30:4c57a022a56c 1854 return 0x40 + column;
kenjiArai 30:4c57a022a56c 1855 case 3:
kenjiArai 30:4c57a022a56c 1856 return 0x60 + column;
kenjiArai 30:4c57a022a56c 1857 // Should never get here.
kenjiArai 30:4c57a022a56c 1858 // default:
kenjiArai 30:4c57a022a56c 1859 // return 0x00;
wim 8:03116f75b66e 1860 }
wim 8:03116f75b66e 1861
kenjiArai 30:4c57a022a56c 1862 case LCD_T_D1:
kenjiArai 30:4c57a022a56c 1863 //Alternate addressing mode for 3 row displays. Used by PCF21XX, KS0073, KS0078, SSD1803
kenjiArai 30:4c57a022a56c 1864 //The 4 available rows start at a hardcoded address.
kenjiArai 30:4c57a022a56c 1865 //Skips top row of 4 row display and starts display at row 1
kenjiArai 30:4c57a022a56c 1866 switch (row) {
kenjiArai 30:4c57a022a56c 1867 case 0:
kenjiArai 30:4c57a022a56c 1868 return 0x20 + column;
kenjiArai 30:4c57a022a56c 1869 case 1:
kenjiArai 30:4c57a022a56c 1870 return 0x40 + column;
kenjiArai 30:4c57a022a56c 1871 case 2:
kenjiArai 30:4c57a022a56c 1872 return 0x60 + column;
kenjiArai 30:4c57a022a56c 1873 // Should never get here.
kenjiArai 30:4c57a022a56c 1874 // default:
kenjiArai 30:4c57a022a56c 1875 // return 0x00;
wim 8:03116f75b66e 1876 }
kenjiArai 30:4c57a022a56c 1877
kenjiArai 30:4c57a022a56c 1878 case LCD_T_E:
kenjiArai 30:4c57a022a56c 1879 // LCD40x4 is a special case since it has 2 controllers.
kenjiArai 30:4c57a022a56c 1880 // Each controller is configured as 40x2 (Type A)
wim 15:b70ebfffb258 1881 if (row<2) {
wim 15:b70ebfffb258 1882 // Test to see if we need to switch between controllers
wim 19:c747b9e2e7b8 1883 if (_ctrl_idx != _LCDCtrl_0) {
wim 17:652ab113bc2e 1884
wim 15:b70ebfffb258 1885 // Second LCD controller Cursor Off
wim 21:9eb628d9e164 1886 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
wim 15:b70ebfffb258 1887
wim 15:b70ebfffb258 1888 // Select primary controller
wim 19:c747b9e2e7b8 1889 _ctrl_idx = _LCDCtrl_0;
wim 15:b70ebfffb258 1890
wim 15:b70ebfffb258 1891 // Restore cursormode on primary LCD controller
wim 17:652ab113bc2e 1892 _setCursorAndDisplayMode(_currentMode, _currentCursor);
wim 15:b70ebfffb258 1893 }
wim 15:b70ebfffb258 1894
wim 15:b70ebfffb258 1895 return 0x00 + (row * 0x40) + column;
wim 15:b70ebfffb258 1896 }
wim 15:b70ebfffb258 1897 else {
wim 15:b70ebfffb258 1898
wim 15:b70ebfffb258 1899 // Test to see if we need to switch between controllers
wim 19:c747b9e2e7b8 1900 if (_ctrl_idx != _LCDCtrl_1) {
wim 15:b70ebfffb258 1901 // Primary LCD controller Cursor Off
wim 21:9eb628d9e164 1902 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
wim 15:b70ebfffb258 1903
wim 15:b70ebfffb258 1904 // Select secondary controller
wim 19:c747b9e2e7b8 1905 _ctrl_idx = _LCDCtrl_1;
wim 15:b70ebfffb258 1906
wim 15:b70ebfffb258 1907 // Restore cursormode on secondary LCD controller
wim 17:652ab113bc2e 1908 _setCursorAndDisplayMode(_currentMode, _currentCursor);
wim 15:b70ebfffb258 1909 }
wim 15:b70ebfffb258 1910
wim 15:b70ebfffb258 1911 return 0x00 + ((row-2) * 0x40) + column;
wim 15:b70ebfffb258 1912 }
wim 8:03116f75b66e 1913
kenjiArai 30:4c57a022a56c 1914 case LCD_T_F:
kenjiArai 30:4c57a022a56c 1915 //Alternate addressing mode for 3 row displays.
kenjiArai 30:4c57a022a56c 1916 //The first half of 3rd row continues from 1st row, the second half continues from 2nd row.
kenjiArai 30:4c57a022a56c 1917 switch (row) {
kenjiArai 30:4c57a022a56c 1918 case 0:
kenjiArai 30:4c57a022a56c 1919 return 0x00 + column;
kenjiArai 30:4c57a022a56c 1920 case 1:
kenjiArai 30:4c57a022a56c 1921 return 0x40 + column;
kenjiArai 30:4c57a022a56c 1922 case 2:
kenjiArai 30:4c57a022a56c 1923 if (column < (_nr_cols >> 1)) // check first or second half of line
kenjiArai 30:4c57a022a56c 1924 return (0x00 + _nr_cols + column);
kenjiArai 30:4c57a022a56c 1925 else
kenjiArai 30:4c57a022a56c 1926 return (0x40 + _nr_cols + (column - (_nr_cols >> 1)));
kenjiArai 30:4c57a022a56c 1927 // Should never get here.
kenjiArai 30:4c57a022a56c 1928 // default:
kenjiArai 30:4c57a022a56c 1929 // return 0x00;
kenjiArai 30:4c57a022a56c 1930 }
kenjiArai 30:4c57a022a56c 1931
kenjiArai 30:4c57a022a56c 1932 case LCD_T_G:
kenjiArai 30:4c57a022a56c 1933 //Alternate addressing mode for 3 row displays. Used by ST7036
kenjiArai 30:4c57a022a56c 1934 switch (row) {
kenjiArai 30:4c57a022a56c 1935 case 0:
kenjiArai 30:4c57a022a56c 1936 return 0x00 + column;
kenjiArai 30:4c57a022a56c 1937 case 1:
kenjiArai 30:4c57a022a56c 1938 return 0x10 + column;
kenjiArai 30:4c57a022a56c 1939 case 2:
kenjiArai 30:4c57a022a56c 1940 return 0x20 + column;
kenjiArai 30:4c57a022a56c 1941 // Should never get here.
kenjiArai 30:4c57a022a56c 1942 // default:
kenjiArai 30:4c57a022a56c 1943 // return 0x00;
kenjiArai 30:4c57a022a56c 1944 }
kenjiArai 30:4c57a022a56c 1945
kenjiArai 30:4c57a022a56c 1946 // Should never get here.
wim 8:03116f75b66e 1947 default:
wim 8:03116f75b66e 1948 return 0x00;
kenjiArai 30:4c57a022a56c 1949
kenjiArai 30:4c57a022a56c 1950 } // switch _addr_mode
wim 8:03116f75b66e 1951 }
wim 8:03116f75b66e 1952
wim 8:03116f75b66e 1953
kenjiArai 30:4c57a022a56c 1954 /** Set the memoryaddress of screen column and row location
kenjiArai 30:4c57a022a56c 1955 *
kenjiArai 30:4c57a022a56c 1956 * @param column The horizontal position from the left, indexed from 0
kenjiArai 30:4c57a022a56c 1957 * @param row The vertical position from the top, indexed from 0
kenjiArai 30:4c57a022a56c 1958 */
wim 21:9eb628d9e164 1959 void TextLCD_Base::setAddress(int column, int row) {
wim 15:b70ebfffb258 1960
wim 15:b70ebfffb258 1961 // Sanity Check column
wim 15:b70ebfffb258 1962 if (column < 0) {
wim 15:b70ebfffb258 1963 _column = 0;
wim 15:b70ebfffb258 1964 }
kenjiArai 30:4c57a022a56c 1965 else if (column >= _nr_cols) {
kenjiArai 30:4c57a022a56c 1966 _column = _nr_cols - 1;
wim 15:b70ebfffb258 1967 } else _column = column;
wim 8:03116f75b66e 1968
wim 15:b70ebfffb258 1969 // Sanity Check row
wim 15:b70ebfffb258 1970 if (row < 0) {
wim 15:b70ebfffb258 1971 _row = 0;
wim 15:b70ebfffb258 1972 }
kenjiArai 30:4c57a022a56c 1973 else if (row >= _nr_rows) {
kenjiArai 30:4c57a022a56c 1974 _row = _nr_rows - 1;
wim 15:b70ebfffb258 1975 } else _row = row;
wim 15:b70ebfffb258 1976
wim 15:b70ebfffb258 1977
wim 15:b70ebfffb258 1978 // Compute the memory address
wim 15:b70ebfffb258 1979 // For LCD40x4: switch controllers if needed
wim 15:b70ebfffb258 1980 // switch cursor if needed
wim 15:b70ebfffb258 1981 int addr = getAddress(_column, _row);
wim 8:03116f75b66e 1982
wim 13:24506ba22480 1983 _writeCommand(0x80 | addr);
wim 8:03116f75b66e 1984 }
simon 1:ac48b187213c 1985
kenjiArai 30:4c57a022a56c 1986
kenjiArai 30:4c57a022a56c 1987 /** Return the number of columns
kenjiArai 30:4c57a022a56c 1988 *
kenjiArai 30:4c57a022a56c 1989 * @return The number of columns
kenjiArai 30:4c57a022a56c 1990 *
kenjiArai 30:4c57a022a56c 1991 * Note: some configurations are commented out because they have not yet been tested due to lack of hardware
kenjiArai 30:4c57a022a56c 1992 */
wim 21:9eb628d9e164 1993 int TextLCD_Base::columns() {
kenjiArai 30:4c57a022a56c 1994
kenjiArai 30:4c57a022a56c 1995 // Columns encoded in b7..b0
kenjiArai 30:4c57a022a56c 1996 //return (_type & 0xFF);
kenjiArai 30:4c57a022a56c 1997 return _nr_cols;
simon 1:ac48b187213c 1998 }
simon 1:ac48b187213c 1999
kenjiArai 30:4c57a022a56c 2000 /** Return the number of rows
kenjiArai 30:4c57a022a56c 2001 *
kenjiArai 30:4c57a022a56c 2002 * @return The number of rows
kenjiArai 30:4c57a022a56c 2003 *
kenjiArai 30:4c57a022a56c 2004 * Note: some configurations are commented out because they have not yet been tested due to lack of hardware
kenjiArai 30:4c57a022a56c 2005 */
wim 21:9eb628d9e164 2006 int TextLCD_Base::rows() {
kenjiArai 30:4c57a022a56c 2007
kenjiArai 30:4c57a022a56c 2008 // Rows encoded in b15..b8
kenjiArai 30:4c57a022a56c 2009 //return ((_type >> 8) & 0xFF);
kenjiArai 30:4c57a022a56c 2010 return _nr_rows;
simon 1:ac48b187213c 2011 }
wim 10:dd9b3a696acd 2012
kenjiArai 30:4c57a022a56c 2013 /** Set the Cursormode
kenjiArai 30:4c57a022a56c 2014 *
kenjiArai 30:4c57a022a56c 2015 * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn)
kenjiArai 30:4c57a022a56c 2016 */
wim 21:9eb628d9e164 2017 void TextLCD_Base::setCursor(LCDCursor cursorMode) {
wim 15:b70ebfffb258 2018
wim 17:652ab113bc2e 2019 // Save new cursor mode, needed when 2 controllers are in use or when display is switched off/on
wim 17:652ab113bc2e 2020 _currentCursor = cursorMode;
wim 10:dd9b3a696acd 2021
wim 17:652ab113bc2e 2022 // Configure only current LCD controller
kenjiArai 30:4c57a022a56c 2023 _setCursorAndDisplayMode(_currentMode, _currentCursor);
wim 15:b70ebfffb258 2024 }
wim 15:b70ebfffb258 2025
kenjiArai 30:4c57a022a56c 2026 /** Set the Displaymode
kenjiArai 30:4c57a022a56c 2027 *
kenjiArai 30:4c57a022a56c 2028 * @param displayMode The Display mode (DispOff, DispOn)
kenjiArai 30:4c57a022a56c 2029 */
wim 21:9eb628d9e164 2030 void TextLCD_Base::setMode(LCDMode displayMode) {
wim 17:652ab113bc2e 2031
wim 17:652ab113bc2e 2032 // Save new displayMode, needed when 2 controllers are in use or when cursor is changed
wim 17:652ab113bc2e 2033 _currentMode = displayMode;
kenjiArai 30:4c57a022a56c 2034
kenjiArai 30:4c57a022a56c 2035 #if (LCD_TWO_CTRL == 1)
wim 17:652ab113bc2e 2036 // Select and configure second LCD controller when needed
wim 17:652ab113bc2e 2037 if(_type==LCD40x4) {
wim 21:9eb628d9e164 2038 if (_ctrl_idx==_LCDCtrl_0) {
wim 17:652ab113bc2e 2039 // Configure primary LCD controller
wim 17:652ab113bc2e 2040 _setCursorAndDisplayMode(_currentMode, _currentCursor);
wim 11:9ec02df863a1 2041
wim 17:652ab113bc2e 2042 // Select 2nd controller
wim 21:9eb628d9e164 2043 _ctrl_idx=_LCDCtrl_1;
wim 17:652ab113bc2e 2044
wim 17:652ab113bc2e 2045 // Configure secondary LCD controller
wim 21:9eb628d9e164 2046 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
wim 11:9ec02df863a1 2047
wim 17:652ab113bc2e 2048 // Restore current controller
wim 21:9eb628d9e164 2049 _ctrl_idx=_LCDCtrl_0;
wim 17:652ab113bc2e 2050 }
wim 17:652ab113bc2e 2051 else {
wim 17:652ab113bc2e 2052 // Select primary controller
wim 21:9eb628d9e164 2053 _ctrl_idx=_LCDCtrl_0;
wim 17:652ab113bc2e 2054
wim 17:652ab113bc2e 2055 // Configure primary LCD controller
wim 21:9eb628d9e164 2056 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
wim 17:652ab113bc2e 2057
wim 17:652ab113bc2e 2058 // Restore current controller
wim 21:9eb628d9e164 2059 _ctrl_idx=_LCDCtrl_1;
wim 11:9ec02df863a1 2060
wim 17:652ab113bc2e 2061 // Configure secondary LCD controller
wim 17:652ab113bc2e 2062 _setCursorAndDisplayMode(_currentMode, _currentCursor);
wim 10:dd9b3a696acd 2063 }
wim 17:652ab113bc2e 2064 }
wim 17:652ab113bc2e 2065 else {
wim 17:652ab113bc2e 2066 // Configure primary LCD controller
wim 17:652ab113bc2e 2067 _setCursorAndDisplayMode(_currentMode, _currentCursor);
kenjiArai 30:4c57a022a56c 2068 }
kenjiArai 30:4c57a022a56c 2069 #else
kenjiArai 30:4c57a022a56c 2070 // Support only one LCD controller
kenjiArai 30:4c57a022a56c 2071 _setCursorAndDisplayMode(_currentMode, _currentCursor);
kenjiArai 30:4c57a022a56c 2072
kenjiArai 30:4c57a022a56c 2073 #endif
wim 17:652ab113bc2e 2074 }
wim 17:652ab113bc2e 2075
kenjiArai 30:4c57a022a56c 2076 /** Low level method to restore the cursortype and display mode for current controller
kenjiArai 30:4c57a022a56c 2077 */
kenjiArai 30:4c57a022a56c 2078 void TextLCD_Base::_setCursorAndDisplayMode(LCDMode displayMode, LCDCursor cursorType) {
kenjiArai 30:4c57a022a56c 2079
kenjiArai 30:4c57a022a56c 2080 // Configure current LCD controller
kenjiArai 30:4c57a022a56c 2081 switch (_ctrl) {
kenjiArai 30:4c57a022a56c 2082 case ST7070:
kenjiArai 30:4c57a022a56c 2083 //ST7070 does not support Cursorblink. The P bit selects the font instead !
kenjiArai 30:4c57a022a56c 2084 _writeCommand(0x08 | displayMode | (cursorType & 0x02));
kenjiArai 30:4c57a022a56c 2085 break;
kenjiArai 30:4c57a022a56c 2086 default:
kenjiArai 30:4c57a022a56c 2087 _writeCommand(0x08 | displayMode | cursorType);
kenjiArai 30:4c57a022a56c 2088 break;
kenjiArai 30:4c57a022a56c 2089 } //switch
wim 10:dd9b3a696acd 2090 }
wim 10:dd9b3a696acd 2091
kenjiArai 30:4c57a022a56c 2092 /** Set the Backlight mode
kenjiArai 30:4c57a022a56c 2093 *
kenjiArai 30:4c57a022a56c 2094 * @param backlightMode The Backlight mode (LightOff, LightOn)
kenjiArai 30:4c57a022a56c 2095 */
wim 21:9eb628d9e164 2096 void TextLCD_Base::setBacklight(LCDBacklight backlightMode) {
wim 20:e0da005a777f 2097
kenjiArai 30:4c57a022a56c 2098 #if (BACKLIGHT_INV==0)
kenjiArai 30:4c57a022a56c 2099 // Positive Backlight control pin logic
wim 20:e0da005a777f 2100 if (backlightMode == LightOn) {
kenjiArai 30:4c57a022a56c 2101 this->_setBL(true);
wim 20:e0da005a777f 2102 }
wim 20:e0da005a777f 2103 else {
wim 21:9eb628d9e164 2104 this->_setBL(false);
wim 20:e0da005a777f 2105 }
kenjiArai 30:4c57a022a56c 2106 #else
kenjiArai 30:4c57a022a56c 2107 // Inverted Backlight control pin logic
kenjiArai 30:4c57a022a56c 2108 if (backlightMode == LightOn) {
kenjiArai 30:4c57a022a56c 2109 this->_setBL(false);
kenjiArai 30:4c57a022a56c 2110 }
kenjiArai 30:4c57a022a56c 2111 else {
kenjiArai 30:4c57a022a56c 2112 this->_setBL(true);
kenjiArai 30:4c57a022a56c 2113 }
kenjiArai 30:4c57a022a56c 2114 #endif
wim 20:e0da005a777f 2115 }
wim 20:e0da005a777f 2116
kenjiArai 30:4c57a022a56c 2117 /** Set User Defined Characters
kenjiArai 30:4c57a022a56c 2118 *
kenjiArai 30:4c57a022a56c 2119 * @param unsigned char c The Index of the UDC (0..7) for HD44780 or clones and (0..15) for some more advanced controllers
kenjiArai 30:4c57a022a56c 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))
kenjiArai 30:4c57a022a56c 2121 */
wim 21:9eb628d9e164 2122 void TextLCD_Base::setUDC(unsigned char c, char *udc_data) {
kenjiArai 30:4c57a022a56c 2123
kenjiArai 30:4c57a022a56c 2124 #if (LCD_TWO_CTRL == 1)
wim 15:b70ebfffb258 2125 // Select and configure second LCD controller when needed
wim 15:b70ebfffb258 2126 if(_type==LCD40x4) {
wim 19:c747b9e2e7b8 2127 _LCDCtrl_Idx current_ctrl_idx = _ctrl_idx; // Temp save current controller
wim 15:b70ebfffb258 2128
wim 15:b70ebfffb258 2129 // Select primary controller
wim 21:9eb628d9e164 2130 _ctrl_idx=_LCDCtrl_0;
wim 15:b70ebfffb258 2131
wim 15:b70ebfffb258 2132 // Configure primary LCD controller
wim 15:b70ebfffb258 2133 _setUDC(c, udc_data);
wim 15:b70ebfffb258 2134
wim 15:b70ebfffb258 2135 // Select 2nd controller
wim 21:9eb628d9e164 2136 _ctrl_idx=_LCDCtrl_1;
wim 15:b70ebfffb258 2137
wim 15:b70ebfffb258 2138 // Configure secondary LCD controller
wim 15:b70ebfffb258 2139 _setUDC(c, udc_data);
wim 11:9ec02df863a1 2140
wim 15:b70ebfffb258 2141 // Restore current controller
wim 19:c747b9e2e7b8 2142 _ctrl_idx=current_ctrl_idx;
wim 15:b70ebfffb258 2143 }
wim 15:b70ebfffb258 2144 else {
wim 15:b70ebfffb258 2145 // Configure primary LCD controller
wim 15:b70ebfffb258 2146 _setUDC(c, udc_data);
kenjiArai 30:4c57a022a56c 2147 }
kenjiArai 30:4c57a022a56c 2148 #else
kenjiArai 30:4c57a022a56c 2149 // Support only one LCD controller
kenjiArai 30:4c57a022a56c 2150 _setUDC(c, udc_data);
kenjiArai 30:4c57a022a56c 2151 #endif
wim 15:b70ebfffb258 2152 }
wim 15:b70ebfffb258 2153
kenjiArai 30:4c57a022a56c 2154 /** Low level method to store user defined characters for current controller
kenjiArai 30:4c57a022a56c 2155 *
kenjiArai 30:4c57a022a56c 2156 * @param unsigned char c The Index of the UDC (0..7) for HD44780 clones and (0..15) for some more advanced controllers
kenjiArai 30:4c57a022a56c 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))
kenjiArai 30:4c57a022a56c 2158 */
wim 21:9eb628d9e164 2159 void TextLCD_Base::_setUDC(unsigned char c, char *udc_data) {
wim 15:b70ebfffb258 2160
kenjiArai 30:4c57a022a56c 2161 switch (_ctrl) {
kenjiArai 30:4c57a022a56c 2162 case PCF2103_3V3 : // Some UDCs may be used for Icons
kenjiArai 30:4c57a022a56c 2163 case PCF2113_3V3 : // Some UDCs may be used for Icons
kenjiArai 30:4c57a022a56c 2164 case PCF2116_3V3 :
kenjiArai 30:4c57a022a56c 2165 case PCF2116_5V :
kenjiArai 30:4c57a022a56c 2166 case PCF2119_3V3 : // Some UDCs may be used for Icons
kenjiArai 30:4c57a022a56c 2167 case PCF2119R_3V3: // Some UDCs may be used for Icons
kenjiArai 30:4c57a022a56c 2168 c = c & 0x0F; // mask down to valid range
kenjiArai 30:4c57a022a56c 2169 break;
kenjiArai 30:4c57a022a56c 2170
kenjiArai 30:4c57a022a56c 2171 default:
kenjiArai 30:4c57a022a56c 2172 c = c & 0x07; // mask down to valid range
kenjiArai 30:4c57a022a56c 2173 break;
kenjiArai 30:4c57a022a56c 2174 } //switch _ctrl
kenjiArai 30:4c57a022a56c 2175
kenjiArai 30:4c57a022a56c 2176 // Select DD RAM for current LCD controller
kenjiArai 30:4c57a022a56c 2177 // This is needed to correctly set Bit 6 of the addresspointer for controllers that support 16 UDCs
kenjiArai 30:4c57a022a56c 2178 _writeCommand(0x80 | ((c << 3) & 0x40)) ;
kenjiArai 30:4c57a022a56c 2179
wim 15:b70ebfffb258 2180 // Select CG RAM for current LCD controller
kenjiArai 30:4c57a022a56c 2181 _writeCommand(0x40 | ((c << 3) & 0x3F)); //Set CG-RAM address, (note that Bit 6 is retained and can not be set by this command !)
wim 15:b70ebfffb258 2182 //8 sequential locations needed per UDC
wim 15:b70ebfffb258 2183 // Store UDC pattern
wim 11:9ec02df863a1 2184 for (int i=0; i<8; i++) {
wim 13:24506ba22480 2185 _writeData(*udc_data++);
wim 11:9ec02df863a1 2186 }
wim 15:b70ebfffb258 2187
kenjiArai 30:4c57a022a56c 2188 //Select DD RAM again for current LCD controller and restore the addresspointer
kenjiArai 30:4c57a022a56c 2189 int addr = getAddress(_column, _row);
kenjiArai 30:4c57a022a56c 2190 _writeCommand(0x80 | addr);
kenjiArai 30:4c57a022a56c 2191 }
kenjiArai 30:4c57a022a56c 2192
kenjiArai 30:4c57a022a56c 2193 #if(LCD_BLINK == 1)
kenjiArai 30:4c57a022a56c 2194 /** Set UDC Blink and Icon blink
kenjiArai 30:4c57a022a56c 2195 * setUDCBlink method is supported by some compatible devices (eg SSD1803)
kenjiArai 30:4c57a022a56c 2196 *
kenjiArai 30:4c57a022a56c 2197 * @param blinkMode The Blink mode (BlinkOff, BlinkOn)
kenjiArai 30:4c57a022a56c 2198 */
kenjiArai 30:4c57a022a56c 2199 void TextLCD_Base::setUDCBlink(LCDBlink blinkMode){
kenjiArai 30:4c57a022a56c 2200 // Blinking UDCs (and icons) are enabled when a specific controlbit (BE) is set.
kenjiArai 30:4c57a022a56c 2201 // The blinking pixels in the UDC and icons can be controlled by setting additional bits in the UDC or icon bitpattern.
kenjiArai 30:4c57a022a56c 2202 // UDCs are defined by an 8 byte bitpattern. The P0..P4 form the character pattern.
kenjiArai 30:4c57a022a56c 2203 // P7 P6 P5 P4 P3 P2 P1 P0
kenjiArai 30:4c57a022a56c 2204 // 0 B1 B0 x 0 1 1 1 0
kenjiArai 30:4c57a022a56c 2205 // 1 B1 B0 x 1 0 0 0 1
kenjiArai 30:4c57a022a56c 2206 // .............
kenjiArai 30:4c57a022a56c 2207 // 7 B1 B0 x 1 0 0 0 1
kenjiArai 30:4c57a022a56c 2208 //
kenjiArai 30:4c57a022a56c 2209 // Bit 6 and Bit 7 in the pattern will control the blinking mode when Blink is enabled through BE.
kenjiArai 30:4c57a022a56c 2210 // B1 B0 Mode
kenjiArai 30:4c57a022a56c 2211 // 0 0 No Blinking in this row of the UDC
kenjiArai 30:4c57a022a56c 2212 // 0 1 Enabled pixels in P4 will blink
kenjiArai 30:4c57a022a56c 2213 // 1 x Enabled pixels in P0..P4 will blink
kenjiArai 30:4c57a022a56c 2214 //
kenjiArai 30:4c57a022a56c 2215 // Note: the PCF2103 and PCF2113 use UDCs to set Icons
kenjiArai 30:4c57a022a56c 2216 // 3 x 8 rows x 5 bits = 120 bits Icons for Normal pattern (UDC 0..2) and
kenjiArai 30:4c57a022a56c 2217 // 3 x 8 rows x 5 bits = 120 bits Icons for Blink pattern (UDC 4..6)
kenjiArai 30:4c57a022a56c 2218 // Note: the PCF2119 uses UDCs to set Icons
kenjiArai 30:4c57a022a56c 2219 // 4 x 8 rows x 5 bits = 160 bits Icons for Normal pattern (UDC 0..3) and
kenjiArai 30:4c57a022a56c 2220 // 4 x 8 rows x 5 bits = 160 bits Icons for Blink pattern (UDC 4..7)
kenjiArai 30:4c57a022a56c 2221 switch (blinkMode) {
kenjiArai 30:4c57a022a56c 2222 case BlinkOn:
kenjiArai 30:4c57a022a56c 2223 // Controllers that support UDC/Icon Blink
kenjiArai 30:4c57a022a56c 2224 switch (_ctrl) {
kenjiArai 30:4c57a022a56c 2225 case KS0073 :
kenjiArai 30:4c57a022a56c 2226 case KS0078 :
kenjiArai 30:4c57a022a56c 2227 case HD66712 :
kenjiArai 30:4c57a022a56c 2228 _function_1 |= 0x02; // Enable UDC/Icon Blink
kenjiArai 30:4c57a022a56c 2229 _writeCommand(0x20 | _function_1); // Function set 0 0 1 DL N RE(1) BE 0/LP (Ext Regs)
kenjiArai 30:4c57a022a56c 2230
kenjiArai 30:4c57a022a56c 2231 _writeCommand(0x20 | _function); // Function set 0 0 1 DL N RE(0) DH REV (Std Regs)
kenjiArai 30:4c57a022a56c 2232 break; // case KS0073, KS0078, HD66712 Controller
kenjiArai 30:4c57a022a56c 2233
kenjiArai 30:4c57a022a56c 2234 case US2066_3V3 :
kenjiArai 30:4c57a022a56c 2235 case SSD1803_3V3 :
kenjiArai 30:4c57a022a56c 2236 _function_1 |= 0x04; // Enable UDC/Icon Blink
kenjiArai 30:4c57a022a56c 2237 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
kenjiArai 30:4c57a022a56c 2238 // Select Ext Instr Set
kenjiArai 30:4c57a022a56c 2239
kenjiArai 30:4c57a022a56c 2240 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
kenjiArai 30:4c57a022a56c 2241 // Select Std Instr set, Select IS=0
kenjiArai 30:4c57a022a56c 2242 break; // case SSD1803, US2066
kenjiArai 30:4c57a022a56c 2243
kenjiArai 30:4c57a022a56c 2244 case PCF2103_3V3 :
kenjiArai 30:4c57a022a56c 2245 case PCF2113_3V3 :
kenjiArai 30:4c57a022a56c 2246 case PCF2119_3V3 :
kenjiArai 30:4c57a022a56c 2247 case PCF2119R_3V3 :
kenjiArai 30:4c57a022a56c 2248 // Enable Icon Blink
kenjiArai 30:4c57a022a56c 2249 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
kenjiArai 30:4c57a022a56c 2250 _writeCommand(0x08 | 0x02); // ICON Conf 0000 1, IM=0 (Char mode), IB=1 (Icon blink), 0 (Instr. Set 1)
kenjiArai 30:4c57a022a56c 2251 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
kenjiArai 30:4c57a022a56c 2252
kenjiArai 30:4c57a022a56c 2253 break;
kenjiArai 30:4c57a022a56c 2254
kenjiArai 30:4c57a022a56c 2255 default:
kenjiArai 30:4c57a022a56c 2256 //Unsupported feature for other controllers
kenjiArai 30:4c57a022a56c 2257 break;
kenjiArai 30:4c57a022a56c 2258 } //switch _ctrl
kenjiArai 30:4c57a022a56c 2259
kenjiArai 30:4c57a022a56c 2260 break; // BlinkOn
kenjiArai 30:4c57a022a56c 2261
kenjiArai 30:4c57a022a56c 2262 case BlinkOff:
kenjiArai 30:4c57a022a56c 2263 // Controllers that support UDC Blink
kenjiArai 30:4c57a022a56c 2264 switch (_ctrl) {
kenjiArai 30:4c57a022a56c 2265 case KS0073 :
kenjiArai 30:4c57a022a56c 2266 case KS0078 :
kenjiArai 30:4c57a022a56c 2267 case HD66712:
kenjiArai 30:4c57a022a56c 2268 _function_1 &= ~0x02; // Disable UDC/Icon Blink
kenjiArai 30:4c57a022a56c 2269 _writeCommand(0x20 | _function_1); // Function set 0 0 1 DL N RE(1) BE 0/LP (Ext Regs)
kenjiArai 30:4c57a022a56c 2270
kenjiArai 30:4c57a022a56c 2271 _writeCommand(0x20 | _function); // Function set 0 0 1 DL N RE(0) DH REV (Std Regs)
kenjiArai 30:4c57a022a56c 2272 break; // case KS0073, KS0078, HD66712 Controller
kenjiArai 30:4c57a022a56c 2273
kenjiArai 30:4c57a022a56c 2274 case US2066_3V3 :
kenjiArai 30:4c57a022a56c 2275 case SSD1803_3V3 :
kenjiArai 30:4c57a022a56c 2276 _function_1 &= ~0x04; // Disable UDC/Icon Blink
kenjiArai 30:4c57a022a56c 2277 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
kenjiArai 30:4c57a022a56c 2278 // Select Ext Instr Set
kenjiArai 30:4c57a022a56c 2279
kenjiArai 30:4c57a022a56c 2280 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
kenjiArai 30:4c57a022a56c 2281 // Select Std Instr set, Select IS=0
kenjiArai 30:4c57a022a56c 2282 break; // case SSD1803, US2066
kenjiArai 30:4c57a022a56c 2283
kenjiArai 30:4c57a022a56c 2284 case PCF2103_3V3 :
kenjiArai 30:4c57a022a56c 2285 case PCF2113_3V3 :
kenjiArai 30:4c57a022a56c 2286 case PCF2119_3V3 :
kenjiArai 30:4c57a022a56c 2287 case PCF2119R_3V3 :
kenjiArai 30:4c57a022a56c 2288 // Disable Icon Blink
kenjiArai 30:4c57a022a56c 2289 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
kenjiArai 30:4c57a022a56c 2290 _writeCommand(0x08); // ICON Conf 0000 1, IM=0 (Char mode), IB=1 (Icon blink), 0 (Instr. Set 1)
kenjiArai 30:4c57a022a56c 2291 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
kenjiArai 30:4c57a022a56c 2292
kenjiArai 30:4c57a022a56c 2293 break;
kenjiArai 30:4c57a022a56c 2294
kenjiArai 30:4c57a022a56c 2295 default:
kenjiArai 30:4c57a022a56c 2296 //Unsupported feature for other controllers
kenjiArai 30:4c57a022a56c 2297 break;
kenjiArai 30:4c57a022a56c 2298 } //switch _ctrl
kenjiArai 30:4c57a022a56c 2299
kenjiArai 30:4c57a022a56c 2300 break; //BlinkOff
kenjiArai 30:4c57a022a56c 2301
kenjiArai 30:4c57a022a56c 2302 default:
kenjiArai 30:4c57a022a56c 2303 break;
kenjiArai 30:4c57a022a56c 2304 } // blinkMode
kenjiArai 30:4c57a022a56c 2305
kenjiArai 30:4c57a022a56c 2306 } // setUDCBlink()
kenjiArai 30:4c57a022a56c 2307 #endif
kenjiArai 30:4c57a022a56c 2308
kenjiArai 30:4c57a022a56c 2309 #if(LCD_CONTRAST == 1)
kenjiArai 30:4c57a022a56c 2310 /** Set Contrast
kenjiArai 30:4c57a022a56c 2311 * setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation
kenjiArai 30:4c57a022a56c 2312 * Initial code for ST70XX imported from fork by JH1PJL
kenjiArai 30:4c57a022a56c 2313 *
kenjiArai 30:4c57a022a56c 2314 * @param unsigned char c contrast data (6 significant bits, valid range 0..63, Value 0 will disable the Vgen)
kenjiArai 30:4c57a022a56c 2315 * @return none
kenjiArai 30:4c57a022a56c 2316 */
kenjiArai 30:4c57a022a56c 2317 //@TODO Add support for 40x4 dual controller
kenjiArai 30:4c57a022a56c 2318 void TextLCD_Base::setContrast(unsigned char c) {
kenjiArai 30:4c57a022a56c 2319
kenjiArai 30:4c57a022a56c 2320 // Function set mode stored during Init. Make sure we dont accidentally switch between 1-line and 2-line mode!
kenjiArai 30:4c57a022a56c 2321 // Icon/Booster mode stored during Init. Make sure we dont accidentally change this!
kenjiArai 30:4c57a022a56c 2322
kenjiArai 30:4c57a022a56c 2323 _contrast = c & 0x3F; // Sanity check
kenjiArai 30:4c57a022a56c 2324
kenjiArai 30:4c57a022a56c 2325 switch (_ctrl) {
kenjiArai 30:4c57a022a56c 2326 case PCF2113_3V3 :
kenjiArai 30:4c57a022a56c 2327 case PCF2119_3V3 :
kenjiArai 30:4c57a022a56c 2328 case PCF2119R_3V3 :
kenjiArai 30:4c57a022a56c 2329 if (_contrast < 5) _contrast = 0; // See datasheet. Sanity check for PCF2113/PCF2119
kenjiArai 30:4c57a022a56c 2330 if (_contrast > 55) _contrast = 55;
kenjiArai 30:4c57a022a56c 2331
kenjiArai 30:4c57a022a56c 2332 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instruction Set = 1
kenjiArai 30:4c57a022a56c 2333 _writeCommand(0x80 | 0x00 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=0, VA=contrast
kenjiArai 30:4c57a022a56c 2334 _writeCommand(0x80 | 0x40 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=1, VB=contrast
kenjiArai 30:4c57a022a56c 2335 _writeCommand(0x20 | _function); // Select Instruction Set = 0
kenjiArai 30:4c57a022a56c 2336 break;
kenjiArai 30:4c57a022a56c 2337
kenjiArai 30:4c57a022a56c 2338 case ST7032_3V3 :
kenjiArai 30:4c57a022a56c 2339 case ST7032_5V :
kenjiArai 30:4c57a022a56c 2340 case ST7036_3V3 :
kenjiArai 30:4c57a022a56c 2341 // case ST7036_5V :
kenjiArai 30:4c57a022a56c 2342 case SSD1803_3V3 :
kenjiArai 30:4c57a022a56c 2343 case SPLC792A_3V3 :
kenjiArai 30:4c57a022a56c 2344 _writeCommand(0x20 | _function | 0x01); // Select Instruction Set = 1
kenjiArai 30:4c57a022a56c 2345 _writeCommand(0x70 | (_contrast & 0x0F)); // Contrast Low bits
kenjiArai 30:4c57a022a56c 2346 _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Contrast High bits
kenjiArai 30:4c57a022a56c 2347 _writeCommand(0x20 | _function); // Select Instruction Set = 0
kenjiArai 30:4c57a022a56c 2348 break;
kenjiArai 30:4c57a022a56c 2349
kenjiArai 30:4c57a022a56c 2350 case US2066_3V3 :
kenjiArai 30:4c57a022a56c 2351 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
kenjiArai 30:4c57a022a56c 2352 // Select Extended Instruction Set
kenjiArai 30:4c57a022a56c 2353
kenjiArai 30:4c57a022a56c 2354 _writeCommand(0x79); // Function Select OLED: 0 1 1 1 1 0 0 1 (Ext Instr Set)
kenjiArai 30:4c57a022a56c 2355
kenjiArai 30:4c57a022a56c 2356 _writeCommand(0x81); // Set Contrast Control: 1 0 0 0 0 0 0 1 (Ext Instr Set, OLED)
kenjiArai 30:4c57a022a56c 2357 _writeCommand((_contrast << 2) | 0x03); // Set Contrast Value: 8 bits. Use 6 bits for compatibility
kenjiArai 30:4c57a022a56c 2358
kenjiArai 30:4c57a022a56c 2359 _writeCommand(0x78); // Function Disable OLED: 0 1 1 1 1 0 0 0 (Ext Instr Set)
kenjiArai 30:4c57a022a56c 2360
kenjiArai 30:4c57a022a56c 2361 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
kenjiArai 30:4c57a022a56c 2362 // Select Std Instr set, Select IS=0
kenjiArai 30:4c57a022a56c 2363 break;
kenjiArai 30:4c57a022a56c 2364
kenjiArai 30:4c57a022a56c 2365 //not yet tested on hardware
kenjiArai 30:4c57a022a56c 2366 case PT6314 :
kenjiArai 30:4c57a022a56c 2367 // Only 2 significant bits
kenjiArai 30:4c57a022a56c 2368 // 0x00 = 100%
kenjiArai 30:4c57a022a56c 2369 // 0x01 = 75%
kenjiArai 30:4c57a022a56c 2370 // 0x02 = 50%
kenjiArai 30:4c57a022a56c 2371 // 0x03 = 25%
kenjiArai 30:4c57a022a56c 2372 _writeCommand(0x20 | _function | ((~_contrast) >> 4)); // Invert and shift to use 2 MSBs
kenjiArai 30:4c57a022a56c 2373 break;
kenjiArai 30:4c57a022a56c 2374
kenjiArai 30:4c57a022a56c 2375 default:
kenjiArai 30:4c57a022a56c 2376 //Unsupported feature for other controllers
kenjiArai 30:4c57a022a56c 2377 break;
kenjiArai 30:4c57a022a56c 2378 } // end switch
kenjiArai 30:4c57a022a56c 2379 } // end setContrast()
kenjiArai 30:4c57a022a56c 2380 #endif
kenjiArai 30:4c57a022a56c 2381
kenjiArai 30:4c57a022a56c 2382 #if(LCD_POWER == 1)
kenjiArai 30:4c57a022a56c 2383 /** Set Power
kenjiArai 30:4c57a022a56c 2384 * setPower method is supported by some compatible devices (eg SSD1803) that have power down modes
kenjiArai 30:4c57a022a56c 2385 *
kenjiArai 30:4c57a022a56c 2386 * @param bool powerOn Power on/off
kenjiArai 30:4c57a022a56c 2387 * @return none
kenjiArai 30:4c57a022a56c 2388 */
kenjiArai 30:4c57a022a56c 2389 //@TODO Add support for 40x4 dual controller
kenjiArai 30:4c57a022a56c 2390 void TextLCD_Base::setPower(bool powerOn) {
kenjiArai 30:4c57a022a56c 2391
kenjiArai 30:4c57a022a56c 2392 if (powerOn) {
kenjiArai 30:4c57a022a56c 2393 // Switch on
kenjiArai 30:4c57a022a56c 2394 setMode(DispOn);
kenjiArai 30:4c57a022a56c 2395
kenjiArai 30:4c57a022a56c 2396 // Controllers that supports specific Power Down mode
kenjiArai 30:4c57a022a56c 2397 switch (_ctrl) {
kenjiArai 30:4c57a022a56c 2398
kenjiArai 30:4c57a022a56c 2399 // case PCF2113_3V3 :
kenjiArai 30:4c57a022a56c 2400 // case PCF2119_3V3 :
kenjiArai 30:4c57a022a56c 2401 // case PCF2119R_3V3 :
kenjiArai 30:4c57a022a56c 2402 // case ST7032_3V3 :
kenjiArai 30:4c57a022a56c 2403 //@todo
kenjiArai 30:4c57a022a56c 2404 // enable Booster Bon
kenjiArai 30:4c57a022a56c 2405
kenjiArai 30:4c57a022a56c 2406 case WS0010:
kenjiArai 30:4c57a022a56c 2407 _writeCommand(0x17); // Char mode, DC/DC on
kenjiArai 30:4c57a022a56c 2408 WAIT_MS(10); // Wait 10ms to ensure powered up
kenjiArai 30:4c57a022a56c 2409 break;
kenjiArai 30:4c57a022a56c 2410
kenjiArai 30:4c57a022a56c 2411 case KS0073:
kenjiArai 30:4c57a022a56c 2412 case KS0078:
kenjiArai 30:4c57a022a56c 2413 case SSD1803_3V3 :
kenjiArai 30:4c57a022a56c 2414 // case SSD1803_5V :
kenjiArai 30:4c57a022a56c 2415 _writeCommand(0x20 | _function_1); // Select Ext Instr Set
kenjiArai 30:4c57a022a56c 2416 _writeCommand(0x02); // Power On
kenjiArai 30:4c57a022a56c 2417 _writeCommand(0x20 | _function); // Select Std Instr Set
kenjiArai 30:4c57a022a56c 2418 break;
kenjiArai 30:4c57a022a56c 2419
kenjiArai 30:4c57a022a56c 2420 default:
kenjiArai 30:4c57a022a56c 2421 //Unsupported feature for other controllers
kenjiArai 30:4c57a022a56c 2422 break;
kenjiArai 30:4c57a022a56c 2423 } // end switch
kenjiArai 30:4c57a022a56c 2424 }
kenjiArai 30:4c57a022a56c 2425 else {
kenjiArai 30:4c57a022a56c 2426 // Switch off
kenjiArai 30:4c57a022a56c 2427 setMode(DispOff);
kenjiArai 30:4c57a022a56c 2428
kenjiArai 30:4c57a022a56c 2429 // Controllers that support specific Power Down mode
kenjiArai 30:4c57a022a56c 2430 switch (_ctrl) {
kenjiArai 30:4c57a022a56c 2431
kenjiArai 30:4c57a022a56c 2432 // case PCF2113_3V3 :
kenjiArai 30:4c57a022a56c 2433 // case PCF2119_3V3 :
kenjiArai 30:4c57a022a56c 2434 // case PCF2119R_3V3 :
kenjiArai 30:4c57a022a56c 2435 // case ST7032_3V3 :
kenjiArai 30:4c57a022a56c 2436 //@todo
kenjiArai 30:4c57a022a56c 2437 // disable Booster Bon
kenjiArai 30:4c57a022a56c 2438
kenjiArai 30:4c57a022a56c 2439 case WS0010:
kenjiArai 30:4c57a022a56c 2440 _writeCommand(0x13); // Char mode, DC/DC off
kenjiArai 30:4c57a022a56c 2441 break;
kenjiArai 30:4c57a022a56c 2442
kenjiArai 30:4c57a022a56c 2443 case KS0073:
kenjiArai 30:4c57a022a56c 2444 case KS0078:
kenjiArai 30:4c57a022a56c 2445 case SSD1803_3V3 :
kenjiArai 30:4c57a022a56c 2446 // case SSD1803_5V :
kenjiArai 30:4c57a022a56c 2447 _writeCommand(0x20 | _function_1); // Select Ext Instr Set
kenjiArai 30:4c57a022a56c 2448 _writeCommand(0x03); // Power Down
kenjiArai 30:4c57a022a56c 2449 _writeCommand(0x20 | _function); // Select Std Instr Set
kenjiArai 30:4c57a022a56c 2450 break;
kenjiArai 30:4c57a022a56c 2451
kenjiArai 30:4c57a022a56c 2452 default:
kenjiArai 30:4c57a022a56c 2453 //Unsupported feature for other controllers
kenjiArai 30:4c57a022a56c 2454 break;
kenjiArai 30:4c57a022a56c 2455 } // end switch
kenjiArai 30:4c57a022a56c 2456 }
kenjiArai 30:4c57a022a56c 2457 } // end setPower()
kenjiArai 30:4c57a022a56c 2458 #endif
kenjiArai 30:4c57a022a56c 2459
kenjiArai 30:4c57a022a56c 2460 #if(LCD_ORIENT == 1)
kenjiArai 30:4c57a022a56c 2461 /** Set Orient
kenjiArai 30:4c57a022a56c 2462 * setOrient method is supported by some compatible devices (eg SSD1803, US2066) that have top/bottom view modes
kenjiArai 30:4c57a022a56c 2463 *
kenjiArai 30:4c57a022a56c 2464 * @param LCDOrient orient Orientation
kenjiArai 30:4c57a022a56c 2465 * @return none
kenjiArai 30:4c57a022a56c 2466 */
kenjiArai 30:4c57a022a56c 2467 void TextLCD_Base::setOrient(LCDOrient orient){
kenjiArai 30:4c57a022a56c 2468
kenjiArai 30:4c57a022a56c 2469 switch (orient) {
kenjiArai 30:4c57a022a56c 2470
kenjiArai 30:4c57a022a56c 2471 case Top:
kenjiArai 30:4c57a022a56c 2472 switch (_ctrl) {
kenjiArai 30:4c57a022a56c 2473 case PCF2103_3V3:
kenjiArai 30:4c57a022a56c 2474 case PCF2116_3V3:
kenjiArai 30:4c57a022a56c 2475 case PCF2116_5V:
kenjiArai 30:4c57a022a56c 2476 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
kenjiArai 30:4c57a022a56c 2477 _writeCommand(0x05); // Display Conf Set 0000 0, 1, P=0, Q=1 (Instr. Set 1)
kenjiArai 30:4c57a022a56c 2478 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
kenjiArai 30:4c57a022a56c 2479 break;
kenjiArai 30:4c57a022a56c 2480
kenjiArai 30:4c57a022a56c 2481 case PCF2119_3V3:
kenjiArai 30:4c57a022a56c 2482 case PCF2119R_3V3:
kenjiArai 30:4c57a022a56c 2483 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
kenjiArai 30:4c57a022a56c 2484 _writeCommand(0x07); // Display Conf Set 0000 0, 1, P=1, Q=1 (Instr. Set 1)
kenjiArai 30:4c57a022a56c 2485 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
kenjiArai 30:4c57a022a56c 2486 break;
kenjiArai 30:4c57a022a56c 2487
kenjiArai 30:4c57a022a56c 2488 case SSD1803_3V3 :
kenjiArai 30:4c57a022a56c 2489 // case SSD1803_5V :
kenjiArai 30:4c57a022a56c 2490 case US2066_3V3 :
kenjiArai 30:4c57a022a56c 2491 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
kenjiArai 30:4c57a022a56c 2492 // Select Extended Instruction Set
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 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)
kenjiArai 30:4c57a022a56c 2495
kenjiArai 30:4c57a022a56c 2496 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
kenjiArai 30:4c57a022a56c 2497 // Select Std Instr set, Select IS=0
kenjiArai 30:4c57a022a56c 2498 break;
kenjiArai 30:4c57a022a56c 2499
kenjiArai 30:4c57a022a56c 2500 case ST7070:
kenjiArai 30:4c57a022a56c 2501 _writeCommand(0x20 | _function | 0x04); // Set function, 0 0 1 DL, N, EXT=1, x, x (Select Instr Se