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 22:03:16 2015 +0000
Revision:
44:fd3889afbe11
Parent:
43:63e5deba31ff
Child:
45:8625be98ecd4
remove debug serial

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