ssss

Committer:
irsanjul
Date:
Tue Aug 18 14:57:10 2020 +0000
Revision:
0:d51588bf1724
ssss

Who changed what in which revision?

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