LCD 4bit interface

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

According to the 2x20 LCD HITACHI datasheet, E cycletime must be > 800 ns.

This LCD write routine is executed twice for each 8 bit write and works well

if the delay is 1 mS, with delay = 100 uS neither initializing of anything else works

any idea?

 

;___________________________________________

;WriteLCD4

;write r18     b7,b6,b5,b4 to LCD D7,D6,D5,D4

;      r18       b2 = RS, b3=E

;___________________________________________

WriteLCD4:

ori r18,1<<3 ;E=1

sts PortE_OUT,r18

ldi r20,10

rcall delay100uS

andi r18,0xff-(1<<3) ;E=0

sts PortE_OUT,r18

ldi r20,10

rcall delay100uS

ret

;______________________________________________

 

THe delay100us routine is tested ok, no interrupts.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Most of us use the LCD software by Peter Fleury, http://homepage.hispeed.ch/peter...

You can roll your own if you must, but compare your code to his and pay attention to the delays he uses as they follow the datasheet specs.

LCD's can be finicky if not fed data exactly as the DS says too. 

 

Jim

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

GBaars wrote:
if the delay is 1 mS, with delay = 100 uS neither initializing of anything else works any idea?

 

General hip-shot questions:

 

1. Are you following the special timing requirements that hold for the init sequence?

 

2. How have you verified that your delay100us is correct w.r.t. timing?

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Spent some more time on it, reading

datasheets from begin to end is always a pleasure.

Cleardisplay instruction is an exception with 1.53 mS exec time

and it won't initialize if less. Tcyc=800nS isn't accurate either.

Last Edited: Thu. Oct 5, 2017 - 07:24 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have been working with LCD displays in 4 bit mode for over 16 years.  There is a lot of variation in the delay timing.  The older large displays that I bought 15 years ago surplus need long delays.  Recently I have been playing about with the Arduino (New) LCD Library and a bunch of old surplus displays.  I found I had to change the delay in the library as each display needed a different delay.  A number of these displays came from old vending machines and had a ATMega8535 backing board.  I stripped this board and found they used the standard 14 wire interface.

 

I also wrote an emulator for the HD44780 so I could use a bare wire VFD.  I wanted it to be a drop in replacement.  The code for this is on my github https://github.com/sheepdoll/AVRVFDCLOCK.git. The protocol is basically a shift register state machine. It is quite simple.  I chose to use I2C as I was out of pins on the ATMega328.

 

The delay can also be found by timing the polling bit in the read register.  Normally the read mode is disabled as the delay system is sufficient and saves a number of wires. Getting this timing is a bit more work. More wires are needed. A simple Arduino script makes it practical to get this number. 

Last Edited: Thu. Oct 5, 2017 - 07:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You haven't included many comments so we can only guess....
 

ldi r20,10
rcall delay100uS

 

Are you attempting to achieve a 1 mSec delay by using the value in r20 to call your delay100uS routine 10 times? 

If that is so wouldn't it be a good idea to check the value in r20 at some point?

 

Don

Last Edited: Thu. Oct 5, 2017 - 09:13 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I read unlike the original HD44780's LCD's bought on EBAY for a few euro

have a ST7066 which apparently is some Chinese clone so you never can be sure

what specs they're gonna meet. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

These specs, I expect:

https://www.newhavendisplay.com/...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

GBaars wrote:

I read unlike the original HD44780's LCD's bought on EBAY for a few euro

have a ST7066 which apparently is some Chinese clone so you never can be sure

what specs they're gonna meet. 

 

Yes, the HD44780 is the industry standard, so there are endless clones, that usually have different timings, but in most cases they are faster than the original and/or allow a more sloppy initialization sequence. Here is a link with a (clearly incomplete) list: http://midibox.org/dokuwiki/offl...

 

Usually the display module documentation will tell you which specific clone is used, but for cheap stuff from China most of the time you won't have any documentation, you just know it's HD44780 compatible.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I guess there is something to be gained by writing it all from scratch again but many examples of 4/8 bit HD44780 in Asm exist. This is one:

 

http://www.avrbeginners.net/inte...

with 4 bit here:

http://www.avrbeginners.net/inte...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jporter wrote:
The delay can also be found by timing the polling bit in the read register. Normally the read mode is disabled as the delay system is sufficient and saves a number of wires.

LOL.  I've been roundly lambasted here over the years -- I must be the only "busy bit" reader in captivity.

 

So here again the thread goes back-and-forth about proper delay intervals, variations between clone controllers, variations between models, and similar.  If the solution is to time the busy bit -- then why not watch the busy bit?!?

 

Now jporter does more sophisticated stuff than I do, so I certainly cannot claim one approach is better than another.  But I'm interested in this "number of wires"... I guess "1" is indeed "a number".

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

theusch wrote:

 

Now jporter does more sophisticated stuff than I do, so I certainly cannot claim one approach is better than another.  But I'm interested in this "number of wires"... I guess "1" is indeed "a number".

 

My guess is that when the read line is held low, then everything fits into a nice neat 8 bit byte.  A lot of Arduino interfaces use I2C expenders.  That is only 2 wires.  SPI is also popular as that is simply the old 74HC595 needs a bit more wires.  Ardiuno seems to be a one size fits all methodology.  The code is clever but not too space efficient. Arrays of pin instances are sorted so that the user only sees what they need to see.  Takes advantage of C++ overlays. Surprisingly it works.

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jporter wrote:
A lot of Arduino interfaces use I2C expenders. That is only 2 wires. SPI is also popular as that is simply the old 74HC595 needs a bit more wires.

I'm old fashioned, and connect my display to my AVR.

 

More pins?  Yeah; 1.

Less parts?  Yes; no "expander" needed.

Avoid issues with tailoring delays to different character LCD models?  Yes.  (ditto for VFD and similar)

Allows for read-back to check that the display is really there and alive?  Yes.

Faster?  Dunno.  I'd think perhaps "yes" if the delays need to be conservative.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you're really short of AVR pins and want to push it: 2 wires to a '174 with a diode and a resistor. Sort of slow, but works.

 

http://www.radanpro.com/Radan240...

https://sites.google.com/site/zo...

 

Second link has C code - for a PIC but is easy to port to an AVR.

 

(I know I've mentioned this before, but it was maany years since..

"He used to carry his guitar in a gunny sack, or sit beneath the tree by the railroad track. Oh the engineers would see him sitting in the shade, Strumming with the rhythm that the drivers made. People passing by, they would stop and say, "Oh, my, what that little country boy could play!" [Chuck Berry]

 

"Some questions have no answers."[C Baird] "There comes a point where the spoon-feeding has to stop and the independent thinking has to start." [C Lawson] "There are always ways to disagree, without being disagreeable."[E Weddington] "Words represent concepts. Use the wrong words, communicate the wrong concept." [J Morin] "Persistence only goes so far if you set yourself up for failure." [Kartman]