The Acme Systems shipping office will be closed for holidays from 14 august to 22 august
PLEASE NOTE: This article is obsolete or related to a discontinued product.

Using the I2C driver to access a HD44780 LCD

Schematic

First of all you will have to get a PCF8574 I/O port expander from phillips. The next step is to solder the following circuit.

Writing code to access the LCD

The following code initialises the LCD and outputs some data on it
#include "stdio.h"
#include "stdlib.h"
#include "unistd.h"
#include "sys/ioctl.h"
#include "fcntl.h"
#include "time.h"
#include "string.h"
#include "asm/etraxi2c.h"

// Global variables
int fd_i2c;

int I2C_Open(void) {
      fd_i2c = open("/dev/i2c", O_RDWR);
      if (fd_i2c <= 0) {
          printf("I2C: open error on /dev/i2c\n");
          return(-1);
     }

     return(0);
}

void I2C_Close(void) {
     close(fd_i2c);
}

int main(int argc, char **argv) {
        int retcode;

        retcode = I2C_Open();
        if (retcode != 0) {
                exit(1);
        }

        I2C_LCD i2clcd;
        i2clcd.slave=64;
        i2clcd.x = 1;
        i2clcd.y = 1;
        sprintf(i2clcd.text, "Hello World");
        ioctl(fd_i2c, _IO(ETRAXI2C_IOCTYPE, I2C_LCDINIT), &i2clcd);
        ioctl(fd_i2c, _IO(ETRAXI2C_IOCTYPE, I2C_LCDPRINT), &i2clcd);
        i2clcd.y = 2;
        i2clcd.x = 3;
        ioctl(fd_i2c, _IO(ETRAXI2C_IOCTYPE, I2C_LCDPRINT), &i2clcd);

        I2C_Close();

        return(0);
};