8051 LCD programming help

Hello, I have a sample program that is written in micro-c and shows examples of how to write data to an LCD connected to the 8051 micro-controller. Could someone please explain what the following function is doing?

void WriteCommon( unsigned char value ) { clrbit(READ); value = value & 0x0F; value = value 4) & 7 ) ); delay(1); WriteCtrl(pos & 0x0F); delay(1); } void CursorHome() { /* Cursor home */ WriteCtrl(0); delay(1); WriteCtrl(2); delay(1); } void WriteLCD( unsigned char* message ) { unsigned char i; for( i=0; i> 4 ); WriteCommon( value ); } void WriteCommon( unsigned char value ) { clrbit(READ); value = value & 0x0F; value = value

Reply to
Steve
Loading thread data ...

Hi Steve,

Take a peek at

formatting link
~6KB There are some comments that may clear up LCD programming for you. Also this method implements low level C functions so you can write to the LCD with printf().

Julyan Ilett's excellent articles "How to use intelligent LCD's" are also very useful.

formatting link
formatting link

First 2 lines shrink value down to a 4 bit number in the upper 4 bits of value. Next 2 clear the upper 4 bits of port 0, and send value out on these. Then the LCD is strobed to read the 4 bit message. Its just a routine to write 4 bit values to the LCD when using it in 4 line mode.

Dave Dunfield is a clever sod. I like his filesystem especially.

Regards, Murray R. Van Luyn.

Reply to
Murray R. Van Luyn

void WriteCommon( unsigned char value ) { // look like the chip is in 4 bit mode clrbit(READ); // assert read value = value & 0x0F; // get low nibble (4bits) value = value

Reply to
Neil Kurzman

Hi, Thanks for the explanation and the links you provided. It helped allot. Thanks again

Reply to
Steve

... snip ...

You should indent your program properly. If your newsreader is removing leading spaces and tabs get a better newsreader.

That routine is wrapping three actions together. At the innermost level it turns on a line named STROBE, pauses, and turns it off. Outside that it takes the lower 4 bits of the input value and puts them on the higher 4 bits of a port named P0 without disturbing the lower 4 bits. It wraps that whole process in setting a line called READ, and then resetting it.

actually implemented in the lower 4 bits of that port. Waveforms are approximately:

READ ___________----------------______________

STROBE __________________-______________________

bits set up ______________---------------------------

in function _______-----------------------___________

--
Chuck F (cbfalconer@yahoo.com) (cbfalconer@worldnet.att.net)
   Available for consulting/temporary embedded and systems.
     USE worldnet address!
Reply to
CBFalconer

It is writing the bottom four bits of a byte to the LCD. This is because the LCD can be used in byte or nybble mode. Your example is using the latter (fewer I/O pins, but slower)

In this mode, you have to specify "command" or "data" and send the two (one?) nybbles corresponding to whatever you want to send.

This function is called by several other "wrapper" functions to perform send-data, send-command and probably a few others.

I think commands can sometimes be sent in only 4 bits (especially for initialisation)

Richard [in PE12]

Reply to
Endymion Ponsonby-Withermoor III

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.