Updated for more display types. Fixed memoryaddress confusion in address() method. Added new getAddress() method. Added support for UDCs, Backlight control and other features such as control through I2C and SPI port expanders and controllers with native I2C and SPI interfaces. Refactored to fix issue with pins that are default declared as NC.
Dependents: GPSDevice TestTextLCD SD to Flash Data Transfer DrumMachine ... more
Fork of TextLCD by
Example
Hello World! for the TextLCD
#include "mbed.h" #include "TextLCD.h" // Host PC Communication channels Serial pc(USBTX, USBRX); // tx, rx // I2C Communication I2C i2c_lcd(p28,p27); // SDA, SCL // SPI Communication SPI spi_lcd(p5, NC, p7); // MOSI, MISO, SCLK //TextLCD lcd(p15, p16, p17, p18, p19, p20); // RS, E, D4-D7, LCDType=LCD16x2, BL=NC, E2=NC, LCDTCtrl=HD44780 //TextLCD_SPI lcd(&spi_lcd, p8, TextLCD::LCD40x4); // SPI bus, 74595 expander, CS pin, LCD Type TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD20x4); // I2C bus, PCF8574 Slaveaddress, LCD Type //TextLCD_I2C lcd(&i2c_lcd, 0x42, TextLCD::LCD16x2, TextLCD::WS0010); // I2C bus, PCF8574 Slaveaddress, LCD Type, Device Type //TextLCD_SPI_N lcd(&spi_lcd, p8, p9); // SPI bus, CS pin, RS pin, LCDType=LCD16x2, BL=NC, LCDTCtrl=ST7032_3V3 //TextLCD_I2C_N lcd(&i2c_lcd, ST7032_SA, TextLCD::LCD16x2, NC, TextLCD::ST7032_3V3); // I2C bus, Slaveaddress, LCD Type, BL=NC, LCDTCtrl=ST7032_3V3 int main() { pc.printf("LCD Test. Columns=%d, Rows=%d\n\r", lcd.columns(), lcd.rows()); for (int row=0; row<lcd.rows(); row++) { int col=0; pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); // lcd.putc('-'); lcd.putc('0' + row); for (col=1; col<lcd.columns()-1; col++) { lcd.putc('*'); } pc.printf("MemAddr(Col=%d, Row=%d)=0x%02X\n\r", col, row, lcd.getAddress(col, row)); lcd.putc('+'); } // Show cursor as blinking character lcd.setCursor(TextLCD::CurOff_BlkOn); // Set and show user defined characters. A maximum of 8 UDCs are supported by the HD44780. // They are defined by a 5x7 bitpattern. lcd.setUDC(0, (char *) udc_0); // Show |> lcd.putc(0); lcd.setUDC(1, (char *) udc_1); // Show <| lcd.putc(1); }
Handbook page
More info is here
Revision 41:111ca62e8a59, committed 2015-11-06
- Comitter:
- wim
- Date:
- Fri Nov 06 18:59:27 2015 +0000
- Parent:
- 40:d3496c3ea301
- Commit message:
- Added setFont() support (for SSD1803, US2066, ST7070) and support for UTF-8 code (Cyrillic language), added SPLC792A controller.
Changed in this revision
--- a/TextLCD.cpp Wed May 20 18:46:51 2015 +0000 +++ b/TextLCD.cpp Fri Nov 06 18:59:27 2015 +0000 @@ -22,6 +22,8 @@ * 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 @@ -44,6 +46,7 @@ #include "mbed.h" #include "TextLCD.h" #include "TextLCD_UDC.inc" +#include "TextLCD_UTF8.inc" /** Create a TextLCD_Base interface * @@ -54,13 +57,13 @@ // 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 @@ -76,11 +79,13 @@ 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 @@ -97,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 @@ -149,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 @@ -264,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) @@ -291,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) @@ -309,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) @@ -332,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 @@ -363,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 @@ -399,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 { @@ -1318,7 +1345,65 @@ // 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 @@ -1399,6 +1484,7 @@ */ 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 @@ -1413,6 +1499,7 @@ _ctrl_idx=_LCDCtrl_0; // Select primary controller } + // Primary LCD controller Clearscreen _writeCommand(0x01); // cls, and set cursor to 0 @@ -1423,6 +1510,13 @@ 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. @@ -1461,11 +1555,23 @@ } else { //Character to write -#if (LCD_DEF_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()) { @@ -1474,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 @@ -1490,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 @@ -1497,24 +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 -//LCD_C_FT2 for PCF21XXR series +//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; + 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 @@ -1657,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. @@ -1852,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) { @@ -1886,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 @@ -1935,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 @@ -1959,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 @@ -2116,6 +2306,7 @@ } // 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 @@ -2148,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 @@ -2185,6 +2377,7 @@ break; } // end switch } // end setContrast() +#endif #if(LCD_POWER == 1) /** Set Power @@ -2498,6 +2691,104 @@ } // 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 * @@ -2544,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) @@ -2642,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++) { @@ -2966,6 +3259,7 @@ // 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 |= LCD_BUS_I2C_E; // Set E bit @@ -2982,6 +3276,16 @@ _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) @@ -3086,46 +3390,6 @@ } #endif -#if(0) -//orig v017 -// 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) { - - // Set bit by bit to support any mapping of expander portpins to LCD pins - if (value & 0x01){ - _lcd_bus |= LCD_BUS_I2C_D4; // Set Databit - } - else { - _lcd_bus &= ~LCD_BUS_I2C_D4; // Reset Databit - } - - if (value & 0x02){ - _lcd_bus |= LCD_BUS_I2C_D5; // Set Databit - } - else { - _lcd_bus &= ~LCD_BUS_I2C_D5; // Reset Databit - } - - if (value & 0x04) { - _lcd_bus |= LCD_BUS_I2C_D6; // Set Databit - } - else { - _lcd_bus &= ~LCD_BUS_I2C_D6; // Reset Databit - } - - if (value & 0x08) { - _lcd_bus |= LCD_BUS_I2C_D7; // Set Databit - } - else { - _lcd_bus &= ~LCD_BUS_I2C_D7; // Reset Databit - } -} -#endif - -#if(1) -//orig v017, with optimised codesize // 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 @@ -3151,7 +3415,7 @@ _lcd_bus |= LCD_BUS_I2C_D7; // Set Databit } } -#endif + // Place the 4bit data on the databus // Used for mbed pins, I2C bus expander or SPI shifregister
--- a/TextLCD.h Wed May 20 18:46:51 2015 +0000 +++ b/TextLCD.h Fri Nov 06 18:59:27 2015 +0000 @@ -22,6 +22,8 @@ * 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 @@ -87,41 +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 -#define LCD_T_R6 0x00000600 +// 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) */ @@ -132,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, C */ -#define LCD_C_FT2 0x00002000 /*Font2, R */ +#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 * @@ -168,7 +192,7 @@ // 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) */ + 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 */ @@ -177,7 +201,7 @@ 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 */ + 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) */ @@ -191,10 +215,10 @@ 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 */ +// 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 */ + 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 */ @@ -203,12 +227,15 @@ 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 */ + 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 }; @@ -222,19 +249,20 @@ 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 */ -// PCF2116C_3V3 = | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_FT1), /**< PCF2116C 3V3 with Booster, 4/8 bit, I2C */ -// PCF2116K_3V3 = | (LCD_C_PAR | LCD_C_I2C | LCD_C_BST | LCD_C_FT2), /**< PCF2116K 3V3 with Booster, 4/8 bit, I2C */ +// 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_FT1), /**< PCF2116C 3V3 with 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_FT1), /**< 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_FT2), /**< PCF2119R 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, 4/8 bit, SPI3 */ + 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 */ @@ -242,16 +270,17 @@ 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 */ // 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 */ + 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 */ @@ -278,6 +307,7 @@ Bottom /**< Upside down view */ }; +#if (LCD_BIGFONT == 1) /** LCD BigFont control, supported for some Controllers */ enum LCDBigFont { None, /**< no lines */ @@ -286,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 @@ -399,6 +467,7 @@ 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 @@ -407,6 +476,7 @@ * @return none */ void setContrast(unsigned char c = LCD_DEF_CONTRAST); +#endif #if(LCD_POWER == 1) /** Set Power @@ -435,10 +505,22 @@ * @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 *
--- a/TextLCD_Config.h Wed May 20 18:46:51 2015 +0000 +++ b/TextLCD_Config.h Fri Nov 06 18:59:27 2015 +0000 @@ -8,6 +8,8 @@ * 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 @@ -50,9 +52,16 @@ #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 PCF2116C, PCF2119R) -#define LCD_DEF_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. @@ -510,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 @@ -520,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 @@ -552,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
--- a/TextLCD_UDC.h Wed May 20 18:46:51 2015 +0000 +++ b/TextLCD_UDC.h Fri Nov 06 18:59:27 2015 +0000 @@ -2,6 +2,7 @@ * 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 @@ -66,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 @@ -95,6 +97,7 @@ //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[];
--- a/TextLCD_UDC.inc Wed May 20 18:46:51 2015 +0000 +++ b/TextLCD_UDC.inc Fri Nov 06 18:59:27 2015 +0000 @@ -2,6 +2,7 @@ * 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 @@ -80,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 @@ -110,6 +113,7 @@ //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};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD_UTF8.inc Fri Nov 06 18:59:27 2015 +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