address modified to run with my LCD

Dependents:   DS1302_test_with_STM32_and_LCD16x2

Committer:
wim
Date:
Sat Apr 18 11:33:02 2015 +0000
Revision:
38:cbe275b0b647
Parent:
37:ce348c002929
Child:
39:e9c2319de9c5
Fixed Adafruit I2C/SPI portexpander pinmappings, fixed SYDZ Backlight control

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