when writing to lcd the first character is black

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
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<delay; i++);
}


void lcdmsdelay(int delay)
{
 int d;
 for( d=0; d < delay; d++ )
 delay1ms();
}


void delay1ms(void) /* 1ms delay met een 12Mhz kristal. */
{
  int i;
  for(i=0; i<200; i++);
}


void lcdinit( void )
{   lcdmsdelay(15);     /* wait for 15 ms after power on            */

 lcdwrite(0x03);     /* function set command                     */
 lcdmsdelay(5);      /* wait for 5 ms                            */

 lcdwrite(0x03);     /* function set command                     */
    lcdmsdelay(1);      /* wait for 1 ms                            */

 lcdwrite(0x03);     /* function set command                     */
    lcdmsdelay(5);      /* wait for 5 ms                            */

    lcdwrite(0x02);     /* function set (4bit interface)            */
    lcdmsdelay(1);

    lcdwrite(0x02);     /* function set 4bit 1/16 duty font = 5x8   */
    lcdwrite(0x08);
    lcdmsdelay(1);

 lcdwrite(0x00);     /* display off cursor off blink off         */
    lcdwrite(0x08);
 lcdmsdelay(1);

 lcdwrite(0x00);     /* display on cursor on blink on            */
 lcdwrite(0x0F);
 lcdmsdelay(1);

 lcdwrite(0x00);     /* clear display and send cursor to address 0*/
 lcdwrite(0x01);
 lcdmsdelay(1);

}

/* function for init writing */
void lcdwrite(unsigned char lcd_data)
{
e = 1;
lcdusdelay(40);
P3 = lcd_data;
lcdusdelay(40);
e = 0;
}


void printchar(unsigned char c)
{
 unsigned char High, Low;

 High = (c >> 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




Re: when writing to lcd the first character is black
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.


Re: when writing to lcd the first character is black
Why should it clear after a write ?

Yours Bram

Quoted text here. Click to load it
and
initialize
blinking
then



Re: when writing to lcd the first character is black
Quoted text here. Click to load it

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.



Re: when writing to lcd the first character is black
Ok after reset the cursor is blinking.

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

We've slightly trimmed the long signature. Click to see the full one.
Re: when writing to lcd the first character is black
Quoted text here. Click to load it

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.



Site Timeline