I2C 1602 LCD display for WC8

CAI_Support

Senior Member
This I2C based LCD display could be connected to I2C port on WC8 for displaying things through I2C commands:
 

http://www.ebay.com/itm/251592029465


 
Anybody has any interest on that?  It will need to have initialization routine, then send out to LCD 4 bit at a time.  If you have a lot of string to display, it will probably need to have external EEPROM to store them.
 
Okay,  we will test out and put out some PLC command sequences. 
There are two parts in this process. One is PCF8574T chip, that does I2C to parallel 8 bit communication.
Another part is talk to LCD controller HD44780 in nibbles through the I2C chip.
The trick talking to LCD is that LCD is a slow device, so that PLC code must delay a lot to make sure it done executing last command over the nibble.
 
LCD with PCF8574T is wired so that only upper nibble is connected to higher four bits of the parallel port.
The lower four bits are wired to RS, RW, E, BackLight control bits.
The wiring sequence are:
bit#   pin#   LCDpin#   function
0        4              4          R/S
1        5              5          R/W
2        6              6          E
3        7
4        9              11        D4
5        10            12        D5
6        11            13        D6
7        12            14        D7
 
From this wiring, we can only write upper nibble at a time. If we want to send to LCD a byte, we need to send through the PLC command twice
First, send upper 4 bits, then lower 4 bits 
We will need to have a write function to do that.
After initialization, we can write the location address, then the byte to display at that location,
Two line LCD byte locations are 0x00 to 0x0F, and 0x40 to 0x4F
 
We will need to develop LCD write nibble subroutine, LCD write byte subroutine, LCD read byte subroutine.
 
On the PCF8574T I2C adapter board, there are 3 pairs of solder pads, labeled A0, A1, A2.
By default, they are not connected, flow at high 4.81V.
If you do not solder any of those pads, the default I2C address is 0x4E for write to, 0x4F for read
 
On the LCD side, after power on, it will require >15ms wait time before communicate with the LCD.
The initialization sequences are:
power on
wait >15ms after VDD >4,5V
 
write nibble 0x3
 
wait  5ms
 
write nibble 0x3
 
wait > 100us
 
write nibble 0x3  ; function set starts
write nibble 0x2  ; 4 bit mode
 
write nibble 0x2  ; 4 bit mode
write nibble 0x8  ;  two line display, 5x8 matrix display font
 
wait > 4ms
write nibble 0x0  ; write, instruction register
write nibble 0x8  ; display off
 
wait > 4ms
write nibble 0x0  , write, instruction register
write nibble 0x1 ; clear all display
 
wait > 4ms
write nibble 0x0  ; write, instruction register
write nibble 0x6 ; enter mode set, cursor increment, and no display shifting
 
wait > 4ms
finish initialization.
 
 
 
E bit only used for data read and write, also R/W only for data and address.  All instruction send to LCD with RS bit 0 to indicate the communication for instruction, not data.
 
Hmm, I need some help to get this running.
Is it possible to display the value of a temp sensor, or can it only display values from a I2C device?
A example code for initialization, and getting something to show up in the display would be great!
 
Sure, I will work on that one step at a time. First I showed initialization sequence, then I will show how to do that in PLC. I will test it the code before upload here.
After initialization code, I will show how to display a character at certain location on the LCD. 
Basically, after initialization, you tell the LCD the address you want to write, then send data bytes. 
If a sequence of characters to display, you can specify the first address, then start sending data.
I hope users by reading this topic understanding the low level action, so that they can work on their own code by themselves later on.
 
initialization code are like this:
 

START
callsub lcd_init
tasks:
# you tasks go to here
goto tasks
end

LCD_INIT:
DELAY 15
I2CWRITE 1 0 0x4E #tell module we are write
I2CWRITE 0 0 0x30 #first nibble
I2CWRITE 0 0 0x34 #stobe bit on
I2CWRITE 0 0 0x30 #strobe off
DELAY 5
I2CWRITE 0 0 0x30 #first nibble
I2CWRITE 0 0 0x34 #stobe bit on
I2CWRITE 0 0 0x30 #strobe off
DELAY 1
I2CWRITE 0 0 0x30 #function set starts
I2CWRITE 0 0 0x34 #stobe bit on
I2CWRITE 0 0 0x20 #4 bit mode
I2CWRITE 0 0 0x24 #stobe bit on
I2CWRITE 0 0 0x20 # 4 bit mode
I2CWRITE 0 0 0x24 #stobe bit on
I2CWRITE 0 0 0x80 # two line display, 5x8 matrix display font
I2CWRITE 0 0 0x84 #stobe bit on
DELAY 4
I2CWRITE 0 0 0x00 # write, instruction register
I2CWRITE 0 0 0x04 #stobe bit on
I2CWRITE 0 0 0x80 # display off
I2CWRITE 0 0 0x84 #stobe bit on
DELAY 4
I2CWRITE 0 0 0x00 # write, instruction register
I2CWRITE 0 0 0x04 #stobe bit on
I2CWRITE 0 0 0x10 # clear all display
I2CWRITE 0 0 0x14 #stobe bit on
DELAY 4
I2CWRITE 0 0 0x00 # write, instruction register
I2CWRITE 0 0 0x04 #stobe bit on
I2CWRITE 0 0 0x60 # enter mode set, cursor increment, and no display shifting
I2CWRITE 0 0 0x64 #stobe bit on
DELAY 4
RET

 
compare this to the above #6.
 
