Change config file suit LCD used

Dependents:   System_Project_V6

Fork of TextLCD by Wim Huiskamp

Committer:
wim
Date:
Fri Oct 10 15:47:56 2014 +0000
Revision:
35:311be6444a39
Parent:
34:e5a0dcb43ecc
Child:
36:9f5f86dfd44a
Added AC780 support, added I2C expander module types, fixed setBacklight() for inverted logic I2C expander modules. Fixed bug in LCD_SPI_N define.

Who changed what in which revision?

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