stm32nucleof401re_05_lcd

Dependencies:   mbed-os

Committer:
perlatecnica
Date:
Fri Feb 07 08:37:50 2020 +0000
Revision:
0:579569ff83cb
v1.0

Who changed what in which revision?

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