JNP3 SmartAlarm / Mbed 2 deprecated budzik

Dependencies:   TextLCD nRF24L01P mbed

Committer:
jackmax
Date:
Tue Dec 20 11:40:33 2016 +0100
Revision:
3:fc871995b3fc
zxczxc

Who changed what in which revision?

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