Somehow those sequence did not work.  We did logic analyzer capture and working with LCD factory engineers to see where is the problem.  We will get this work and publish the working PLC program.  Thanks for your patience.
 
Thanks, that's great!
It will be a great addon where the plc is not connected to a pc. I have a project using a WC32 to control temperature for de-ice a pavement and outdoor steps in concrete.
I am using the WC32 since I need to set the temperatures after the conditions. I will even add a rain sensor to monitor snow. It will then over-run the temperature readings.
With a WC8 and display I can get it to work using a wireless remote to configure the choosen settings.
 
Just update on this. We have connection to the LCD manufacture who provided us LCD engineering resources to analyze our PLC command. They think the sequences sent to LCD are alright. However, since it is not working in our test. The assigned engineer will get exact I2C module to test.  Please be patience.
We are committed to make this work, just taking a longer time than we thought due to 3rd party I2C LCD module.
 
START
CALLSUB LCD_INIT
DELAY 4
SET RAM20 0x80 # address first line, first byte
CALLSUB LCD_CMD
SET RAM20 0x30 # data byte ascii code for 0
CALLSUB LCD_DATA
TASKS:
SET VAR2 T1
GOTO TASKS
END

LCD_INIT:
DELAY 20
I2CWRITE 1 0 78 #I2C address
I2CWRITE 0 0 0x38 #write 0x3 lit on
I2CWRITE 0 0 0x3C #E bit on
I2CWRITE 0 0 0x38 #write 0x3
DELAY 7
I2CWRITE 0 0 0x38 #write 0x3
I2CWRITE 0 0 0x3C #E bit on
I2CWRITE 0 0 0x38 #write 0x3
DELAY 1
SET RAM20 0x32 # still part of init
CALLSUB LCD_CMD
DELAY 5
SET RAM20 0x28 # 4 bit, 2 line, font size 5x8
CALLSUB LCD_CMD
DELAY 5
SET RAM20 8 #display off
CALLSUB LCD_CMD
DELAY 5
SET RAM20 1 # return home
CALLSUB LCD_CMD
DELAY 5
SET RAM20 6 # entry mode on
CALLSUB LCD_CMD
DELAY 5
SET RAM20 0xF #display on, cursor on, blink on
CALLSUB LCD_CMD
RET

LCD_CMD:
ANDB RAM20 0xF0 RAM21 #upper nibble
ORB RAM21 8 RAM21 #turn on lit
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM21
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
ROTL RAM20 4 RAM21 #move to upper nibble
ANDB RAM21 0xF0 RAM21 #only upper 4 bit
ORB RAM21 8 RAM21 #turn on lit
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM21
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
RET

LCD_DATA:
ANDB RAM20 0xF0 RAM21 #upper nibble
ORB RAM21 9 RAM21 #turn on lit, R/S bit on
I2CWRITE 0 0 RAM21
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
ROTL RAM20 4 RAM21 #move up 4 bits
ANDB RAM21 0xF0 RAM21 #upper nibble
ORB RAM21 9 RAM21 #turn on lit, R/S bit on
I2CWRITE 0 0 RAM21
ORB RAM21 4 RAM22 #E bit on
I2CWRITE 0 0 RAM22
I2CWRITE 0 0 RAM21
DELAY 1
RET



We got answer from LCD factory after exam the I2C module, the p3 pin has to be 1 to turn on the back light.  We modified the PLC code.  It display 0 at first line, first byte location....
 
Is it possible for you to creat a step by step topic to show how use this device, I'm very interrested but i need to know the base.
 
 
Thank you !!!
 
In 3.02.18Bx and 3.02.18Dx firmware, both have I2C support.  3.02.18Dx firmware also has SPI bus support.
This particular LCD is I2C connection, that work for both 3.02.18Bx and 3.02.18Dx firmware.  This example was done on the 3.02.18B4 firmware.
The I2C connection can be seen on the user guide page 2:

http://www.cainetworks.com/manuals/webcontrol/WebControlPLCUserGuide3-02-18d.pdf

SCL and SDA connect to LCD module SCL and SDA, GND is connected to pin1 of the humidity sensor, VCC is  5V, in this test, we also connected to the humidity sensor pin3.  Please note, because LCD using a lot of current, this will cause 5V regulator heating up, using separate 5V power supply is recommended.  If you temporarily use 5V on board, please make sure add heatsink to the 5V regulator.
 
After wiring up the LCD and WC8, paste this PLC code into PLC window, you will see LCD from power on display one row, then to two row with 0 displayed on row 0, position 0.
 
This PLC program using 3 RAM bytes, RAM20, RAM21, and RAM22.  If your program already used up those 3 bytes, you can change them to other RAM bytes.  RAM20 is the byte of command or data send to LCD, RAM21 and RAM22 just intermediate temporary storage.
 
 
If you have any other question about this PLC code or setup, please ask here. 
 
Back
Top