Multiple I2C Adapters (LCD_IO 12)

Introduction:

Connection mode 12 supports up to four I2C LCD adapters, each addressed independently.

The system variable LCD_I2C_Address_Current specifies which adapter’s address subsequent LCD write actions target. To use multiple adapters, define an address for each one, then set LCD_I2C_Address_Current to the address of the adapter you want to write to next.

Command Availability:

Available on all microcontrollers, using LCD_IO connection mode 12.

Example:

    ' ----- Define Hardware settings
    ' Define I2C settings - CHANGE PORTS
    #define I2C_MODE Master
    #define I2C_DATA PORTC.4
    #define I2C_CLOCK PORTC.5
    #define I2C_DISABLE_INTERRUPTS ON

    'Set up LCD
    #define LCD_IO 12
    #define LCD_WIDTH 20                ;specified lcd width for clarity only.  20 is the default width
    #define LCD_I2C_Address_1 0x4E ; LCD 1
    #define LCD_I2C_Address_2 0x4C ; LCD 2
    #define LCD_I2C_Address_3 0x4A ; LCD 3
    #define LCD_I2C_Address_4 0x49 ; LCD 4

    ;Change to the correct LCD by setting
    ;LCD_I2C_Address_Current to the correct address then write to LCD.
    LCD_I2C_Address_Current = LCD_I2C_Address_1
    Print "Adapter #1"
    LCD_I2C_Address_Current = LCD_I2C_Address_2
    Print "Adapter #2"
    LCD_I2C_Address_Current = LCD_I2C_Address_3          ' <<< switching the active adapter this page documents
    Print "Adapter #3"
    LCD_I2C_Address_Current = LCD_I2C_Address_4
    Print "Adapter #4"
    wait 4 s
    LCD_I2C_Address_Current = LCD_I2C_Address_1: CLS
    LCD_I2C_Address_Current = LCD_I2C_Address_2: CLS
    LCD_I2C_Address_Current = LCD_I2C_Address_3: CLS
    LCD_I2C_Address_Current = LCD_I2C_Address_4: CLS

Key line: LCD_I2C_Address_Current = LCD_I2C_Address_3 — writing to LCD_I2C_Address_Current redirects every subsequent LCD command to a different physical adapter, without needing four separate sets of LCD write commands.

See Also: