and here if you have pbp3
http://support.melabs.com/threads/98...F8574-20x4-LCD
and here if you have pbp3
http://support.melabs.com/threads/98...F8574-20x4-LCD
Great, thank you. Lots of information in those posts.
Hmm, I am still having difficulty with this even after reading the above referenced threads.
I am working with PBP 3.0.7.0 and a pic 12F629. I am able to get the code writen by norohs (above) to work but I am having difficulty figuring it all out so that I can modify it for my own use.
Basically, I'd like to send some data and or ascii from my 12F629 to my LCD1602 via the I2C "adapter".
Can someone give me a bit more guidance?
you might get something from this
http://support.melabs.com/threads/1075-I2C-to-LCD
or tell us more on what your trying to achieve and post your code (in code tags)
I also found this code written by norohs difficult to work out and eventually I decided that it works more by accident than design and that there has to be a better way of doing this. This is what I worked out.
The LCD works in four bit mode which makes every byte sent a four bit control nibble plus a nibble of data. To send a byte of data two bytes have to be sent consisting of a control nibble plus high data nibble then control nibble plus low data nibble.
To send "H" which is $48
requires two LCDWRITE instructions
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $48
GOSUB LCDWRITE
In each instruction the first 4 after the $ sets the R/W bit to write and $48 is made up from the 4 and 8 in red.
and "D" would be
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
and to print "DHD" would be
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $48
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
LCD_CMD = $44
GOSUB LCDWRITE
Looking at the LCDWRITE
LCDWRITE:
I2CWRITE D,C,ADDR,[LCD_CMD]
E=1
I2CWRITE D,C,ADDR,[LCD_CMD]
E=0
I2CWRITE D,C,ADDR,[LCD_CMD]
RETURN
each command is sent three times with E=0 then E=1 then E=0 which I think is an error, the first line is not needed.
LCDWRITE:
E=1
I2CWRITE D,C,ADDR,[LCD_CMD]
E=0
I2CWRITE D,C,ADDR,[LCD_CMD]
RETURN
but you can test this.
Why send it twice? On the LCD with the E bit set to 1 the data is loaded into a buffer and E has to change from 1 to 0 for the data to be transferred to the screen which is why the second instruction is required.
I decided to look for a better solution as I was not totally confident that the above was correct.
Darrel Taylor came to the rescue here
http://support.melabs.com/threads/98...F8574-20x4-LCD
As you can see from this not all Arduino LCDs are wired the same. The control and data nibbles can be either data/control or control/data.
johncouture worked this out for us in the thread above.
Steve Earl www.datageo.co.uk
EarlyBird2, your reply has helped me understand this a bit more. I was able to get the norohs code to work without the initial I2CWRITE command as you suggested.
Darrel Taylor's program seems to be a work of art but I think with the INCLUDE, it's just too big for my 12F629 as I am getting, "Unable to fit variable" errors.
I have been able to use the lcdout command to write data to my LCD1602. My goal is to do the same with the i2cwrite command.
I will try to get a better understanding of how to send the control commands by studying Darrel's code.
I think what I am trying to figure out is...
Hey, you need to initialize the LCD to nibble / 4 bit mode by sending I2CWRITE commands with code $xx, ...
then to turn on the backlight you need to I2CWRITE $yy (mabe needs 2 commands for high and low nibbles)
to send data you need to I2CWRITE highNibble, then I2CWRITE lowNibble...
I will reread the thread you referenced, http://support.melabs.com/threads/98...F8574-20x4-LCD
I did not realise you were using a pic12f the dt code won't work on those chips becauseDarrel Taylor's program seems to be a work of art but I think with the INCLUDE, it's just too big for my 12F629 as I am getting, "Unable to fit variable" errors.
ARRAYWRITE is not supported on 12-bit core PIC MCUs due to RAM and stack
constraints
I believe Darrel Taylor was using a 12F1822. Doesn't that have the same "bit core" as my 12F629?
According to the Microchip datasheet on the 12F1822,
"This family of devices contains an enhanced mid-range 8-bit CPU core"
Bookmarks