LCD_IO 10 provides support for character LCD modules that use an I2C/TWI interface based on the PCF8574 or PCF8574A I/O expander. These I/O expanders are commonly found on low‑cost LCD “I2C backpacks” sold under many brand names (YwRobot, Sainsmart, Joy-It, generic blue/black I2C adapters, etc.).
The PCF8574 device converts an I2C bus signal into 8 digital output lines, which are then wired to the LCD’s RS, EN, D4–D7, and backlight control pins.
LCD_IO 10 implements the correct signalling for this type of I/O expander.
Use LCD_IO 10 whenever your LCD module uses a PCF8574‑based I2C
adapter, regardless of brand or PCB layout. You can configure the specific LCD port layout, if required.
To use mode 10:
- Configure your I2C/TWI pins normally in your GCBASIC program.
- Define the LCD type by using
LCD_IO 10 - Set the I2C address of the PCF8574 adapter, if required. Typical PCF8574 I2C addresses range from 0x40 to 0x4E, depending on the A0–A2 jumper settings on the adapter board.
- Optionally set LCD speed and backlight behaviour.
- Optionally set the LCD port layout.
Relevant Constants
These constants configure the Liquid Crystal Display routines in
GCBASIC. Add them to your main program using #define.
| Constant Name | Controls | Value |
|---|---|---|
|
|
Selects the I/O mode. Must be 10 for PCF8574 I2C LCDs. |
|
|
Constant Name |
Controls |
Default |
|
I2C_LCD_E |
LCD Enable - Expander Port Bit |
|
|
I2C_LCD_RW |
LCD RW - Expander Port Bit |
|
|
I2C_LCD_RS |
LCD RS - Expander Port Bit |
|
|
I2C_LCD_BL |
LCD Back Light - Expander Port Bit |
|
|
I2C_LCD_D4 |
LCD Data Bit4 - Expander Port Bit |
|
|
I2C_LCD_D5 |
LCD Data Bit5 - Expander Port Bit |
|
|
I2C_LCD_D6 |
LCD Data Bit6 - Expander Port Bit |
|
|
I2C_LCD_D7 |
LCD Data Bit7 - Expander Port Bit |
|
|
|
PCF8574 I2C address (A0–A2 = 111) |
|
|
|
PCF8574 I2C address (A0–A2 = 110) |
|
|
|
PCF8574 I2C address (A0–A2 = 101) |
|
|
|
PCF8574 I2C address (A0–A2 = 100) |
|
|
|
PCF8574 I2C address (A0–A2 = 011) |
|
|
|
PCF8574 I2C address (A0–A2 = 010) |
|
|
|
PCF8574 I2C address (A0–A2 = 001) |
|
|
|
PCF8574 I2C address (A0–A2 = 000) |
|
Example Usage
This example demonstrates using two PCF8574‑based I2C LCDs on the same I2C bus. Up to eight LCDs may be connected simultaneously, each with a unique PCF8574 address (0x40–0x4E).
Set up I2C-LCD
#DEFINE LCD_IO 10
/* LCD_IO 10 is for PCF8574-based I2C LCD adapters.
Examples include YwRobot LCD1602 IIC V1, Sainsmart LCD_PIC,
and most generic blue/black I2C LCD backpacks.
LCD_IO 12 is used for adapters based on the Ywmjkdz layout
with the potentiometer bent over the IC.
*/
#DEFINE LCD_I2C_ADDRESS_1 0x4E ' First LCD at address 0x4E
PRINT "Hello World"This example demonstrates using two PCF8574‑based I2C LCDs on the same I2C bus. Up to eight LCDs may be connected simultaneously, each with a unique PCF8574 address (0x40–0x4E).
Set up I2C-LCD
#DEFINE LCD_IO 10
/* LCD_IO 10 is for PCF8574-based I2C LCD adapters.
Examples include YwRobot LCD1602 IIC V1, Sainsmart LCD_PIC,
and most generic blue/black I2C LCD backpacks.
LCD_IO 12 is used for adapters based on the Ywmjkdz layout
with the potentiometer bent over the IC.
*/
#DEFINE LCD_I2C_ADDRESS_1 0x4E ' First LCD at address 0x4E
#DEFINE LCD_I2C_ADDRESS_6 0x44 ' Second LCD at address 0x44
' Switch between LCDs:
LCD_I2C_ADDRESS_Current = LCD_I2C_ADDRESS_6 ' Activate second LCD
PRINT "Hello World"
LCD_I2C_ADDRESS_Current = LCD_I2C_ADDRESS_1 ' Activate first LCD
PRINT "Hello World"See other sections of the Help file for details on alternative connection modes.
For more help, see LCD_IO 0, LCD_IO 1, LCD_IO 2, LCD_IO 2_74xx164, LCD_IO 2_74xx174, LCD_IO 4, LCD_IO 8, LCD_IO 12

