address modified to run with my LCD

Dependents:   DS1302_test_with_STM32_and_LCD16x2

Committer:
wim
Date:
Tue May 19 18:13:00 2015 +0000
Revision:
39:e9c2319de9c5
Parent:
38:cbe275b0b647
Child:
40:d3496c3ea301
Working version PCF2119

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 39:e9c2319de9c5 24 * Fixed and Added more fonttable support for PCF2119K, 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 39:e9c2319de9c5 1228 _function = 0x02; // Function set 001 DL N RE(0) DH REV (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 39:e9c2319de9c5 1231 // RE=0 (Dis. Extended Regs, special mode for KS0073)
wim 39:e9c2319de9c5 1232 // DH=1 (Disp shift enable, special mode for KS0073)
wim 39:e9c2319de9c5 1233 // REV=0 (Reverse normal, special mode for KS0073)
wim 39:e9c2319de9c5 1234
wim 39:e9c2319de9c5 1235 _function_1 = 0x04; // Function set 001 DL N RE(1) BE LP (Ext Regs)
wim 39:e9c2319de9c5 1236 // DL=0 (4 bits bus)
wim 39:e9c2319de9c5 1237 // N=0 (1-line mode, N=1 2-line mode)
wim 39:e9c2319de9c5 1238 // RE=1 (Ena Extended Regs, special mode for KS0073)
wim 39:e9c2319de9c5 1239 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073)
wim 39:e9c2319de9c5 1240 // LP=0 (LP=1 Low power mode, LP=0 Normal)
wim 39:e9c2319de9c5 1241
wim 39:e9c2319de9c5 1242 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
wim 39:e9c2319de9c5 1243 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073)
wim 39:e9c2319de9c5 1244 break;
wim 39:e9c2319de9c5 1245
wim 39:e9c2319de9c5 1246 // case LCD12x3D: // Special mode for KS0073, KS0078 and PCF21XX
wim 39:e9c2319de9c5 1247 // case LCD12x3D1: // Special mode for KS0073, KS0078 and PCF21XX
wim 39:e9c2319de9c5 1248 case LCD12x4D: // Special mode for KS0073, KS0078, PCF21XX and HD66712
wim 39:e9c2319de9c5 1249 // case LCD16x3D: // Special mode for KS0073, KS0078
wim 39:e9c2319de9c5 1250 // case LCD16x4D: // Special mode for KS0073, KS0078
wim 39:e9c2319de9c5 1251 case LCD20x4D: // Special mode for KS0073, KS0078 and HD66712
wim 39:e9c2319de9c5 1252 _function = 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs)
wim 39:e9c2319de9c5 1253 // DL=0 (4 bits bus)
wim 39:e9c2319de9c5 1254 // N=0 (dont care for 4 line mode)
wim 39:e9c2319de9c5 1255 // RE=0 (Dis. Extended Regs, special mode for KS0073)
wim 39:e9c2319de9c5 1256 // DH=1 (Disp shift enable, special mode for KS0073)
wim 39:e9c2319de9c5 1257 // REV=0 (Reverse normal, special mode for KS0073)
wim 39:e9c2319de9c5 1258
wim 39:e9c2319de9c5 1259 _function_1 = 0x04; // Function set 001 DL N RE(1) BE LP (Ext Regs)
wim 39:e9c2319de9c5 1260 // DL=0 (4 bits bus)
wim 39:e9c2319de9c5 1261 // N=0 (1-line mode), N=1 (2-line mode)
wim 39:e9c2319de9c5 1262 // RE=1 (Ena Extended Regs, special mode for KS0073)
wim 39:e9c2319de9c5 1263 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073)
wim 39:e9c2319de9c5 1264 // LP=0 (LP=1 Low power mode, LP=0 Normal)
wim 39:e9c2319de9c5 1265
wim 39:e9c2319de9c5 1266 _function_x = 0x01; // Ext Function set 0000 1 FW BW NW (Ext Regs)
wim 39:e9c2319de9c5 1267 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073)
wim 39:e9c2319de9c5 1268 break;
wim 39:e9c2319de9c5 1269
wim 39:e9c2319de9c5 1270
wim 39:e9c2319de9c5 1271 case LCD16x3G: // Special mode for ST7036
wim 39:e9c2319de9c5 1272 // case LCD24x3D: // Special mode for KS0078
wim 39:e9c2319de9c5 1273 // case LCD24x3D1: // Special mode for KS0078
wim 39:e9c2319de9c5 1274 case LCD24x4D: // Special mode for KS0078
wim 39:e9c2319de9c5 1275 error("Error: LCD Controller type does not support this Display type\n\r");
wim 39:e9c2319de9c5 1276 break;
wim 39:e9c2319de9c5 1277
wim 39:e9c2319de9c5 1278 default:
wim 39:e9c2319de9c5 1279 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
wim 39:e9c2319de9c5 1280 _function = 0x0A; // Function set 001 DL N RE(0) DH REV (Std Regs)
wim 39:e9c2319de9c5 1281 // DL=0 (4 bits bus)
wim 39:e9c2319de9c5 1282 // N=1 (2-line mode), N=0 (1-line mode)
wim 39:e9c2319de9c5 1283 // RE=0 (Dis. Extended Regs, special mode for KS0073)
wim 39:e9c2319de9c5 1284 // DH=1 (Disp shift enable, special mode for KS0073)
wim 39:e9c2319de9c5 1285 // REV=0 (Reverse normal, special mode for KS0073)
wim 39:e9c2319de9c5 1286
wim 39:e9c2319de9c5 1287 _function_1 = 0x0C; // Function set 001 DL N RE(1) BE LP (Ext Regs)
wim 39:e9c2319de9c5 1288 // DL=0 (4 bits bus)
wim 39:e9c2319de9c5 1289 // N=1 (2 line mode), N=0 (1-line mode)
wim 39:e9c2319de9c5 1290 // RE=1 (Ena Extended Regs, special mode for KS0073)
wim 39:e9c2319de9c5 1291 // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073)
wim 39:e9c2319de9c5 1292 // LP=0 (LP=1 Low power mode, LP=0 Normal)
wim 39:e9c2319de9c5 1293
wim 39:e9c2319de9c5 1294 _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs)
wim 39:e9c2319de9c5 1295 // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073)
wim 39:e9c2319de9c5 1296 break;
wim 39:e9c2319de9c5 1297 } // switch type
wim 39:e9c2319de9c5 1298
wim 39:e9c2319de9c5 1299 // init special features
wim 39:e9c2319de9c5 1300 _writeCommand(0x20 | _function_1);// Function set 001 DL N RE(1) BE LP (Ext Regs)
wim 39:e9c2319de9c5 1301 // DL=0 (4 bits bus), DL=1 (8 bits mode)
wim 39:e9c2319de9c5 1302 // N=0 (1 line mode), N=1 (2 line mode)
wim 39:e9c2319de9c5 1303 // RE=1 (Ena Extended Regs, special mode for KS0073)
wim 39:e9c2319de9c5 1304 // BE=0 (Blink Enable/Disable, CG/SEG RAM, special mode for KS0073)
wim 39:e9c2319de9c5 1305 // LP=0 (LP=1 Low power mode, LP=0 Normal)
wim 39:e9c2319de9c5 1306
wim 39:e9c2319de9c5 1307 _writeCommand(0x08 | _function_x); // Ext Function set 0000 1 FW BW NW (Ext Regs)
wim 39:e9c2319de9c5 1308 // FW=0 (5-dot font, special mode for KS0073)
wim 39:e9c2319de9c5 1309 // BW=0 (Cur BW invert disable, special mode for KS0073)
wim 39:e9c2319de9c5 1310 // NW=0 (1,2 Line), NW=1 (4 line, special mode for KS0073)
wim 39:e9c2319de9c5 1311
wim 39:e9c2319de9c5 1312 _writeCommand(0x10); // Scroll/Shift set 0001 DS/HS4 DS/HS3 DS/HS2 DS/HS1 (Ext Regs)
wim 39:e9c2319de9c5 1313 // Dotscroll/Display shift enable (Special mode for KS0073)
wim 39:e9c2319de9c5 1314
wim 39:e9c2319de9c5 1315 _writeCommand(0x80); // Scroll Quantity set 1 0 SQ5 SQ4 SQ3 SQ2 SQ1 SQ0 (Ext Regs)
wim 39:e9c2319de9c5 1316 // Scroll quantity (Special mode for KS0073)
wim 39:e9c2319de9c5 1317
wim 39:e9c2319de9c5 1318 _writeCommand(0x20 | _function); // Function set 001 DL N RE(0) DH REV (Std Regs)
wim 39:e9c2319de9c5 1319 // DL=0 (4 bits bus), DL=1 (8 bits mode)
wim 39:e9c2319de9c5 1320 // N=0 (1 line mode), N=1 (2 line mode)
wim 39:e9c2319de9c5 1321 // RE=0 (Dis. Extended Regs, special mode for KS0073)
wim 39:e9c2319de9c5 1322 // DH=1 (Disp shift enable/disable, special mode for KS0073)
wim 39:e9c2319de9c5 1323 // REV=0 (Reverse/Normal, special mode for KS0073)
wim 39:e9c2319de9c5 1324 break; // case HD66712 Controller
wim 39:e9c2319de9c5 1325
wim 29:a3663151aa65 1326
wim 37:ce348c002929 1327 case ST7066_ACM: // ST7066 4/8 bit, I2C on ACM1602 using a PIC
wim 19:c747b9e2e7b8 1328 default:
wim 32:59c4b8f648d4 1329 // Devices fully compatible to HD44780 that do not use any DC/DC Voltage converters but external VLCD, no icons etc
wim 10:dd9b3a696acd 1330
wim 29:a3663151aa65 1331 // Initialise Display configuration
wim 29:a3663151aa65 1332 switch (_type) {
wim 29:a3663151aa65 1333 case LCD8x1: //8x1 is a regular 1 line display
wim 29:a3663151aa65 1334 case LCD8x2B: //8x2B is a special case of 16x1
wim 29:a3663151aa65 1335 // case LCD12x1:
wim 29:a3663151aa65 1336 case LCD16x1:
wim 30:033048611c01 1337 // case LCD20x1:
wim 29:a3663151aa65 1338 case LCD24x1:
wim 30:033048611c01 1339 // case LCD40x1:
wim 32:59c4b8f648d4 1340 _function = 0x00; // Function set 001 DL N F - -
wim 29:a3663151aa65 1341 // DL=0 (4 bits bus)
wim 29:a3663151aa65 1342 // N=0 (1 line)
wim 29:a3663151aa65 1343 // F=0 (5x7 dots font)
wim 29:a3663151aa65 1344 break;
wim 29:a3663151aa65 1345
wim 32:59c4b8f648d4 1346 case LCD12x3D: // Special mode for KS0078 and PCF21XX
wim 32:59c4b8f648d4 1347 case LCD12x3D1: // Special mode for KS0078 and PCF21XX
wim 32:59c4b8f648d4 1348 case LCD12x4D: // Special mode for KS0078 and PCF21XX:
wim 33:900a94bc7585 1349 case LCD16x3D: // Special mode for KS0078
wim 32:59c4b8f648d4 1350 // case LCD16x3D1: // Special mode for KS0078
wim 30:033048611c01 1351 // case LCD24x3D: // Special mode for KS0078
wim 32:59c4b8f648d4 1352 // case LCD24x3D1: // Special mode for KS0078
wim 30:033048611c01 1353 case LCD24x4D: // Special mode for KS0078
wim 30:033048611c01 1354 error("Error: LCD Controller type does not support this Display type\n\r");
wim 30:033048611c01 1355 break;
wim 30:033048611c01 1356
wim 30:033048611c01 1357 // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4)
wim 29:a3663151aa65 1358 default:
wim 32:59c4b8f648d4 1359 _function = 0x08; // Function set 001 DL N F - -
wim 29:a3663151aa65 1360 // DL=0 (4 bits bus)
wim 29:a3663151aa65 1361 // Note: 4 bit mode is ignored for native SPI and I2C devices
wim 29:a3663151aa65 1362 // N=1 (2 lines)
wim 29:a3663151aa65 1363 // F=0 (5x7 dots font, only option for 2 line display)
wim 32:59c4b8f648d4 1364 // - (Don't care)
wim 29:a3663151aa65 1365 break;
wim 29:a3663151aa65 1366 } // switch type
wim 10:dd9b3a696acd 1367
wim 34:e5a0dcb43ecc 1368 _writeCommand(0x20 | _function);
wim 29:a3663151aa65 1369 break; // case default Controller
wim 29:a3663151aa65 1370
wim 34:e5a0dcb43ecc 1371 } // switch Controller specific initialisations
wim 10:dd9b3a696acd 1372
wim 30:033048611c01 1373 // Controller general initialisations
wim 39:e9c2319de9c5 1374 // _writeCommand(0x01); // Clear Display and set cursor to 0
wim 32:59c4b8f648d4 1375 // wait_ms(10); // The CLS command takes 1.64 ms.
wim 32:59c4b8f648d4 1376 // // Since we are not using the Busy flag, Lets be safe and take 10 ms
wim 28:30fa94f7341c 1377
wim 39:e9c2319de9c5 1378 _writeCommand(0x02); // Cursor Home, DDRAM Address to Origin
wim 39:e9c2319de9c5 1379 wait_ms(10); // The Return Home command takes 1.64 ms.
wim 39:e9c2319de9c5 1380 // Since we are not using the Busy flag, Lets be safe and take 10 ms
wim 28:30fa94f7341c 1381
wim 28:30fa94f7341c 1382 _writeCommand(0x06); // Entry Mode 0000 0 1 I/D S
wim 13:24506ba22480 1383 // Cursor Direction and Display Shift
wim 28:30fa94f7341c 1384 // I/D=1 (Cur incr)
wim 28:30fa94f7341c 1385 // S=0 (No display shift)
wim 10:dd9b3a696acd 1386
wim 29:a3663151aa65 1387 _writeCommand(0x14); // Cursor or Display shift 0001 S/C R/L x x
wim 29:a3663151aa65 1388 // S/C=0 Cursor moves
wim 29:a3663151aa65 1389 // R/L=1 Right
wim 29:a3663151aa65 1390 //
wim 29:a3663151aa65 1391
wim 13:24506ba22480 1392 // _writeCommand(0x0C); // Display Ctrl 0000 1 D C B
wim 17:652ab113bc2e 1393 // // Display On, Cursor Off, Blink Off
wim 36:9f5f86dfd44a 1394
wim 39:e9c2319de9c5 1395 // setCursor(CurOff_BlkOff);
wim 39:e9c2319de9c5 1396 setCursor(CurOn_BlkOff);
wim 21:9eb628d9e164 1397 setMode(DispOn);
simon 1:ac48b187213c 1398 }
simon 1:ac48b187213c 1399
wim 8:03116f75b66e 1400
wim 21:9eb628d9e164 1401 /** Clear the screen, Cursor home.
wim 39:e9c2319de9c5 1402 * Note: The whole display is initialised to charcode 0x20, which may not be a 'space' on some controllers with a
wim 39:e9c2319de9c5 1403 * different fontset such as the PCF2116C or PCF2119R. In this case you should fill the display with 'spaces'.
wim 21:9eb628d9e164 1404 */
wim 21:9eb628d9e164 1405 void TextLCD_Base::cls() {
wim 15:b70ebfffb258 1406
wim 15:b70ebfffb258 1407 // Select and configure second LCD controller when needed
wim 15:b70ebfffb258 1408 if(_type==LCD40x4) {
wim 21:9eb628d9e164 1409 _ctrl_idx=_LCDCtrl_1; // Select 2nd controller
wim 15:b70ebfffb258 1410
wim 15:b70ebfffb258 1411 // Second LCD controller Cursor always Off
wim 21:9eb628d9e164 1412 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
wim 15:b70ebfffb258 1413
wim 15:b70ebfffb258 1414 // Second LCD controller Clearscreen
wim 27:22d5086f6ba6 1415 _writeCommand(0x01); // cls, and set cursor to 0
wim 39:e9c2319de9c5 1416 wait_ms(20); // The CLS command takes 1.64 ms.
wim 29:a3663151aa65 1417 // Since we are not using the Busy flag, Lets be safe and take 10 ms
wim 15:b70ebfffb258 1418
wim 21:9eb628d9e164 1419 _ctrl_idx=_LCDCtrl_0; // Select primary controller
wim 15:b70ebfffb258 1420 }
wim 15:b70ebfffb258 1421
wim 15:b70ebfffb258 1422 // Primary LCD controller Clearscreen
wim 27:22d5086f6ba6 1423 _writeCommand(0x01); // cls, and set cursor to 0
wim 39:e9c2319de9c5 1424 wait_ms(20); // The CLS command takes 1.64 ms.
wim 29:a3663151aa65 1425 // Since we are not using the Busy flag, Lets be safe and take 10 ms
wim 15:b70ebfffb258 1426
wim 15:b70ebfffb258 1427 // Restore cursormode on primary LCD controller when needed
wim 15:b70ebfffb258 1428 if(_type==LCD40x4) {
wim 17:652ab113bc2e 1429 _setCursorAndDisplayMode(_currentMode,_currentCursor);
wim 15:b70ebfffb258 1430 }
wim 15:b70ebfffb258 1431
wim 29:a3663151aa65 1432 setAddress(0, 0); // Reset Cursor location
wim 32:59c4b8f648d4 1433 // Note: This is needed because some displays (eg PCF21XX) don't use line 0 in the '3 Line' mode.
simon 1:ac48b187213c 1434 }
simon 1:ac48b187213c 1435
wim 29:a3663151aa65 1436 /** Locate cursor to a screen column and row
wim 29:a3663151aa65 1437 *
wim 29:a3663151aa65 1438 * @param column The horizontal position from the left, indexed from 0
wim 29:a3663151aa65 1439 * @param row The vertical position from the top, indexed from 0
wim 29:a3663151aa65 1440 */
wim 21:9eb628d9e164 1441 void TextLCD_Base::locate(int column, int row) {
wim 15:b70ebfffb258 1442
wim 15:b70ebfffb258 1443 // setAddress() does all the heavy lifting:
wim 15:b70ebfffb258 1444 // check column and row sanity,
wim 15:b70ebfffb258 1445 // switch controllers for LCD40x4 if needed
wim 15:b70ebfffb258 1446 // switch cursor for LCD40x4 if needed
wim 15:b70ebfffb258 1447 // set the new memory address to show cursor at correct location
wim 32:59c4b8f648d4 1448 setAddress(column, row);
wim 15:b70ebfffb258 1449 }
wim 30:033048611c01 1450
wim 15:b70ebfffb258 1451
wim 21:9eb628d9e164 1452 /** Write a single character (Stream implementation)
wim 21:9eb628d9e164 1453 */
wim 21:9eb628d9e164 1454 int TextLCD_Base::_putc(int value) {
wim 15:b70ebfffb258 1455 int addr;
wim 15:b70ebfffb258 1456
wim 15:b70ebfffb258 1457 if (value == '\n') {
wim 15:b70ebfffb258 1458 //No character to write
wim 15:b70ebfffb258 1459
wim 15:b70ebfffb258 1460 //Update Cursor
wim 15:b70ebfffb258 1461 _column = 0;
wim 15:b70ebfffb258 1462 _row++;
wim 15:b70ebfffb258 1463 if (_row >= rows()) {
wim 15:b70ebfffb258 1464 _row = 0;
wim 15:b70ebfffb258 1465 }
wim 15:b70ebfffb258 1466 }
wim 15:b70ebfffb258 1467 else {
wim 37:ce348c002929 1468 //Character to write
wim 37:ce348c002929 1469 #if (LCD_DEFAULT_FONT == 1)
wim 37:ce348c002929 1470 _writeData(value);
wim 37:ce348c002929 1471 #else
wim 37:ce348c002929 1472 _writeData(ASCII_2_LCD(value));
wim 37:ce348c002929 1473 #endif
wim 15:b70ebfffb258 1474 //Update Cursor
wim 15:b70ebfffb258 1475 _column++;
wim 15:b70ebfffb258 1476 if (_column >= columns()) {
wim 15:b70ebfffb258 1477 _column = 0;
wim 15:b70ebfffb258 1478 _row++;
wim 15:b70ebfffb258 1479 if (_row >= rows()) {
wim 15:b70ebfffb258 1480 _row = 0;
wim 15:b70ebfffb258 1481 }
wim 15:b70ebfffb258 1482 }
wim 15:b70ebfffb258 1483 } //else
wim 15:b70ebfffb258 1484
wim 15:b70ebfffb258 1485 //Set next memoryaddress, make sure cursor blinks at next location
wim 15:b70ebfffb258 1486 addr = getAddress(_column, _row);
wim 15:b70ebfffb258 1487 _writeCommand(0x80 | addr);
wim 15:b70ebfffb258 1488
wim 15:b70ebfffb258 1489 return value;
wim 15:b70ebfffb258 1490 }
wim 15:b70ebfffb258 1491
wim 15:b70ebfffb258 1492
wim 16:c276b75e6585 1493 // get a single character (Stream implementation)
wim 21:9eb628d9e164 1494 int TextLCD_Base::_getc() {
simon 1:ac48b187213c 1495 return -1;
simon 1:ac48b187213c 1496 }
simon 1:ac48b187213c 1497
wim 37:ce348c002929 1498 /** Convert ASCII character code to the LCD fonttable code
wim 37:ce348c002929 1499 *
wim 37:ce348c002929 1500 * @param c The character to write to the display
wim 37:ce348c002929 1501 * @return The character code for the specific fonttable of the controller
wim 37:ce348c002929 1502 */
wim 37:ce348c002929 1503 int TextLCD_Base::ASCII_2_LCD (int c) {
wim 37:ce348c002929 1504
wim 37:ce348c002929 1505 //LCD_C_FT0 is default for HD44780 and compatible series
wim 37:ce348c002929 1506 if (_font == LCD_C_FT0) return c;
wim 37:ce348c002929 1507
wim 37:ce348c002929 1508 //LCD_C_FT1 for PCF21XXC series
wim 39:e9c2319de9c5 1509 //LCD_C_FT2 for PCF21XXR series
wim 39:e9c2319de9c5 1510 //Used code from Suga koubou library for PCF2119K and PCF2119R
wim 37:ce348c002929 1511 if (((c >= ' ') && (c <= '?')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) {
wim 37:ce348c002929 1512 c |= 0x80;
wim 39:e9c2319de9c5 1513 } else if (c >= 0xF0 && c <= 0xFF) {
wim 37:ce348c002929 1514 c &= 0x0f;
wim 37:ce348c002929 1515 }
wim 37:ce348c002929 1516 return c;
wim 37:ce348c002929 1517
wim 37:ce348c002929 1518 //LCD_C_FT2 ...
wim 37:ce348c002929 1519 //@TODO add more, eg cyrillic
wim 37:ce348c002929 1520 //@TODO add method to switch between fonts for controllers that support this
wim 37:ce348c002929 1521 }
wim 37:ce348c002929 1522
wim 14:0c32b66b14b8 1523
wim 34:e5a0dcb43ecc 1524 #if(LCD_PRINTF != 1)
wim 34:e5a0dcb43ecc 1525 /** Write a character to the LCD
wim 34:e5a0dcb43ecc 1526 *
wim 34:e5a0dcb43ecc 1527 * @param c The character to write to the display
wim 34:e5a0dcb43ecc 1528 */
wim 34:e5a0dcb43ecc 1529 int TextLCD_Base::putc(int c){
wim 34:e5a0dcb43ecc 1530 return _putc(c);
wim 34:e5a0dcb43ecc 1531 }
wim 34:e5a0dcb43ecc 1532
wim 34:e5a0dcb43ecc 1533
wim 34:e5a0dcb43ecc 1534 /** Write a raw string to the LCD
wim 34:e5a0dcb43ecc 1535 *
wim 34:e5a0dcb43ecc 1536 * @param string text, may be followed by variables to emulate formatting the string.
wim 34:e5a0dcb43ecc 1537 * However, printf formatting is NOT supported and variables will be ignored!
wim 34:e5a0dcb43ecc 1538 */
wim 34:e5a0dcb43ecc 1539 int TextLCD_Base::printf(const char* text, ...) {
wim 34:e5a0dcb43ecc 1540
wim 34:e5a0dcb43ecc 1541 while (*text !=0) {
wim 34:e5a0dcb43ecc 1542 _putc(*text);
wim 34:e5a0dcb43ecc 1543 text++;
wim 34:e5a0dcb43ecc 1544 }
wim 34:e5a0dcb43ecc 1545 return 0;
wim 34:e5a0dcb43ecc 1546 }
wim 34:e5a0dcb43ecc 1547 #endif
wim 34:e5a0dcb43ecc 1548
wim 34:e5a0dcb43ecc 1549
wim 17:652ab113bc2e 1550 // Write a nibble using the 4-bit interface
wim 21:9eb628d9e164 1551 void TextLCD_Base::_writeNibble(int value) {
wim 17:652ab113bc2e 1552
wim 17:652ab113bc2e 1553 // Enable is Low
wim 21:9eb628d9e164 1554 this->_setEnable(true);
wim 38:cbe275b0b647 1555 this->_setData(value); // Low nibble of value on D4..D7
wim 17:652ab113bc2e 1556 wait_us(1); // Data setup time
wim 21:9eb628d9e164 1557 this->_setEnable(false);
wim 17:652ab113bc2e 1558 wait_us(1); // Datahold time
wim 17:652ab113bc2e 1559 // Enable is Low
wim 17:652ab113bc2e 1560 }
wim 17:652ab113bc2e 1561
wim 16:c276b75e6585 1562 // Write a byte using the 4-bit interface
wim 21:9eb628d9e164 1563 void TextLCD_Base::_writeByte(int value) {
wim 15:b70ebfffb258 1564
wim 15:b70ebfffb258 1565 // Enable is Low
wim 21:9eb628d9e164 1566 this->_setEnable(true);
wim 21:9eb628d9e164 1567 this->_setData(value >> 4); // High nibble
wim 15:b70ebfffb258 1568 wait_us(1); // Data setup time
wim 21:9eb628d9e164 1569 this->_setEnable(false);
wim 15:b70ebfffb258 1570 wait_us(1); // Data hold time
wim 15:b70ebfffb258 1571
wim 21:9eb628d9e164 1572 this->_setEnable(true);
wim 37:ce348c002929 1573 this->_setData(value); // Low nibble
wim 15:b70ebfffb258 1574 wait_us(1); // Data setup time
wim 21:9eb628d9e164 1575 this->_setEnable(false);
wim 15:b70ebfffb258 1576 wait_us(1); // Datahold time
wim 15:b70ebfffb258 1577
wim 15:b70ebfffb258 1578 // Enable is Low
simon 1:ac48b187213c 1579 }
simon 1:ac48b187213c 1580
wim 21:9eb628d9e164 1581 // Write a command byte to the LCD controller
wim 21:9eb628d9e164 1582 void TextLCD_Base::_writeCommand(int command) {
wim 15:b70ebfffb258 1583
wim 21:9eb628d9e164 1584 this->_setRS(false);
wim 16:c276b75e6585 1585 wait_us(1); // Data setup time for RS
wim 15:b70ebfffb258 1586
wim 21:9eb628d9e164 1587 this->_writeByte(command);
wim 15:b70ebfffb258 1588 wait_us(40); // most instructions take 40us
simon 1:ac48b187213c 1589 }
simon 1:ac48b187213c 1590
wim 21:9eb628d9e164 1591 // Write a data byte to the LCD controller
wim 21:9eb628d9e164 1592 void TextLCD_Base::_writeData(int data) {
wim 15:b70ebfffb258 1593
wim 21:9eb628d9e164 1594 this->_setRS(true);
wim 16:c276b75e6585 1595 wait_us(1); // Data setup time for RS
wim 15:b70ebfffb258 1596
wim 21:9eb628d9e164 1597 this->_writeByte(data);
wim 15:b70ebfffb258 1598 wait_us(40); // data writes take 40us
simon 1:ac48b187213c 1599 }
simon 1:ac48b187213c 1600
wim 8:03116f75b66e 1601
wim 32:59c4b8f648d4 1602 // This replaces the original _address() method.
wim 8:03116f75b66e 1603 // It is confusing since it returns the memoryaddress or-ed with the set memorycommand 0x80.
wim 8:03116f75b66e 1604 // Left it in here for compatibility with older code. New applications should use getAddress() instead.
wim 21:9eb628d9e164 1605 int TextLCD_Base::_address(int column, int row) {
wim 8:03116f75b66e 1606 return 0x80 | getAddress(column, row);
wim 8:03116f75b66e 1607 }
wim 8:03116f75b66e 1608
wim 30:033048611c01 1609
wim 30:033048611c01 1610 // This is new method to return the memory address based on row, column and displaytype.
wim 30:033048611c01 1611 //
wim 30:033048611c01 1612 /** Return the memoryaddress of screen column and row location
wim 30:033048611c01 1613 *
wim 30:033048611c01 1614 * @param column The horizontal position from the left, indexed from 0
wim 30:033048611c01 1615 * @param row The vertical position from the top, indexed from 0
wim 36:9f5f86dfd44a 1616 * @return The memoryaddress of screen column and row location
wim 30:033048611c01 1617 *
wim 30:033048611c01 1618 */
wim 30:033048611c01 1619 int TextLCD_Base::getAddress(int column, int row) {
wim 30:033048611c01 1620
wim 30:033048611c01 1621 switch (_addr_mode) {
wim 30:033048611c01 1622
wim 30:033048611c01 1623 case LCD_T_A:
wim 30:033048611c01 1624 //Default addressing mode for 1, 2 and 4 rows (except 40x4)
wim 30:033048611c01 1625 //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 1626 //Displays top rows when less than four are used.
wim 30:033048611c01 1627 switch (row) {
wim 30:033048611c01 1628 case 0:
wim 30:033048611c01 1629 return 0x00 + column;
wim 30:033048611c01 1630 case 1:
wim 30:033048611c01 1631 return 0x40 + column;
wim 30:033048611c01 1632 case 2:
wim 30:033048611c01 1633 return 0x00 + _nr_cols + column;
wim 30:033048611c01 1634 case 3:
wim 30:033048611c01 1635 return 0x40 + _nr_cols + column;
wim 30:033048611c01 1636 // Should never get here.
wim 39:e9c2319de9c5 1637 // default:
wim 39:e9c2319de9c5 1638 // return 0x00;
wim 30:033048611c01 1639 }
wim 30:033048611c01 1640
wim 30:033048611c01 1641 case LCD_T_B:
wim 30:033048611c01 1642 // LCD8x2B is a special layout of LCD16x1
wim 30:033048611c01 1643 if (row==0)
wim 30:033048611c01 1644 return 0x00 + column;
wim 30:033048611c01 1645 else
wim 30:033048611c01 1646 // return _nr_cols + column;
wim 30:033048611c01 1647 return 0x08 + column;
wim 30:033048611c01 1648
wim 30:033048611c01 1649 case LCD_T_C:
wim 30:033048611c01 1650 // LCD16x1C is a special layout of LCD8x2
wim 33:900a94bc7585 1651 // LCD32x1C is a special layout of LCD16x2
wim 33:900a94bc7585 1652 // LCD40x1C is a special layout of LCD20x2
wim 33:900a94bc7585 1653 #if(0)
wim 32:59c4b8f648d4 1654 if (column < 8)
wim 30:033048611c01 1655 return 0x00 + column;
wim 30:033048611c01 1656 else
wim 30:033048611c01 1657 return 0x40 + (column - 8);
wim 32:59c4b8f648d4 1658 #else
wim 32:59c4b8f648d4 1659 if (column < (_nr_cols >> 1))
wim 32:59c4b8f648d4 1660 return 0x00 + column;
wim 32:59c4b8f648d4 1661 else
wim 32:59c4b8f648d4 1662 return 0x40 + (column - (_nr_cols >> 1));
wim 32:59c4b8f648d4 1663 #endif
wim 30:033048611c01 1664
wim 30:033048611c01 1665 // Not sure about this one, seems wrong.
wim 30:033048611c01 1666 // Left in for compatibility with original library
wim 30:033048611c01 1667 // case LCD16x2B:
wim 30:033048611c01 1668 // return 0x00 + (row * 40) + column;
wim 30:033048611c01 1669
wim 30:033048611c01 1670 case LCD_T_D:
wim 36:9f5f86dfd44a 1671 //Alternate addressing mode for 3 and 4 row displays (except 40x4). Used by PCF21XX, KS0073, KS0078, SSD1803
wim 30:033048611c01 1672 //The 4 available rows start at a hardcoded address.
wim 30:033048611c01 1673 //Displays top rows when less than four are used.
wim 30:033048611c01 1674 switch (row) {
wim 30:033048611c01 1675 case 0:
wim 30:033048611c01 1676 return 0x00 + column;
wim 30:033048611c01 1677 case 1:
wim 30:033048611c01 1678 return 0x20 + column;
wim 30:033048611c01 1679 case 2:
wim 30:033048611c01 1680 return 0x40 + column;
wim 30:033048611c01 1681 case 3:
wim 30:033048611c01 1682 return 0x60 + column;
wim 30:033048611c01 1683 // Should never get here.
wim 39:e9c2319de9c5 1684 // default:
wim 39:e9c2319de9c5 1685 // return 0x00;
wim 30:033048611c01 1686 }
wim 30:033048611c01 1687
wim 30:033048611c01 1688 case LCD_T_D1:
wim 36:9f5f86dfd44a 1689 //Alternate addressing mode for 3 row displays. Used by PCF21XX, KS0073, KS0078, SSD1803
wim 30:033048611c01 1690 //The 4 available rows start at a hardcoded address.
wim 30:033048611c01 1691 //Skips top row of 4 row display and starts display at row 1
wim 30:033048611c01 1692 switch (row) {
wim 30:033048611c01 1693 case 0:
wim 30:033048611c01 1694 return 0x20 + column;
wim 30:033048611c01 1695 case 1:
wim 30:033048611c01 1696 return 0x40 + column;
wim 30:033048611c01 1697 case 2:
wim 30:033048611c01 1698 return 0x60 + column;
wim 30:033048611c01 1699 // Should never get here.
wim 39:e9c2319de9c5 1700 // default:
wim 39:e9c2319de9c5 1701 // return 0x00;
wim 30:033048611c01 1702 }
wim 30:033048611c01 1703
wim 30:033048611c01 1704 case LCD_T_E:
wim 30:033048611c01 1705 // LCD40x4 is a special case since it has 2 controllers.
wim 30:033048611c01 1706 // Each controller is configured as 40x2 (Type A)
wim 30:033048611c01 1707 if (row<2) {
wim 30:033048611c01 1708 // Test to see if we need to switch between controllers
wim 30:033048611c01 1709 if (_ctrl_idx != _LCDCtrl_0) {
wim 30:033048611c01 1710
wim 30:033048611c01 1711 // Second LCD controller Cursor Off
wim 30:033048611c01 1712 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
wim 30:033048611c01 1713
wim 30:033048611c01 1714 // Select primary controller
wim 30:033048611c01 1715 _ctrl_idx = _LCDCtrl_0;
wim 30:033048611c01 1716
wim 30:033048611c01 1717 // Restore cursormode on primary LCD controller
wim 30:033048611c01 1718 _setCursorAndDisplayMode(_currentMode, _currentCursor);
wim 30:033048611c01 1719 }
wim 30:033048611c01 1720
wim 30:033048611c01 1721 return 0x00 + (row * 0x40) + column;
wim 30:033048611c01 1722 }
wim 30:033048611c01 1723 else {
wim 30:033048611c01 1724
wim 30:033048611c01 1725 // Test to see if we need to switch between controllers
wim 30:033048611c01 1726 if (_ctrl_idx != _LCDCtrl_1) {
wim 30:033048611c01 1727 // Primary LCD controller Cursor Off
wim 30:033048611c01 1728 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
wim 30:033048611c01 1729
wim 30:033048611c01 1730 // Select secondary controller
wim 30:033048611c01 1731 _ctrl_idx = _LCDCtrl_1;
wim 30:033048611c01 1732
wim 30:033048611c01 1733 // Restore cursormode on secondary LCD controller
wim 30:033048611c01 1734 _setCursorAndDisplayMode(_currentMode, _currentCursor);
wim 30:033048611c01 1735 }
wim 30:033048611c01 1736
wim 30:033048611c01 1737 return 0x00 + ((row-2) * 0x40) + column;
wim 30:033048611c01 1738 }
wim 30:033048611c01 1739
wim 32:59c4b8f648d4 1740 case LCD_T_F:
wim 32:59c4b8f648d4 1741 //Alternate addressing mode for 3 row displays.
wim 32:59c4b8f648d4 1742 //The first half of 3rd row continues from 1st row, the second half continues from 2nd row.
wim 32:59c4b8f648d4 1743 switch (row) {
wim 32:59c4b8f648d4 1744 case 0:
wim 32:59c4b8f648d4 1745 return 0x00 + column;
wim 32:59c4b8f648d4 1746 case 1:
wim 32:59c4b8f648d4 1747 return 0x40 + column;
wim 32:59c4b8f648d4 1748 case 2:
wim 32:59c4b8f648d4 1749 if (column < (_nr_cols >> 1)) // check first or second half of line
wim 32:59c4b8f648d4 1750 return (0x00 + _nr_cols + column);
wim 32:59c4b8f648d4 1751 else
wim 32:59c4b8f648d4 1752 return (0x40 + _nr_cols + (column - (_nr_cols >> 1)));
wim 32:59c4b8f648d4 1753 // Should never get here.
wim 39:e9c2319de9c5 1754 // default:
wim 39:e9c2319de9c5 1755 // return 0x00;
wim 32:59c4b8f648d4 1756 }
wim 32:59c4b8f648d4 1757
wim 32:59c4b8f648d4 1758 case LCD_T_G:
wim 32:59c4b8f648d4 1759 //Alternate addressing mode for 3 row displays. Used by ST7036
wim 32:59c4b8f648d4 1760 switch (row) {
wim 32:59c4b8f648d4 1761 case 0:
wim 32:59c4b8f648d4 1762 return 0x00 + column;
wim 32:59c4b8f648d4 1763 case 1:
wim 32:59c4b8f648d4 1764 return 0x10 + column;
wim 32:59c4b8f648d4 1765 case 2:
wim 32:59c4b8f648d4 1766 return 0x20 + column;
wim 32:59c4b8f648d4 1767 // Should never get here.
wim 39:e9c2319de9c5 1768 // default:
wim 39:e9c2319de9c5 1769 // return 0x00;
wim 32:59c4b8f648d4 1770 }
wim 32:59c4b8f648d4 1771
wim 30:033048611c01 1772 // Should never get here.
wim 30:033048611c01 1773 default:
wim 30:033048611c01 1774 return 0x00;
wim 32:59c4b8f648d4 1775
wim 32:59c4b8f648d4 1776 } // switch _addr_mode
wim 30:033048611c01 1777 }
wim 30:033048611c01 1778
wim 30:033048611c01 1779
wim 29:a3663151aa65 1780 /** Set the memoryaddress of screen column and row location
wim 29:a3663151aa65 1781 *
wim 29:a3663151aa65 1782 * @param column The horizontal position from the left, indexed from 0
wim 29:a3663151aa65 1783 * @param row The vertical position from the top, indexed from 0
wim 29:a3663151aa65 1784 */
wim 21:9eb628d9e164 1785 void TextLCD_Base::setAddress(int column, int row) {
wim 15:b70ebfffb258 1786
wim 15:b70ebfffb258 1787 // Sanity Check column
wim 15:b70ebfffb258 1788 if (column < 0) {
wim 15:b70ebfffb258 1789 _column = 0;
wim 15:b70ebfffb258 1790 }
wim 36:9f5f86dfd44a 1791 else if (column >= _nr_cols) {
wim 36:9f5f86dfd44a 1792 _column = _nr_cols - 1;
wim 15:b70ebfffb258 1793 } else _column = column;
wim 8:03116f75b66e 1794
wim 15:b70ebfffb258 1795 // Sanity Check row
wim 15:b70ebfffb258 1796 if (row < 0) {
wim 15:b70ebfffb258 1797 _row = 0;
wim 15:b70ebfffb258 1798 }
wim 36:9f5f86dfd44a 1799 else if (row >= _nr_rows) {
wim 36:9f5f86dfd44a 1800 _row = _nr_rows - 1;
wim 15:b70ebfffb258 1801 } else _row = row;
wim 15:b70ebfffb258 1802
wim 15:b70ebfffb258 1803
wim 15:b70ebfffb258 1804 // Compute the memory address
wim 15:b70ebfffb258 1805 // For LCD40x4: switch controllers if needed
wim 15:b70ebfffb258 1806 // switch cursor if needed
wim 15:b70ebfffb258 1807 int addr = getAddress(_column, _row);
wim 8:03116f75b66e 1808
wim 13:24506ba22480 1809 _writeCommand(0x80 | addr);
wim 8:03116f75b66e 1810 }
simon 1:ac48b187213c 1811
wim 29:a3663151aa65 1812
wim 29:a3663151aa65 1813 /** Return the number of columns
wim 29:a3663151aa65 1814 *
wim 36:9f5f86dfd44a 1815 * @return The number of columns
wim 30:033048611c01 1816 *
wim 30:033048611c01 1817 * Note: some configurations are commented out because they have not yet been tested due to lack of hardware
wim 29:a3663151aa65 1818 */
wim 21:9eb628d9e164 1819 int TextLCD_Base::columns() {
wim 30:033048611c01 1820
wim 30:033048611c01 1821 // Columns encoded in b7..b0
wim 30:033048611c01 1822 //return (_type & 0xFF);
wim 31:ef31cd8a00d1 1823 return _nr_cols;
simon 1:ac48b187213c 1824 }
simon 1:ac48b187213c 1825
wim 29:a3663151aa65 1826 /** Return the number of rows
wim 29:a3663151aa65 1827 *
wim 36:9f5f86dfd44a 1828 * @return The number of rows
wim 30:033048611c01 1829 *
wim 30:033048611c01 1830 * Note: some configurations are commented out because they have not yet been tested due to lack of hardware
wim 29:a3663151aa65 1831 */
wim 21:9eb628d9e164 1832 int TextLCD_Base::rows() {
wim 30:033048611c01 1833
wim 30:033048611c01 1834 // Rows encoded in b15..b8
wim 30:033048611c01 1835 //return ((_type >> 8) & 0xFF);
wim 30:033048611c01 1836 return _nr_rows;
simon 1:ac48b187213c 1837 }
wim 10:dd9b3a696acd 1838
wim 29:a3663151aa65 1839 /** Set the Cursormode
wim 29:a3663151aa65 1840 *
wim 29:a3663151aa65 1841 * @param cursorMode The Cursor mode (CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn)
wim 29:a3663151aa65 1842 */
wim 21:9eb628d9e164 1843 void TextLCD_Base::setCursor(LCDCursor cursorMode) {
wim 15:b70ebfffb258 1844
wim 17:652ab113bc2e 1845 // Save new cursor mode, needed when 2 controllers are in use or when display is switched off/on
wim 17:652ab113bc2e 1846 _currentCursor = cursorMode;
wim 10:dd9b3a696acd 1847
wim 17:652ab113bc2e 1848 // Configure only current LCD controller
wim 31:ef31cd8a00d1 1849 _setCursorAndDisplayMode(_currentMode, _currentCursor);
wim 15:b70ebfffb258 1850 }
wim 15:b70ebfffb258 1851
wim 29:a3663151aa65 1852 /** Set the Displaymode
wim 29:a3663151aa65 1853 *
wim 29:a3663151aa65 1854 * @param displayMode The Display mode (DispOff, DispOn)
wim 29:a3663151aa65 1855 */
wim 21:9eb628d9e164 1856 void TextLCD_Base::setMode(LCDMode displayMode) {
wim 17:652ab113bc2e 1857
wim 17:652ab113bc2e 1858 // Save new displayMode, needed when 2 controllers are in use or when cursor is changed
wim 17:652ab113bc2e 1859 _currentMode = displayMode;
wim 15:b70ebfffb258 1860
wim 17:652ab113bc2e 1861 // Select and configure second LCD controller when needed
wim 17:652ab113bc2e 1862 if(_type==LCD40x4) {
wim 21:9eb628d9e164 1863 if (_ctrl_idx==_LCDCtrl_0) {
wim 17:652ab113bc2e 1864 // Configure primary LCD controller
wim 17:652ab113bc2e 1865 _setCursorAndDisplayMode(_currentMode, _currentCursor);
wim 11:9ec02df863a1 1866
wim 17:652ab113bc2e 1867 // Select 2nd controller
wim 21:9eb628d9e164 1868 _ctrl_idx=_LCDCtrl_1;
wim 17:652ab113bc2e 1869
wim 17:652ab113bc2e 1870 // Configure secondary LCD controller
wim 21:9eb628d9e164 1871 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
wim 11:9ec02df863a1 1872
wim 17:652ab113bc2e 1873 // Restore current controller
wim 21:9eb628d9e164 1874 _ctrl_idx=_LCDCtrl_0;
wim 17:652ab113bc2e 1875 }
wim 17:652ab113bc2e 1876 else {
wim 17:652ab113bc2e 1877 // Select primary controller
wim 21:9eb628d9e164 1878 _ctrl_idx=_LCDCtrl_0;
wim 17:652ab113bc2e 1879
wim 17:652ab113bc2e 1880 // Configure primary LCD controller
wim 21:9eb628d9e164 1881 _setCursorAndDisplayMode(_currentMode, CurOff_BlkOff);
wim 17:652ab113bc2e 1882
wim 17:652ab113bc2e 1883 // Restore current controller
wim 21:9eb628d9e164 1884 _ctrl_idx=_LCDCtrl_1;
wim 11:9ec02df863a1 1885
wim 17:652ab113bc2e 1886 // Configure secondary LCD controller
wim 17:652ab113bc2e 1887 _setCursorAndDisplayMode(_currentMode, _currentCursor);
wim 10:dd9b3a696acd 1888 }
wim 17:652ab113bc2e 1889 }
wim 17:652ab113bc2e 1890 else {
wim 17:652ab113bc2e 1891 // Configure primary LCD controller
wim 17:652ab113bc2e 1892 _setCursorAndDisplayMode(_currentMode, _currentCursor);
wim 30:033048611c01 1893 }
wim 17:652ab113bc2e 1894 }
wim 17:652ab113bc2e 1895
wim 29:a3663151aa65 1896 /** Low level method to restore the cursortype and display mode for current controller
wim 29:a3663151aa65 1897 */
wim 36:9f5f86dfd44a 1898 void TextLCD_Base::_setCursorAndDisplayMode(LCDMode displayMode, LCDCursor cursorType) {
wim 36:9f5f86dfd44a 1899
wim 36:9f5f86dfd44a 1900 // Configure current LCD controller
wim 36:9f5f86dfd44a 1901 switch (_ctrl) {
wim 36:9f5f86dfd44a 1902 case ST7070:
wim 36:9f5f86dfd44a 1903 //ST7070 does not support Cursorblink. The P bit selects the font instead !
wim 36:9f5f86dfd44a 1904 _writeCommand(0x08 | displayMode | (cursorType & 0x02));
wim 36:9f5f86dfd44a 1905 break;
wim 36:9f5f86dfd44a 1906 default:
wim 36:9f5f86dfd44a 1907 _writeCommand(0x08 | displayMode | cursorType);
wim 36:9f5f86dfd44a 1908 break;
wim 36:9f5f86dfd44a 1909 } //switch
wim 10:dd9b3a696acd 1910 }
wim 10:dd9b3a696acd 1911
wim 29:a3663151aa65 1912 /** Set the Backlight mode
wim 29:a3663151aa65 1913 *
wim 29:a3663151aa65 1914 * @param backlightMode The Backlight mode (LightOff, LightOn)
wim 29:a3663151aa65 1915 */
wim 21:9eb628d9e164 1916 void TextLCD_Base::setBacklight(LCDBacklight backlightMode) {
wim 20:e0da005a777f 1917
wim 35:311be6444a39 1918 #if (BACKLIGHT_INV==0)
wim 35:311be6444a39 1919 // Positive Backlight control pin logic
wim 20:e0da005a777f 1920 if (backlightMode == LightOn) {
wim 35:311be6444a39 1921 this->_setBL(true);
wim 20:e0da005a777f 1922 }
wim 20:e0da005a777f 1923 else {
wim 21:9eb628d9e164 1924 this->_setBL(false);
wim 20:e0da005a777f 1925 }
wim 35:311be6444a39 1926 #else
wim 35:311be6444a39 1927 // Inverted Backlight control pin logic
wim 35:311be6444a39 1928 if (backlightMode == LightOn) {
wim 35:311be6444a39 1929 this->_setBL(false);
wim 35:311be6444a39 1930 }
wim 35:311be6444a39 1931 else {
wim 35:311be6444a39 1932 this->_setBL(true);
wim 35:311be6444a39 1933 }
wim 35:311be6444a39 1934 #endif
wim 20:e0da005a777f 1935 }
wim 20:e0da005a777f 1936
wim 29:a3663151aa65 1937 /** Set User Defined Characters
wim 29:a3663151aa65 1938 *
wim 34:e5a0dcb43ecc 1939 * @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 1940 * @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 1941 */
wim 21:9eb628d9e164 1942 void TextLCD_Base::setUDC(unsigned char c, char *udc_data) {
wim 15:b70ebfffb258 1943
wim 15:b70ebfffb258 1944 // Select and configure second LCD controller when needed
wim 15:b70ebfffb258 1945 if(_type==LCD40x4) {
wim 19:c747b9e2e7b8 1946 _LCDCtrl_Idx current_ctrl_idx = _ctrl_idx; // Temp save current controller
wim 15:b70ebfffb258 1947
wim 15:b70ebfffb258 1948 // Select primary controller
wim 21:9eb628d9e164 1949 _ctrl_idx=_LCDCtrl_0;
wim 15:b70ebfffb258 1950
wim 15:b70ebfffb258 1951 // Configure primary LCD controller
wim 15:b70ebfffb258 1952 _setUDC(c, udc_data);
wim 15:b70ebfffb258 1953
wim 15:b70ebfffb258 1954 // Select 2nd controller
wim 21:9eb628d9e164 1955 _ctrl_idx=_LCDCtrl_1;
wim 15:b70ebfffb258 1956
wim 15:b70ebfffb258 1957 // Configure secondary LCD controller
wim 15:b70ebfffb258 1958 _setUDC(c, udc_data);
wim 11:9ec02df863a1 1959
wim 15:b70ebfffb258 1960 // Restore current controller
wim 19:c747b9e2e7b8 1961 _ctrl_idx=current_ctrl_idx;
wim 15:b70ebfffb258 1962 }
wim 15:b70ebfffb258 1963 else {
wim 15:b70ebfffb258 1964 // Configure primary LCD controller
wim 15:b70ebfffb258 1965 _setUDC(c, udc_data);
wim 34:e5a0dcb43ecc 1966 }
wim 15:b70ebfffb258 1967 }
wim 15:b70ebfffb258 1968
wim 34:e5a0dcb43ecc 1969 /** Low level method to store user defined characters for current controller
wim 34:e5a0dcb43ecc 1970 *
wim 34:e5a0dcb43ecc 1971 * @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 1972 * @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 1973 */
wim 34:e5a0dcb43ecc 1974 void TextLCD_Base::_setUDC(unsigned char c, char *udc_data) {
wim 34:e5a0dcb43ecc 1975
wim 34:e5a0dcb43ecc 1976 switch (_ctrl) {
wim 34:e5a0dcb43ecc 1977 case PCF2103_3V3 : // Some UDCs may be used for Icons
wim 34:e5a0dcb43ecc 1978 case PCF2113_3V3 : // Some UDCs may be used for Icons
wim 34:e5a0dcb43ecc 1979 case PCF2116_3V3 :
wim 34:e5a0dcb43ecc 1980 case PCF2116_5V :
wim 34:e5a0dcb43ecc 1981 case PCF2119_3V3 : // Some UDCs may be used for Icons
wim 34:e5a0dcb43ecc 1982 c = c & 0x0F; // mask down to valid range
wim 34:e5a0dcb43ecc 1983 break;
wim 34:e5a0dcb43ecc 1984
wim 34:e5a0dcb43ecc 1985 default:
wim 34:e5a0dcb43ecc 1986 c = c & 0x07; // mask down to valid range
wim 34:e5a0dcb43ecc 1987 break;
wim 34:e5a0dcb43ecc 1988 } //switch _ctrl
wim 34:e5a0dcb43ecc 1989
wim 34:e5a0dcb43ecc 1990 // Select DD RAM for current LCD controller
wim 34:e5a0dcb43ecc 1991 // This is needed to correctly set Bit 6 of the addresspointer for controllers that support 16 UDCs
wim 34:e5a0dcb43ecc 1992 _writeCommand(0x80 | ((c << 3) & 0x40)) ;
wim 34:e5a0dcb43ecc 1993
wim 34:e5a0dcb43ecc 1994 // Select CG RAM for current LCD controller
wim 34:e5a0dcb43ecc 1995 _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 1996 //8 sequential locations needed per UDC
wim 34:e5a0dcb43ecc 1997 // Store UDC pattern
wim 34:e5a0dcb43ecc 1998 for (int i=0; i<8; i++) {
wim 34:e5a0dcb43ecc 1999 _writeData(*udc_data++);
wim 34:e5a0dcb43ecc 2000 }
wim 34:e5a0dcb43ecc 2001
wim 34:e5a0dcb43ecc 2002 //Select DD RAM again for current LCD controller and restore the addresspointer
wim 34:e5a0dcb43ecc 2003 int addr = getAddress(_column, _row);
wim 34:e5a0dcb43ecc 2004 _writeCommand(0x80 | addr);
wim 34:e5a0dcb43ecc 2005 }
wim 32:59c4b8f648d4 2006
wim 39:e9c2319de9c5 2007 #if(LCD_BLINK == 1)
wim 36:9f5f86dfd44a 2008 /** Set UDC Blink and Icon blink
wim 33:900a94bc7585 2009 * setUDCBlink method is supported by some compatible devices (eg SSD1803)
wim 33:900a94bc7585 2010 *
wim 33:900a94bc7585 2011 * @param blinkMode The Blink mode (BlinkOff, BlinkOn)
wim 33:900a94bc7585 2012 */
wim 33:900a94bc7585 2013 void TextLCD_Base::setUDCBlink(LCDBlink blinkMode){
wim 36:9f5f86dfd44a 2014 // Blinking UDCs (and icons) are enabled when a specific controlbit (BE) is set.
wim 36:9f5f86dfd44a 2015 // The blinking pixels in the UDC and icons can be controlled by setting additional bits in the UDC or icon bitpattern.
wim 36:9f5f86dfd44a 2016 // UDCs are defined by an 8 byte bitpattern. The P0..P4 form the character pattern.
wim 33:900a94bc7585 2017 // P7 P6 P5 P4 P3 P2 P1 P0
wim 33:900a94bc7585 2018 // 0 B1 B0 x 0 1 1 1 0
wim 33:900a94bc7585 2019 // 1 B1 B0 x 1 0 0 0 1
wim 33:900a94bc7585 2020 // .............
wim 33:900a94bc7585 2021 // 7 B1 B0 x 1 0 0 0 1
wim 33:900a94bc7585 2022 //
wim 33:900a94bc7585 2023 // Bit 6 and Bit 7 in the pattern will control the blinking mode when Blink is enabled through BE.
wim 33:900a94bc7585 2024 // B1 B0 Mode
wim 33:900a94bc7585 2025 // 0 0 No Blinking in this row of the UDC
wim 33:900a94bc7585 2026 // 0 1 Enabled pixels in P4 will blink
wim 33:900a94bc7585 2027 // 1 x Enabled pixels in P0..P4 will blink
wim 36:9f5f86dfd44a 2028 //
wim 36:9f5f86dfd44a 2029 // Note: the PCF2103 and PCF2113 use UDCs to set Icons
wim 36:9f5f86dfd44a 2030 // 3 x 8 rows x 5 bits = 120 bits Icons for Normal pattern (UDC 0..2) and
wim 36:9f5f86dfd44a 2031 // 3 x 8 rows x 5 bits = 120 bits Icons for Blink pattern (UDC 4..6)
wim 36:9f5f86dfd44a 2032 // Note: the PCF2119 uses UDCs to set Icons
wim 36:9f5f86dfd44a 2033 // 4 x 8 rows x 5 bits = 160 bits Icons for Normal pattern (UDC 0..3) and
wim 36:9f5f86dfd44a 2034 // 4 x 8 rows x 5 bits = 160 bits Icons for Blink pattern (UDC 4..7)
wim 33:900a94bc7585 2035 switch (blinkMode) {
wim 33:900a94bc7585 2036 case BlinkOn:
wim 36:9f5f86dfd44a 2037 // Controllers that support UDC/Icon Blink
wim 33:900a94bc7585 2038 switch (_ctrl) {
wim 36:9f5f86dfd44a 2039 case KS0073 :
wim 33:900a94bc7585 2040 case KS0078 :
wim 36:9f5f86dfd44a 2041 _function_1 |= 0x02; // Enable UDC/Icon Blink
wim 36:9f5f86dfd44a 2042 _writeCommand(0x20 | _function_1); // Function set 0 0 1 DL N RE(1) BE 0/LP (Ext Regs)
wim 33:900a94bc7585 2043
wim 33:900a94bc7585 2044 _writeCommand(0x20 | _function); // Function set 0 0 1 DL N RE(0) DH REV (Std Regs)
wim 36:9f5f86dfd44a 2045 break; // case KS0073, KS0078 Controller
wim 33:900a94bc7585 2046
wim 33:900a94bc7585 2047 case US2066_3V3 :
wim 33:900a94bc7585 2048 case SSD1803_3V3 :
wim 36:9f5f86dfd44a 2049 _function_1 |= 0x04; // Enable UDC/Icon Blink
wim 33:900a94bc7585 2050 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
wim 33:900a94bc7585 2051 // Select Ext Instr Set
wim 33:900a94bc7585 2052
wim 33:900a94bc7585 2053 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
wim 33:900a94bc7585 2054 // Select Std Instr set, Select IS=0
wim 33:900a94bc7585 2055 break; // case SSD1803, US2066
wim 36:9f5f86dfd44a 2056
wim 36:9f5f86dfd44a 2057 case PCF2103_3V3 :
wim 36:9f5f86dfd44a 2058 case PCF2113_3V3 :
wim 36:9f5f86dfd44a 2059 case PCF2119_3V3 :
wim 39:e9c2319de9c5 2060 case PCF2119R_3V3 :
wim 36:9f5f86dfd44a 2061 // Enable Icon Blink
wim 36:9f5f86dfd44a 2062 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
wim 36:9f5f86dfd44a 2063 _writeCommand(0x08 | 0x02); // ICON Conf 0000 1, IM=0 (Char mode), IB=1 (Icon blink), 0 (Instr. Set 1)
wim 36:9f5f86dfd44a 2064 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
wim 36:9f5f86dfd44a 2065
wim 36:9f5f86dfd44a 2066 break;
wim 33:900a94bc7585 2067
wim 33:900a94bc7585 2068 default:
wim 33:900a94bc7585 2069 //Unsupported feature for other controllers
wim 33:900a94bc7585 2070 break;
wim 33:900a94bc7585 2071 } //switch _ctrl
wim 33:900a94bc7585 2072
wim 36:9f5f86dfd44a 2073 break; // BlinkOn
wim 33:900a94bc7585 2074
wim 33:900a94bc7585 2075 case BlinkOff:
wim 33:900a94bc7585 2076 // Controllers that support UDC Blink
wim 33:900a94bc7585 2077 switch (_ctrl) {
wim 36:9f5f86dfd44a 2078 case KS0073 :
wim 33:900a94bc7585 2079 case KS0078 :
wim 36:9f5f86dfd44a 2080 _function_1 &= ~0x02; // Disable UDC/Icon Blink
wim 36:9f5f86dfd44a 2081 _writeCommand(0x20 | _function_1); // Function set 0 0 1 DL N RE(1) BE 0/LP (Ext Regs)
wim 33:900a94bc7585 2082
wim 33:900a94bc7585 2083 _writeCommand(0x20 | _function); // Function set 0 0 1 DL N RE(0) DH REV (Std Regs)
wim 36:9f5f86dfd44a 2084 break; // case KS0073, KS0078 Controller
wim 33:900a94bc7585 2085
wim 33:900a94bc7585 2086 case US2066_3V3 :
wim 33:900a94bc7585 2087 case SSD1803_3V3 :
wim 36:9f5f86dfd44a 2088 _function_1 &= ~0x04; // Disable UDC/Icon Blink
wim 33:900a94bc7585 2089 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
wim 33:900a94bc7585 2090 // Select Ext Instr Set
wim 33:900a94bc7585 2091
wim 33:900a94bc7585 2092 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
wim 33:900a94bc7585 2093 // Select Std Instr set, Select IS=0
wim 33:900a94bc7585 2094 break; // case SSD1803, US2066
wim 36:9f5f86dfd44a 2095
wim 36:9f5f86dfd44a 2096 case PCF2103_3V3 :
wim 39:e9c2319de9c5 2097 case PCF2113_3V3 :
wim 39:e9c2319de9c5 2098 case PCF2119_3V3 :
wim 39:e9c2319de9c5 2099 case PCF2119R_3V3 :
wim 36:9f5f86dfd44a 2100 // Disable Icon Blink
wim 36:9f5f86dfd44a 2101 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
wim 36:9f5f86dfd44a 2102 _writeCommand(0x08); // ICON Conf 0000 1, IM=0 (Char mode), IB=1 (Icon blink), 0 (Instr. Set 1)
wim 36:9f5f86dfd44a 2103 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
wim 36:9f5f86dfd44a 2104
wim 36:9f5f86dfd44a 2105 break;
wim 33:900a94bc7585 2106
wim 33:900a94bc7585 2107 default:
wim 33:900a94bc7585 2108 //Unsupported feature for other controllers
wim 33:900a94bc7585 2109 break;
wim 33:900a94bc7585 2110 } //switch _ctrl
wim 33:900a94bc7585 2111
wim 36:9f5f86dfd44a 2112 break; //BlinkOff
wim 33:900a94bc7585 2113
wim 33:900a94bc7585 2114 default:
wim 33:900a94bc7585 2115 break;
wim 33:900a94bc7585 2116 } // blinkMode
wim 33:900a94bc7585 2117
wim 33:900a94bc7585 2118 } // setUDCBlink()
wim 39:e9c2319de9c5 2119 #endif
wim 33:900a94bc7585 2120
wim 32:59c4b8f648d4 2121 /** Set Contrast
wim 32:59c4b8f648d4 2122 * setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation
wim 32:59c4b8f648d4 2123 * Initial code for ST70XX imported from fork by JH1PJL
wim 32:59c4b8f648d4 2124 *
wim 32:59c4b8f648d4 2125 * @param unsigned char c contrast data (6 significant bits, valid range 0..63, Value 0 will disable the Vgen)
wim 32:59c4b8f648d4 2126 * @return none
wim 32:59c4b8f648d4 2127 */
wim 32:59c4b8f648d4 2128 //@TODO Add support for 40x4 dual controller
wim 32:59c4b8f648d4 2129 void TextLCD_Base::setContrast(unsigned char c) {
wim 32:59c4b8f648d4 2130
wim 32:59c4b8f648d4 2131 // Function set mode stored during Init. Make sure we dont accidentally switch between 1-line and 2-line mode!
wim 32:59c4b8f648d4 2132 // Icon/Booster mode stored during Init. Make sure we dont accidentally change this!
wim 32:59c4b8f648d4 2133
wim 32:59c4b8f648d4 2134 _contrast = c & 0x3F; // Sanity check
wim 32:59c4b8f648d4 2135
wim 33:900a94bc7585 2136 switch (_ctrl) {
wim 32:59c4b8f648d4 2137 case PCF2113_3V3 :
wim 39:e9c2319de9c5 2138 case PCF2119_3V3 :
wim 39:e9c2319de9c5 2139 case PCF2119R_3V3 :
wim 32:59c4b8f648d4 2140 if (_contrast < 5) _contrast = 0; // See datasheet. Sanity check for PCF2113/PCF2119
wim 32:59c4b8f648d4 2141 if (_contrast > 55) _contrast = 55;
wim 32:59c4b8f648d4 2142
wim 32:59c4b8f648d4 2143 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instruction Set = 1
wim 32:59c4b8f648d4 2144 _writeCommand(0x80 | 0x00 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=0, VA=contrast
wim 32:59c4b8f648d4 2145 _writeCommand(0x80 | 0x40 | (_contrast & 0x3F)); // VLCD_set (Instr. Set 1) V=1, VB=contrast
wim 32:59c4b8f648d4 2146 _writeCommand(0x20 | _function); // Select Instruction Set = 0
wim 32:59c4b8f648d4 2147 break;
wim 32:59c4b8f648d4 2148
wim 32:59c4b8f648d4 2149 case ST7032_3V3 :
wim 32:59c4b8f648d4 2150 case ST7032_5V :
wim 32:59c4b8f648d4 2151 case ST7036_3V3 :
wim 32:59c4b8f648d4 2152 // case ST7036_5V :
wim 32:59c4b8f648d4 2153 case SSD1803_3V3 :
wim 32:59c4b8f648d4 2154 _writeCommand(0x20 | _function | 0x01); // Select Instruction Set = 1
wim 32:59c4b8f648d4 2155 _writeCommand(0x70 | (_contrast & 0x0F)); // Contrast Low bits
wim 32:59c4b8f648d4 2156 _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Contrast High bits
wim 32:59c4b8f648d4 2157 _writeCommand(0x20 | _function); // Select Instruction Set = 0
wim 32:59c4b8f648d4 2158 break;
wim 32:59c4b8f648d4 2159
wim 33:900a94bc7585 2160 case US2066_3V3 :
wim 33:900a94bc7585 2161 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 DL N BE RE(1) REV
wim 33:900a94bc7585 2162 // Select Extended Instruction Set
wim 33:900a94bc7585 2163
wim 33:900a94bc7585 2164 _writeCommand(0x79); // Function Select OLED: 0 1 1 1 1 0 0 1 (Ext Instr Set)
wim 33:900a94bc7585 2165
wim 33:900a94bc7585 2166 _writeCommand(0x81); // Set Contrast Control: 1 0 0 0 0 0 0 1 (Ext Instr Set, OLED)
wim 33:900a94bc7585 2167 _writeCommand((_contrast << 2) | 0x03); // Set Contrast Value: 8 bits. Use 6 bits for compatibility
wim 33:900a94bc7585 2168
wim 33:900a94bc7585 2169 _writeCommand(0x78); // Function Disable OLED: 0 1 1 1 1 0 0 0 (Ext Instr Set)
wim 33:900a94bc7585 2170
wim 33:900a94bc7585 2171 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
wim 33:900a94bc7585 2172 // Select Std Instr set, Select IS=0
wim 33:900a94bc7585 2173 break;
wim 33:900a94bc7585 2174
wim 34:e5a0dcb43ecc 2175 //not yet tested on hardware
wim 32:59c4b8f648d4 2176 case PT6314 :
wim 32:59c4b8f648d4 2177 // Only 2 significant bits
wim 32:59c4b8f648d4 2178 // 0x00 = 100%
wim 32:59c4b8f648d4 2179 // 0x01 = 75%
wim 32:59c4b8f648d4 2180 // 0x02 = 50%
wim 32:59c4b8f648d4 2181 // 0x03 = 25%
wim 32:59c4b8f648d4 2182 _writeCommand(0x20 | _function | ((~_contrast) >> 4)); // Invert and shift to use 2 MSBs
wim 32:59c4b8f648d4 2183 break;
wim 32:59c4b8f648d4 2184
wim 32:59c4b8f648d4 2185 default:
wim 32:59c4b8f648d4 2186 //Unsupported feature for other controllers
wim 33:900a94bc7585 2187 break;
wim 33:900a94bc7585 2188 } // end switch
wim 33:900a94bc7585 2189 } // end setContrast()
wim 32:59c4b8f648d4 2190
wim 39:e9c2319de9c5 2191 #if(LCD_POWER == 1)
wim 32:59c4b8f648d4 2192 /** Set Power
wim 32:59c4b8f648d4 2193 * setPower method is supported by some compatible devices (eg SSD1803) that have power down modes
wim 32:59c4b8f648d4 2194 *
wim 32:59c4b8f648d4 2195 * @param bool powerOn Power on/off
wim 32:59c4b8f648d4 2196 * @return none
wim 32:59c4b8f648d4 2197 */
wim 32:59c4b8f648d4 2198 //@TODO Add support for 40x4 dual controller
wim 32:59c4b8f648d4 2199 void TextLCD_Base::setPower(bool powerOn) {
wim 32:59c4b8f648d4 2200
wim 32:59c4b8f648d4 2201 if (powerOn) {
wim 32:59c4b8f648d4 2202 // Switch on
wim 32:59c4b8f648d4 2203 setMode(DispOn);
wim 32:59c4b8f648d4 2204
wim 32:59c4b8f648d4 2205 // Controllers that supports specific Power Down mode
wim 32:59c4b8f648d4 2206 switch (_ctrl) {
wim 32:59c4b8f648d4 2207
wim 32:59c4b8f648d4 2208 // case PCF2113_3V3 :
wim 39:e9c2319de9c5 2209 // case PCF2119_3V3 :
wim 39:e9c2319de9c5 2210 // case PCF2119R_3V3 :
wim 32:59c4b8f648d4 2211 // case ST7032_3V3 :
wim 32:59c4b8f648d4 2212 //@todo
wim 33:900a94bc7585 2213 // enable Booster Bon
wim 33:900a94bc7585 2214
wim 33:900a94bc7585 2215 case WS0010:
wim 33:900a94bc7585 2216 _writeCommand(0x17); // Char mode, DC/DC on
wim 33:900a94bc7585 2217 wait_ms(10); // Wait 10ms to ensure powered up
wim 33:900a94bc7585 2218 break;
wim 33:900a94bc7585 2219
wim 36:9f5f86dfd44a 2220 case KS0073:
wim 33:900a94bc7585 2221 case KS0078:
wim 32:59c4b8f648d4 2222 case SSD1803_3V3 :
wim 32:59c4b8f648d4 2223 // case SSD1803_5V :
wim 33:900a94bc7585 2224 _writeCommand(0x20 | _function_1); // Select Ext Instr Set
wim 33:900a94bc7585 2225 _writeCommand(0x02); // Power On
wim 32:59c4b8f648d4 2226 _writeCommand(0x20 | _function); // Select Std Instr Set
wim 32:59c4b8f648d4 2227 break;
wim 32:59c4b8f648d4 2228
wim 32:59c4b8f648d4 2229 default:
wim 32:59c4b8f648d4 2230 //Unsupported feature for other controllers
wim 32:59c4b8f648d4 2231 break;
wim 32:59c4b8f648d4 2232 } // end switch
wim 32:59c4b8f648d4 2233 }
wim 32:59c4b8f648d4 2234 else {
wim 32:59c4b8f648d4 2235 // Switch off
wim 32:59c4b8f648d4 2236 setMode(DispOff);
wim 32:59c4b8f648d4 2237
wim 32:59c4b8f648d4 2238 // Controllers that support specific Power Down mode
wim 32:59c4b8f648d4 2239 switch (_ctrl) {
wim 32:59c4b8f648d4 2240
wim 32:59c4b8f648d4 2241 // case PCF2113_3V3 :
wim 39:e9c2319de9c5 2242 // case PCF2119_3V3 :
wim 39:e9c2319de9c5 2243 // case PCF2119R_3V3 :
wim 32:59c4b8f648d4 2244 // case ST7032_3V3 :
wim 32:59c4b8f648d4 2245 //@todo
wim 33:900a94bc7585 2246 // disable Booster Bon
wim 33:900a94bc7585 2247
wim 33:900a94bc7585 2248 case WS0010:
wim 33:900a94bc7585 2249 _writeCommand(0x13); // Char mode, DC/DC off
wim 33:900a94bc7585 2250 break;
wim 33:900a94bc7585 2251
wim 36:9f5f86dfd44a 2252 case KS0073:
wim 33:900a94bc7585 2253 case KS0078:
wim 32:59c4b8f648d4 2254 case SSD1803_3V3 :
wim 32:59c4b8f648d4 2255 // case SSD1803_5V :
wim 33:900a94bc7585 2256 _writeCommand(0x20 | _function_1); // Select Ext Instr Set
wim 33:900a94bc7585 2257 _writeCommand(0x03); // Power Down
wim 32:59c4b8f648d4 2258 _writeCommand(0x20 | _function); // Select Std Instr Set
wim 32:59c4b8f648d4 2259 break;
wim 32:59c4b8f648d4 2260
wim 32:59c4b8f648d4 2261 default:
wim 32:59c4b8f648d4 2262 //Unsupported feature for other controllers
wim 32:59c4b8f648d4 2263 break;
wim 32:59c4b8f648d4 2264 } // end switch
wim 32:59c4b8f648d4 2265 }
wim 33:900a94bc7585 2266 } // end setPower()
wim 39:e9c2319de9c5 2267 #endif
wim 39:e9c2319de9c5 2268
wim 39:e9c2319de9c5 2269 #if(LCD_ORIENT == 1)
wim 33:900a94bc7585 2270 /** Set Orient
wim 33:900a94bc7585 2271 * setOrient method is supported by some compatible devices (eg SSD1803, US2066) that have top/bottom view modes
wim 33:900a94bc7585 2272 *
wim 33:900a94bc7585 2273 * @param LCDOrient orient Orientation
wim 33:900a94bc7585 2274 * @return none
wim 33:900a94bc7585 2275 */
wim 33:900a94bc7585 2276 void TextLCD_Base::setOrient(LCDOrient orient){
wim 33:900a94bc7585 2277
wim 33:900a94bc7585 2278 switch (orient) {
wim 33:900a94bc7585 2279
wim 33:900a94bc7585 2280 case Top:
wim 33:900a94bc7585 2281 switch (_ctrl) {
wim 34:e5a0dcb43ecc 2282 case PCF2103_3V3:
wim 34:e5a0dcb43ecc 2283 case PCF2116_3V3:
wim 34:e5a0dcb43ecc 2284 case PCF2116_5V:
wim 34:e5a0dcb43ecc 2285 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
wim 34:e5a0dcb43ecc 2286 _writeCommand(0x05); // Display Conf Set 0000 0, 1, P=0, Q=1 (Instr. Set 1)
wim 34:e5a0dcb43ecc 2287 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
wim 34:e5a0dcb43ecc 2288 break;
wim 39:e9c2319de9c5 2289
wim 39:e9c2319de9c5 2290 case PCF2119_3V3:
wim 39:e9c2319de9c5 2291 case PCF2119R_3V3:
wim 39:e9c2319de9c5 2292 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
wim 39:e9c2319de9c5 2293 _writeCommand(0x07); // Display Conf Set 0000 0, 1, P=1, Q=1 (Instr. Set 1)
wim 39:e9c2319de9c5 2294 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
wim 39:e9c2319de9c5 2295 break;
wim 34:e5a0dcb43ecc 2296
wim 33:900a94bc7585 2297 case SSD1803_3V3 :
wim 33:900a94bc7585 2298 // case SSD1803_5V :
wim 33:900a94bc7585 2299 case US2066_3V3 :
wim 33:900a94bc7585 2300 _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV
wim 33:900a94bc7585 2301 // Select Extended Instruction Set
wim 33:900a94bc7585 2302 // _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 2303 _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 2304
wim 33:900a94bc7585 2305 _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS=0 Select Instruction Set 0
wim 33:900a94bc7585 2306 // Select Std Instr set, Select IS=0
wim 33:900a94bc7585 2307 break;
wim 36:9f5f86dfd44a 2308
wim 36:9f5f86dfd44a 2309 case ST7070:
wim 36:9f5f86dfd44a 2310 _writeCommand(0x20 | _function | 0x04); // Set function, 0 0 1 DL, N, EXT=1, x, x (Select Instr Set = 1)
wim 36:9f5f86dfd44a 2311
wim 36:9f5f86dfd44a 2312 _writeCommand(0x40 | 0x00); // COM/SEG directions 0 1 0 0 C1, C2, S1, S2 (Instr Set 1)
wim 36:9f5f86dfd44a 2313 // C1=1: Com1-8 -> Com8-1; C2=1: Com9-16 -> Com16-9
wim 36:9f5f86dfd44a 2314 // S1=1: Seg1-40 -> Seg40-1; S2=1: Seg41-80 -> Seg80-41
wim 36:9f5f86dfd44a 2315 wait_ms(5); // Wait to ensure completion or ST7070 fails to set Top/Bottom after reset..
wim 36:9f5f86dfd44a 2316
wim 36:9f5f86dfd44a 2317 _writeCommand(0x20 | _function); // Set function, EXT=0 (Select Instr Set = 0)
wim 36:9f5f86dfd44a 2318
wim 36:9f5f86dfd44a 2319 break; // case ST7070 Controller
wim 33:900a94bc7585 2320
wim 33:900a94bc7585 2321 default:
wim 33:900a94bc7585 2322 //Unsupported feature for other controllers
wim 33:900a94bc7585 2323 break;
wim 33:900a94bc7585 2324
wim 33:900a94bc7585 2325 } // end switch _ctrl
wim 33:900a94bc7585 2326 break; // end Top
wim 33:900a94bc7585 2327
wim 33:900a94bc7585 2328 case Bottom:
wim 33:900a94bc7585 2329 switch (_ctrl) {
wim 34:e5a0dcb43ecc 2330 case PCF2103_3V3:
wim 34:e5a0dcb43ecc 2331 case PCF2116_3V3:
wim 34:e5a0dcb43ecc 2332 case PCF2116_5V:
wim 34:e5a0dcb43ecc 2333 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
wim 34:e5a0dcb43ecc 2334 _writeCommand(0x06); // Display Conf Set 0000 0, 1, P=1, Q=0 (Instr. Set 1)
wim 34:e5a0dcb43ecc 2335 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
wim 34:e5a0dcb43ecc 2336 break;
wim 39:e9c2319de9c5 2337
wim 39:e9c2319de9c5 2338 case PCF2119_3V3:
wim 39:e9c2319de9c5 2339 case PCF2119R_3V3 :
wim 39:e9c2319de9c5 2340 _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1
wim 39:e9c2319de9c5 2341 _writeCommand(0x04); // Display Conf Set 0000 0, 1, P=0, Q=0 (Instr. Set 1)
wim 39:e9c2319de9c5 2342 _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0
wim 39:e9c2319de9c5 2343 break;
wim 34:e5a0dcb43ecc 2344
wim 33:900a94bc7585 2345 case SSD1803_3V3 :
wim 33:900a94bc7585 2346 // case SSD1803_5V :
wim 33:900a94bc7585 2347 case US2066_3V3 :
wim 33:900a94bc7585