Trying i2c LCD using TextLCD library
Fork of TextLCD by
Revision 42:9585a1cce408, committed 2017-04-10
- Comitter:
- rtandil
- Date:
- Mon Apr 10 07:48:10 2017 +0000
- Parent:
- 37:ce348c002929
- Commit message:
- First try
Changed in this revision
diff -r ce348c002929 -r 9585a1cce408 TextLCD.cpp --- a/TextLCD.cpp Sun Mar 29 13:08:03 2015 +0000 +++ b/TextLCD.cpp Mon Apr 10 07:48:10 2017 +0000 @@ -18,6 +18,12 @@ * 2014, v15: WH, Added AC780 support, added I2C expander modules, fixed setBacklight() for inverted logic modules. Fixed bug in LCD_SPI_N define * 2014, v16: WH, Added ST7070 and KS0073 support, added setIcon(), clrIcon() and setInvert() method for supported devices * 2015, v17: WH, Clean up low-level _writeCommand() and _writeData(), Added support for alternative fonttables (eg PCF21XX), Added ST7066_ACM controller for ACM1602 module + * 2015, v18: WH, Performance improvement I2C portexpander + * 2015, v19: WH, Fixed Adafruit I2C/SPI portexpander pinmappings, fixed SYDZ Backlight + * 2015, v20: WH, Fixed occasional Init fail caused by insufficient wait time after ReturnHome command (0x02), Added defines to reduce memory footprint (eg LCD_ICON), + * Fixed and Added more fonttable support for PCF2119R_3V3, Added HD66712 controller. + * 2015, v21: WH, Added LCD32x2 defines and code, Fixed KS0073 DL=1 init for SPI, Added defines to reduce memory footprint (LCD_TWO_CTRL, LCD_CONTRAST, LCD_UTF8_FONT) + * Added SPLC792A controller, Added UTF8_2_LCD decode for Cyrilic font (By Andriy Ribalko). Added setFont() * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -40,6 +46,7 @@ #include "mbed.h" #include "TextLCD.h" #include "TextLCD_UDC.inc" +#include "TextLCD_UTF8.inc" /** Create a TextLCD_Base interface * @@ -50,17 +57,17 @@ // Extract LCDType data - // Columns encoded in b7..b0 - _nr_cols = (_type & 0xFF); - - // Rows encoded in b15..b8 - _nr_rows = ((_type >> 8) & 0xFF); - - // Addressing mode encoded in b19..b16 + // Columns encoded in b15..b8 + _nr_cols = (_type & LCD_T_COL_MSK) >> LCD_T_COL_SHFT; + + // Rows encoded in b23..b16 + _nr_rows = (_type & LCD_T_ROW_MSK) >> LCD_T_ROW_SHFT; + + // Addressing mode encoded in b27..b24 _addr_mode = _type & LCD_T_ADR_MSK; // Font table, encoded in LCDCtrl - _font = _type & LCD_C_FNT_MSK; + _font = _ctrl & LCD_C_FNT_MSK; } /** Init the LCD Controller(s) @@ -69,12 +76,16 @@ * @return none */ void TextLCD_Base::_init(_LCDDatalength dl) { + + wait_ms(100); // Wait 100ms to ensure powered up +#if (LCD_TWO_CTRL == 1) // Select and configure second LCD controller when needed if(_type==LCD40x4) { _ctrl_idx=_LCDCtrl_1; // Select 2nd controller _initCtrl(dl); // Init 2nd controller } +#endif // Select and configure primary LCD controller _ctrl_idx=_LCDCtrl_0; // Select primary controller @@ -91,7 +102,7 @@ * The controller is accessed in 4-bit parallel mode either directly via mbed pins or through I2C or SPI expander. * Some controllers also support native I2C or SPI interfaces. * - * @param _LCDDatalength dl sets the 4 or 8 bit datalength of data/commands. Required for some native serial modes. + * @param _LCDDatalength dl sets the 4 or 8 bit datalength of data/commands. Required for some native serial modes that dont work when DL=0. * @return none * * Note: some configurations are commented out because they have not yet been tested due to lack of hardware @@ -101,8 +112,6 @@ int _lines=0; // Set lines (Ext Instr Set), temporary variable. this->_setRS(false); // command mode - - wait_ms(20); // Wait 20ms to ensure powered up if (dl == _LCD_DL_4) { // The Controller could be in 8 bit mode (power-on reset) or in 4 bit mode (warm reboot) at this point. @@ -110,18 +119,18 @@ // between the uP and the LCD can only write the 4 most significant bits (Most Significant Nibble, MSN). // In 4 bit mode the LCD expects the MSN first, followed by the LSN. // - // Current state: 8 bit mode | 4 bit mode, MSN is next | 4 bit mode, LSN is next + // Current state: 8 bit mode | 4 bit mode, MSN is next | 4 bit mode, LSN is next //------------------------------------------------------------------------------------------------- - _writeNibble(0x3); // set 8 bit mode (MSN) and dummy LSN, | set 8 bit mode (MSN), | set dummy LSN, - // remains in 8 bit mode | change to 8 bit mode | remains in 4 bit mode + _writeNibble(0x3); // set 8 bit mode (MSN) and dummy LSN, | set 8 bit mode (MSN), | set dummy LSN, + // remains in 8 bit mode | remains in 4 bit mode | remains in 4 bit mode wait_ms(15); // - _writeNibble(0x3); // set 8 bit mode and dummy LSN, | set 8 bit mode and dummy LSN, | set 8bit mode (MSN), - // remains in 8 bit mode | remains in 8 bit mode | remains in 4 bit mode + _writeNibble(0x3); // set 8 bit mode (MSN) and dummy LSN, | set dummy LSN, | set 8bit mode (MSN), + // remains in 8 bit mode | change to 8 bit mode | remains in 4 bit mode wait_ms(15); // - _writeNibble(0x3); // set 8 bit mode and dummy LSN, | set 8 bit mode and dummy LSN, | set dummy LSN, - // remains in 8 bit mode | remains in 8 bit mode | change to 8 bit mode + _writeNibble(0x3); // set 8 bit mode (MSN) and dummy LSN, | set 8 bit mode (MSN) and dummy LSN, | set dummy LSN, + // remains in 8 bit mode | remains in 8 bit mode | change to 8 bit mode wait_ms(15); // // Controller is now in 8 bit mode @@ -132,6 +141,11 @@ // Controller is now in 4-bit mode // Note: 4/8 bit mode is ignored for most native SPI and I2C devices. They dont use the parallel bus. // However, _writeNibble() method is void anyway for native SPI and I2C devices. + } + else { + // Reset in 8 bit mode, final Function set will follow + _writeCommand(0x30); // Function set 0 0 1 DL=1 N F x x + wait_ms(1); // most instructions take 40us } // Device specific initialisations: DC/DC converter to generate VLCD or VLED, number of lines etc @@ -140,82 +154,94 @@ case KS0073: // Initialise Display configuration switch (_type) { +// case LCD6x1: case LCD8x1: //8x1 is a regular 1 line display +// case LCD8x2B: //8x1 is a 16x1 line display case LCD12x1: case LCD16x1: case LCD20x1: case LCD24x1: // case LCD32x1: // EXT pin is High, extension driver needed -// case LCD40x1: // EXT pin is High, extension driver needed - _function = 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs) - // DL=0 (4 bits bus) - // N=0 (1-line mode, N=1 2-line mode) - // RE=0 (Dis. Extended Regs, special mode for KS0073) - // DH=1 (Disp shift enable, special mode for KS0073) - // REV=0 (Reverse normal, special mode for KS0073) - - _function_1 = 0x04; // Function set 001 DL N RE(1) BE LP (Ext Regs) - // DL=0 (4 bits bus) - // N=0 (1-line mode, N=1 2-line mode) - // RE=1 (Ena Extended Regs, special mode for KS0073) - // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073) - // LP=0 (LP=1 Low power mode, LP=0 Normal) +// case LCD40x1: // EXT pin is High, extension driver needed +// case LCD52x1: // EXT pin is High, extension driver needed + _function = dl | 0x02; // Set function, 0 0 1 DL, N, RE(0), DH, REV + // Note: 4 bit mode is NOT ignored for native SPI ! + // DL=1 (8 bits bus), DL=0 (4 bits bus) + // N=0 (1-line mode), N=1 (2-line mode), dont care for 4 line mode + // RE=0 (Dis. Extended Regs, special mode for KS0073) + // DH=1 (Disp shift enable, special mode for KS0073) + // REV=0 (Reverse normal, special mode for KS0073) + + _function_1 = dl | 0x04; // Set function, 0 0 1 DL, N, RE(1), BE, LP (Ext Regs) + // Note: 4 bit mode is NOT ignored for native SPI ! + // DL=1 (8 bits bus), DL=0 (4 bits bus) + // N=0 (1-line mode), N=1 (2-line mode), dont care for 4 line mode + // RE=1 (Ena Extended Regs, special mode for KS0073) + // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073) + // LP=0 (LP=1 Low power mode, LP=0 Normal) _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs) - // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073) + // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073) break; // case LCD12x3D: // Special mode for KS0073, KS0078 and PCF21XX // case LCD12x3D1: // Special mode for KS0073, KS0078 and PCF21XX case LCD12x4D: // Special mode for KS0073, KS0078 and PCF21XX // case LCD16x3D: // Special mode for KS0073, KS0078 +// case LCD16x3D1: // Special mode for KS0073, KS0078 // case LCD16x4D: // Special mode for KS0073, KS0078 case LCD20x4D: // Special mode for KS0073, KS0078 - _function = 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs) - // DL=0 (4 bits bus) - // N=0 (dont care for 4 line mode) - // RE=0 (Dis. Extended Regs, special mode for KS0073) - // DH=1 (Disp shift enable, special mode for KS0073) - // REV=0 (Reverse normal, special mode for KS0073) + _function = dl | 0x02; // Set function, 0 0 1 DL, N, RE(0), DH, REV + // Note: 4 bit mode is NOT ignored for native SPI ! + // DL=1 (8 bits bus), DL=0 (4 bits bus) + // N=0 (1-line mode), N=1 (2-line mode), dont care for 4 line mode + // RE=0 (Dis. Extended Regs, special mode for KS0073) + // DH=1 (Disp shift enable, special mode for KS0073) + // REV=0 (Reverse normal, special mode for KS0073) - _function_1 = 0x04; // Function set 001 DL N RE(1) BE LP (Ext Regs) - // DL=0 (4 bits bus) - // N=0 (1-line mode), N=1 (2-line mode) - // RE=1 (Ena Extended Regs, special mode for KS0073) - // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073) - // LP=0 (LP=1 Low power mode, LP=0 Normal) + _function_1 = dl | 0x04; // Set function, 0 0 1 DL, N, RE(1), BE, LP (Ext Regs) + // Note: 4 bit mode is NOT ignored for native SPI ! + // DL=1 (8 bits bus), DL=0 (4 bits bus) + // N=0 (1-line mode), N=1 (2-line mode), dont care for 4 line mode + // RE=1 (Ena Extended Regs, special mode for KS0073) + // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073) + // LP=0 (LP=1 Low power mode, LP=0 Normal) _function_x = 0x01; // Ext Function set 0000 1 FW BW NW (Ext Regs) - // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073) + // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073) break; - - case LCD16x3G: // Special mode for ST7036 -// case LCD24x3D: // Special mode for KS0078 -// case LCD24x3D1: // Special mode for KS0078 - case LCD24x4D: // Special mode for KS0078 - error("Error: LCD Controller type does not support this Display type\n\r"); - break; - - default: - // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4) - _function = 0x0A; // Function set 001 DL N RE(0) DH REV (Std Regs) - // DL=0 (4 bits bus) - // N=1 (2-line mode), N=0 (1-line mode) - // RE=0 (Dis. Extended Regs, special mode for KS0073) - // DH=1 (Disp shift enable, special mode for KS0073) - // REV=0 (Reverse normal, special mode for KS0073) +// case LCD6x2: + case LCD8x2: + case LCD16x2: +// case LCD16x1C: + case LCD20x2: + case LCD24x2: + case LCD32x2: + // All other LCD types are initialised as 2 Line displays + _function = dl | 0x0A; // Set function, 0 0 1 DL, N, RE(0), DH, REV + // Note: 4 bit mode is NOT ignored for native SPI ! + // DL=1 (8 bits bus), DL=0 (4 bits bus) + // N=1 (2-line mode), N=0 (1-line mode) + // RE=0 (Dis. Extended Regs, special mode for KS0073) + // DH=1 (Disp shift enable, special mode for KS0073) + // REV=0 (Reverse normal, special mode for KS0073) - _function_1 = 0x0C; // Function set 001 DL N RE(1) BE LP (Ext Regs) - // DL=0 (4 bits bus) - // N=1 (2 line mode), N=0 (1-line mode) - // RE=1 (Ena Extended Regs, special mode for KS0073) - // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073) - // LP=0 (LP=1 Low power mode, LP=0 Normal) + _function_1 = dl | 0x0C; // Set function, 0 0 1 DL, N, RE(1), BE, LP (Ext Regs) + // Note: 4 bit mode is NOT ignored for native SPI ! + // DL=1 (8 bits bus), DL=0 (4 bits bus) + // N=1 (2 line mode), N=0 (1-line mode) + // RE=1 (Ena Extended Regs, special mode for KS0073) + // BE=0 (Blink Enable, CG/SEG RAM, special mode for KS0073) + // LP=0 (LP=1 Low power mode, LP=0 Normal) _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs) // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0073) break; + + default: + error("Error: LCD Controller type does not support this Display type\n\r"); + break; } // switch type // init special features @@ -255,14 +281,14 @@ case LCD16x1: // case LCD20x1: case LCD24x1: - _function = 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs) + _function = dl | 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs) // DL=0 (4 bits bus) // N=0 (1 line mode), N=1 (2 line mode) // RE=0 (Dis. Extended Regs, special mode for KS0078) // DH=1 (Disp shift enable, special mode for KS0078) // REV=0 (Reverse normal, special mode for KS0078) - _function_1 = 0x04; // Function set 001 DL N RE(1) BE 0 (Ext Regs) + _function_1 = dl | 0x04; // Function set 001 DL N RE(1) BE 0 (Ext Regs) // DL=0 (4 bits bus) // N=0 (1 line mode), N=1 (2 line mode) // RE=1 (Ena Extended Regs, special mode for KS0078) @@ -282,14 +308,14 @@ // case LCD24x3D: // Special mode for KS0078 // case LCD24x3D1: // Special mode for KS0078 case LCD24x4D: // Special mode for KS0078 - _function = 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs) + _function = dl | 0x02; // Function set 001 DL N RE(0) DH REV (Std Regs) // DL=0 (4 bits bus) // N=0 (dont care for 4 line mode) // RE=0 (Dis. Extended Regs, special mode for KS0078) // DH=1 (Disp shift enable, special mode for KS0078) // REV=0 (Reverse normal, special mode for KS0078) - _function_1 = 0x04; // Function set 001 DL N RE(1) BE 0 (Ext Regs) + _function_1 = dl | 0x04; // Function set 001 DL N RE(1) BE 0 (Ext Regs) // DL=0 (4 bits bus) // N=0 (1 line mode), N=1 (2 line mode) // RE=1 (Ena Extended Regs, special mode for KS0078) @@ -300,20 +326,23 @@ // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0078) break; - case LCD16x3G: // Special mode for ST7036 - error("Error: LCD Controller type does not support this Display type\n\r"); - break; - - default: +// case LCD6x2: + case LCD8x2: + case LCD16x2: +// case LCD16x1C: + case LCD20x2: + case LCD24x2: + case LCD32x2: + case LCD40x2: // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4) - _function = 0x0A; // Function set 001 DL N RE(0) DH REV (Std Regs) + _function = dl | 0x0A; // Function set 001 DL N RE(0) DH REV (Std Regs) // DL=0 (4 bits bus) // N=1 (1 line mode), N=1 (2 line mode) // RE=0 (Dis. Extended Regs, special mode for KS0078) // DH=1 (Disp shift enable, special mode for KS0078) // REV=0 (Reverse normal, special mode for KS0078) - _function_1 = 0x0C; // Function set 001 DL N RE(1) BE 0 (Ext Regs) + _function_1 = dl | 0x0C; // Function set 001 DL N RE(1) BE 0 (Ext Regs) // DL=0 (4 bits bus) // N=1 (1 line mode), N=1 (2 line mode) // RE=1 (Ena Extended Regs, special mode for KS0078) @@ -323,6 +352,10 @@ _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs) // NW=0 (1,2 line), NW=1 (4 Line, special mode for KS0078) break; + + default: + error("Error: LCD Controller type does not support this Display type\n\r"); + break; } // switch type // init special features @@ -354,9 +387,10 @@ case ST7032_3V3: // ST7032 controller: Initialise Voltage booster for VLCD. VDD=3V3 + // Note: very similar to SPLC792A case ST7032_5V: // ST7032 controller: Disable Voltage booster for VLCD. VDD=5V - + // Initialise Display configuration switch (_type) { case LCD8x1: //8x1 is a regular 1 line display @@ -390,14 +424,16 @@ _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N F 0 IS=1 Select Instr Set = 1 _writeCommand(0x1C); // Internal OSC frequency adjustment Framefreq=183HZ, Bias will be 1/4 (Instr Set=1) + // Note: Bias and Osc register not available on SPLC792A _contrast = LCD_ST7032_CONTRAST; _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast Low bits, 0 1 1 1 C3 C2 C1 C0 (IS=1) if (_ctrl == ST7032_3V3) { -// _icon_power = 0x04; // Icon display off, Booster circuit is turned on (IS=1) - _icon_power = 0x0C; // Icon display on, Booster circuit is turned on (IS=1) +// _icon_power = 0x04; // Icon display off (Bit3=0), Booster circuit is turned on (Bit2=1) (IS=1) + _icon_power = 0x0C; // Icon display on (Bit3=1), Booster circuit is turned on (Bit2=1) (IS=1) + // Note: Booster circuit always on for SPLC792A, Bit2 is dont care // Saved to allow contrast change at later time } else { @@ -595,6 +631,8 @@ // NW=1 3-Line LCD (N=0) break; +// case LCD10x2D: // Special mode for SSD1803, 4-line mode but switch to double height font + case LCD10x4D: // Special mode for SSD1803 case LCD20x4D: // Special mode for SSD1803 _function = 0x08; // Set function 0 0 1 DL N DH RE(0) IS // Saved to allow switch between Instruction sets at later time @@ -868,6 +906,7 @@ break; // case PCF2116_5V Controller case PCF2119_3V3: + case PCF2119R_3V3: // PCF2119 controller: Initialise Voltage booster for VLCD. VDD=3V3. VA and VB control contrast. // Note1: See datasheet, the PCF2119 supports icons and provides separate constrast control for Icons and characters. // Note2: Vgen is switched off when the contrast voltage VA or VB is set to 0x00. @@ -906,7 +945,11 @@ // Init special features _writeCommand(0x20 | _function | 0x01); // Set function, Select Instruction Set = 1 - _writeCommand(0x04); // DISP CONF SET (Instr. Set 1) 0000, 0, 1, P=0, Q=0 +// _writeCommand(0x04); // DISP CONF SET (Instr. Set 1) 0000, 0, 1, P=0, Q=0 (IC at Bottom) +// _writeCommand(0x05); // Display Conf Set 0000, 0, 1, P=0, Q=1 +// _writeCommand(0x06); // Display Conf Set 0000, 0, 1, P=1, Q=0 + _writeCommand(0x07); // Display Conf Set 0000, 0, 1, P=1, Q=1 (IC at Top) + _writeCommand(0x10); // TEMP CTRL SET (Instr. Set 1) 0001, 0, 0, TC1=0, TC2=0 // _writeCommand(0x42); // HV GEN (Instr. Set 1) 0100, 0, 0, S1=1, S2=0 (2x multiplier) _writeCommand(0x40 | (LCD_PCF2_S12 & 0x03)); // HV GEN (Instr. Set 1) 0100, 0, 0, S1=1, S2=0 (2x multiplier) @@ -1198,7 +1241,169 @@ _contrast = LCD_PT63_CONTRAST; _writeCommand(0x20 | _function | ((~_contrast) >> 4)); // Invert and shift to use 2 MSBs break; // case PT6314 Controller (VFD) - + + + case HD66712: + // Initialise Display configuration + switch (_type) { + case LCD8x1: //8x1 is a regular 1 line display + case LCD12x1: + case LCD16x1: + case LCD20x1: + case LCD24x1: +// case LCD32x1: // EXT pin is High, extension driver needed + _function = 0x02; // Function set 001 DL N RE(0) - - (Std Regs) + // DL=0 (4 bits bus) + // N=0 (1-line mode, N=1 2-line mode) + // RE=0 (Dis. Extended Regs, special mode for HD66712) + // + + _function_1 = 0x04; // Function set 001 DL N RE(1) BE LP (Ext Regs) + // DL=0 (4 bits bus) + // N=0 (1-line mode, N=1 2-line mode) + // RE=1 (Ena Extended Regs; special mode for HD66712) + // BE=0 (Blink Enable, CG/SEG RAM; special mode for HD66712) + // LP=0 (LP=1 Low power mode, LP=0 Normal; special mode for HD66712) + + _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs) + // NW=0 (1,2 line), NW=1 (4 Line, special mode for HD66712) + break; + +// case LCD12x3D: // Special mode for KS0073, KS0078, PCF21XX and HD66712 +// case LCD12x3D1: // Special mode for KS0073, KS0078, PCF21XX and HD66712 + case LCD12x4D: // Special mode for KS0073, KS0078, PCF21XX and HD66712 +// case LCD16x3D: // Special mode for KS0073, KS0078 and HD66712 +// case LCD16x4D: // Special mode for KS0073, KS0078 and HD66712 + case LCD20x4D: // Special mode for KS0073, KS0078 and HD66712 + _function = 0x02; // Function set 001 DL N RE(0) - - (Std Regs) + // DL=0 (4 bits bus) + // N=0 (1-line mode, N=1 2-line mode) + // RE=0 (Dis. Extended Regs, special mode for HD66712) + // + + _function_1 = 0x04; // Function set 001 DL N RE(1) BE LP (Ext Regs) + // DL=0 (4 bits bus) + // N=0 (1-line mode, N=1 2-line mode) + // RE=1 (Ena Extended Regs; special mode for HD66712) + // BE=0 (Blink Enable, CG/SEG RAM; special mode for HD66712) + // LP=0 (LP=1 Low power mode, LP=0 Normal; special mode for HD66712) + + _function_x = 0x01; // Ext Function set 0000 1 FW BW NW (Ext Regs) + // NW=0 (1,2 line), NW=1 (4 Line, special mode for HD66712) + break; + + case LCD16x3G: // Special mode for ST7036 +// case LCD24x3D: // Special mode for KS0078 +// case LCD24x3D1: // Special mode for KS0078 + case LCD24x4D: // Special mode for KS0078 + error("Error: LCD Controller type does not support this Display type\n\r"); + break; + + default: + // All other LCD types are initialised as 2 Line displays (including LCD16x1C and LCD40x4) + _function = 0x0A; // Function set 001 DL N RE(0) - - (Std Regs) + // DL=0 (4 bits bus) + // N=1 (2-line mode), N=0 (1-line mode) + // RE=0 (Dis. Extended Regs, special mode for HD66712) + + _function_1 = 0x0C; // Function set 001 DL N RE(1) BE LP (Ext Regs) + // DL=0 (4 bits bus) + // N=1 (2 line mode), N=0 (1-line mode) + // RE=1 (Ena Extended Regs, special mode for HD66712) + // BE=0 (Blink Enable, CG/SEG RAM, special mode for HD66712) + // LP=0 (LP=1 Low power mode, LP=0 Normal) + + _function_x = 0x00; // Ext Function set 0000 1 FW BW NW (Ext Regs) + // NW=0 (1,2 line), NW=1 (4 Line, special mode for HD66712) + break; + } // switch type + + // init special features + _writeCommand(0x20 | _function_1);// Function set 001 DL N RE(1) BE LP (Ext Regs) + // DL=0 (4 bits bus), DL=1 (8 bits mode) + // N=0 (1 line mode), N=1 (2 line mode) + // RE=1 (Ena Extended Regs, special mode for HD66712) + // BE=0 (Blink Enable/Disable, CG/SEG RAM, special mode for HD66712) + // LP=0 (LP=1 Low power mode, LP=0 Normal) + + _writeCommand(0x08 | _function_x); // Ext Function set 0000 1 FW BW NW (Ext Regs) + // FW=0 (5-dot font, special mode for HD66712) + // BW=0 (Cur BW invert disable, special mode for HD66712) + // NW=0 (1,2 Line), NW=1 (4 line, special mode for HD66712) + + _writeCommand(0x10); // Scroll/Shift set 0001 HS4 HS3 HS2 HS1 (Ext Regs) + // Dotscroll/Display shift enable (Special mode for HD66712) + + _writeCommand(0x80); // Scroll Quantity set 1 0 HDS5 HDS4 HDS3 HDS2 HDS1 HDS0 (Ext Regs) + // Scroll quantity (Special mode for HD66712) + + _writeCommand(0x20 | _function); // Function set 001 DL N RE(0) DH REV (Std Regs) + // DL=0 (4 bits bus), DL=1 (8 bits mode) + // N=0 (1 line mode), N=1 (2 line mode) + // RE=0 (Dis. Extended Regs, special mode for HD66712) + // DH=1 (Disp shift enable/disable, special mode for HD66712) + // REV=0 (Reverse/Normal, special mode for HD66712) + break; // case HD66712 Controller + + case SPLC792A_3V3: + // SPLC792A controller: Initialise Voltage booster for VLCD. VDD=3V3 + // Note very similar to ST7032 + + // Initialise Display configuration + switch (_type) { + case LCD8x1: //8x1 is a regular 1 line display + case LCD8x2B: //8x2B is a special case of 16x1 +// case LCD12x1: + case LCD16x1: +// case LCD20x1: + case LCD24x1: + _function = 0x00; // FUNCTION SET 0 0 1 DL=0 (4 bit), N=0 (1-line display mode), F=0 (5*7dot), 0, IS + // Note: 4 bit mode is ignored for native SPI and I2C devices + // Saved to allow switch between Instruction sets at later time + break; + + case LCD12x3D: // Special mode for KS0078 and PCF21XX + case LCD12x3D1: // Special mode for KS0078 and PCF21XX + case LCD12x4D: // Special mode for KS0078 and PCF21XX + case LCD16x3G: // Special mode for ST7036 + case LCD24x4D: // Special mode for KS0078 + error("Error: LCD Controller type does not support this Display type\n\r"); + break; + + default: + // All other LCD types are initialised as 2 Line displays + _function = 0x08; // FUNCTION SET 0 0 1 DL=0 (4 bit), N=1 (2-line display mode), F=0 (5*7dot), 0, IS + // Note: 4 bit mode is ignored for native SPI and I2C devices + // Saved to allow switch between Instruction sets at later time + break; + } // switch type + + // init special features + _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N F 0 IS=1 Select Instr Set = 1 + +//SPLC792A Does not support Bias and Internal Osc register +// _writeCommand(0x1C); // Internal OSC frequency adjustment Framefreq=183HZ, Bias will be 1/4 (Instr Set=1) + + _contrast = LCD_SPLC792A_CONTRAST; + _writeCommand(0x70 | (_contrast & 0x0F)); // Set Contrast Low bits, 0 1 1 1 C3 C2 C1 C0 (IS=1) + + +// _icon_power = 0x04; // Icon display off (Bit3=0), Booster circuit is turned on (Bit2=1) (IS=1) + _icon_power = 0x0C; // Icon display on (Bit3=1), Booster circuit is turned on (Bit2=1) (IS=1) + // Note: Booster circuit always on for SPLC792A, Bit2 is dont care + // Saved to allow contrast change at later time + + _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Set Icon, Booster and Contrast High bits, 0 1 0 1 Ion Bon C5 C4 (IS=1) + wait_ms(10); // Wait 10ms to ensure powered up + + _writeCommand(0x68 | (LCD_SPLC792A_RAB & 0x07)); // Voltage follower, 0 1 1 0 FOn=1, Ampl ratio Rab2=1, Rab1=0, Rab0=0 (IS=1) + // Note: Follower circuit always on for SPLC792A, Bit3 is dont care + wait_ms(10); // Wait 10ms to ensure powered up + + _writeCommand(0x20 | _function); // Select Instruction Set = 0 + + break; // case SPLC792A_3V3 Controller + case ST7066_ACM: // ST7066 4/8 bit, I2C on ACM1602 using a PIC default: // Devices fully compatible to HD44780 that do not use any DC/DC Voltage converters but external VLCD, no icons etc @@ -1246,12 +1451,13 @@ } // switch Controller specific initialisations // Controller general initialisations -// _writeCommand(0x01); // cls, and set cursor to 0 +// _writeCommand(0x01); // Clear Display and set cursor to 0 // wait_ms(10); // The CLS command takes 1.64 ms. // // Since we are not using the Busy flag, Lets be safe and take 10 ms - _writeCommand(0x02); // Return Home - // Cursor Home, DDRAM Address to Origin + _writeCommand(0x02); // Cursor Home, DDRAM Address to Origin + wait_ms(10); // The Return Home command takes 1.64 ms. + // Since we are not using the Busy flag, Lets be safe and take 10 ms _writeCommand(0x06); // Entry Mode 0000 0 1 I/D S // Cursor Direction and Display Shift @@ -1266,15 +1472,19 @@ // _writeCommand(0x0C); // Display Ctrl 0000 1 D C B // // Display On, Cursor Off, Blink Off - setCursor(CurOff_BlkOff); +// setCursor(CurOff_BlkOff); + setCursor(CurOn_BlkOff); setMode(DispOn); } /** Clear the screen, Cursor home. + * Note: The whole display is initialised to charcode 0x20, which may not be a 'space' on some controllers with a + * different fontset such as the PCF2116C or PCF2119R. In this case you should fill the display with 'spaces'. */ void TextLCD_Base::cls() { +#if (LCD_TWO_CTRL == 1) // Select and configure second LCD controller when needed if(_type==LCD40x4) { _ctrl_idx=_LCDCtrl_1; // Select 2nd controller @@ -1284,21 +1494,29 @@ // Second LCD controller Clearscreen _writeCommand(0x01); // cls, and set cursor to 0 - wait_ms(10); // The CLS command takes 1.64 ms. + wait_ms(20); // The CLS command takes 1.64 ms. // Since we are not using the Busy flag, Lets be safe and take 10 ms _ctrl_idx=_LCDCtrl_0; // Select primary controller } + // Primary LCD controller Clearscreen _writeCommand(0x01); // cls, and set cursor to 0 - wait_ms(10); // The CLS command takes 1.64 ms. + wait_ms(20); // The CLS command takes 1.64 ms. // Since we are not using the Busy flag, Lets be safe and take 10 ms // Restore cursormode on primary LCD controller when needed if(_type==LCD40x4) { _setCursorAndDisplayMode(_currentMode,_currentCursor); } + +#else + // Support only one LCD controller + _writeCommand(0x01); // cls, and set cursor to 0 + wait_ms(20); // The CLS command takes 1.64 ms. + // Since we are not using the Busy flag, Lets be safe and take 10 ms +#endif setAddress(0, 0); // Reset Cursor location // Note: This is needed because some displays (eg PCF21XX) don't use line 0 in the '3 Line' mode. @@ -1337,11 +1555,23 @@ } else { //Character to write -#if (LCD_DEFAULT_FONT == 1) + +#if (LCD_DEF_FONT == 1) //Default HD44780 font _writeData(value); +#elif (LCD_C_FONT == 1) || (LCD_R_FONT == 1) //PCF21xxC or PCF21xxR font + _writeData(ASCII_2_LCD(value)); +#elif (LCD_UTF8_FONT == 1) // UTF8 2 byte font (eg Cyrillic) +// value = UTF_2_LCD(value, utf_seq_rec_first_cyr, utf_seq_recode_cyr, &utf_rnd_recode_cyr[0][0]); + value = UTF_2_LCD(value); + if (value >= 0) { + _writeData(value); + + // Only increment cursor when there is something to write + // Continue below to closing bracket... #else - _writeData(ASCII_2_LCD(value)); -#endif + _writeData('?'); //Oops, no font defined +#endif + //Update Cursor _column++; if (_column >= columns()) { @@ -1350,7 +1580,19 @@ if (_row >= rows()) { _row = 0; } - } + } + +#if (LCD_DEF_FONT == 1) //Default HD44780 font + +#elif (LCD_C_FONT == 1) || (LCD_R_FONT == 1) //PCF21xxC or PCF21xxR font + +#elif (LCD_UTF8_FONT == 1) //UTF8 2 byte font (eg Cyrillic) + // Continue code above to close bracket... + } // if (value >= 0) {.. +#else + +#endif + } //else //Set next memoryaddress, make sure cursor blinks at next location @@ -1366,6 +1608,8 @@ return -1; } + +#if ((LCD_C_FONT == 1) || (LCD_R_FONT == 1)) //PCF21xxC or PCF21xxR font /** Convert ASCII character code to the LCD fonttable code * * @param c The character to write to the display @@ -1373,23 +1617,88 @@ */ int TextLCD_Base::ASCII_2_LCD (int c) { -//LCD_C_FT0 is default for HD44780 and compatible series - if (_font == LCD_C_FT0) return c; - -//LCD_C_FT1 for PCF21XXC series -//Used code from Suga koubou library for PCF2119 +//LCD_C_F0 is default for HD44780 and compatible series +// if (_font == LCD_C_F0) return c; + +//LCD_C_FC for PCF21XXC series +//LCD_C_FR for PCF21XXR series +//Used code from Suga koubou library for PCF2119K and PCF2119R if (((c >= ' ') && (c <= '?')) || ((c >= 'A') && (c <= 'Z')) || ((c >= 'a') && (c <= 'z'))) { c |= 0x80; - } else if (c >= 0xf0 && c <= 0xff) { - c &= 0x0f; + } else if (c >= 0xF0 && c <= 0xFF) { + c &= 0x0F; } return c; - -//LCD_C_FT2 ... -//@TODO add more, eg cyrillic -//@TODO add method to switch between fonts for controllers that support this } - +#endif + +#if(LCD_UTF8_FONT == 1) + +/** Convert UTF8 2-byte character code to the LCD fonttable code + * @param c The character to write to the display + * @return character code for the specific fonttable of the controller or -1 if UTF8 code is not yet complete or incorrect + * + * Orig by Andriy, Modified by WH + * + * Note: The UTF8 decoding table for a specific controller is defined and selected in file TextLCD_UTF8.inc + * The table is accessed in this UTF_2_LCD() method through + * #define UTF_FIRST, UTF_LAST, UTF_SEQ_REC_FIRST, UTF_SEQ_REC_LAST and + * #define UTF_SEQ_RECODE and UTF_RND_RECODE + */ +int TextLCD_Base::UTF_2_LCD (int c) { + int utf_code; + int utf_low_byte; // Low byte UTF8 + static int utf_hi_byte = 0; // High byte UTF8 + + if (c < 0x80) { // Regular ASCII code, no need to convert + return c; + } + else { // UTF8 handling, See wikipedia.org/wiki/UTF-8 and www.utf8-chartable.de +// printf("0x%X ", c); + + if (c >= 0xC0) { // First UTF8 byte should be formatted as 110b bbaa, Do sanity check + utf_hi_byte = c & 0x1F; // Mask out significant bits (0x1F) and save high byte + return -1; // Nothing to display as yet, wait for second UTF8 byte + } + + if (c <= 0xBF) { // Second UTF8 byte should be formatted as 10aa aaaa, Do sanity check + utf_low_byte = c & 0x3F; // Mask out significant bits (0x3F) + + // Compose UTF character code from UTF8 bytes. The UTF codes will be between U+0080 and U+07FF + utf_code = (utf_hi_byte << 6) | utf_low_byte; // 00000bbb aaaaaaaa +// printf("0x%4X ", utf_code); + + // Sanity check on UTF codes + // For example Cyrillic characters are UTF encoded between 0x0400 and 0x04FF + if ((utf_code < UTF_FIRST) || (utf_code > UTF_LAST)) { + return -1; // Invalid UTF8 code + }; + + //Map some specific UTF codes on a character in LCD fonttable using a special correcting lookup table + for (char i=0; UTF_RND_RECODE[i][0]; i++) { // Step through table until endvalue 0 is found or until a match is found + if (utf_code == UTF_RND_RECODE[i][0]) { // UTF8 code match is found + c = UTF_RND_RECODE[1][1]; + return c; // found match in correcting random table + } + } + + //Sanity check on table idx range + if ((utf_code < UTF_SEQ_REC_FIRST) || (utf_code > UTF_SEQ_REC_LAST)) { + return -1; // Invalid UTF8 code + }; + + //Map all other UTF codes on a character in LCD fonttable using a sequential lookup table + c = UTF_SEQ_RECODE[utf_code - UTF_SEQ_REC_FIRST]; + return c; // entry in sequential table + } + else { + return -1; // Invalid UTF8 code for second byte + } + } // End UTF8 handling +} + +#endif + #if(LCD_PRINTF != 1) /** Write a character to the LCD @@ -1422,7 +1731,7 @@ // Enable is Low this->_setEnable(true); - this->_setData(value); // Low nibble + this->_setData(value); // Low nibble of value on D4..D7 wait_us(1); // Data setup time this->_setEnable(false); wait_us(1); // Datahold time @@ -1504,8 +1813,8 @@ case 3: return 0x40 + _nr_cols + column; // Should never get here. - default: - return 0x00; +// default: +// return 0x00; } case LCD_T_B: @@ -1532,11 +1841,6 @@ return 0x40 + (column - (_nr_cols >> 1)); #endif -// Not sure about this one, seems wrong. -// Left in for compatibility with original library -// case LCD16x2B: -// return 0x00 + (row * 40) + column; - case LCD_T_D: //Alternate addressing mode for 3 and 4 row displays (except 40x4). Used by PCF21XX, KS0073, KS0078, SSD1803 //The 4 available rows start at a hardcoded address. @@ -1551,8 +1855,8 @@ case 3: return 0x60 + column; // Should never get here. - default: - return 0x00; +// default: +// return 0x00; } case LCD_T_D1: @@ -1567,8 +1871,8 @@ case 2: return 0x60 + column; // Should never get here. - default: - return 0x00; +// default: +// return 0x00; } case LCD_T_E: @@ -1621,8 +1925,8 @@ else return (0x40 + _nr_cols + (column - (_nr_cols >> 1))); // Should never get here. - default: - return 0x00; +// default: +// return 0x00; } case LCD_T_G: @@ -1635,8 +1939,8 @@ case 2: return 0x20 + column; // Should never get here. - default: - return 0x00; +// default: +// return 0x00; } // Should never get here. @@ -1727,7 +2031,8 @@ // Save new displayMode, needed when 2 controllers are in use or when cursor is changed _currentMode = displayMode; - + +#if (LCD_TWO_CTRL == 1) // Select and configure second LCD controller when needed if(_type==LCD40x4) { if (_ctrl_idx==_LCDCtrl_0) { @@ -1761,6 +2066,11 @@ // Configure primary LCD controller _setCursorAndDisplayMode(_currentMode, _currentCursor); } +#else + // Support only one LCD controller + _setCursorAndDisplayMode(_currentMode, _currentCursor); + +#endif } /** Low level method to restore the cursortype and display mode for current controller @@ -1810,7 +2120,8 @@ * @param char *udc_data The bitpatterns for the UDC (8 bytes of 5 significant bits for bitpattern and 3 bits for blinkmode (advanced types)) */ void TextLCD_Base::setUDC(unsigned char c, char *udc_data) { - + +#if (LCD_TWO_CTRL == 1) // Select and configure second LCD controller when needed if(_type==LCD40x4) { _LCDCtrl_Idx current_ctrl_idx = _ctrl_idx; // Temp save current controller @@ -1834,6 +2145,10 @@ // Configure primary LCD controller _setUDC(c, udc_data); } +#else + // Support only one LCD controller + _setUDC(c, udc_data); +#endif } /** Low level method to store user defined characters for current controller @@ -1848,7 +2163,8 @@ case PCF2113_3V3 : // Some UDCs may be used for Icons case PCF2116_3V3 : case PCF2116_5V : - case PCF2119_3V3 : // Some UDCs may be used for Icons + case PCF2119_3V3 : // Some UDCs may be used for Icons + case PCF2119R_3V3: // Some UDCs may be used for Icons c = c & 0x0F; // mask down to valid range break; @@ -1874,6 +2190,7 @@ _writeCommand(0x80 | addr); } +#if(LCD_BLINK == 1) /** Set UDC Blink and Icon blink * setUDCBlink method is supported by some compatible devices (eg SSD1803) * @@ -1905,13 +2222,14 @@ case BlinkOn: // Controllers that support UDC/Icon Blink switch (_ctrl) { - case KS0073 : - case KS0078 : + case KS0073 : + case KS0078 : + case HD66712 : _function_1 |= 0x02; // Enable UDC/Icon Blink _writeCommand(0x20 | _function_1); // Function set 0 0 1 DL N RE(1) BE 0/LP (Ext Regs) _writeCommand(0x20 | _function); // Function set 0 0 1 DL N RE(0) DH REV (Std Regs) - break; // case KS0073, KS0078 Controller + break; // case KS0073, KS0078, HD66712 Controller case US2066_3V3 : case SSD1803_3V3 : @@ -1926,6 +2244,7 @@ case PCF2103_3V3 : case PCF2113_3V3 : case PCF2119_3V3 : + case PCF2119R_3V3 : // Enable Icon Blink _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1 _writeCommand(0x08 | 0x02); // ICON Conf 0000 1, IM=0 (Char mode), IB=1 (Icon blink), 0 (Instr. Set 1) @@ -1943,13 +2262,14 @@ case BlinkOff: // Controllers that support UDC Blink switch (_ctrl) { - case KS0073 : - case KS0078 : + case KS0073 : + case KS0078 : + case HD66712: _function_1 &= ~0x02; // Disable UDC/Icon Blink _writeCommand(0x20 | _function_1); // Function set 0 0 1 DL N RE(1) BE 0/LP (Ext Regs) _writeCommand(0x20 | _function); // Function set 0 0 1 DL N RE(0) DH REV (Std Regs) - break; // case KS0073, KS0078 Controller + break; // case KS0073, KS0078, HD66712 Controller case US2066_3V3 : case SSD1803_3V3 : @@ -1962,8 +2282,9 @@ break; // case SSD1803, US2066 case PCF2103_3V3 : - case PCF2113_3V3 : - case PCF2119_3V3 : + case PCF2113_3V3 : + case PCF2119_3V3 : + case PCF2119R_3V3 : // Disable Icon Blink _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1 _writeCommand(0x08); // ICON Conf 0000 1, IM=0 (Char mode), IB=1 (Icon blink), 0 (Instr. Set 1) @@ -1983,8 +2304,9 @@ } // blinkMode } // setUDCBlink() - - +#endif + +#if(LCD_CONTRAST == 1) /** Set Contrast * setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation * Initial code for ST70XX imported from fork by JH1PJL @@ -2002,7 +2324,8 @@ switch (_ctrl) { case PCF2113_3V3 : - case PCF2119_3V3 : + case PCF2119_3V3 : + case PCF2119R_3V3 : if (_contrast < 5) _contrast = 0; // See datasheet. Sanity check for PCF2113/PCF2119 if (_contrast > 55) _contrast = 55; @@ -2016,7 +2339,8 @@ case ST7032_5V : case ST7036_3V3 : // case ST7036_5V : - case SSD1803_3V3 : + case SSD1803_3V3 : + case SPLC792A_3V3 : _writeCommand(0x20 | _function | 0x01); // Select Instruction Set = 1 _writeCommand(0x70 | (_contrast & 0x0F)); // Contrast Low bits _writeCommand(0x50 | _icon_power | ((_contrast >> 4) & 0x03)); // Contrast High bits @@ -2053,8 +2377,9 @@ break; } // end switch } // end setContrast() - - +#endif + +#if(LCD_POWER == 1) /** Set Power * setPower method is supported by some compatible devices (eg SSD1803) that have power down modes * @@ -2072,7 +2397,8 @@ switch (_ctrl) { // case PCF2113_3V3 : -// case PCF2119_3V3 : +// case PCF2119_3V3 : +// case PCF2119R_3V3 : // case ST7032_3V3 : //@todo // enable Booster Bon @@ -2104,7 +2430,8 @@ switch (_ctrl) { // case PCF2113_3V3 : -// case PCF2119_3V3 : +// case PCF2119_3V3 : +// case PCF2119R_3V3 : // case ST7032_3V3 : //@todo // disable Booster Bon @@ -2128,8 +2455,9 @@ } // end switch } } // end setPower() - - +#endif + +#if(LCD_ORIENT == 1) /** Set Orient * setOrient method is supported by some compatible devices (eg SSD1803, US2066) that have top/bottom view modes * @@ -2145,11 +2473,17 @@ case PCF2103_3V3: case PCF2116_3V3: case PCF2116_5V: - case PCF2119_3V3: _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1 _writeCommand(0x05); // Display Conf Set 0000 0, 1, P=0, Q=1 (Instr. Set 1) _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0 break; + + case PCF2119_3V3: + case PCF2119R_3V3: + _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1 + _writeCommand(0x07); // Display Conf Set 0000 0, 1, P=1, Q=1 (Instr. Set 1) + _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0 + break; case SSD1803_3V3 : // case SSD1803_5V : @@ -2187,11 +2521,17 @@ case PCF2103_3V3: case PCF2116_3V3: case PCF2116_5V: - case PCF2119_3V3: _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1 _writeCommand(0x06); // Display Conf Set 0000 0, 1, P=1, Q=0 (Instr. Set 1) _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0 break; + + case PCF2119_3V3: + case PCF2119R_3V3 : + _writeCommand(0x20 | _function | 0x01); // Set function, Select Instr Set = 1 + _writeCommand(0x04); // Display Conf Set 0000 0, 1, P=0, Q=0 (Instr. Set 1) + _writeCommand(0x20 | _function); // Set function, Select Instr Set = 0 + break; case SSD1803_3V3 : // case SSD1803_5V : @@ -2231,7 +2571,9 @@ break; // end Bottom } // end switch orient } // end setOrient() - +#endif + +#if(LCD_BIGFONT == 1) /** Set Big Font * setBigFont method is supported by some compatible devices (eg SSD1803, US2066) * @@ -2347,8 +2689,107 @@ } // end switch lines } // end setBigFont() - - +#endif + + +#if (LCD_FONTSEL == 1) +/** Set Font + * setFont method is supported by some compatible devices (eg SSD1803, US2066, ST7070) + * + * @param LCDFont font The selected Font + * @return none + * + * Note: most controllers support only one font and the hardware specific + * fonttable is encoded as part of the controller type number (eg PCF21XXC or PCF21XXR). + * Some controllers support multiple tables that can only be selected by logic levels on a few pins. + * Some controllers also support runtime fontable switching through a specific instruction + */ +void TextLCD_Base::setFont(LCDFont font) { + + switch (font) { + case Font_RA: // UK/EU + switch (_ctrl) { + case SSD1803_3V3 : + case US2066_3V3 : + _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV + // Select Extended Instruction Set + _writeCommand(0x72); // ROM Select command, 0 1 1 1 0 0 1 0 (Ext Instr Set) + _writeData(0x00); // ROM_0 Select data, 0 0 0 0 ROM2 ROM1 0 0 (Ext Instr Set) + + _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS (Std Instr Set) + + _font = font; // Save active font + break; // end SSD1803, US2066 + + case ST7070: + //ST7070 does not support Cursorblink. The P bit selects the font instead ! + _writeCommand(0x08 | _currentMode | (_currentCursor & 0x02)); + + _font = font; // Save active font + break; // end ST7070 + + default: + break; // end default + } // end switch _ctrl + break; // end Font_RA + + case Font_RB: // UK/CYR + switch (_ctrl) { + case SSD1803_3V3 : + case US2066_3V3 : + _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV + // Select Extended Instruction Set + _writeCommand(0x72); // ROM Select command, 0 1 1 1 0 0 1 0 (Ext Instr Set) + _writeData(0x04); // ROM_0 Select data, 0 0 0 0 ROM2 ROM1 0 0 (Ext Instr Set) + + _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS (Std Instr Set) + + _font = font; // Save active font + break; // end SSD1803, US2066 + + case ST7070: + //ST7070 does not support Cursorblink. The P bit selects the font instead ! + _writeCommand(0x08 | _currentMode | (_currentCursor & 0x02) | 0x01); + + _font = font; // Save active font + break; // end ST7070 + + default: + break; // end default + } // end switch _ctrl + break; // end Font_RB + + case Font_0: //Font_O is pretty similar to ROM_C + case Font_RC: // UK/JAP + switch (_ctrl) { + case SSD1803_3V3 : + case US2066_3V3 : + _writeCommand(0x20 | _function_1); // Set function, 0 0 1 X N BE RE(1) REV + // Select Extended Instruction Set + _writeCommand(0x72); // ROM Select command, 0 1 1 1 0 0 1 0 (Ext Instr Set) + _writeData(0x08); // ROM_0 Select data, 0 0 0 0 ROM2 ROM1 0 0 (Ext Instr Set) + + _writeCommand(0x20 | _function); // Set function, 0 0 1 DL N DH RE(0) IS (Std Instr Set) + + _font = font; // Save active font + break; // end SSD1803, US2066 + + default: + break; // end default + } // end switch _ctrl + break; // end Font_RC + } // end switch font + + //SSD1803 seems to screw up cursor position after selecting new font. Restore to make sure... + //Set next memoryaddress, make sure cursor blinks at next location + int addr = getAddress(_column, _row); + _writeCommand(0x80 | addr); + +} +#endif + + +#if(LCD_ICON==1) /** Set Icons * * @param unsigned char idx The Index of the icon pattern (0..15) for KS0073 and similar controllers @@ -2394,6 +2835,7 @@ case ST7032_3V3: case ST7032_5V: + case SPLC792A_3V3: _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N F 0 IS=1 Select Instr Set = 1 _writeCommand(0x40 | (idx & 0x0F)); // Set Icon Address, mask Address to valid range (Instr Set 1) @@ -2427,7 +2869,8 @@ case PCF2103_3V3: case PCF2113_3V3: - case PCF2119_3V3: + case PCF2119_3V3: + case PCF2119R_3V3: // Store UDC/Icon pattern for PCF2103 and PCF2113: // 3 x 8 rows x 5 bits = 120 bits for Normal pattern (UDC 0..2) and // 3 x 8 rows x 5 bits = 120 bits for Blink pattern (UDC 4..6) @@ -2491,6 +2934,7 @@ case ST7032_3V3: case ST7032_5V: + case SPLC792A_3V3: _writeCommand(0x20 | _function | 0x01); // Set function, 0 0 1 DL N F 0 IS=1 Select Instr Set = 1 for (idx=0; idx<16; idx++) { @@ -2548,7 +2992,8 @@ } break; // case PCF2103_3V3 Controller - case PCF2119_3V3: + case PCF2119_3V3: + case PCF2119R_3V3: // PCF2119 uses part of the UDC RAM to control Icons // Select CG RAM @@ -2576,8 +3021,9 @@ int addr = getAddress(_column, _row); _writeCommand(0x80 | addr); } //end clrIcon() - - +#endif + +#if(LCD_INVERT == 1) /** Set Invert * setInvert method is supported by some compatible devices (eg KS0073) to swap between black and white * @@ -2635,6 +3081,7 @@ } // end switch } } // end setInvert() +#endif //--------- End TextLCD_Base ----------- @@ -2676,8 +3123,8 @@ // No Hardware Enable pin _e2 = NULL; //Construct dummy pin } - - _init(_LCD_DL_4); // Set Datalength to 4 bit for mbed bus interfaces + + _init(_LCD_DL_4); // Set Datalength to 4 bit for mbed bus interfaces } /** Destruct a TextLCD interface for using regular mbed pins @@ -2791,7 +3238,7 @@ // _writeRegister(OLAT, 0x00); // Output Latch // Init the portexpander bus - _lcd_bus = D_LCD_BUS_DEF; + _lcd_bus = LCD_BUS_I2C_DEF; // write the new data to the portexpander _writeRegister(GPIO, _lcd_bus); @@ -2799,7 +3246,7 @@ // PCF8574 of PCF8574A portexpander // Init the portexpander bus - _lcd_bus = D_LCD_BUS_DEF; + _lcd_bus = LCD_BUS_I2C_DEF; // write the new data to the portexpander _i2c->write(_slaveAddress, &_lcd_bus, 1); @@ -2812,22 +3259,33 @@ // Used for mbed I2C bus expander void TextLCD_I2C::_setEnableBit(bool value) { +#if (LCD_TWO_CTRL == 1) if(_ctrl_idx==_LCDCtrl_0) { if (value) { - _lcd_bus |= D_LCD_E; // Set E bit + _lcd_bus |= LCD_BUS_I2C_E; // Set E bit } else { - _lcd_bus &= ~D_LCD_E; // Reset E bit + _lcd_bus &= ~LCD_BUS_I2C_E; // Reset E bit } } else { if (value) { - _lcd_bus |= D_LCD_E2; // Set E2 bit + _lcd_bus |= LCD_BUS_I2C_E2; // Set E2 bit } else { - _lcd_bus &= ~D_LCD_E2; // Reset E2bit + _lcd_bus &= ~LCD_BUS_I2C_E2; // Reset E2bit } } +#else +// Support only one controller + if (value) { + _lcd_bus |= LCD_BUS_I2C_E; // Set E bit + } + else { + _lcd_bus &= ~LCD_BUS_I2C_E; // Reset E bit + } + +#endif } // Set E pin (or E2 pin) @@ -2856,10 +3314,10 @@ void TextLCD_I2C::_setRS(bool value) { if (value) { - _lcd_bus |= D_LCD_RS; // Set RS bit + _lcd_bus |= LCD_BUS_I2C_RS; // Set RS bit } else { - _lcd_bus &= ~D_LCD_RS; // Reset RS bit + _lcd_bus &= ~LCD_BUS_I2C_RS; // Reset RS bit } #if (MCP23008==1) @@ -2880,10 +3338,10 @@ void TextLCD_I2C::_setBL(bool value) { if (value) { - _lcd_bus |= D_LCD_BL; // Set BL bit + _lcd_bus |= LCD_BUS_I2C_BL; // Set BL bit } else { - _lcd_bus &= ~D_LCD_BL; // Reset BL bit + _lcd_bus &= ~LCD_BUS_I2C_BL; // Reset BL bit } #if (MCP23008==1) @@ -2899,41 +3357,66 @@ #endif } - +#if(0) +// New optimized v018 +// Test faster _writeByte 0.11s vs 0.27s for a 20x4 fillscreen (PCF8574), same as v018 +// Place the 4bit data in the databus shadowvalue +// Used for mbed I2C bus expander +const char _LCD_DATA_BITS[16] = { + 0x00, + ( LCD_BUS_I2C_D4), + ( LCD_BUS_I2C_D5 ), + ( LCD_BUS_I2C_D5 | LCD_BUS_I2C_D4), + ( LCD_BUS_I2C_D6 ), + ( LCD_BUS_I2C_D6 | LCD_BUS_I2C_D4), + ( LCD_BUS_I2C_D6 | LCD_BUS_I2C_D5 ), + ( LCD_BUS_I2C_D6 | LCD_BUS_I2C_D5 | LCD_BUS_I2C_D4), + (LCD_BUS_I2C_D7 ), + (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D4), + (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D5 ), + (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D5 | LCD_BUS_I2C_D4), + (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D6 ), + (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D6 | LCD_BUS_I2C_D4), + (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D6 | LCD_BUS_I2C_D5 ), + (LCD_BUS_I2C_D7 | LCD_BUS_I2C_D6 | LCD_BUS_I2C_D5 | LCD_BUS_I2C_D4) + }; +void TextLCD_I2C::_setDataBits(int value) { + + //Clear all databits + _lcd_bus &= ~LCD_BUS_I2C_MSK; + + // Set bit by bit to support any mapping of expander portpins to LCD pins + _lcd_bus |= _LCD_DATA_BITS[value & 0x0F]; +} +#endif + +// Test faster _writeByte 0.11s vs 0.27s for a 20x4 fillscreen (PCF8574) // Place the 4bit data in the databus shadowvalue // Used for mbed I2C bus expander void TextLCD_I2C::_setDataBits(int value) { + //Clear all databits + _lcd_bus &= ~LCD_BUS_I2C_MSK; + // Set bit by bit to support any mapping of expander portpins to LCD pins if (value & 0x01){ - _lcd_bus |= D_LCD_D4; // Set Databit - } - else { - _lcd_bus &= ~D_LCD_D4; // Reset Databit + _lcd_bus |= LCD_BUS_I2C_D4; // Set Databit } if (value & 0x02){ - _lcd_bus |= D_LCD_D5; // Set Databit - } - else { - _lcd_bus &= ~D_LCD_D5; // Reset Databit + _lcd_bus |= LCD_BUS_I2C_D5; // Set Databit } if (value & 0x04) { - _lcd_bus |= D_LCD_D6; // Set Databit - } - else { - _lcd_bus &= ~D_LCD_D6; // Reset Databit + _lcd_bus |= LCD_BUS_I2C_D6; // Set Databit } if (value & 0x08) { - _lcd_bus |= D_LCD_D7; // Set Databit + _lcd_bus |= LCD_BUS_I2C_D7; // Set Databit } - else { - _lcd_bus &= ~D_LCD_D7; // Reset Databit - } } + // Place the 4bit data on the databus // Used for mbed pins, I2C bus expander or SPI shifregister void TextLCD_I2C::_setData(int value) { @@ -3032,8 +3515,7 @@ TextLCD_SPI::TextLCD_SPI(SPI *spi, PinName cs, LCDType type, LCDCtrl ctrl) : TextLCD_Base(type, ctrl), _spi(spi), - _cs(cs) { - + _cs(cs) { // Init cs _cs = 1; @@ -3043,8 +3525,10 @@ _spi->frequency(500000); //_spi.frequency(1000000); + wait_ms(100); // Wait 100ms to ensure LCD powered up + // Init the portexpander bus - _lcd_bus = D_LCD_BUS_DEF; + _lcd_bus = LCD_BUS_SPI_DEF; // write the new data to the portexpander _cs = 0; @@ -3060,18 +3544,18 @@ if(_ctrl_idx==_LCDCtrl_0) { if (value) { - _lcd_bus |= D_LCD_E; // Set E bit + _lcd_bus |= LCD_BUS_SPI_E; // Set E bit } else { - _lcd_bus &= ~D_LCD_E; // Reset E bit + _lcd_bus &= ~LCD_BUS_SPI_E; // Reset E bit } } else { if (value) { - _lcd_bus |= D_LCD_E2; // Set E2 bit + _lcd_bus |= LCD_BUS_SPI_E2; // Set E2 bit } else { - _lcd_bus &= ~D_LCD_E2; // Reset E2 bit + _lcd_bus &= ~LCD_BUS_SPI_E2; // Reset E2 bit } } @@ -3086,10 +3570,10 @@ void TextLCD_SPI::_setRS(bool value) { if (value) { - _lcd_bus |= D_LCD_RS; // Set RS bit + _lcd_bus |= LCD_BUS_SPI_RS; // Set RS bit } else { - _lcd_bus &= ~D_LCD_RS; // Reset RS bit + _lcd_bus &= ~LCD_BUS_SPI_RS; // Reset RS bit } // write the new data to the SPI portexpander @@ -3103,10 +3587,10 @@ void TextLCD_SPI::_setBL(bool value) { if (value) { - _lcd_bus |= D_LCD_BL; // Set BL bit + _lcd_bus |= LCD_BUS_SPI_BL; // Set BL bit } else { - _lcd_bus &= ~D_LCD_BL; // Reset BL bit + _lcd_bus &= ~LCD_BUS_SPI_BL; // Reset BL bit } // write the new data to the SPI portexpander @@ -3121,31 +3605,31 @@ // Set bit by bit to support any mapping of expander portpins to LCD pins if (value & 0x01) { - _lcd_bus |= D_LCD_D4; // Set Databit + _lcd_bus |= LCD_BUS_SPI_D4; // Set Databit } else { - _lcd_bus &= ~D_LCD_D4; // Reset Databit + _lcd_bus &= ~LCD_BUS_SPI_D4; // Reset Databit } if (value & 0x02) { - _lcd_bus |= D_LCD_D5; // Set Databit + _lcd_bus |= LCD_BUS_SPI_D5; // Set Databit } else { - _lcd_bus &= ~D_LCD_D5; // Reset Databit + _lcd_bus &= ~LCD_BUS_SPI_D5; // Reset Databit } if (value & 0x04) { - _lcd_bus |= D_LCD_D6; // Set Databit + _lcd_bus |= LCD_BUS_SPI_D6; // Set Databit } else { - _lcd_bus &= ~D_LCD_D6; // Reset Databit + _lcd_bus &= ~LCD_BUS_SPI_D6; // Reset Databit } if (value & 0x08) { - _lcd_bus |= D_LCD_D7; // Set Databit + _lcd_bus |= LCD_BUS_SPI_D7; // Set Databit } else { - _lcd_bus &= ~D_LCD_D7; // Reset Databit + _lcd_bus &= ~LCD_BUS_SPI_D7; // Reset Databit } // write the new data to the SPI portexpander
diff -r ce348c002929 -r 9585a1cce408 TextLCD.h --- a/TextLCD.h Sun Mar 29 13:08:03 2015 +0000 +++ b/TextLCD.h Mon Apr 10 07:48:10 2017 +0000 @@ -18,6 +18,12 @@ * 2014, v15: WH, Added AC780 support, added I2C expander modules, fixed setBacklight() for inverted logic modules. Fixed bug in LCD_SPI_N define * 2014, v16: WH, Added ST7070 and KS0073 support, added setIcon(), clrIcon() and setInvert() method for supported devices * 2015, v17: WH, Clean up low-level _writeCommand() and _writeData(), Added support for alternative fonttables (eg PCF21XX), Added ST7066_ACM controller for ACM1602 module + * 2015, v18: WH, Performance improvement I2C portexpander + * 2015, v19: WH, Added 10x2D and 10x4D type for SSD1803 + * 2015, v20: WH, Fixed occasional Init fail caused by insufficient wait time after ReturnHome command (0x02), Added defines to reduce memory footprint (eg LCD_ICON), + * Fixed and Added more fonttable support for PCF2119R_3V3, Added HD66712 controller. + * 2015, v21: WH, Added LCD32x2 defines and code, Fixed LCD12x4D enum, Added font enums, Added SPLC792A controller, + * Added UTF8_2_LCD decode for Cyrilic font (By Andriy Ribalko). Added setFont() * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -83,40 +89,51 @@ /* LCD Type information on Rows, Columns and Variant. This information is encoded in * an int and used for the LCDType enumerators in order to simplify code maintenance */ -// Columns encoded in b7..b0 -#define LCD_T_COL_MSK 0x000000FF -#define LCD_T_C6 0x00000006 -#define LCD_T_C8 0x00000008 -#define LCD_T_C10 0x0000000A -#define LCD_T_C12 0x0000000C -#define LCD_T_C16 0x00000010 -#define LCD_T_C20 0x00000014 -#define LCD_T_C24 0x00000018 -#define LCD_T_C32 0x00000020 -#define LCD_T_C40 0x00000028 + +// Type ID encoded in b7..b0 +#define LCD_T_ID_MSK 0x000000FF +#define LCD_T_ID_SHFT 0 + +// Columns encoded in b15..b8 +#define LCD_T_COL_MSK 0x0000FF00 +#define LCD_T_COL_SHFT 8 +#define LCD_T_C6 0x00000600 +#define LCD_T_C8 0x00000800 +#define LCD_T_C10 0x00000A00 +#define LCD_T_C12 0x00000C00 +#define LCD_T_C16 0x00001000 +#define LCD_T_C20 0x00001400 +#define LCD_T_C24 0x00001800 +#define LCD_T_C32 0x00002000 +#define LCD_T_C40 0x00002800 +//#define LCD_T_C52 0x00003400 -// Rows encoded in b15..b8 -#define LCD_T_ROW_MSK 0x0000FF00 -#define LCD_T_R1 0x00000100 -#define LCD_T_R2 0x00000200 -#define LCD_T_R3 0x00000300 -#define LCD_T_R4 0x00000400 +// Rows encoded in b23..b16 +#define LCD_T_ROW_MSK 0x00FF0000 +#define LCD_T_ROW_SHFT 16 +#define LCD_T_R1 0x00010000 +#define LCD_T_R2 0x00020000 +#define LCD_T_R3 0x00030000 +#define LCD_T_R4 0x00040000 +#define LCD_T_R6 0x00060000 -// Addressing mode encoded in b19..b16 -#define LCD_T_ADR_MSK 0x000F0000 +// Addressing mode encoded in b27..b24 +#define LCD_T_ADR_MSK 0x0F000000 +#define LCD_T_ADR_SHFT 24 #define LCD_T_A 0x00000000 /*Mode A Default 1, 2 or 4 line display */ -#define LCD_T_B 0x00010000 /*Mode B, Alternate 8x2 (actually 16x1 display) */ -#define LCD_T_C 0x00020000 /*Mode C, Alternate 16x1 (actually 8x2 display) */ -#define LCD_T_D 0x00030000 /*Mode D, Alternate 3 or 4 line display (12x4, 20x4, 24x4) */ -#define LCD_T_D1 0x00040000 /*Mode D1, Alternate 3 out of 4 line display (12x3, 20x3, 24x3) */ -#define LCD_T_E 0x00050000 /*Mode E, 40x4 display (actually two 40x2) */ -#define LCD_T_F 0x00060000 /*Mode F, 16x3 display (actually 24x2) */ -#define LCD_T_G 0x00070000 /*Mode G, 16x3 display */ +#define LCD_T_B 0x01000000 /*Mode B, Alternate 8x2 (actually 16x1 display) */ +#define LCD_T_C 0x02000000 /*Mode C, Alternate 16x1 (actually 8x2 display) */ +#define LCD_T_D 0x03000000 /*Mode D, Alternate 3 or 4 line display (12x4, 20x4, 24x4) */ +#define LCD_T_D1 0x04000000 /*Mode D1, Alternate 3 out of 4 line display (12x3, 20x3, 24x3) */ +#define LCD_T_E 0x05000000 /*Mode E, 40x4 display (actually two 40x2) */ +#define LCD_T_F 0x06000000 /*Mode F, 16x3 display (actually 24x2) */ +#define LCD_T_G 0x07000000 /*Mode G, 16x3 display */ /* LCD Ctrl information on interface support and features. This information is encoded in * an int and used for the LCDCtrl enumerators in order to simplify code maintenance */ // Interface encoded in b31..b24 #define LCD_C_BUS_MSK 0xFF000000 +#define LCD_C_BUS_SHFT 24 #define LCD_C_PAR 0x01000000 /*Parallel 4 or 8 bit data, E pin, RS pin, RW=GND */ #define LCD_C_SPI3_8 0x02000000 /*SPI 3 line (MOSI, SCL, CS pins), 8 bits (Count Command initiates Data transfer) */ #define LCD_C_SPI3_9 0x04000000 /*SPI 3 line (MOSI, SCL, CS pins), 9 bits (RS + 8 Data) */ @@ -127,15 +144,27 @@ #define LCD_C_I2C 0x80000000 /*I2C (SDA, SCL pin), 8 control bits (Co, RS, RW) + 8 Data */ // Features encoded in b23..b16 #define LCD_C_FTR_MSK 0x00FF0000 +#define LCD_C_FTR_SHFT 16 #define LCD_C_BST 0x00010000 /*Booster */ #define LCD_C_CTR 0x00020000 /*Contrast Control */ #define LCD_C_ICN 0x00040000 /*Icons */ #define LCD_C_PDN 0x00080000 /*Power Down */ // Fonttable encoded in b15..b12 -#define LCD_C_FNT_MSK 0x0000F000 -#define LCD_C_FT0 0x00000000 /*Default */ -#define LCD_C_FT1 0x00001000 /*Font1 */ -#define LCD_C_FT2 0x00002000 /*Font2 */ +#define LCD_C_FNT_MSK 0x0000F000 +#define LCD_C_FNT_SHFT 12 +#define LCD_C_F0 0x00000000 /*Default HD44780 UK/JAP */ +#define LCD_C_FC 0x00001000 /*PCF21xxC */ +#define LCD_C_FR 0x00002000 /*PCF21XXR */ +#define LCD_C_FK 0x00003000 /*PCF21XXK */ +#define LCD_C_FRA 0x00004000 /*SSD1803 ROM_A UK/EU */ +#define LCD_C_FRB 0x00005000 /*SSD1803 ROM_B UK/Cyrillic */ +#define LCD_C_FRC 0x00006000 /*SSD1803 ROM_C UK/JAP */ +#define LCD_C_FD 0x00007000 /*SPLC780D EU/Cyrillic */ +#define LCD_C_FT 0x00008000 /*ST7066-0T EU/Cyrillic */ + +// Type ID encoded in b7..b0 +#define LCD_C_ID_MSK 0x000000FF +#define LCD_C_ID_SHFT 0 /** A TextLCD interface for driving 4-bit HD44780-based LCDs * @@ -159,48 +188,54 @@ /** LCD panel format */ // The commented out types exist but have not yet been tested with the library enum LCDType { -// LCD6x1 = (LCD_T_A | LCD_T_C6 | LCD_T_R1), /**< 6x1 LCD panel */ -// LCD6x2 = (LCD_T_A | LCD_T_C6 | LCD_T_R2), /**< 6x2 LCD panel */ - LCD8x1 = (LCD_T_A | LCD_T_C8 | LCD_T_R1), /**< 8x1 LCD panel */ - LCD8x2 = (LCD_T_A | LCD_T_C8 | LCD_T_R2), /**< 8x2 LCD panel */ - LCD8x2B = (LCD_T_D | LCD_T_C8 | LCD_T_R2), /**< 8x2 LCD panel (actually 16x1) */ - LCD12x1 = (LCD_T_A | LCD_T_C12 | LCD_T_R1), /**< 12x1 LCD panel */ - LCD12x2 = (LCD_T_A | LCD_T_C12 | LCD_T_R2), /**< 12x2 LCD panel */ - LCD12x3D = (LCD_T_D | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode PCF21XX, KS0073 */ - LCD12x3D1 = (LCD_T_D1 | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode PCF21XX, KS0073 */ -// LCD12x3G = (LCD_T_G | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode ST7036 */ - LCD12x4 = (LCD_T_A | LCD_T_C12 | LCD_T_R4), /**< 12x4 LCD panel */ - LCD12x4D = (LCD_T_B | LCD_T_C12 | LCD_T_R4), /**< 12x4 LCD panel, special mode PCF21XX, KS0073 */ - LCD16x1 = (LCD_T_A | LCD_T_C16 | LCD_T_R1), /**< 16x1 LCD panel */ - LCD16x1C = (LCD_T_C | LCD_T_C16 | LCD_T_R1), /**< 16x1 LCD panel (actually 8x2) */ +// LCD6x1 = (LCD_T_A | LCD_T_C6 | LCD_T_R1), /**< 6x1 LCD panel */ +// LCD6x2 = (LCD_T_A | LCD_T_C6 | LCD_T_R2), /**< 6x2 LCD panel */ + LCD8x1 = (LCD_T_A | LCD_T_C8 | LCD_T_R1), /**< 8x1 LCD panel */ + LCD8x2 = (LCD_T_A | LCD_T_C8 | LCD_T_R2), /**< 8x2 LCD panel */ + LCD8x2B = (LCD_T_B | LCD_T_C8 | LCD_T_R2), /**< 8x2 LCD panel (actually 16x1) */ +// LCD10x2D = (LCD_T_D | LCD_T_C10 | LCD_T_R2), /**< 10x2 LCD panel, special mode SSD1803, 4-line but double height */ + LCD10x4D = (LCD_T_D | LCD_T_C10 | LCD_T_R4), /**< 10x4 LCD panel, special mode SSD1803 */ + LCD12x1 = (LCD_T_A | LCD_T_C12 | LCD_T_R1), /**< 12x1 LCD panel */ + LCD12x2 = (LCD_T_A | LCD_T_C12 | LCD_T_R2), /**< 12x2 LCD panel */ + LCD12x3D = (LCD_T_D | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode PCF21XX, KS0073 */ + LCD12x3D1 = (LCD_T_D1 | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode PCF21XX, KS0073 */ +// LCD12x3G = (LCD_T_G | LCD_T_C12 | LCD_T_R3), /**< 12x3 LCD panel, special mode ST7036 */ + LCD12x4 = (LCD_T_A | LCD_T_C12 | LCD_T_R4), /**< 12x4 LCD panel */ + LCD12x4D = (LCD_T_D | LCD_T_C12 | LCD_T_R4), /**< 12x4 LCD panel, special mode PCF21XX, KS0073 */ + LCD16x1 = (LCD_T_A | LCD_T_C16 | LCD_T_R1), /**< 16x1 LCD panel */ + LCD16x1C = (LCD_T_C | LCD_T_C16 | LCD_T_R1), /**< 16x1 LCD panel (actually 8x2) */ LCD16x2 = (LCD_T_A | LCD_T_C16 | LCD_T_R2), /**< 16x2 LCD panel (default) */ // LCD16x2B = (LCD_T_B | LCD_T_C16 | LCD_T_R2), /**< 16x2 LCD panel, alternate addressing, wrong.. */ - LCD16x3D = (LCD_T_D | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode SSD1803 */ -// LCD16x3D1 = (LCD_T_D1 | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode SSD1803 */ - LCD16x3F = (LCD_T_F | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel (actually 24x2) */ - LCD16x3G = (LCD_T_G | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode ST7036 */ - LCD16x4 = (LCD_T_A | LCD_T_C16 | LCD_T_R4), /**< 16x4 LCD panel */ -// LCD16x4D = (LCD_T_D | LCD_T_C16 | LCD_T_R4), /**< 16x4 LCD panel, special mode SSD1803 */ + LCD16x3D = (LCD_T_D | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode SSD1803 */ +// LCD16x3D1 = (LCD_T_D1 | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode SSD1803 */ + LCD16x3F = (LCD_T_F | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel (actually 24x2) */ + LCD16x3G = (LCD_T_G | LCD_T_C16 | LCD_T_R3), /**< 16x3 LCD panel, special mode ST7036 */ + LCD16x4 = (LCD_T_A | LCD_T_C16 | LCD_T_R4), /**< 16x4 LCD panel */ +// LCD16x4D = (LCD_T_D | LCD_T_C16 | LCD_T_R4), /**< 16x4 LCD panel, special mode SSD1803 */ LCD20x1 = (LCD_T_A | LCD_T_C20 | LCD_T_R1), /**< 20x1 LCD panel */ LCD20x2 = (LCD_T_A | LCD_T_C20 | LCD_T_R2), /**< 20x2 LCD panel */ -// LCD20x3 = (LCD_T_A | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel */ -// LCD20x3D = (LCD_T_D | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel, special mode SSD1803 */ -// LCD20x3D1 = (LCD_T_D1 | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel, special mode SSD1803 */ +// LCD20x3 = (LCD_T_A | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel */ +// LCD20x3D = (LCD_T_D | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel, special mode SSD1803, KS0073 */ +// LCD20x3D1 = (LCD_T_D1 | LCD_T_C20 | LCD_T_R3), /**< 20x3 LCD panel, special mode SSD1803, KS0073 */ LCD20x4 = (LCD_T_A | LCD_T_C20 | LCD_T_R4), /**< 20x4 LCD panel */ - LCD20x4D = (LCD_T_D | LCD_T_C20 | LCD_T_R4), /**< 20x4 LCD panel, special mode SSD1803 */ - LCD24x1 = (LCD_T_A | LCD_T_C24 | LCD_T_R1), /**< 24x1 LCD panel */ - LCD24x2 = (LCD_T_A | LCD_T_C24 | LCD_T_R2), /**< 24x2 LCD panel */ -// LCD24x3D = (LCD_T_D | LCD_T_C24 | LCD_T_R3), /**< 24x3 LCD panel */ -// LCD24x3D1 = (LCD_T_D | LCD_T_C24 | LCD_T_R3), /**< 24x3 LCD panel */ - LCD24x4D = (LCD_T_D | LCD_T_C24 | LCD_T_R4), /**< 24x4 LCD panel, special mode KS0078 */ + LCD20x4D = (LCD_T_D | LCD_T_C20 | LCD_T_R4), /**< 20x4 LCD panel, special mode SSD1803, KS0073 */ +// LCD20x6 = (LCD_T_E | LCD_T_C20 | LCD_T_R6), /**< 20x6 LCD panel, Two controller version */ + LCD24x1 = (LCD_T_A | LCD_T_C24 | LCD_T_R1), /**< 24x1 LCD panel */ + LCD24x2 = (LCD_T_A | LCD_T_C24 | LCD_T_R2), /**< 24x2 LCD panel */ +// LCD24x3D = (LCD_T_D | LCD_T_C24 | LCD_T_R3), /**< 24x3 LCD panel */ +// LCD24x3D1 = (LCD_T_D | LCD_T_C24 | LCD_T_R3), /**< 24x3 LCD panel */ + LCD24x4D = (LCD_T_D | LCD_T_C24 | LCD_T_R4), /**< 24x4 LCD panel, special mode KS0078 */ // LCD32x1 = (LCD_T_A | LCD_T_C32 | LCD_T_R1), /**< 32x1 LCD panel */ -// LCD32x1C = (LCD_T_C | LCD_T_C32 | LCD_T_R1), /**< 32x1 LCD panel (actually 16x2) */ -// LCD32x2 = (LCD_T_A | LCD_T_C32 | LCD_T_R2), /**< 32x2 LCD panel */ -// LCD32x4 = (LCD_T_A | LCD_T_C32 | LCD_T_R4), /**< 32x4 LCD panel */ -// LCD40x1 = (LCD_T_A | LCD_T_C40 | LCD_T_R1), /**< 40x1 LCD panel */ -// LCD40x1C = (LCD_T_C | LCD_T_C40 | LCD_T_R1), /**< 40x1 LCD panel (actually 20x2) */ - LCD40x2 = (LCD_T_A | LCD_T_C40 | LCD_T_R2), /**< 40x2 LCD panel */ - LCD40x4 = (LCD_T_E | LCD_T_C40 | LCD_T_R4) /**< 40x4 LCD panel, Two controller version */ +// LCD32x1C = (LCD_T_C | LCD_T_C32 | LCD_T_R1), /**< 32x1 LCD panel (actually 16x2) */ + LCD32x2 = (LCD_T_A | LCD_T_C32 | LCD_T_R2), /**< 32x2 LCD panel */ +// LCD32x4 = (LCD_T_A | LCD_T_C32 | LCD_T_R4), /**< 32x4 LCD panel, Two controller version ? */ +// LCD40x1 = (LCD_T_A | LCD_T_C40 | LCD_T_R1), /**< 40x1 LCD panel */ +// LCD40x1C = (LCD_T_C | LCD_T_C40 | LCD_T_R1), /**< 40x1 LCD panel (actually 20x2) */ + LCD40x2 = (LCD_T_A | LCD_T_C40 | LCD_T_R2), /**< 40x2 LCD panel */ +// LCD52x1 = (LCD_T_A | LCD_T_C52 | LCD_T_R1), /**< 52x1 LCD panel, special mode KS0073 */ +#if (LCD_TWO_CTRL == 1) + LCD40x4 = (LCD_T_E | LCD_T_C40 | LCD_T_R4) /**< 40x4 LCD panel, Two controller version */ +#endif }; @@ -214,33 +249,38 @@ PCF2103_3V3 = 5 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2103 3V3 no Booster, 4/8 bit, I2C */ PCF2113_3V3 = 6 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< PCF2113 3V3 with Booster, 4/8 bit, I2C */ PCF2116_3V3 = 7 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST), /**< PCF2116 3V3 with Booster, 4/8 bit, I2C */ - PCF2116_5V = 8 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2116 5V no Booster, 4/8 bit, I2C */ - PCF2116C_5V = 9 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST) | LCD_C_FT1, /**< PCF2116C 3V3 with Booster, 4/8 bit, I2C */ - PCF2119_3V3 = 10 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< PCF2119 3V3 with Booster, 4/8 bit, I2C */ -// PCF2119C_3V3 = 11 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), LCD_C_FT1, /**< PCF2119K 3V3 with Booster, 4/8 bit, I2C */ -// PCF2119_5V = 12 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2119 5V no Booster, 4/8 bit, I2C */ - PT6314 = 13 | (LCD_C_PAR | LCD_C_SPI3_16 | LCD_C_CTR), /**< PT6314 VFD, 4/8 bit, SPI3 */ +// PCF2116C_3V3 = | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_FC), /**< PCF2116C 3V3 with Booster, 4/8 bit, I2C */ +// PCF2116K_3V3 = | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_FK), /**< PCF2116K 3V3 with Booster, 4/8 bit, I2C */ + PCF2116_5V = 8 | (LCD_C_PAR | LCD_C_I2C), /**< PCF2116 5V no Booster, 4/8 bit, I2C */ + PCF2116C_5V = 9 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_FC), /**< PCF2116C 3V3 with Booster, 4/8 bit, I2C */ + PCF2119_3V3 = 10 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< PCF2119 3V3 with Booster, 4/8 bit, I2C */ +// PCF2119C_3V3 = 11 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_FC), /**< PCF2119K 3V3 with Booster, 4/8 bit, I2C */ + PCF2119R_3V3 = 12 | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_FR), /**< PCF2119R 3V3 with Booster, 4/8 bit, I2C */ +// PCF2119_5V = | (LCD_C_PAR | LCD_C_I2C), /**< PCF2119 5V no Booster, 4/8 bit, I2C */ + PT6314 = 13 | (LCD_C_PAR | LCD_C_SPI3_16 | LCD_C_CTR), /**< PT6314 VFD Controller, 4/8 bit, SPI3 */ +// PT6880 = xx | (LCD_C_PAR | LCD_C_SPI3_16 | LCD_C_CTR), /**< PT6880 OLED controller, 4/8 bit, SPI3 */ SSD1803_3V3 = 14 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_PDN), /**< SSD1803 3V3 with Booster, 4/8 bit, I2C, SPI3 */ // SSD1803_5V = 15 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR | LCD_C_PDN), /**< SSD1803 3V3 with Booster, 4/8 bit, I2C, SPI3 */ - ST7032_3V3 = 16 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7032 3V3 with Booster, 4/8 bit, SPI4, I2C */ - ST7032_5V = 17 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_CTR), /**< ST7032 5V no Booster, 4/8 bit, SPI4, I2C */ + ST7032_3V3 = 16 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7032/SPLC792A 3V3 with Booster, 4/8 bit, SPI4, I2C */ + ST7032_5V = 17 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_CTR), /**< ST7032/SPLC792A 5V no Booster, 4/8 bit, SPI4, I2C */ ST7036_3V3 = 18 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7036 3V3 with Booster, 4/8 bit, SPI4, I2C */ ST7036_5V = 19 | (LCD_C_PAR | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR), /**< ST7036 5V no Booster, 4/8 bit, SPI4, I2C */ ST7066_ACM = 20 | (LCD_C_PAR | LCD_C_I2C), /**< ST7066 4/8 bit, I2C on ACM1602 using a PIC */ ST7070 = 21 | (LCD_C_PAR | LCD_C_SPI3_8 | LCD_C_SPI4), /**< ST7070 4/8 bit, SPI3 */ US2066_3V3 = 22 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_I2C | LCD_C_CTR | LCD_C_PDN), /**< US2066/SSD1311 3V3, 4/8 bit, I2C, SPI3 */ - WS0010 = 23 | (LCD_C_PAR | LCD_C_SPI3_10 | LCD_C_PDN) /**< WS0010/RS0010 OLED Controller, 4/8 bit, SPI3 */ + WS0010 = 23 | (LCD_C_PAR | LCD_C_SPI3_10 | LCD_C_PDN), /**< WS0010/RS0010 OLED Controller, 4/8 bit, SPI3 */ // WS0012 = 24 | (LCD_C_PAR | LCD_C_SPI3_10 | LCD_C_I2C | LCD_C_PDN), /**< WS0012 4/8 bit, SPI, I2C */ - + HD66712 = 25 | (LCD_C_PAR | LCD_C_SPI3_24 | LCD_C_BST | LCD_C_PDN), /**< HD66712 Controller, 4/8 bit, SPI3 */ + SPLC792A_3V3 = 26 | (LCD_C_PAR | LCD_C_SPI3_9 | LCD_C_SPI4 | LCD_C_I2C | LCD_C_BST | LCD_C_CTR) /**< ST7032/SPLC792A 3V3 with Booster, 4/8 bit, SPI3, SPI4, I2C */ }; /** LCD Cursor control */ enum LCDCursor { CurOff_BlkOff = 0x00, /**< Cursor Off, Blinking Char Off */ - CurOn_BlkOff = 0x02, /**< Cursor On, Blinking Char Off */ - CurOff_BlkOn = 0x01, /**< Cursor Off, Blinking Char On */ - CurOn_BlkOn = 0x03 /**< Cursor On, Blinking Char On */ + CurOff_BlkOn = 0x01, /**< Cursor Off, Blinking Char On */ + CurOn_BlkOff = 0x02, /**< Cursor On, Blinking Char Off */ + CurOn_BlkOn = 0x03 /**< Cursor On, Blinking Char On */ }; /** LCD Display control */ @@ -267,6 +307,7 @@ Bottom /**< Upside down view */ }; +#if (LCD_BIGFONT == 1) /** LCD BigFont control, supported for some Controllers */ enum LCDBigFont { None, /**< no lines */ @@ -275,15 +316,53 @@ BottomLine, /**< 2+3 line or 3+4 line */ TopBottomLine /**< 1+2 line and 3+4 line */ }; +#endif +#if (LCD_FONTSEL == 1) + /** LCD setFont control. + Note: most controllers support only one font and the hardware specific + fonttable is encoded as part of the controller type number (eg PCF21XXC or PCF21XXR). + Some controllers support multiple tables that can only be selected by logic levels on a few pins. + Some controllers also support runtime fontable switching through a specific instruction */ + enum LCDFont { + /**< HD44780 fonttable */ + Font_0 = LCD_C_F0, /**< default, UK/JAP */ + /**< PCF21XX fonttables */ + Font_C = LCD_C_FC, /**< PCF21XXC */ + Font_R = LCD_C_FR, /**< PCF21XXR */ + /**< SSD1803 ROM tables */ + Font_RA = LCD_C_FRA, /**< UK/EU */ + Font_RB = LCD_C_FRB, /**< UK/Cyrillic */ + Font_RC = LCD_C_FRC, /**< default, UK/JAP */ + Font_D = LCD_C_FD, /**< SPLC780D Cyrillic */ + Font_T = LCD_C_FT /**< ST7066-0T Cyrillic */ + }; +#endif +#if ((LCD_C_FONT == 1) || (LCD_R_FONT == 1)) //PCF21xxC or PCF21xxR font /** Convert ASCII character code to the LCD fonttable code * * @param c The character to write to the display * @return The character code for the specific fonttable of the controller */ int ASCII_2_LCD (int c); +#endif +#if(LCD_UTF8_FONT == 1) + /** Convert UTF8 2-byte character code to the LCD fonttable code + * @param c The character to write to the display + * @return character code for the specific fonttable of the controller or -1 if UTF8 code is not yet complete or incorrect + * + * Orig by Andriy, Modified by WH + * + * Note: The UTF8 decoding table for a specific controller is defined and selected in file TextLCD_UTF8.inc + * The table is accessed in this UTF_2_LCD() method through + * #define UTF_FIRST, UTF_LAST, UTF_SEQ_REC_FIRST, UTF_SEQ_REC_LAST and + * #define UTF_SEQ_RECODE and UTF_RND_RECODE + */ + int UTF_2_LCD (int c); +#endif + #if(LCD_PRINTF != 1) /** Write a character to the LCD @@ -329,7 +408,7 @@ * @param row The vertical position from the top, indexed from 0 * @return The memoryaddress of screen column and row location */ - int getAddress(int column, int row); + int getAddress(int column, int row); /** Set the memoryaddress of screen column and row location * @@ -379,13 +458,16 @@ */ void setUDC(unsigned char c, char *udc_data); +#if(LCD_BLINK == 1) /** Set UDC Blink and Icon blink * setUDCBlink method is supported by some compatible devices (eg SSD1803) * * @param blinkMode The Blink mode (BlinkOff, BlinkOn) */ void setUDCBlink(LCDBlink blinkMode); +#endif +#if(LCD_CONTRAST == 1) /** Set Contrast * setContrast method is supported by some compatible devices (eg ST7032i) that have onboard LCD voltage generation * Code imported from fork by JH1PJL @@ -394,7 +476,9 @@ * @return none */ void setContrast(unsigned char c = LCD_DEF_CONTRAST); +#endif +#if(LCD_POWER == 1) /** Set Power * setPower method is supported by some compatible devices (eg SSD1803) that have power down modes * @@ -402,7 +486,9 @@ * @return none */ void setPower(bool powerOn = true); +#endif +#if(LCD_ORIENT == 1) /** Set Orient * setOrient method is supported by some compatible devices (eg SSD1803, US2066) that have top/bottom view modes * @@ -410,16 +496,32 @@ * @return none */ void setOrient(LCDOrient orient = Top); +#endif +#if(LCD_BIGFONT == 1) /** Set Big Font * setBigFont method is supported by some compatible devices (eg SSD1803, US2066) * * @param lines The selected Big Font lines (None, TopLine, CenterLine, BottomLine, TopBottomLine) * Double height characters can be shown on lines 1+2, 2+3, 3+4 or 1+2 and 3+4 * Valid double height lines depend on the LCDs number of rows. + * @return none */ void setBigFont(LCDBigFont lines); +#endif +#if(LCD_FONTSEL == 1) + /** Set Font + * setFont method is supported by some compatible devices (eg SSD1803, US2066, ST7070) + * + * @param LCDFont font The selected Font + * @return none + */ + void setFont(LCDFont font = Font_0); +#endif + + +#if(LCD_ICON==1) /** Set Icons * * @param unsigned char idx The Index of the icon pattern (0..15) for KS0073 and similar controllers @@ -436,7 +538,9 @@ */ //@TODO Add support for 40x4 dual controller void clrIcon(); +#endif +#if(LCD_INVERT == 1) /** Set Invert * setInvert method is supported by some compatible devices (eg KS0073) to swap between black and white * @@ -445,8 +549,9 @@ */ //@TODO Add support for 40x4 dual controller void setInvert(bool invertOn); +#endif -protected: +public: /** LCD controller select, mainly used for LCD40x4 */ @@ -1215,4 +1320,5 @@ #endif /* Native SPI bus */ //-------- End TextLCD_SPI_N_3_24 ---------- + #endif
diff -r ce348c002929 -r 9585a1cce408 TextLCD_Config.h --- a/TextLCD_Config.h Sun Mar 29 13:08:03 2015 +0000 +++ b/TextLCD_Config.h Mon Apr 10 07:48:10 2017 +0000 @@ -5,6 +5,11 @@ * 2014, v03: WH, Added LCD_SPI_N_3_8 define for ST7070 * 2015, v04: WH, Added support for alternative fonttables (eg PCF21XX) * 2015, v05: WH, Clean up low-level _writeCommand() and _writeData(), Added support for alt fonttables (eg PCF21XX), Added ST7066_ACM for ACM1602 module, fixed contrast for ST7032 + * 2015, v06: WH, Performance improvement I2C portexpander + * 2015, v07: WH, Fixed Adafruit I2C/SPI portexpander pinmappings, fixed SYDZ Backlight + * 2015, v08: WH, Added defines to reduce memory footprint (eg LCD_ICON), added some I2C portexpander defines + * 2015, v09: WH, Added defines to reduce memory footprint (LCD_TWO_CTRL, LCD_CONTRAST, LCD_UTF8_FONT), + * Added UTF8_2_LCD decode for Cyrilic font (By Andriy Ribalko). Added setFont() * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -29,33 +34,50 @@ //Select hardware interface options to reduce memory footprint (multiple options allowed) #define LCD_I2C 1 /* I2C Expander PCF8574/MCP23008 */ -#define LCD_SPI 1 /* SPI Expander SN74595 */ -#define LCD_I2C_N 1 /* Native I2C bus */ -#define LCD_SPI_N 1 /* Native SPI bus */ -#define LCD_SPI_N_3_8 1 /* Native SPI bus */ -#define LCD_SPI_N_3_9 1 /* Native SPI bus */ -#define LCD_SPI_N_3_10 1 /* Native SPI bus */ -#define LCD_SPI_N_3_16 1 /* Native SPI bus */ -#define LCD_SPI_N_3_24 1 /* Native SPI bus */ +#define LCD_SPI 0 /* SPI Expander SN74595 */ +#define LCD_I2C_N 0 /* Native I2C bus */ +#define LCD_SPI_N 0 /* Native SPI bus */ +#define LCD_SPI_N_3_8 0 /* Native SPI bus */ +#define LCD_SPI_N_3_9 0 /* Native SPI bus */ +#define LCD_SPI_N_3_10 0 /* Native SPI bus */ +#define LCD_SPI_N_3_16 0 /* Native SPI bus */ +#define LCD_SPI_N_3_24 0 /* Native SPI bus */ //Select options to reduce memory footprint (multiple options allowed) -#define LCD_UDC 1 /* Enable predefined UDC example*/ -#define LCD_PRINTF 1 /* Enable Stream implementation */ +#define LCD_UDC 1 /* Enable predefined UDC example*/ +#define LCD_PRINTF 1 /* Enable Stream implementation */ +#define LCD_ICON 1 /* Enable Icon implementation -2.0K codesize*/ +#define LCD_ORIENT 1 /* Enable Orientation switch implementation -0.9K codesize*/ +#define LCD_BIGFONT 1 /* Enable Big Font implementation -0.6K codesize */ +#define LCD_INVERT 1 /* Enable display Invert implementation -0.5K codesize*/ +#define LCD_POWER 1 /* Enable Power control implementation -0.1K codesize*/ +#define LCD_BLINK 1 /* Enable UDC and Icon Blink control implementation -0.8K codesize*/ +#define LCD_CONTRAST 1 /* Enable Contrast control implementation -0.9K codesize*/ +#define LCD_TWO_CTRL 1 /* Enable LCD40x4 (two controller) implementation -0.1K codesize*/ +#define LCD_FONTSEL 0 /* Enable runtime font select implementation using setFont -0.9K codesize*/ -//Select option to activate default fonttable or alternatively use conversion for specific controller versions (eg PCF2119C) -#define LCD_DEFAULT_FONT 1 +//Select option to activate default fonttable or alternatively use conversion for specific controller versions (eg PCF2116C, PCF2119R, SSD1803, US2066) +#define LCD_DEF_FONT 1 //Default HD44780 font +//#define LCD_C_FONT 1 //PCF21xxC font +//#define LCD_R_FONT 1 //PCF21xxR font +//#define LCD_UTF8_FONT 1 /* Enable UTF8 Support (eg Cyrillic tables) -0.4K codesize*/ +//#define LCD_UTF8_CYR_B 1 /* Select specific UTF8 Cyrillic table (SSD1803 ROM_B) */ //Pin Defines for I2C PCF8574/PCF8574A or MCP23008 and SPI 74595 bus expander interfaces //Different commercially available LCD portexpanders use different wiring conventions. //LCD and serial portexpanders should be wired according to the tables below. // //Select Serial Port Expander Hardware module (one option only) -#define DEFAULT 1 +#define DEFAULT 0 #define ADAFRUIT 0 #define DFROBOT 0 +#define LCM1602 1 #define YWROBOT 0 #define GYLCD 0 +#define MJKDZ 0 #define SYDZ 0 +#define WIDEHK 0 +#define LCDPLUG 0 #if (DEFAULT==1) //Definitions for default (WH) mapping between serial port expander pins and LCD controller @@ -65,16 +87,30 @@ //Note: LCD RW pin must be connected to GND // E2 is used for LCD40x4 (second controller) // BL may be used to control backlight -#define D_LCD_PIN_D4 0 -#define D_LCD_PIN_D5 1 -#define D_LCD_PIN_D6 2 -#define D_LCD_PIN_D7 3 -#define D_LCD_PIN_RS 4 -#define D_LCD_PIN_E 5 -#define D_LCD_PIN_E2 6 -#define D_LCD_PIN_BL 7 + +//I2C bus expander (PCF8574/PCF8574A or MCP23008) interface +#define LCD_BUS_I2C_D4 (1 << 0) +#define LCD_BUS_I2C_D5 (1 << 1) +#define LCD_BUS_I2C_D6 (1 << 2) +#define LCD_BUS_I2C_D7 (1 << 3) +#define LCD_BUS_I2C_RS (1 << 4) +#define LCD_BUS_I2C_E (1 << 5) +#define LCD_BUS_I2C_E2 (1 << 6) +#define LCD_BUS_I2C_BL (1 << 7) -#define D_LCD_PIN_RW D_LCD_PIN_E2 +#define LCD_BUS_I2C_RW (1 << 6) + +//SPI bus expander (74595) interface, same as I2C +#define LCD_BUS_SPI_D4 LCD_BUS_I2C_D4 +#define LCD_BUS_SPI_D5 LCD_BUS_I2C_D5 +#define LCD_BUS_SPI_D6 LCD_BUS_I2C_D6 +#define LCD_BUS_SPI_D7 LCD_BUS_I2C_D7 +#define LCD_BUS_SPI_RS LCD_BUS_I2C_RS +#define LCD_BUS_SPI_E LCD_BUS_I2C_E +#define LCD_BUS_SPI_E2 LCD_BUS_I2C_E2 +#define LCD_BUS_SPI_BL LCD_BUS_I2C_BL + +#define LCD_BUS_SPI_RW LCD_BUS_I2C_RW //Select I2C Portexpander type (one option only) #define PCF8574 1 @@ -93,16 +129,33 @@ //Note: LCD RW pin must be kept LOW // E2 is not available on this hardware and so it does not support LCD40x4 (second controller) // BL is used to control backlight -#define D_LCD_PIN_0 0 -#define D_LCD_PIN_RS 1 -#define D_LCD_PIN_E 2 -#define D_LCD_PIN_D4 3 -#define D_LCD_PIN_D5 4 -#define D_LCD_PIN_D6 5 -#define D_LCD_PIN_D7 6 -#define D_LCD_PIN_BL 7 +//Note: The pinmappings are different for the MCP23008 and the 74595! + +//I2C bus expander (MCP23008) interface +#define LCD_BUS_I2C_0 (1 << 0) +#define LCD_BUS_I2C_RS (1 << 1) +#define LCD_BUS_I2C_E (1 << 2) +#define LCD_BUS_I2C_D4 (1 << 3) +#define LCD_BUS_I2C_D5 (1 << 4) +#define LCD_BUS_I2C_D6 (1 << 5) +#define LCD_BUS_I2C_D7 (1 << 6) +#define LCD_BUS_I2C_BL (1 << 7) -#define D_LCD_PIN_E2 D_LCD_PIN_0 +#define LCD_BUS_I2C_E2 (1 << 0) +#define LCD_BUS_I2C_RW (1 << 0) + +//SPI bus expander (74595) interface +#define LCD_BUS_SPI_0 (1 << 0) +#define LCD_BUS_SPI_RS (1 << 1) +#define LCD_BUS_SPI_E (1 << 2) +#define LCD_BUS_SPI_D7 (1 << 3) +#define LCD_BUS_SPI_D6 (1 << 4) +#define LCD_BUS_SPI_D5 (1 << 5) +#define LCD_BUS_SPI_D4 (1 << 6) +#define LCD_BUS_SPI_BL (1 << 7) + +#define LCD_BUS_SPI_E2 (1 << 0) +#define LCD_BUS_SPI_RW (1 << 0) //Force I2C portexpander type #define PCF8574 0 @@ -127,16 +180,31 @@ //Note: LCD RW pin must be kept LOW // E2 is not available on default Arduino hardware and so it does not support LCD40x4 (second controller) // BL is used to control backlight -#define D_LCD_PIN_RS 0 -#define D_LCD_PIN_RW 1 -#define D_LCD_PIN_E 2 -#define D_LCD_PIN_BL 3 -#define D_LCD_PIN_D4 4 -#define D_LCD_PIN_D5 5 -#define D_LCD_PIN_D6 6 -#define D_LCD_PIN_D7 7 + +//I2C bus expander PCF8574 interface +#define LCD_BUS_I2C_RS (1 << 0) +#define LCD_BUS_I2C_RW (1 << 1) +#define LCD_BUS_I2C_E (1 << 2) +#define LCD_BUS_I2C_BL (1 << 3) +#define LCD_BUS_I2C_D4 (1 << 4) +#define LCD_BUS_I2C_D5 (1 << 5) +#define LCD_BUS_I2C_D6 (1 << 6) +#define LCD_BUS_I2C_D7 (1 << 7) + +#define LCD_BUS_I2C_E2 (1 << 1) -#define D_LCD_PIN_E2 D_LCD_PIN_RW +//SPI bus expander (74595) interface, same as I2C +#define LCD_BUS_SPI_RS LCD_BUS_I2C_RS +#define LCD_BUS_SPI_RW LCD_BUS_I2C_RW +#define LCD_BUS_SPI_E LCD_BUS_I2C_E +#define LCD_BUS_SPI_BL LCD_BUS_I2C_BL +#define LCD_BUS_SPI_D4 LCD_BUS_I2C_D4 +#define LCD_BUS_SPI_D5 LCD_BUS_I2C_D5 +#define LCD_BUS_SPI_D6 LCD_BUS_I2C_D6 +#define LCD_BUS_SPI_D7 LCD_BUS_I2C_D7 + +#define LCD_BUS_SPI_E2 LCD_BUS_I2C_E2 + //Force I2C portexpander type #define PCF8574 1 @@ -146,25 +214,39 @@ #define BACKLIGHT_INV 0 #endif -#if (YWROBOT==1) +#if ((YWROBOT==1) || (LCM1602==1)) //Definitions for YWROBOT LCM1602 V1 Module mapping between serial port expander pins and LCD controller. -//Very similar to DFROBOT. This hardware uses PCF8574. +//Very similar to DFROBOT. Also marked as 'Funduino'. This hardware uses PCF8574. //Slaveaddress may be set by solderbridges (default 0x4E). SDA/SCL has no pullup Resistors onboard. //See http://arduino-info.wikispaces.com/LCD-Blue-I2C // //Note: LCD RW pin must be kept LOW // E2 is not available on default hardware and so it does not support LCD40x4 (second controller) -// BL is used to control backlight, reverse logic: Low turns on Backlight. This is handled in setBacklight() -#define D_LCD_PIN_RS 0 -#define D_LCD_PIN_RW 1 -#define D_LCD_PIN_E 2 -#define D_LCD_PIN_BL 3 -#define D_LCD_PIN_D4 4 -#define D_LCD_PIN_D5 5 -#define D_LCD_PIN_D6 6 -#define D_LCD_PIN_D7 7 +// BL is used to control backlight. + +//I2C bus expander PCF8574 interface +#define LCD_BUS_I2C_RS (1 << 0) +#define LCD_BUS_I2C_RW (1 << 1) +#define LCD_BUS_I2C_E (1 << 2) +#define LCD_BUS_I2C_BL (1 << 3) +#define LCD_BUS_I2C_D4 (1 << 4) +#define LCD_BUS_I2C_D5 (1 << 5) +#define LCD_BUS_I2C_D6 (1 << 6) +#define LCD_BUS_I2C_D7 (1 << 7) -#define D_LCD_PIN_E2 D_LCD_PIN_RW +#define LCD_BUS_I2C_E2 (1 << 1) + +//SPI bus expander (74595) interface, same as I2C +#define LCD_BUS_SPI_RS LCD_BUS_I2C_RS +#define LCD_BUS_SPI_RW LCD_BUS_I2C_RW +#define LCD_BUS_SPI_E LCD_BUS_I2C_E +#define LCD_BUS_SPI_BL LCD_BUS_I2C_BL +#define LCD_BUS_SPI_D4 LCD_BUS_I2C_D4 +#define LCD_BUS_SPI_D5 LCD_BUS_I2C_D5 +#define LCD_BUS_SPI_D6 LCD_BUS_I2C_D6 +#define LCD_BUS_SPI_D7 LCD_BUS_I2C_D7 + +#define LCD_BUS_SPI_E2 LCD_BUS_I2C_E2 //Force I2C portexpander type #define PCF8574 1 @@ -174,8 +256,8 @@ #define BACKLIGHT_INV 0 #endif -#if (GYLCD==1) -//Definitions for Arduino-IIC-LCD GY-LCD-V1 Module mapping between serial port expander pins and LCD controller. +#if ((GYLCD==1) || (MJKDZ==1)) +//Definitions for Arduino-IIC-LCD GY-LCD-V1, for GY-IICLCD and for MJKDZ Module mapping between serial port expander pins and LCD controller. //Very similar to DFROBOT. This hardware uses PCF8574. //Slaveaddress may be set by solderbridges (default 0x4E). SDA/SCL has pullup Resistors onboard. //See http://arduino-info.wikispaces.com/LCD-Blue-I2C @@ -183,16 +265,30 @@ //Note: LCD RW pin must be kept LOW // E2 is not available on default hardware and so it does not support LCD40x4 (second controller) // BL is used to control backlight, reverse logic: Low turns on Backlight. This is handled in setBacklight() -#define D_LCD_PIN_D4 0 -#define D_LCD_PIN_D5 1 -#define D_LCD_PIN_D6 2 -#define D_LCD_PIN_D7 3 -#define D_LCD_PIN_EN 4 -#define D_LCD_PIN_RW 5 -#define D_LCD_PIN_RS 6 -#define D_LCD_PIN_BL 7 + +//I2C bus expander PCF8574 interface +#define LCD_BUS_I2C_D4 (1 << 0) +#define LCD_BUS_I2C_D5 (1 << 1) +#define LCD_BUS_I2C_D6 (1 << 2) +#define LCD_BUS_I2C_D7 (1 << 3) +#define LCD_BUS_I2C_E (1 << 4) +#define LCD_BUS_I2C_RW (1 << 5) +#define LCD_BUS_I2C_RS (1 << 6) +#define LCD_BUS_I2C_BL (1 << 7) -#define D_LCD_PIN_E2 D_LCD_PIN_RW +#define LCD_BUS_I2C_E2 (1 << 5) + +//SPI bus expander (74595) interface +#define LCD_BUS_SPI_D4 LCD_BUS_I2C_D4 +#define LCD_BUS_SPI_D5 LCD_BUS_I2C_D5 +#define LCD_BUS_SPI_D6 LCD_BUS_I2C_D6 +#define LCD_BUS_SPI_D7 LCD_BUS_I2C_D7 +#define LCD_BUS_SPI_E LCD_BUS_I2C_E +#define LCD_BUS_SPI_RW LCD_BUS_I2C_RW +#define LCD_BUS_SPI_RS LCD_BUS_I2C_RS +#define LCD_BUS_SPI_BL LCD_BUS_I2C_BL + +#define LCD_BUS_SPI_E2 LCD_BUS_I2C_E2 //Force I2C portexpander type #define PCF8574 1 @@ -204,47 +300,149 @@ #if (SYDZ==1) //Definitions for SYDZ Module mapping between serial port expander pins and LCD controller. -//Very similar to DFROBOT. This hardware uses PCF8574A and uses inverted Backlight control -//Slaveaddress may be set by switches (default 0x40). SDA/SCL has pullup Resistors onboard. +//Very similar to DFROBOT. This hardware uses PCF8574A. +//Slaveaddress may be set by switches (default 0x70). SDA/SCL has pullup Resistors onboard. //See ebay // //Note: LCD RW pin must be kept LOW // E2 is not available on default hardware and so it does not support LCD40x4 (second controller) -// BL is used to control backlight, reverse logic: Low turns on Backlight. This is handled in setBacklight() -#define D_LCD_PIN_RS 0 -#define D_LCD_PIN_RW 1 -#define D_LCD_PIN_E 2 -#define D_LCD_PIN_BL 3 -#define D_LCD_PIN_D4 4 -#define D_LCD_PIN_D5 5 -#define D_LCD_PIN_D6 6 -#define D_LCD_PIN_D7 7 +// BL is used to control backlight + +//I2C bus expander PCF8574A interface +#define LCD_BUS_I2C_RS (1 << 0) +#define LCD_BUS_I2C_RW (1 << 1) +#define LCD_BUS_I2C_E (1 << 2) +#define LCD_BUS_I2C_BL (1 << 3) +#define LCD_BUS_I2C_D4 (1 << 4) +#define LCD_BUS_I2C_D5 (1 << 5) +#define LCD_BUS_I2C_D6 (1 << 6) +#define LCD_BUS_I2C_D7 (1 << 7) -#define D_LCD_PIN_E2 D_LCD_PIN_RW +#define LCD_BUS_I2C_E2 (1 << 1) + +//SPI bus expander (74595) interface, same as I2C +#define LCD_BUS_SPI_RS LCD_BUS_I2C_RS +#define LCD_BUS_SPI_RW LCD_BUS_I2C_RW +#define LCD_BUS_SPI_E LCD_BUS_I2C_E +#define LCD_BUS_SPI_BL LCD_BUS_I2C_BL +#define LCD_BUS_SPI_D4 LCD_BUS_I2C_D4 +#define LCD_BUS_SPI_D5 LCD_BUS_I2C_D5 +#define LCD_BUS_SPI_D6 LCD_BUS_I2C_D6 +#define LCD_BUS_SPI_D7 LCD_BUS_I2C_D7 + +#define LCD_BUS_SPI_E2 LCD_BUS_I2C_E2 //Force I2C portexpander type #define PCF8574 1 #define MCP23008 0 //Force Inverted Backlight control -#define BACKLIGHT_INV 1 +#define BACKLIGHT_INV 0 +#endif + +#if (WIDEHK==1) +//Definitions for WIDE.HK I2C backpack mapping between serial port expander pins and LCD controller +//This hardware uses an MCP23008 I2C expander. +//Slaveaddress is hardcoded at 0x4E. SDA/SCL has pullup Resistors onboard (3k3). +//See http://www.wide.hk +// +//Note: LCD RW pin must be kept LOW +// E2 is not available on this hardware and so it does not support LCD40x4 (second controller) +// BL is used to control backlight +// + +//I2C bus expander (MCP23008) interface +#define LCD_BUS_I2C_D4 (1 << 0) +#define LCD_BUS_I2C_D5 (1 << 1) +#define LCD_BUS_I2C_D6 (1 << 2) +#define LCD_BUS_I2C_D7 (1 << 3) +#define LCD_BUS_I2C_RS (1 << 4) +#define LCD_BUS_I2C_RW (1 << 5) +#define LCD_BUS_I2C_BL (1 << 6) +#define LCD_BUS_I2C_E (1 << 7) + +#define LCD_BUS_I2C_E2 (1 << 5) + +//SPI bus expander (74595) interface, same as I2C +#define LCD_BUS_SPI_D4 LCD_BUS_I2C_D4 +#define LCD_BUS_SPI_D5 LCD_BUS_I2C_D5 +#define LCD_BUS_SPI_D6 LCD_BUS_I2C_D6 +#define LCD_BUS_SPI_D7 LCD_BUS_I2C_D7 +#define LCD_BUS_SPI_RS LCD_BUS_I2C_RS +#define LCD_BUS_SPI_RW LCD_BUS_I2C_RW +#define LCD_BUS_SPI_BL LCD_BUS_I2C_BL +#define LCD_BUS_SPI_E LCD_BUS_I2C_E + +#define LCD_BUS_SPI_E2 LCD_BUS_I2C_E2 + +//Force I2C portexpander type +#define PCF8574 0 +#define MCP23008 1 + +//Inverted Backlight control +#define BACKLIGHT_INV 0 #endif +#if (LCDPLUG==1) +//Definitions for Jeelabs LCD_Plug I2C backpack mapping between serial port expander pins and LCD controller +//This hardware uses an MCP23008 I2C expander. +//Slaveaddress is hardcoded at 0x48. SDA/SCL has no pullup Resistors onboard. +//See http://jeelabs.net/projects/hardware/wiki/lcd_plug +// +//Note: LCD RW pin must be kept LOW +// E2 is available on a plug and so it does support LCD40x4 (second controller) +// BL is used to control backlight +// + +//I2C bus expander (MCP23008) interface +#define LCD_BUS_I2C_D4 (1 << 0) +#define LCD_BUS_I2C_D5 (1 << 1) +#define LCD_BUS_I2C_D6 (1 << 2) +#define LCD_BUS_I2C_D7 (1 << 3) +#define LCD_BUS_I2C_RS (1 << 4) +#define LCD_BUS_I2C_E2 (1 << 5) +#define LCD_BUS_I2C_E (1 << 6) +#define LCD_BUS_I2C_BL (1 << 7) + +#define LCD_BUS_I2C_RW (1 << 5) + +//SPI bus expander (74595) interface, same as I2C +#define LCD_BUS_SPI_D4 LCD_BUS_I2C_D4 +#define LCD_BUS_SPI_D5 LCD_BUS_I2C_D5 +#define LCD_BUS_SPI_D6 LCD_BUS_I2C_D6 +#define LCD_BUS_SPI_D7 LCD_BUS_I2C_D7 +#define LCD_BUS_SPI_RS LCD_BUS_I2C_RS +#define LCD_BUS_SPI_E2 LCD_BUS_I2C_E2 +#define LCD_BUS_SPI_E LCD_BUS_I2C_E +#define LCD_BUS_SPI_BL LCD_BUS_I2C_BL + +#define LCD_BUS_SPI_RW LCD_BUS_I2C_RW + +//Force I2C portexpander type +#define PCF8574 0 +#define MCP23008 1 + +//Inverted Backlight control +#define BACKLIGHT_INV 0 +#endif + + //Bitpattern Defines for I2C PCF8574/PCF8574A, MCP23008 and SPI 74595 Bus expanders //Don't change! -// -#define D_LCD_D4 (1<<D_LCD_PIN_D4) -#define D_LCD_D5 (1<<D_LCD_PIN_D5) -#define D_LCD_D6 (1<<D_LCD_PIN_D6) -#define D_LCD_D7 (1<<D_LCD_PIN_D7) -#define D_LCD_RS (1<<D_LCD_PIN_RS) -#define D_LCD_E (1<<D_LCD_PIN_E) -#define D_LCD_E2 (1<<D_LCD_PIN_E2) -#define D_LCD_BL (1<<D_LCD_PIN_BL) -//#define D_LCD_RW (1<<D_LCD_PIN_RW) +#define LCD_BUS_I2C_MSK (LCD_BUS_I2C_D4 | LCD_BUS_I2C_D5 | LCD_BUS_I2C_D6 | LCD_BUS_I2C_D7) +#if (BACKLIGHT_INV == 1) +#define LCD_BUS_I2C_DEF (0x00 | LCD_BUS_I2C_BL) +#else +#define LCD_BUS_I2C_DEF 0x00 +#endif -#define D_LCD_BUS_MSK (D_LCD_D4 | D_LCD_D5 | D_LCD_D6 | D_LCD_D7) -#define D_LCD_BUS_DEF 0x00 +#define LCD_BUS_SPI_MSK (LCD_BUS_SPI_D4 | LCD_BUS_SPI_D5 | LCD_BUS_SPI_D6 | LCD_BUS_SPI_D7) +#if (BACKLIGHT_INV == 1) +#define LCD_BUS_SPI_DEF (0x00 | LCD_BUS_SPI_BL) +#else +#define LCD_BUS_SPI_DEF 0x00 +#endif + /* PCF8574/PCF8574A I2C portexpander slave address */ #define PCF8574_SA0 0x40 @@ -321,6 +519,12 @@ #define AC780_SA2 0x7C #define AC780_SA3 0x7E +/* SPLC792A is clone of ST7032i */ +#define SPLC792A_SA0 0x78 +#define SPLC792A_SA1 0x7A +#define SPLC792A_SA2 0x7C +#define SPLC792A_SA3 0x7E + //Some native I2C controllers dont support ACK. Set define to '0' to allow code to proceed even without ACK //#define LCD_I2C_ACK 0 #define LCD_I2C_ACK 1 @@ -331,8 +535,16 @@ #define LCD_DEF_CONTRAST 0x20 //ST7032 EastRising ERC1602FS-4 display -//Contrast setting 6 significant bits -//Voltage Multiplier setting 3 significant bits +//Contrast setting 6 significant bits (0..63) +//Voltage Multiplier setting 3 significant bits: +// 0: 1.818V +// 1: 2.222V +// 2: 2.667V +// 3: 3.333V +// 4: 3.636V (ST7032 default) +// 5: 4.000V +// 6: 4.444V +// 7: 5.000V #define LCD_ST7032_CONTRAST 0x28 #define LCD_ST7032_RAB 0x04 @@ -363,5 +575,18 @@ //Contrast setting 2 significant bits, use 6 for compatibility #define LCD_PT63_CONTRAST 0x3F +//SPLC792A is clone of ST7032i +//Contrast setting 6 significant bits (0..63) +//Voltage Multiplier setting 3 significant bits: +// 0: 1.818V +// 1: 2.222V +// 2: 2.667V +// 3: 3.333V (SPLC792A default) +// 4: 3.636V +// 5: 4.000V +// 6: 4.444V +// 7: 5.000V +#define LCD_SPLC792A_CONTRAST 0x28 +#define LCD_SPLC792A_RAB 0x04 #endif //MBED_TEXTLCDCONFIG_H \ No newline at end of file
diff -r ce348c002929 -r 9585a1cce408 TextLCD_UDC.h --- a/TextLCD_UDC.h Sun Mar 29 13:08:03 2015 +0000 +++ b/TextLCD_UDC.h Mon Apr 10 07:48:10 2017 +0000 @@ -1,6 +1,8 @@ /* mbed TextLCD Library, for LCDs based on HD44780 controllers * Copyright (c) 2014, WH * 2014, v01: WH, Extracted from TextLCD.h as of v14 + * 2015, v02: WH, Added some UDC definitions and commented out several UDCs + * 2015, v03: WH, Added some UDC definitions * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -27,12 +29,12 @@ /** Some sample User Defined Chars 5x7 dots */ #if(LCD_UDC == 1) -//extern const char udc_ae[]; //æ -//extern const char udc_0e[]; //ø -//extern const char udc_ao[]; //å -//extern const char udc_AE[]; //Æ -//extern const char udc_0E[]; //Ø -//extern const char udc_Ao[]; //Å +//extern const char udc_ae[]; //テヲ +//extern const char udc_0e[]; //テク +//extern const char udc_ao[]; //テ・ +//extern const char udc_AE[]; //テ� +//extern const char udc_0E[]; //テ� +//extern const char udc_Ao[]; //テ� //extern const char udc_PO[]; //Padlock Open //extern const char udc_PC[]; //Padlock Closed @@ -51,10 +53,10 @@ extern const char udc_6[]; // checkerboard extern const char udc_7[]; // \ -extern const char udc_degr[]; // Degree symbol +//extern const char udc_degr[]; // Degree symbol -extern const char udc_TM_T[]; // Trademark T -extern const char udc_TM_M[]; // Trademark M +//extern const char udc_TM_T[]; // Trademark T +//extern const char udc_TM_M[]; // Trademark M //extern const char udc_Bat_Hi[]; // Battery Full //extern const char udc_Bat_Ha[]; // Battery Half @@ -65,8 +67,9 @@ extern const char udc_AC[]; // AC Power extern const char udc_smiley[]; // Smiley -//extern const char udc_droopy[]; // Droopey -//extern const char udc_note[]; // Note +//extern const char udc_droopy[]; // Droopey +//extern const char udc_note[]; // Note +//extern const char udc_note_off[]; // Note Off //extern const char udc_bar_1[]; // Bar 1 //extern const char udc_bar_2[]; // Bar 11 @@ -82,8 +85,22 @@ //extern const char udc_ch_mo[]; // Month (kana) //extern const char udc_ch_dy[]; // Day (kana) //extern const char udc_ch_mi[]; // minute (kana) -extern const char udc_None[]; -extern const char udc_All[]; + +//extern const char udc_bell[]; +//extern const char udc_note[]; +//extern const char udc_clock[]; +//extern const char udc_heart[]; +//extern const char udc_duck[]; +//extern const char udc_check[]; +//extern const char udc_cross[]; +//extern const char udc_retarrow[]; +//extern const char udc_OK[]; // Ok +//extern const char udc_1_2[]; // 1/2 +//extern const char udc_Euro[]; // Euro symbol +//extern const char udc_key[]; // Key symbol + +//extern const char udc_None[]; +//extern const char udc_All[]; #endif /* LCD_UDC Examples */ #endif // MBED_TEXTLCDUDC_H \ No newline at end of file
diff -r ce348c002929 -r 9585a1cce408 TextLCD_UDC.inc --- a/TextLCD_UDC.inc Sun Mar 29 13:08:03 2015 +0000 +++ b/TextLCD_UDC.inc Mon Apr 10 07:48:10 2017 +0000 @@ -1,6 +1,8 @@ /* mbed TextLCD Library, for LCDs based on HD44780 controllers * Copyright (c) 2014, WH * 2014, v01: WH, Extracted from TextLCD.cpp as of v14 + * 2015, v02: WH, Added some UDC definitions and commented out several UDCs + * 2015, v03: WH, Added some UDC definitions * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -39,12 +41,12 @@ // 1 x Enabled pixels in P0..P4 will blink /** Some sample User Defined Chars 5x7 dots */ -//const char udc_ae[] = {0x00, 0x00, 0x1B, 0x05, 0x1F, 0x14, 0x1F, 0x00}; //æ -//const char udc_0e[] = {0x00, 0x00, 0x0E, 0x13, 0x15, 0x19, 0x0E, 0x00}; //ø -//const char udc_ao[] = {0x0E, 0x0A, 0x0E, 0x01, 0x0F, 0x11, 0x0F, 0x00}; //å -//const char udc_AE[] = {0x0F, 0x14, 0x14, 0x1F, 0x14, 0x14, 0x17, 0x00}; //Æ -//const char udc_0E[] = {0x0E, 0x13, 0x15, 0x15, 0x15, 0x19, 0x0E, 0x00}; //Ø -//const char udc_Ao[] = {0x0E, 0x0A, 0x0E, 0x11, 0x1F, 0x11, 0x11, 0x00}; //Å +//const char udc_ae[] = {0x00, 0x00, 0x1B, 0x05, 0x1F, 0x14, 0x1F, 0x00}; //テヲ +//const char udc_0e[] = {0x00, 0x00, 0x0E, 0x13, 0x15, 0x19, 0x0E, 0x00}; //テク +//const char udc_ao[] = {0x0E, 0x0A, 0x0E, 0x01, 0x0F, 0x11, 0x0F, 0x00}; //テ・ +//const char udc_AE[] = {0x0F, 0x14, 0x14, 0x1F, 0x14, 0x14, 0x17, 0x00}; //テ� +//const char udc_0E[] = {0x0E, 0x13, 0x15, 0x15, 0x15, 0x19, 0x0E, 0x00}; //テ� +//const char udc_Ao[] = {0x0E, 0x0A, 0x0E, 0x11, 0x1F, 0x11, 0x11, 0x00}; //テ� //const char udc_PO[] = {0x04, 0x0A, 0x0A, 0x1F, 0x1B, 0x1B, 0x1F, 0x00}; //Padlock Open //const char udc_PC[] = {0x1C, 0x10, 0x08, 0x1F, 0x1B, 0x1B, 0x1F, 0x00}; //Padlock Closed @@ -63,10 +65,10 @@ const char udc_6[] = {0x15, 0x0a, 0x15, 0x0a, 0x15, 0x0a, 0x15, 0x00}; // checkerboard const char udc_7[] = {0x10, 0x08, 0x04, 0x02, 0x01, 0x00, 0x10, 0x00}; // \ -const char udc_degr[] = {0x06, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00}; // Degree symbol +//const char udc_degr[] = {0x06, 0x09, 0x09, 0x06, 0x00, 0x00, 0x00, 0x00}; // Degree symbol -const char udc_TM_T[] = {0x1F, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; // Trademark T -const char udc_TM_M[] = {0x11, 0x1B, 0x15, 0x11, 0x00, 0x00, 0x00, 0x00}; // Trademark M +//const char udc_TM_T[] = {0x1F, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00}; // Trademark T +//const char udc_TM_M[] = {0x11, 0x1B, 0x15, 0x11, 0x00, 0x00, 0x00, 0x00}; // Trademark M //const char udc_Bat_Hi[] = {0x0E, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Full //const char udc_Bat_Ha[] = {0x0E, 0x11, 0x13, 0x17, 0x1F, 0x1F, 0x1F, 0x00}; // Battery Half @@ -79,9 +81,11 @@ const char udc_Bat_Lo[] = {0x8E, 0x91, 0x91, 0x91, 0x91, 0x9F, 0x9F, 0x00}; // Battery Low, Blink const char udc_AC[] = {0x0A, 0x0A, 0x1F, 0x11, 0x0E, 0x04, 0x04, 0x00}; // AC Power -const char udc_smiley[] = {0x00, 0x0A, 0x00, 0x04, 0x11, 0x0E, 0x00, 0x00}; // Smiley -//const char udc_droopy[] = {0x00, 0x0A, 0x00, 0x04, 0x00, 0x0E, 0x11, 0x00}; // Droopey -//const char udc_note[] = {0x01, 0x03, 0x05, 0x09, 0x0B, 0x1B, 0x18, 0x00}; // Note +//const char udc_smiley[] = {0x00, 0x0A, 0x00, 0x04, 0x11, 0x0E, 0x00, 0x00}; // Smiley +//const char udc_droopy[] = {0x00, 0x0A, 0x00, 0x04, 0x00, 0x0E, 0x11, 0x00}; // Droopey +//const char udc_note[] = {0x01, 0x03, 0x05, 0x09, 0x0B, 0x1B, 0x18, 0x00}; // Note +//const char udc_note[] = {0x06, 0x04, 0x04, 0x04, 0x0C, 0x1C, 0x08, 0x00}; // Note +//const char udc_note_off[] = {0x16, 0x04, 0x04, 0x06, 0x0D, 0x1C, 0x08, 0x00}; // Note Off //const char udc_bar_1[] = {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00}; // Bar 1 //const char udc_bar_2[] = {0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00}; // Bar 11 @@ -98,15 +102,19 @@ //const char udc_ch_dy[] = {0x1f, 0x11, 0x11, 0x1f, 0x11, 0x11, 0x11, 0x1F}; // Day (kana) //const char udc_ch_mi[] = {0x0C, 0x0a, 0x11, 0x1f, 0x09, 0x09, 0x09, 0x13}; // minute (kana) -//const char udc_bell[] = {0x04,0x0E,0x0E,0x0E,0x1F,0x00,0x04}; -//const char udc_note[] = {0x02,0x03,0x02,0x0E,0x1E,0x0C,0x00}; -//const char udc_clock[] = {0x00,0x0E,0x15,0x17,0x11,0x0E,0x00}; -//const char udc_heart[] = {0x00,0x0a,0x1F,0x1F,0x0E,0x04,0x00}; -//const char udc_duck[] = {0x00,0x0c,0x1D,0x0F,0x0F,0x06,0x00}; -//const char udc_check[] = {0x00,0x01,0x03,0x16,0x1C,0x08,0x00}; -//const char udc_cross[] = {0x00,0x1B,0x0E,0x04,0x0E,0x1B,0x00}; -//const char udc_retarrow[] = {0x01,0x01,0x05,0x09,0x1f,0x08,0x04}; +//const char udc_bell[] = {0x04, 0x0E, 0x0E, 0x0E, 0x1F, 0x00, 0x04, 0x00}; +//const char udc_note[] = {0x02, 0x03, 0x02, 0x0E, 0x1E, 0x0C, 0x00, 0x00}; +//const char udc_clock[] = {0x00, 0x0E, 0x15, 0x17, 0x11, 0x0E, 0x00, 0x00}; +//const char udc_heart[] = {0x00, 0x0a, 0x1F, 0x1F, 0x0E, 0x04, 0x00, 0x00}; +//const char udc_duck[] = {0x00, 0x0c, 0x1D, 0x0F, 0x0F, 0x06, 0x00, 0x00}; +//const char udc_check[] = {0x00, 0x01, 0x03, 0x16, 0x1C, 0x08, 0x00, 0x00}; +//const char udc_cross[] = {0x00, 0x1B, 0x0E, 0x04, 0x0E, 0x1B, 0x00, 0x00}; +//const char udc_retarrow[] = {0x01, 0x01, 0x05, 0x09, 0x1f, 0x08, 0x04, 0x00}; +//const char udc_OK[] = {0x08, 0x14, 0x14, 0x08, 0x05, 0x06, 0x05, 0x05}; // OK +//const char udc_1_2[] = {0x11, 0x12, 0x17, 0x09, 0x13, 0x04, 0x07, 0x00}; // 1/2 +//const char udc_Euro[] = {0x06, 0x09, 0x08, 0x1E, 0x1E, 0x08, 0x09, 0x06}; // Euro symbol +//const char udc_key[] = {0x07, 0x07, 0x04, 0x04, 0x0E, 0x11, 0x0E, 0x00}; // Key symbol -const char udc_None[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; -const char udc_All[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; +//const char udc_None[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +//const char udc_All[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; #endif /* UDC_EXAMPLES */
diff -r ce348c002929 -r 9585a1cce408 TextLCD_UTF8.inc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD_UTF8.inc Mon Apr 10 07:48:10 2017 +0000 @@ -0,0 +1,124 @@ +/* mbed TextLCD Library, for LCDs based on HD44780 controllers + * Copyright (c) 2015, WH + * 2015, v01: WH, AR. Added UTF8 decode tables for Cyrilic font (by Andriy Ribalko). + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef MBED_TEXTLCDUTF8_INC +#define MBED_TEXTLCDUTF8_INC + +#include "TextLCD_Config.h" + +#if(LCD_UTF8_FONT == 1) +// Code by Andriy Ribalko +// UTF8 conversion, please add other tables for your language +// See wikipedia.org/wiki/UTF-8 and www.utf8-chartable.de + +//The two tables below are used to map UTF8 codes onto character codes for an LCD controller that +//supports a specific fonttable. The UTF codes for a specific language like Cyrilic are between 0x0400 and 0x04FF. + +//Select one table for a specific controller and language + +#if(0) +//Table for controller xxxx +//The two tables below are used to map Cyrilic/Russian UTF8 codes onto character codes for an LCD controller that +//supports a Cyrilic fonttable. The UTF codes for Cyrilic are between 0x0400 and 0x04FF + +#define UTF_FIRST 0x0400 +#define UTF_LAST 0x04FF +#define UTF_SEQ_REC_FIRST utf_seq_rec_first_cyr +#define UTF_SEQ_REC_LAST utf_seq_rec_last_cyr +#define UTF_SEQ_RECODE utf_seq_recode_cyr +#define UTF_RND_RECODE utf_rnd_recode_cyr + +#define utf_seq_rec_first_cyr 0x0410 //UTF code of first symbol in sequential table UTF_recode +#define utf_seq_rec_last_cyr 0x044F //UTF code of last symbol in sequential table UTF_recode + +const char utf_seq_recode_cyr[] = { + 0x41,0xa0,0x42,0xa1, 0xe0,0x45,0xa3,0xa4, 0xa5,0xa6,0x4b,0xa7, 0x4d,0x48,0x4f,0xa8, //Upper case Cyrillic + 0x50,0x43,0x54,0xa9, 0xaa,0x58,0xe1,0xab, 0xac,0xe2,0xad,0xae, 0x62,0xaf,0xb0,0xb1, + 0x61,0xb2,0xb3,0xb4, 0xe3,0x65,0xb6,0xb7, 0xb8,0xb9,0xba,0xbb, 0xbc,0xbd,0x6f,0xbe, //Lower case Cyrillic + 0x70,0x63,0xbf,0x79, 0xe4,0x78,0xe5,0xc0, 0xc1,0xe6,0xc2,0xc3, 0xc4,0xc5,0xc6,0xc7 + }; + +//Two dimensional table for some non-sequential symbol decoding (RUS/UKR) +//U+0401 --> 0xa2 (ミ�), U+0451 --> 0xb5 (ム�), U+0406 --> 0x49 (ミ�), U+0456 --> 0x69 (ム�) +const short int utf_rnd_recode_cyr [5][2]= { + {0x0401, 0xa2}, + {0x0451, 0xb5}, + {0x0406, 0x49}, + {0x0456, 0x69}, + {0} //Last element table zero + }; +#endif + +#if(LCD_UTF8_CYR_B == 1) +//ROM_B Table for controller SSD1803 and US2066 +//The two tables below are used to map Cyrilic/Russian UTF8 codes onto character codes for an LCD controller that +//supports a Cyrilic fonttable. The UTF codes for Cyrilic are between 0x0400 and 0x04FF + +#define UTF_FIRST 0x0400 +#define UTF_LAST 0x04FF +#define UTF_SEQ_REC_FIRST utf_seq_rec_first_cyr +#define UTF_SEQ_REC_LAST utf_seq_rec_last_cyr +#define UTF_SEQ_RECODE utf_seq_recode_cyr +#define UTF_RND_RECODE utf_rnd_recode_cyr + +#define utf_seq_rec_first_cyr 0x0410 //UTF code of first symbol in sequential table UTF_recode +#define utf_seq_rec_last_cyr 0x044F //UTF code of last symbol in sequential table UTF_recode +const char utf_seq_recode_cyr[] = { + 0x80,0x81,0x82,0x83, 0x84,0x85,0x86,0x87, 0x88,0x89,0x8A,0x8B, 0x8C,0x8D,0x8E,0x8F, //Upper case Cyrillic + 0x90,0x91,0x92,0x93, 0x94,0x95,0x96,0x97, 0x98,0x99,0x9A,0x9B, 0x9C,0x9D,0x9E,0x9F, + 0x61,0x81,0x62,0x83, 0x84,0x65,0x86,0x87, 0x88,0x89,0x6B,0x8B, 0x6D,0x69,0x6F,0x8F, //Lower case Cyrillic (~Upper) + 0x70,0x63,0x92,0x79, 0x94,0x95,0x96,0x97, 0x98,0x99,0x9A,0x9B, 0x9C,0x9D,0x9E,0x9F + }; + +//Two dimensional table for some non-sequential symbol decoding (RUS/UKR) +//U+0400 --> 0xC8 (E) +//U+0401 --> 0xCB (ミ�) +//U+0405 --> 0x53 (S) +//U+0406 --> 0x49 (ミ�) +//U+0407 --> 0xCF (ミ�) +//U+0408 --> 0x4A (J) +//U+0450 --> 0xE8 ( ) +//U+0451 --> 0xEB (ム�) +//U+0456 --> 0x69 (ム�) +//U+0457 --> 0xCF (ム�) +//U+0458 --> 0x6A (j) +const short int utf_rnd_recode_cyr [][2]= { + {0x0400, 0xC8}, + {0x0401, 0xCB}, + {0x0405, 0x53}, + {0x0406, 0x49}, + {0x0407, 0xCF}, + {0x0408, 0x4A}, + {0x0450, 0xE8}, + {0x0451, 0xEB}, + {0x0456, 0x69}, + {0x0457, 0xCF}, + {0x0458, 0x6A}, + {0 , 0} //Last element table zero + }; +#endif + + +//end UTF conversion +#endif + +#endif \ No newline at end of file