Question

I have an HD44780 LCD screen, and I've been using the LiquidCrystal Library provided with the Arduino development package. However, it's not reliable. I noticed some problems with it, and instead of being interrupt driven, it just sleeps as long as the developer thinks the chip should take to execute the operation.

From the spec sheets, the BUSY flag will be set while it is executing, meaning it is possible to be interrupt driven.

Does anyone know of a library that actually does this, and does it require all 8 bits to be connected or can I keep it at 4 pins?

Was it helpful?

Solution

I don't think you need an interrupt for this. Looking at LiquidCrystal.cpp in the Arduino distribution, you just need to change the LiquidCrystal::write4bits, LiquidCrystal::write8bits, and LiquidCrystal::pulseEnable code. The first two methods should start by monitoring the busy line (BD7) before writing data, and the last one would be modified to remove the 100us pause.

I think the reason this wasn't done in the default code is that many users of these LCDs just tie R/W to ground so the display is always in write mode, making it impossible to read the BUSY signal. However, this is passed into the library by setting _rw_pin to -1, so the pulse and write code can conditionally use the r/w pin as a way of detecting busy as a speed optimization.

OTHER TIPS

It is possible to use 8 bit on three pins; you just need a shift register. I'm using a HEF4094BP from mouser.com (shipping is going to cost more than the actual chip)

the wiring diagram and code modifications for the shift register are here: http://www.arduino.cc/playground/Code/LCD3wires

Some time ago I modified the LiquidCrystal lib to support the busy flag. Please note that real interrupt driven operation is not possible - for each read you need to toggle the Enable line twice. Therefore you will need to poll the busy flag.

Then I did some benchmarks an found, that polling the busy flag is slower than just waiting for most commands. (The exception are the 'clear' and 'home' commands). The reason was, that switching between read mode and write mode requires aditional steps like 8 additional calls to digitaWrite and 8 additional calls to pinMode. Even with 16MHz Arduinos this slower than just waiting 100µs.

After that I wrote a library that manipulates the pin registers directly and in bulk mode - all 8 pins with one register access. After that I was in the ballpark to get some benefit by polling.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top