address modified to run with my LCD

Dependents:   DS1302_test_with_STM32_and_LCD16x2

Committer:
wim
Date:
Wed May 20 18:46:51 2015 +0000
Revision:
40:d3496c3ea301
Parent:
39:e9c2319de9c5
Child:
41:111ca62e8a59
Fixed an occasional init problem. Added PCF2119R support, added HD66712 support, added some more I2C portexpander types.

Who changed what in which revision?

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