when writing to lcd the first character is black

Hi.

When writing to a display (2x16) the first character is completeley black i'm writing at at following way.

init select line 1 write to line 1 select line 2 write to line 2

The display is an 44780 compatible. I'm using an atmel 89c51

This is the code i use:

In this function void lcd_writestring (char *string1, char *string2) the writing is done. before this i used puts and getchar but i didn't like that sollution.

/* lcd controller functions --------------------------------------------------------------*/

void lcdusdelay(int delay) { int i; for(i=0; i 4) | 0xF0; Low = (c & 0x0F) | 0xF0;

rs = 1;

P3 &= High; // Write High Nibble e = 1; e = 0; P3 |= 0x0F;

P3 &= Low; // Write Low Nibble e = 1; e = 0; P3 |= 0x0F;

rs = 0;

}

/* function for writing the complete display*/ void lcd_writestring (char *string1, char *string2) { int i = 0; int j = 0;

lcdwrite(0x08); lcdwrite(0x00); lcdmsdelay(1);

for (i=0; i!=15; ++i) { printchar(string1[i]); }

lcdwrite(0x0c); lcdwrite(0x00); lcdmsdelay(1);

for (j=0; j!=15; ++j) { printchar(string2[j]); }

}

void update_menu(void) { if (up == 1) { up = 0; lcd_writestring("Ma 20:17 ", "up down ent set");

} if (down == 1) { down = 0; lcd_writestring("down is pressed ", "up down set ent"); }

}

The black character can be seen on both lines and it is written in stead of the first real character. So the text doesn't move one character ahead.

Yours Bram

Reply to
Bram van de Kerkhof
Loading thread data ...

I assume you have the R/W line tied low so that it is permanently in Write mode. I also assume you have pull-up resistors on the low 4 bits of Port 3 and that E and RS are initialized to 0 somewhere in your code before you initialize the LCD.

If you disable lcdwritestring(), does the LCD clear and then display a blinking cursor? If not, there's something wrong in your init code. If it does, then there's something wrong with the way you write character data to the LCD.

Reply to
Gary Kato

Why should it clear after a write ?

Yours Bram

and

initialize

blinking

then

Reply to
Bram van de Kerkhof

Not after a write, but after your initialization sequence (before lcdwritestring). The last few commands you send in lcdinit() are to turn the blinking cursor on then clear the LCD.

Reply to
Gary Kato

Ok after reset the cursor is blinking.

-- ================================================== Bram van de Kerkhof

OCE-Technologies BV Building 3N38

St. Urbanusweg 43, Venlo, The Netherlands P.O. Box 101, 5900 MA Venlo ================================================== Direct dial : +31-77-359 2148 Fax : +31-77-359 5473 ================================================== e-mail : mailto: snipped-for-privacy@oce.nl ================================================== www :

formatting link
==================================================

the

Reply to
Bram van de Kerkhof

Good. In that case, it is probably the way you are sending characters to the LCD in printchar(). Is there some reason that you are using ANDs and ORs to write to the I/O port instead of just a MOV?

Using AND and OR means you are reading from the input pins of P3 and assuming they are 1. I don't have a datasheet for the CPU you are using, but you may be assuming that reading from the port is reading what you wrote last (to a latch), but it might be reading straight from the input pin itself. Most 8051 datasheets have a schematic of the port to show exactly what happens when you do a read or write.

Reply to
Gary Kato

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.