cancel
Showing results for 
Search instead for 
Did you mean: 

LCD_8bits

aymen
Associate II
Posted on December 12, 2012 at 10:09

I am trying to use an LCD HD44780 (2X40) with STM3210C-eval. I want to configure it for 8 bits mode.

#re-inventing-the-wheel
33 REPLIES 33
aymen
Associate II
Posted on December 19, 2012 at 10:40

I tried 4bits mode.

if I connect (D4,D5,D6,D7) with 5v, the first line appears black (high contrast)

if I connect (D4,D5,D6,D7) with GND, the first line appears black (low contrast)

after lcd_init();

        lcd_clear();

       lcd_print(''hello'');

there no caracteres printed in the lcd. No change.

zzdz2
Associate II
Posted on December 19, 2012 at 15:30

Some hd44780 clones are slow, you can try slower clocking, longer delay.

jj2
Associate II
Posted on December 19, 2012 at 17:06

Connecting any/all of your lcd data bus to power or ground - prior to proper lcd initialization -accomplishes nothing!  (in fact most all 44780/clone controllers ''pull'' the D-Bus high by default)

Here is the simplest code which can bring your first (top) line of character lcd into view:

Set RS=0

Set R/W =0

Set E =0

Place 0x0E on data bus (2 steps in 4 bit mode - 1st 0X00 then pulse ''E'' H-L. Then 0x0E on data bus - again pulse ''E'' H-L.  If done correctly - the pixel field should come more intensely into view.

Once the pixel field is clearly viewable - place 0X01 on data bus.  (again 2 steps - as above - first 0X00 then 0x01.)  This 0X01 will clear the display and ''home'' the cursor.

As the other poster suggests - long delays during this process will be helpful.

If you can achieve this very basic ''make pixels visible'' and ''home cursor'' functionality you can graduate to fuller initialization (2 line) but ordering the display into 2 line mode may well require a slight negative voltage on Vo - as stated earlier... 

*** Update ***

My suggested use of the minimum 2 commands (0x0E followed by 0x01) is correct for an 8-bit bus implementation - but is inadequate (wrong) for 4 bit operation!

To begin - tie 4 consecutive bits from your MCU to DB4-DB7 of the Lcd.  (DB3-DB0 may float)  Ideally (to simplify) you should use Port bits 4-7 from your MCU.

Now 4 bit initialization is specialized - and must be followed exactly: (this from a 1994 Hitachi LCD Controller Data Book)

Wait for 15mS (minimum) after Lcd's power rises to 5V.

a) Clear RS and R/W and E.

b) Place 0x03 on Lcd pins DB4-DB7.  (i.e. DB4 & DB5 high, others low)

c) drive E high for 450nS minimum - return low.

d) Wait for 4.1mS (minimum) 

e) Place 0x03 on Lcd pins DB4-DB7.  (same as earlier)

f) drive E high for 450nS minimum - return low.

g) Wait for 100uS (minimum) 

h) Place 0x03 on Lcd pins DB4-DB7.  (this is the 3rd time this is done)

i) drive E high for 450nS minimum - return low. 

j) Place 0x02 on Lcd pins DB4-DB7. (i.e. DB5 alone, high)

k) drive E high for 450nS minimum - return low. 

l) Place 0x02 on Lcd pins DB4-DB7.

m) drive E high for 450nS minimum - return low. 

n) Place either 0x00 (1 Line) or 0x08 (2 Lines) on Lcd pins DB4-DB7

o) drive E high for 450nS minimum - return low. 

p) Place 0x00 on DB4-DB7 - strobe E

q) Place 0x01 on DB4-DB7 - strobe E (these 2 commands clear the Lcd)

r) Place 0x00 on DB4-DB7 - strobe E

s) Place 0x0E on DB4-DB7 - strobe E (display should now be visible

*** Now change RS from low to high, leave R/W low

t) Place 0x40 on DB4-DB7 - strobe E

u) Place 0x01 on DB4-DB7 - strobe E (A should now appear @ home position!)

Continue to write to the display via this back to back (2 nibble) mode - with most significant nibble sent first.  Each nibble must be ''strobed in'' via a high going E pulse.

8 bit mode is far more forgiving - but does cost 4 more GPIO.  If you use 4 bit mode in a noisy environment - it is wise to periodically ''re-initialize'' the Lcd - to make certain it has not become ''out of sync'' with your tranfers.

aymen
Associate II
Posted on December 24, 2012 at 10:44

thanks for your help.

up to now i can't write data.

there is in the attachement the file LCD_4bits wich I used to display data.

________________

Attachments :

LCD_4bit.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I162&d=%2Fa%2F0X0000000biK%2F64aizUmXUvZjRxoqUCyGMhmbODZJHLSNhEZwGnDkw34&asPdf=false
jj2
Associate II
Posted on December 24, 2012 at 17:06

You don't state if you used the detailed, 4-bit initialization code I recently supplied.  We have used such code on thousands of 44780/clone lcds (I was co-owner of lcd firm) with success.

Do you see the pixel field both before and after the new 4-bit initialization?  Do you see the cursor? 

Did you honor the relatively long delays specified in the new, 4-bit initialization?

Without correct 4-bit initialization - all is lost.  I recall that your data bits were reversed in your shown code - you're placing roadblocks by not following the ''normal/customary'' set-up & pin configurations.  And - it is always possible that your display has some defect (ESD etc.)  Far better to work w/ a number of displays - just in case... 

zzdz2
Associate II
Posted on December 25, 2012 at 12:52

Your delays are definitely too short, you would rather use about 50us delays in 

lcd_write_4bit.

jj2
Associate II
Posted on December 26, 2012 at 03:26

The 50uS delays you suggest are spec'ed @ 40uS for inter-character spacing when using HD44780/clone @ 5V. 

However - you miss the fact that if the pixel field does not intensify - and the cursor does not ''home'' (via the detailed initialization presented) - inter-character delays will have NO impact!  Initialization always comes first - and must be successful...

zzdz2
Associate II
Posted on December 26, 2012 at 12:01

You are right, of course. Feel free to find all the delay bugs. I found one of them.

aymen
Associate II
Posted on December 27, 2012 at 10:14

@sprague.jj

i use the some configuration as yours but the cursor didn't appears.

juste the first line appears (low contrast).

aymen
Associate II
Posted on December 27, 2012 at 10:15