I2C I/O expander and LCD support

CAI_Support

Senior Member
We start this topic for PCF8574 based IO expander chip and LCD module support for WC8.
PCF8574 is a I2C remote 8 bit IO expander IC.  That is being widely used in a lot of parallel LCD module to I2C converter.
 
That chip's datasheet can be viewed here:
http://www.nxp.com/documents/data_sheet/PCF8574.pdf
 
Those module's default I2C address is 0x20.  This chip seems can be easily write to that address with write flag, then followed with data, or read from the address with read flag, then following the byte being read.
 
Most LCD requires writing the configuration first, wait for a long delay, then write in four bits at a time, so that each byte will need to write two bytes, first lower nibble shift up, then higher nibble.
 
 
When starting to write to LCD, suppose using the default I2C to LCD module address 0x20, sends first command
I2CWRITE   1   0  0x20
 
I2C address is 7 bit. lowest bit on that address byte is read/write flag.  Normally, write flag is zero, read flag is one.
By issuing above command, you tell the chip that you will send data to it.  The next write will follow data byte.
I2CWRITE   0    0   xy
Please notice the first parameter is zero now, to indicate this is not a new write, the 2nd parameter is zero to indicate this is not end of write.
The last byte will have ONE in 2nd parameter to indicate the write is finished.
I2CWRITE   0    1   xy
 
When read from the chip, the same module will have address byte 0x21, that is ORed with READ flag in the address byte.
When read,  you still have to start with write command to tell the slave I2C device you are reading now
 
I2CWRITE   1  0  0x21
then followed by read command
I2CREAD    0   0  RAM1
 
Where RAM1 or any RAM or VAR will be the byte read back from the device.
 
Last read also should have end flag to tell slave that master is done with reading from it.
I2CREAD   0    1   RAM1
 
When working with LCD, please use a separate 5V power to power LCD and the I2C module, since WC8 5V can not provide so much current for the LCD and I2C module.
 
Back
Top