EmbeddedRelated.com
Forums
Memfault Beyond the Launch

What is wrong with this LCD code?

Started by Unknown September 17, 2006
I have 16x4 HD44780 base LCD module.
2 days ago I wrote the code and it worked but I wasn't pleased with it so i
deleted it and started writing new one.
And for the lase 2 days it won't work :((( I lost 5-6 hours already on
this.
I can't even get LCD to initialize and turn cursor and blinking ON.

Can you people find something wrong in this init code? 
MCU is LPC22129 with ARM7 running at 60MHz

void LCDInit(void)
{
	IODIR0=0x7F00;
	IOCLR0=0x7F00;
	IOSET0=0x0200;
	LCDtoggle();
	IOCLR0=0x7F00;
	IOSET0=0x0800;
	LCDtoggle();
	
	IOCLR0=0x7F00;
	LCDtoggle();
	IOSET0=0x0F00;
	LCDtoggle();
}

void LCDtoggle(void)
{
	IOSET0=ENABLE;
	delayus(1);      //wait for 1 microsec
	IOCLR0=ENABLE;
}
Mad I.D. schreef:

> I can't even get LCD to initialize and turn cursor and blinking ON.
I can't comment on your code, but first thing that comes to my mind is timing. Many of these LCD Displays are slow compared to a ARM7 op 60Mhz. So start with adding some realy slow delay loops between each I/O operations. Or even better, write some code that you can step manually through each I/O operation. And maybe things start working.. Otherwise, read and reread all the datasheets, in my experience, i was always wrong, not the datasheet.
On Sunday, in article
     <10uuwt792mqi2.1vnu0l82t1mwt.dlg@40tude.net>
     madid87-MAKNI-@yahoo.com "Mad I.D." wrote:

>I have 16x4 HD44780 base LCD module. >2 days ago I wrote the code and it worked but I wasn't pleased with it so i >deleted it and started writing new one. >And for the lase 2 days it won't work :((( I lost 5-6 hours already on >this. >I can't even get LCD to initialize and turn cursor and blinking ON. > >Can you people find something wrong in this init code? >MCU is LPC22129 with ARM7 running at 60MHz > >void LCDInit(void) >{ > IODIR0=0x7F00; > IOCLR0=0x7F00; > IOSET0=0x0200; > LCDtoggle(); > IOCLR0=0x7F00; > IOSET0=0x0800; > LCDtoggle(); > > IOCLR0=0x7F00; > LCDtoggle(); > IOSET0=0x0F00; > LCDtoggle(); >} > >void LCDtoggle(void) >{ > IOSET0=ENABLE; > delayus(1); //wait for 1 microsec > IOCLR0=ENABLE; >}
Check the data sheets as the FIRST initialise command(s) are expected to be 1 or more milli-seconds. Start with a 10 ms delay between actual commands. Some can later be changed to 1 micro second. LCD controllers like these are VERY slow compared to the micros. There is some C code meant for H8 on GNUH8 site listed below. -- Paul Carpenter | paul@pcserviceselectronics.co.uk <http://www.pcserviceselectronics.co.uk/> PC Services <http://www.gnuh8.org.uk/> GNU H8 & mailing list info <http://www.badweb.org.uk/> For those web sites you hate
"StanV" <jonsquire2000@hotmail.com> writes:
> Mad I.D. schreef: > > > I can't even get LCD to initialize and turn cursor and blinking ON. > > I can't comment on your code, but first thing that comes to my mind is > timing. Many of these LCD Displays are slow compared to a ARM7 op > 60Mhz. So start with adding some realy slow delay loops between each > I/O operations. Or even better, write some code that you can step > manually through each I/O operation. And maybe things start working.. > > Otherwise, read and reread all the datasheets, in my experience, i was > always wrong, not the datasheet.
Very, very true about needing loooong time delays between commands. There's also a status line that can be read to confirm completion of the previous command but be advised that the status does not perform correctly for the first couple of initialization commands.
StanV wrote:
> Mad I.D. schreef: > > > I can't even get LCD to initialize and turn cursor and blinking ON. > > I can't comment on your code, but first thing that comes to my mind is > timing. Many of these LCD Displays are slow compared to a ARM7 op > 60Mhz.
That was exactly my thought. The OP should look on a scope at the actual signals sent to the display, and confirm all the timing is within spec (setup times, strobe times, hold times, everything).
Mad I.D. wrote:
> I have 16x4 HD44780 base LCD module. > 2 days ago I wrote the code and it worked but I wasn't pleased with it so i > deleted it and started writing new one. > And for the lase 2 days it won't work :((( I lost 5-6 hours already on > this. > I can't even get LCD to initialize and turn cursor and blinking ON. > > Can you people find something wrong in this init code? > MCU is LPC22129 with ARM7 running at 60MHz > > void LCDInit(void) > { > IODIR0=0x7F00; > IOCLR0=0x7F00; > IOSET0=0x0200; > LCDtoggle(); > IOCLR0=0x7F00; > IOSET0=0x0800; > LCDtoggle(); > > IOCLR0=0x7F00; > LCDtoggle(); > IOSET0=0x0F00; > LCDtoggle(); > } > > void LCDtoggle(void) > { > IOSET0=ENABLE; > delayus(1); //wait for 1 microsec > IOCLR0=ENABLE; > }
If memory serves the initialisation routine required is around 20mS long, your seems to be about 4uS. Read the datasheet slower.
>> void LCDtoggle(void) >> { >> IOSET0=ENABLE; >> delayus(1); //wait for 1 microsec >> IOCLR0=ENABLE; >> }
Try a 4- or 5-millisecond delay, not a 1-microsecond delay.
On Sun, 17 Sep 2006 09:41:26 +0200, Mad I.D. wrote:
/cut

It works again after 3 hours od programming :)
Yes, ARM is too fast, and delays are very important.

Another thing, there has to be initialization software (the one that is
already done by power up) because it wont work when you do a chip reset.

I can say it is easier to program LCD with 8051 than with all-mighty ARM.

ByTheWay I wrote LCDWait function (it checks busy flag).

And one last thing, here in Croatia 20x4 LCD costs 38 &#4294967295; ! :-( Sad thing
Mad I.D. wrote:
> > I can say it is easier to program LCD with 8051 than with all-mighty ARM.
I know what you mean! Why do we still have to put up with display interfaces that are '70s-slow anyway?
Mike Silva wrote:
> Mad I.D. wrote: > >>I can say it is easier to program LCD with 8051 than with all-mighty ARM. > > > I know what you mean! Why do we still have to put up with display > interfaces that are '70s-slow anyway? >
Because they have to run on a few mA, at most. Rene

Memfault Beyond the Launch