add UTF-8 recode support, Cyrilic rus/ukr tables

Dependents:   Current_load1

Fork of TextLCD by Wim Huiskamp

TextLCD Library UTF-8 recode support, Cyrilic rus/ukr tables

Committer:
andrey_als
Date:
Tue Oct 13 21:59:04 2015 +0000
Revision:
43:63e5deba31ff
Parent:
41:51a77c5a45b6
Child:
44:fd3889afbe11
corect last symbol print

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