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 27, 2012 at 10:16

juste the first line appears.

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

@aymen.bellili

Have you tested your code on some other LCD? I suspect your delays are too short. First of all you need calibrated delay function and use longer delays to make it working. Then you can test faster i/o. Here's my patch (not tested) Use more delay cycles:

/* If processor works on high frequency delay has to be increased, it can be 
increased by factor 2^N by this constant */
#define DELAY_2N 6

Slower i/o:

void lcd_write_4bit (unsigned char c)
{
LCD_RW(0)
LCD_E(1)
LCD_DATA_OUT(c&0x0F)
delay(50);
LCD_E(0)
delay(50);
}
void lcd_write_cmd (unsigned char c)
{
#if 0
wait_while_busy(); /* wait disabled for testing */
#endif
LCD_RS(0)
lcd_write_4bit (c>>4);
lcd_write_4bit (c);
}

Better init:


void lcd_init (void)
{ 
int i;
char const *p;
LCD_CLOCK_EN /* Enable clock for peripheral */
/* Set all pins for LCD as outputs */
LCD_ALL_DIR_OUT
delay (100000);
LCD_RS(0)
lcd_write_4bit (0x3); /* Select 4-bit interface */
delay (10000);
lcd_write_4bit (0x3);
delay (3000);
lcd_write_4bit (0x2);
delay (3000);
lcd_write_cmd (0x28); /* 2 lines, 5x8 character matrix */
delay (3000);
lcd_write_cmd (0x0C); /* Display ctrl:Disp=ON,Curs/Blnk=OFF */
lcd_write_cmd (0x06); /* Entry mode: Move right, no shift */
/* Load user-specific characters into CGRAM */
lcd_write_cmd(0x40); /* Set CGRAM address counter to 0 */
p = &UserFont[0][0];
for (i = 0; i < sizeof(UserFont); i++, p++)
lcd_putchar (*p);
lcd_write_cmd(0x80); /* Set DDRAM address counter to 0 */
}

aymen
Associate II
Posted on December 27, 2012 at 13:34

i tested my code with the lcd livred with the MCBSTM32 Evaluation Board, it's ok.

also i tested your modification and it works .

but my problem is with the second LCD.

http://www.icwic.com/icwic/data/pdf/cd/cd053/Numeric,%20Alphanumeric%20LCD/a/1225pdf

i used another code but also no result.(there is in the attachement)

just the first line appears (low contrast).

________________

Attachments :

LCD_8bits.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HtVF&d=%2Fa%2F0X0000000aQw%2FYkAUbUHm0JJdbFu_RUpVJVBjYSk7nqSFIKpSN2TnA88&asPdf=false

LCD_8bits.h : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HtVK&d=%2Fa%2F0X0000000aQx%2F08L_s_dy5Jna3o_aCSgsnI9lqitG41H8Y7GE0nKojBM&asPdf=false
zzdz2
Associate II
Posted on December 27, 2012 at 14:27

It's strange. Apparently the controller starts up since the first line appears but the MCU interface doesn't work.

Maybe there is some error in the datasheet pinout description or maybe the LCD is just broken, who knows.

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

:(

jj2
Associate II
Posted on December 27, 2012 at 16:35

Cannot justify more time/effort for this single lcd - suggest you toss it - move on.

Bulk of knik's code is useful - but for 2 areas:

a) Horses mouth, ''Hitachi Lcd Controller/Driver LSI Databook'' 1994 lists three (3) transmissions of 0x03 to force the HD44780 into 4 bit mode.  (My example showed 3 - Knik's code has just two.)  My preference is to comply with the maker's datasheet.

b) Knik shows an example for ''custom character generator.''  As a manager - I'd never run before I could walk.  This adds still more complications - my suggestion was basic 0x41 - which should yield a capital A @ home position.

First line turning on - without any initialization - usually is indication of Vo pin over-drive.  Once initialized as one line display - that 1st line should considerably darken - if initialized as two line display the contrast voltage will likely have to be increased to view the pixel field - but now both lines should be of equal intensity.

zzdz2
Associate II
Posted on December 27, 2012 at 17:39

a) Horses mouth, ''Hitachi Lcd Controller/Driver LSI Databook'' 1994 lists three (3) transmissions of 0x03 to force the HD44780 into 4 bit mode.  (My example showed 3 - Knik's code has just two.)  My preference is to comply with the maker's datasheet.

Yes, that's interesting thing, I never found HD44780-compatible LCD that wouldn't work with only two 0x03 to initialize 4-bit mode.

Posted on December 27, 2012 at 19:58

Maybe you can diagram exactly how you have the display wired up with pin numbers and names. If the panel isn't attached properly no amount of faffing about in software is going to fix it.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
jj2
Associate II
Posted on December 28, 2012 at 01:23

Admire your super participation - this forum.  (and met you @ past ST forum)

That said - hardly believe that, ''complying with maker's datasheet'' qualifies as, ''faffing about!''  From get-go - post and data are piece-meal - single lcd issue does not deserve such interest/effort...

zzdz2
Associate II
Posted on December 28, 2012 at 11:04

Clive1 may be right, something's wrong here:

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)

It shouldn't work this way if data i/o is set as input, may be possible if set as outputs.

Maybe R/W pin is broken or maybe swapped with some other pin.

@,  

is there any current flow to these pins when connected to GND or V+.