I2C LCD Displays with PCF8574

Post here to discuss programming with swordfish basic

Moderators: Chuckt, Garth, bitfogav

Post Reply
User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

I2C LCD Displays with PCF8574

Post by bitfogav » Wed Jun 17, 2020 12:14 am

1602lcd.jpg
1602lcd.jpg (72.87 KiB) Viewed 252 times
I just wanted to share that I have added a new module for Swordfish so you can now use the cheap LCD displays with the I2C PCF8574 chip boards :D

Link to the I2C LCD Swordfish page
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

Garth
I practically live here!
I practically live here!
Posts: 224
Joined: Wed Jan 16, 2013 1:17 pm
Contact:

Re: I2C LCD Displays with PCF8574

Post by Garth » Wed Jun 17, 2020 4:47 am

That looks nice. Do you sell the I²C module? I don't see any way to buy it. Actually, I'm sure it could be used for a lot of other things besides an LCD, right? And there are undoubtedly a lot of I²C-to-parallel adapter ICs on the market, probably from Maxim and others; but this one is already made up on a little board with the trimmer for the viewing angle too. I didn't see a voltage. Is it 5V? I think most LCDs still are 5V, but I have not been paying much attention in recent years. Is there a data sheet? [Edit: Never mind. I found the PCF8574 data sheet, at https://www.nxp.com/docs/en/data-sheet/ ... F8574A.pdf.] Your sample code is very neatly formatted, but it's not a language I'm familiar with. I've used LCDs based on the Hitachi controller many times since 1986 (I like that it's so stable; very few things are made for so many decades, just working and working!), and I have my own code in 6502 assembly and in Forth, as well as I²C driver code, so if I can see just the few details of what the board needs to make the conversion, I'm all set. I would like to add it to the displays page of my 6502 primer, at http://wilsonminesco.com/6502primer/displays.html, if my visitors can buy it.
http://WilsonMinesCo.com/ lots of 6502 resources

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: I2C LCD Displays with PCF8574

Post by bitfogav » Wed Jun 17, 2020 6:01 am

Hi Garth..
Thanks for your comments and kind words, Yes they are 5v devices, I think the PCF8574 will even run at 3.3v (I've not tested), but I don't know if that will have any effect on the LCD (I will have to test that).
No I don't actually sell the I2C module or LCD, for me here in the UK they are widely spread around sale websites, Amazon, Ebay etc..
But you can get a HD44780 LCD and PCF8574 breakout board separately and bind them together, which is basically all these are..

The PCF8574 is just a I2C to Parallel-Port Expander chip. You only have 7 pins on the PCF8574 connected to the LCD pins, This is all you need, as we setup the LCD in 4bit mode, and control the LCD control lines via the other 3 pins from the PCF8574.

When you send data to the LCD via the PCF8574 you have to take into consideration the RS,EN and E pins, and make changes to the data byte that you send, which involve a lot of bitwise logic.
I'm sorry I'm not very familiar with 6502 assembly, I did do pic assembly but that must be about 10 years ago now, and I found it very limited or time consuming, that's why I changed to Swordfish or mostly C these days.

If its any help then this is how the PCF8574 is wired to the LCD display, if there is anything I can help with then Ill try my best.
pici2cpcf8574.png
pici2cpcf8574.png (15.29 KiB) Viewed 246 times
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

Garth
I practically live here!
I practically live here!
Posts: 224
Joined: Wed Jan 16, 2013 1:17 pm
Contact:

Re: I2C LCD Displays with PCF8574

Post by Garth » Wed Jun 17, 2020 6:48 am

Thanks. I've usually used these LCDs in 4-bit mode, with 6 lines (just grounding the R/W, which just means you have to give it enough delay that you know each instruction is finished, since you can't poll it). I have working sample code in different forms at http://wilsonminesco.com/6502primer/LCDcode.asm, although I see I don't have PIC16 code there which I thought I did have. I do really like I²C, and SPI too.

As for assembly language, I make heavy use of macros to effectively raise the level of the language, including with Forth-like program-flow-control structures, which really make things a lot more clear and eliminate most of the labels. PIC16's have a lot of mickeymousities; but terrible processor aside, Microchip had a lot of attractions that other suppliers didn't have in the mid-1990's, and these got me started putting PICs in products. This was before microcontrollers were ubiquitous, and back when most microcontrollers were very expensive to get started developing on. Microchip offered a free assembler, workbench programmability, lots of onboard processor support like the power-up timer and watchdog timer in addition to the usual complement of other timers and I/O, lots of versions in stock at lots of distributors, etc.. In almost all cases, the macros assemble exactly the same thing I would do by hand; but they hide many of those PIC16 mickeymousities and in other ways just reduce the length of the source code. This raises programmer productivity, reduces bugs (because you can see what you're doing better), improves code maintainability, etc., with, in most cases, no penalty in run speed or in memory taken. I have examples of similar macros' usage in 6502 code in the last 40% of my page on simple methods for multitasking at http://wilsonminesco.com/multitask/ . See especially WATCH_ACIA, XFER_TM_2_ACCb, and KEY_TASK. You'll find they hardly look like assembly language. The last time I put an LCD with the Hitachi 44780 controller in a product was six years ago, and again it was with a PIC16, multitasking.
http://WilsonMinesCo.com/ lots of 6502 resources

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: I2C LCD Displays with PCF8574

Post by bitfogav » Wed Jun 17, 2020 8:26 am

Garth wrote:
Wed Jun 17, 2020 6:48 am
Thanks. I've usually used these LCDs in 4-bit mode, with 6 lines (just grounding the R/W, which just means you have to give it enough delay that you know each instruction is finished, since you can't poll it). I have working sample code in different forms at http://wilsonminesco.com/6502primer/LCDcode.asm, although I see I don't have PIC16 code there which I thought I did have. I do really like I²C, and SPI too.
Thanks for sharing that information and links, it was interesting to read about 6502..
The PCF8574 comes in two versions PCF8574/A - the only difference is how the address works.
I've only worked with PCF8574 and its very easy to work with, to send data to it you just have to send the address, then followed by the 8 bit data..
To read from it, I just send out the address + setting the last bit to send out the read mode.. I'm sure you aware of that so I don't want to bore you..

I don't do any reading from the HD44780 LCD or check the busy flag, I just make sure that my HD44780 LCD configuration code and sending HD44780 LCD data have enough delay so that the HD44780 LCD has enough time to carry out the instructions. For sending the commands and data to the LCD via the PCF8574 it was just a case of sending out two 8 bits of data which included the configuration of RS,RW,E bits. I hope this is enough to get you started.
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

Garth
I practically live here!
I practically live here!
Posts: 224
Joined: Wed Jan 16, 2013 1:17 pm
Contact:

Re: I2C LCD Displays with PCF8574

Post by Garth » Wed Jun 17, 2020 8:47 am

It sounds pretty easy. If its I²C clock rate is limited to 100kHz (max of 12.5KB per second), you won't be overrunning the LCD's ability to keep up for most instructions, especially with the 4-bit interface. I should probably get some of those ICs to have on hand and play with.
http://WilsonMinesCo.com/ lots of 6502 resources

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: I2C LCD Displays with PCF8574

Post by bitfogav » Thu Jun 18, 2020 12:38 am

I was thinking late last night and I forgot to mention the LCD backlight control. I know I said the PCF8574 only uses 7 pins, that's not totally true. I forgot to mention PCF8574 P3 is actually the LCD backlight control.. So I stand corrected, the PCF8574 uses all 8 pins to control the LCD. So the schematics above isn't totally correct. That will teach me for searching on google for the schematics and assume its correct. :oops:
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest