TextLCD library for controlling various LCD panels based on the HD44780 4-bit interface

Dependents:   STM32_Button_Interrupt_dla_taty

Committer:
fcalzadas
Date:
Wed Nov 13 21:28:23 2019 +0000
Revision:
9:2db641efba7e
Parent:
7:44f34c09bd37
proyecto de LCD

Who changed what in which revision?

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