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

Dependents:   STM32_Button_Interrupt_dla_taty

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TextLCD_Config.h Source File

TextLCD_Config.h

00001 /* mbed TextLCD Library, for LCDs based on HD44780 controllers
00002  * Copyright (c) 2014, WH
00003  *               2014, v01: WH, Extracted from TextLCD.h as of v14
00004  *               2014, v02: WH, Added AC780 support, added I2C expander modules, fixed setBacklight() for inverted logic modules. Fixed bug in LCD_SPI_N define
00005  *               2014, v03: WH, Added LCD_SPI_N_3_8 define for ST7070
00006  *               2015, v04: WH, Added support for alternative fonttables (eg PCF21XX)
00007  *               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 
00008  *
00009  * Permission is hereby granted, free of charge, to any person obtaining a copy
00010  * of this software and associated documentation files (the "Software"), to deal
00011  * in the Software without restriction, including without limitation the rights
00012  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
00013  * copies of the Software, and to permit persons to whom the Software is
00014  * furnished to do so, subject to the following conditions:
00015  *
00016  * The above copyright notice and this permission notice shall be included in
00017  * all copies or substantial portions of the Software.
00018  *
00019  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00020  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00021  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
00022  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
00023  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00024  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
00025  * THE SOFTWARE.
00026  */
00027 #ifndef MBED_TEXTLCDCONFIG_H
00028 #define MBED_TEXTLCDCONFIG_H
00029 
00030 //Select hardware interface options to reduce memory footprint (multiple options allowed)
00031 #define LCD_I2C        1           /* I2C Expander PCF8574/MCP23008 */
00032 #define LCD_SPI        1           /* SPI Expander SN74595          */
00033 #define LCD_I2C_N      1           /* Native I2C bus     */
00034 #define LCD_SPI_N      1           /* Native SPI bus     */
00035 #define LCD_SPI_N_3_8  1           /* Native SPI bus     */
00036 #define LCD_SPI_N_3_9  1           /* Native SPI bus     */
00037 #define LCD_SPI_N_3_10 1           /* Native SPI bus     */
00038 #define LCD_SPI_N_3_16 1           /* Native SPI bus     */
00039 #define LCD_SPI_N_3_24 1           /* Native SPI bus     */
00040 
00041 //Select options to reduce memory footprint (multiple options allowed)
00042 #define LCD_UDC        1           /* Enable predefined UDC example*/                
00043 #define LCD_PRINTF     1           /* Enable Stream implementation */                
00044 
00045 //Select option to activate default fonttable or alternatively use conversion for specific controller versions (eg PCF2119C)
00046 #define LCD_DEFAULT_FONT 1      
00047 
00048 //Pin Defines for I2C PCF8574/PCF8574A or MCP23008 and SPI 74595 bus expander interfaces
00049 //Different commercially available LCD portexpanders use different wiring conventions.
00050 //LCD and serial portexpanders should be wired according to the tables below.
00051 //
00052 //Select Serial Port Expander Hardware module (one option only)
00053 #define DEFAULT        0
00054 #define ADAFRUIT       0
00055 #define DFROBOT        0
00056 #define YWROBOT        0
00057 #define GYLCD          0
00058 #define SYDZ           0
00059 #define ARDUINO        1
00060 
00061 #if (ARDUINO==1)
00062 //Definitions for Arduino I2C PCF8574 mapping port expander pins and LCD controller
00063 //This hardware supports the I2C bus expander (PCF8574/PCF8574A or MCP23008) and SPI bus expander (74595) interfaces
00064 //See https://mbed.org/cookbook/Text-LCD-Enhanced
00065 //
00066 //Note: LCD RW pin must be connected to GND
00067 //      E2 is used for LCD40x4 (second controller)
00068 //      BL may be used to control backlight
00069 
00070 #define D_LCD_PIN_RS   0
00071 #define D_LCD_PIN_E2   1
00072 #define D_LCD_PIN_E    2
00073 #define D_LCD_PIN_BL   3
00074 #define D_LCD_PIN_D4   4
00075 #define D_LCD_PIN_D5   5
00076 #define D_LCD_PIN_D6   6
00077 #define D_LCD_PIN_D7   7
00078 
00079 #define D_LCD_PIN_RW   D_LCD_PIN_E2
00080 
00081 //Select I2C Portexpander type (one option only)
00082 #define PCF8574        1
00083 #define MCP23008       0
00084 
00085 //Inverted Backlight control
00086 #define BACKLIGHT_INV  0
00087 #endif
00088 
00089 
00090 #if (DEFAULT==1)
00091 //Definitions for default (WH) mapping between serial port expander pins and LCD controller
00092 //This hardware supports the I2C bus expander (PCF8574/PCF8574A or MCP23008) and SPI bus expander (74595) interfaces
00093 //See https://mbed.org/cookbook/Text-LCD-Enhanced
00094 //
00095 //Note: LCD RW pin must be connected to GND
00096 //      E2 is used for LCD40x4 (second controller)
00097 //      BL may be used to control backlight
00098 #define D_LCD_PIN_D4   0
00099 #define D_LCD_PIN_D5   1
00100 #define D_LCD_PIN_D6   2
00101 #define D_LCD_PIN_D7   3
00102 #define D_LCD_PIN_RS   4
00103 #define D_LCD_PIN_E    5
00104 #define D_LCD_PIN_E2   6
00105 #define D_LCD_PIN_BL   7
00106 
00107 #define D_LCD_PIN_RW   D_LCD_PIN_E2
00108 
00109 //Select I2C Portexpander type (one option only)
00110 #define PCF8574        1
00111 #define MCP23008       0
00112 
00113 //Inverted Backlight control
00114 #define BACKLIGHT_INV  0
00115 #endif
00116 
00117 #if (ADAFRUIT==1)
00118 //Definitions for Adafruit i2cspilcdbackpack mapping between serial port expander pins and LCD controller
00119 //This hardware supports both an I2C expander (MCP23008) and an SPI expander (74595) selectable by a jumper.
00120 //Slaveaddress may be set by solderbridges (default 0x40). SDA/SCL has pullup Resistors onboard.
00121 //See http://www.ladyada.net/products/i2cspilcdbackpack
00122 //
00123 //Note: LCD RW pin must be kept LOW
00124 //      E2 is not available on this hardware and so it does not support LCD40x4 (second controller)
00125 //      BL is used to control backlight
00126 #define D_LCD_PIN_0    0
00127 #define D_LCD_PIN_RS   1
00128 #define D_LCD_PIN_E    2
00129 #define D_LCD_PIN_D4   3
00130 #define D_LCD_PIN_D5   4
00131 #define D_LCD_PIN_D6   5
00132 #define D_LCD_PIN_D7   6
00133 #define D_LCD_PIN_BL   7
00134 
00135 #define D_LCD_PIN_E2   D_LCD_PIN_0
00136 
00137 //Force I2C portexpander type
00138 #define PCF8574        0
00139 #define MCP23008       1
00140 
00141 //Inverted Backlight control
00142 #define BACKLIGHT_INV  0
00143 #endif
00144 
00145 #if (DFROBOT==1)
00146 //Definitions for DFROBOT LCD2004 Module mapping between serial port expander pins and LCD controller
00147 //This hardware uses PCF8574 and is different from earlier/different Arduino I2C LCD displays
00148 //Slaveaddress hardwired to 0x4E. SDA/SCL has pullup Resistors onboard.
00149 //See http://arduino-info.wikispaces.com/LCD-Blue-I2C
00150 //
00151 //Definitions for DFROBOT V1.1 
00152 //This hardware uses PCF8574. Slaveaddress may be set by jumpers (default 0x40).
00153 //SDA/SCL has pullup Resistors onboard and features a voltage level converter 3V3 <-> 5V.
00154 //See http://www.dfrobot.com/index.php?route=product/product&product_id=135
00155 //
00156 //
00157 //Note: LCD RW pin must be kept LOW
00158 //      E2 is not available on default Arduino hardware and so it does not support LCD40x4 (second controller)
00159 //      BL is used to control backlight
00160 #define D_LCD_PIN_RS   0
00161 #define D_LCD_PIN_RW   1
00162 #define D_LCD_PIN_E    2
00163 #define D_LCD_PIN_BL   3
00164 #define D_LCD_PIN_D4   4
00165 #define D_LCD_PIN_D5   5
00166 #define D_LCD_PIN_D6   6
00167 #define D_LCD_PIN_D7   7
00168 
00169 #define D_LCD_PIN_E2   D_LCD_PIN_RW
00170 
00171 //Force I2C portexpander type
00172 #define PCF8574        1
00173 #define MCP23008       0
00174 
00175 //Inverted Backlight control
00176 #define BACKLIGHT_INV  0
00177 #endif
00178 
00179 #if (YWROBOT==1)
00180 //Definitions for YWROBOT LCM1602 V1 Module mapping between serial port expander pins and LCD controller. 
00181 //Very similar to DFROBOT. This hardware uses PCF8574.
00182 //Slaveaddress may be set by solderbridges (default 0x4E). SDA/SCL has no pullup Resistors onboard.
00183 //See http://arduino-info.wikispaces.com/LCD-Blue-I2C
00184 //
00185 //Note: LCD RW pin must be kept LOW
00186 //      E2 is not available on default hardware and so it does not support LCD40x4 (second controller)
00187 //      BL is used to control backlight, reverse logic: Low turns on Backlight. This is handled in setBacklight()
00188 #define D_LCD_PIN_RS   0
00189 #define D_LCD_PIN_RW   1
00190 #define D_LCD_PIN_E    2
00191 #define D_LCD_PIN_BL   3
00192 #define D_LCD_PIN_D4   4
00193 #define D_LCD_PIN_D5   5
00194 #define D_LCD_PIN_D6   6
00195 #define D_LCD_PIN_D7   7
00196 
00197 #define D_LCD_PIN_E2   D_LCD_PIN_RW
00198 
00199 //Force I2C portexpander type
00200 #define PCF8574        1
00201 #define MCP23008       0
00202 
00203 //Inverted Backlight control
00204 #define BACKLIGHT_INV  0
00205 #endif
00206 
00207 #if (GYLCD==1)
00208 //Definitions for Arduino-IIC-LCD GY-LCD-V1 Module mapping between serial port expander pins and LCD controller. 
00209 //Very similar to DFROBOT. This hardware uses PCF8574.
00210 //Slaveaddress may be set by solderbridges (default 0x4E). SDA/SCL has pullup Resistors onboard.
00211 //See http://arduino-info.wikispaces.com/LCD-Blue-I2C
00212 //
00213 //Note: LCD RW pin must be kept LOW
00214 //      E2 is not available on default hardware and so it does not support LCD40x4 (second controller)
00215 //      BL is used to control backlight, reverse logic: Low turns on Backlight. This is handled in setBacklight()
00216 #define D_LCD_PIN_D4   0
00217 #define D_LCD_PIN_D5   1
00218 #define D_LCD_PIN_D6   2
00219 #define D_LCD_PIN_D7   3
00220 #define D_LCD_PIN_EN   4
00221 #define D_LCD_PIN_RW   5
00222 #define D_LCD_PIN_RS   6
00223 #define D_LCD_PIN_BL   7
00224 
00225 #define D_LCD_PIN_E2   D_LCD_PIN_RW
00226 
00227 //Force I2C portexpander type
00228 #define PCF8574        1
00229 #define MCP23008       0
00230 
00231 //Force Inverted Backlight control
00232 #define BACKLIGHT_INV  1
00233 #endif
00234 
00235 #if (SYDZ==1)
00236 //Definitions for SYDZ Module mapping between serial port expander pins and LCD controller. 
00237 //Very similar to DFROBOT. This hardware uses PCF8574A and uses inverted Backlight control
00238 //Slaveaddress may be set by switches (default 0x40). SDA/SCL has pullup Resistors onboard.
00239 //See ebay
00240 //
00241 //Note: LCD RW pin must be kept LOW
00242 //      E2 is not available on default hardware and so it does not support LCD40x4 (second controller)
00243 //      BL is used to control backlight, reverse logic: Low turns on Backlight. This is handled in setBacklight()
00244 #define D_LCD_PIN_RS   0
00245 #define D_LCD_PIN_RW   1
00246 #define D_LCD_PIN_E    2
00247 #define D_LCD_PIN_BL   3
00248 #define D_LCD_PIN_D4   4
00249 #define D_LCD_PIN_D5   5
00250 #define D_LCD_PIN_D6   6
00251 #define D_LCD_PIN_D7   7
00252 
00253 #define D_LCD_PIN_E2   D_LCD_PIN_RW
00254 
00255 //Force I2C portexpander type
00256 #define PCF8574        1
00257 #define MCP23008       0
00258 
00259 //Force Inverted Backlight control
00260 #define BACKLIGHT_INV  1
00261 #endif
00262 
00263 //Bitpattern Defines for I2C PCF8574/PCF8574A, MCP23008 and SPI 74595 Bus expanders
00264 //Don't change!
00265 //
00266 #define D_LCD_D4       (1<<D_LCD_PIN_D4)
00267 #define D_LCD_D5       (1<<D_LCD_PIN_D5)
00268 #define D_LCD_D6       (1<<D_LCD_PIN_D6)
00269 #define D_LCD_D7       (1<<D_LCD_PIN_D7)
00270 #define D_LCD_RS       (1<<D_LCD_PIN_RS)
00271 #define D_LCD_E        (1<<D_LCD_PIN_E)
00272 #define D_LCD_E2       (1<<D_LCD_PIN_E2)
00273 #define D_LCD_BL       (1<<D_LCD_PIN_BL)
00274 //#define D_LCD_RW       (1<<D_LCD_PIN_RW)
00275 
00276 #define D_LCD_BUS_MSK  (D_LCD_D4 | D_LCD_D5 | D_LCD_D6 | D_LCD_D7)
00277 #define D_LCD_BUS_DEF  0x00
00278 
00279 /* PCF8574/PCF8574A I2C portexpander slave address */
00280 #define PCF8574_SA0    0x40
00281 #define PCF8574_SA1    0x42
00282 #define PCF8574_SA2    0x44
00283 #define PCF8574_SA3    0x46
00284 #define PCF8574_SA4    0x48
00285 #define PCF8574_SA5    0x4A
00286 #define PCF8574_SA6    0x4C
00287 #define PCF8574_SA7    0x4E
00288 
00289 #define PCF8574A_SA0   0x70
00290 #define PCF8574A_SA1   0x72
00291 #define PCF8574A_SA2   0x74
00292 #define PCF8574A_SA3   0x76
00293 #define PCF8574A_SA4   0x78
00294 #define PCF8574A_SA5   0x7A
00295 #define PCF8574A_SA6   0x7C
00296 #define PCF8574A_SA7   0x7E
00297 
00298 /* MCP23008 I2C portexpander slave address */
00299 #define MCP23008_SA0   0x40
00300 #define MCP23008_SA1   0x42
00301 #define MCP23008_SA2   0x44
00302 #define MCP23008_SA3   0x46
00303 #define MCP23008_SA4   0x48
00304 #define MCP23008_SA5   0x4A
00305 #define MCP23008_SA6   0x4C
00306 #define MCP23008_SA7   0x4E
00307 
00308 /* MCP23008 I2C portexpander internal registers */
00309 #define IODIR          0x00
00310 #define IPOL           0x01
00311 #define GPINTEN        0x02
00312 #define DEFVAL         0x03
00313 #define INTCON         0x04
00314 #define IOCON          0x05
00315 #define GPPU           0x06
00316 #define INTF           0x07
00317 #define INTCAP         0x08
00318 #define GPIO           0x09
00319 #define OLAT           0x0A
00320 
00321 /* ST7032i I2C slave address */
00322 #define ST7032_SA      0x7C
00323 
00324 /* ST7036i I2C slave address */
00325 #define ST7036_SA0     0x78
00326 #define ST7036_SA1     0x7A
00327 #define ST7036_SA2     0x7C
00328 #define ST7036_SA3     0x7E
00329 
00330 /* ST7066_ACM I2C slave address, Added for ACM1602 module  */
00331 #define ST7066_SA0     0xA0
00332 
00333 /* PCF21XX I2C slave address */
00334 #define PCF21XX_SA0    0x74
00335 #define PCF21XX_SA1    0x76
00336 
00337 /* AIP31068 I2C slave address */
00338 #define AIP31068_SA    0x7C
00339 
00340 /* SSD1803 I2C slave address */
00341 #define SSD1803_SA0    0x78
00342 #define SSD1803_SA1    0x7A
00343 
00344 /* US2066/SSD1311 I2C slave address */
00345 #define US2066_SA0     0x78
00346 #define US2066_SA1     0x7A
00347 
00348 /* AC780 I2C slave address */
00349 #define AC780_SA0      0x78
00350 #define AC780_SA1      0x7A
00351 #define AC780_SA2      0x7C
00352 #define AC780_SA3      0x7E
00353 
00354 //Some native I2C controllers dont support ACK. Set define to '0' to allow code to proceed even without ACK
00355 //#define LCD_I2C_ACK    0
00356 #define LCD_I2C_ACK    1
00357 
00358 
00359 // Contrast setting, 6 significant bits (only supported for controllers with extended features)
00360 // Voltage Multiplier setting, 2 or 3 significant bits (only supported for controllers with extended features)
00361 #define LCD_DEF_CONTRAST    0x20
00362 
00363 //ST7032 EastRising ERC1602FS-4 display
00364 //Contrast setting 6 significant bits
00365 //Voltage Multiplier setting 3 significant bits
00366 #define LCD_ST7032_CONTRAST 0x28 
00367 #define LCD_ST7032_RAB      0x04
00368 
00369 //ST7036 EA DOGM1603 display
00370 //Contrast setting 6 significant bits
00371 //Voltage Multiplier setting 3 significant bits
00372 #define LCD_ST7036_CONTRAST 0x28
00373 #define LCD_ST7036_RAB      0x04
00374 
00375 //SSD1803 EA DOGM204 display
00376 //Contrast setting 6 significant bits
00377 //Voltage Multiplier setting 3 significant bits
00378 #define LCD_SSD1_CONTRAST   0x28
00379 #define LCD_SSD1_RAB        0x06
00380 
00381 //US2066/SSD1311 EastRising ER-OLEDM2002-4 display
00382 //Contrast setting 8 significant bits, use 6 for compatibility
00383 #define LCD_US20_CONTRAST   0x3F
00384 //#define LCD_US20_CONTRAST   0x1F
00385 
00386 //PCF2113, PCF2119 display
00387 //Contrast setting 6 significant bits
00388 //Voltage Multiplier setting 2 significant bits
00389 #define LCD_PCF2_CONTRAST   0x20
00390 #define LCD_PCF2_S12        0x02
00391 
00392 //PT6314 VFD display
00393 //Contrast setting 2 significant bits, use 6 for compatibility
00394 #define LCD_PT63_CONTRAST   0x3F
00395 
00396 
00397 #endif //MBED_TEXTLCDCONFIG_H