1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

when writing to lcd the first character is black

Discussion in 'Embedded' started by Bram van de Kerkhof, Oct 2, 2003.

  1. 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);
    }

    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
     
    Bram van de Kerkhof, Oct 2, 2003
    #1
    1. Advertisements

  2. Bram van de Kerkhof

    Gary Kato Guest

    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.
     
    Gary Kato, Oct 2, 2003
    #2
    1. Advertisements

  3. Why should it clear after a write ?

    Yours Bram
     
    Bram van de Kerkhof, Oct 3, 2003
    #3
  4. Bram van de Kerkhof

    Gary Kato Guest

    Why should it clear after a write ?
    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.
     
    Gary Kato, Oct 3, 2003
    #4
  5. 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:
    ==================================================
    www : http://www.oce.nl/
    ==================================================
     
    Bram van de Kerkhof, Oct 3, 2003
    #5
  6. Bram van de Kerkhof

    Gary Kato Guest

    Ok after reset the cursor is blinking.
    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.
     
    Gary Kato, Oct 3, 2003
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.