Jump to content
43oh

LCD-I2C For HD44780 LCDs and PCF8574 Expanders


Recommended Posts

Soo, I got busy. Tested the lcd out with my i2c explorer, and then coded up a i2c based lcd controller. It works well enough to initialize and write to an lcd, even commands. At this point, it just runs a test, and that's it. Will be trying to add a RX uart soon (since the biggest code hog was the i2c read routine [i2c.c was about 1k in i2c-explorer] it should fit fine), but it is all setup for 4bit lcd control, and separate functions for lcd commands and lcd data. Two port pins on the expander are still free, and could be used for a larger lcd with 2 enable pins, or reseting the lcd (with a pnp? needs some testing to figure out how to force it to hardware reset) or the same for the led backlight (5v, nearly 300ma from what I read. Could use an extra resistor and/or npn for control.). But you can't do all three from the i2c expander (6 used, 2 free). But the launchpad still has 4 free gpio (5 if you dont need RX)

 

Did add a small bit of debug tool to it. The expander_write function will turn on led1, go into a while loop, then send the actual data. If the i2c system does not receive an ACK, it will keep looping, trying to send the data again and again, and will keep the led on until a ack is received. So this serves two purposes. If you see the led on for an extended period of time, something is up (It really shouldn't even be fast enough for you to see. i2c is running at a [snail-worthy] 8khz, and 8 bits at a time...), and it allows for some form of error-prevention (Some i2c devices will ignore extra read/write commands when processing internal data, so retrying until it responds is standard procedure).

 

Allows you to control a HD44780 compatible LCD through a simple I2C Port Expander.

Tested on DV-16100-S1FBLY LCD (16x1 lcd, 2 Lines of 8 Characters at a time [Weaksauce, sure, but free. Will test a 40x4 lcd after RX works.])

Used with a TI PCF8574(A for alternative slave addresses) 8bit port expander. No special setup needed for this Port Expander. Others need you to write a port address, and possible setup as outputs.

Created for a MSP430G2231. ~900 bytes of code, so can fit on smaller ones. Created on IAR Kickstart.

 

Displays "cde 43oh" on Line 1, " ^___^ " on Line 2.

 

wrra.th.jpg

 

I2C control based on my own work.

 

Based on work by Michael Bok of http://www.nighsoft.com found at:

http://forum.sparkfun.com/viewtopic.php?t=13656

http://hestia.nighsoft.net/files/L1682_MSP430_code.zip

He wrote up a direct gpio to lcd program for the comparable msp430f2012.

lcd-i2c.zip

Link to post
Share on other sites

Update (already?). Made it a bit more flashy (Literally :D). Changed the delay based on if it is a command instruction, or a data instruction. This makes filling the LCD have a very small delay (2 seconds, maybe 4?) but keeps the commands at a longer delay (makes scrolling look nicer). This essentially turns LED1 into a activity light, with a noticeable flashing to it during repeated Command instructions, and a solid on during repeated data instructions. It still serves debugging purposes, because if its solid on for an extended time, something is up (Like pulling out the i2c cable).

 

But most importantly, I implemented it. With some creative memory offsetting, I turned my essentially 8x2 on a single line, into a 16x1. It will init the lcd, write the first 8 chars of Line 1 (The visible 8 out of 40 memory locations), jump to line 2, write all 40 spots, offset by 8 (Visible 8 spots of line 2 are chars 9-16 of the string), then using the lcd's auto-incrementing (Line 1, char 40 jumps to Line 2, char 1, and vice-versa) re-writes all 40 chars to line 1.

 

Clocks in at ~950 bytes (850 code, + Constants + Variables), so can still fit on smaller ones. Not sure if this can make use of the msp430's low power mode, as it needs to constantly send the shifting command instruction.

 

Flash video of the lcd, from init, to scrolling.

wrra.th.jpgFlash video of the lcd, from init, to scrolling.

 

Sets up the LCD, writes "cde 430h.com ^__^ LCD-I2C + MSP430G2231 " on each line (Offset by 8 on line 2), and scrolls to the left indefinitely.

lcd-i2c v1.5.zip

Link to post
Share on other sites
  • 2 months later...

Hi cde,

I have been testing out a Princeton Technology corp PT6523 lcd display driver I salvaged from a car stereo face. I have read the data sheet and see that there are three pins that need to be controlled by the micro-controller (in my case the msp430). The chip enable pin, clock and the data input pin. I am sure that the board that the chip and lcd is on has all the supporting hardware except the micro-controller. Other then getting the backlight to come on and adjust the brightness of it, I have been unable to talk to the lcd. Can you send me some tips on using lcd's like this?

 

Thanks,

Larry

Link to post
Share on other sites
The chip enable pin, clock and the data input pin.

Sounds like I2C. Have you tried cde's code in this thread?

 

Chip Enable leads me to believe SPI. But then I'd be wrong, er, partly.

 

Found the full datasheet at http://www.princeton.com.tw/downloadpro ... PT6523.pdf

 

The IC is a LCD Segment Driver. Not a character or graphic lcd, but essentially an lcd with set shapes and sizes for the different segments. More like a alphanumeric led works. Nothing like a hd44780 or the nokia spi lcds.

 

That send, it uses three pins in a semi SPI receive only mode (like mixed I2C and SPI. Umm, 2.5wire? Ha). Actually 4 pins, as /INH (Pin 57) allows you to disable display output, when tied to ground.

 

Chip Enable is used to tell the chip to read the last 8 bits clocked in, as the address. If it matches the IC's address, it should listen to the rest of the bits clocked in as data, until Chip Enabled is pulled down again.

 

CLK and DI work just like SPI does. (toggle DI, toggle clk high, wait a usec, toggle clk low, toggle DI, adnusium).

Stick with condition 1 for the Chip Enable (Toggle while clock is low, then wait a couple of usec before continuing to clock in data).

 

Basically, stick with SPI mode for the MSP430's USI. SPI is more flexible than i2c, as i2c is 8 bit only, and requires certain things for the USI. Issue the first 8 bits (0x41) to the USI, then toggle Chip enable high like a normal output, then issue the x amount of segment data you need, and the last 4 control bits, then finally toggle chip enable low.

 

One thing of note. The chip's inputs don't seem to be open drain inputs. And the chip is designed for a 5v power level, and the minimum voltage to recognize a "high/1" compared to ground when is 4v. If you run the chip at it's minimum of 4.5v, you might get away with 3.6, but then again, the LCD itself might not work at less than 5v. You might need transistors to drive the chip's data lines (Not too hard, since it is input only).

 

All that you display, will depend on what the LCD was designed to display. You won't be able to add completely arbitrary data display, though the center of the LCD, where the Station and Source (Cd/Radio/Aux, if it displays them as words) display might go, might be like alphanumeric led displays, if your lucky.

 

All of the above is educated conjecture based on the datasheet though. YMMV.

Link to post
Share on other sites

You hit the nail on the head @cde. The lcd on the stereo face plate is made up of a few alpha-numeric segments and the pre made lcd graphics. The board sports several high brightness LEDs and a dozen small buttons. See the pic below. Also your idea to use transistors to help drive the unit is what I am looking at currently. I had some success with the 5v usb power coming from the launchpad but the 500ma is just not enough. This faceplate is going to be the controller for my beagleboard which is going to be installed inside the DIN housing the rest of the stereo/cd player came out of. The original mcu is a tosihba tmp86f but the msp430 should be able to handle just the lcd, backlight and buttons. There is an IR reciever and headphone jack as well as a rotary dial to use in the design also. I will post a full follow up shortly.post-175-135135495252_thumb.jpg

Link to post
Share on other sites

It's obvious now.

 

Change your board preferences back to "prosilver" and the thumbs will show up.

 

@BlueHash: You should probably remove the choice of "Bl@ck" as a theme option.

 

We should probably prune these theme questions off of this thread and put them into the non-existent "board issues" forum. ;)

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...