Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
9 years ago

16x2 lcd interface from 8 bits to 4 bits in the hal driver

Hi everyone,

I am trying to use the altera_avalon_lcd_16207 Driver to drive my Lcd and its working fine for me. But when I am trying to work with 4 bits interface using the same altera_avalon_lcd_16207 driver provided by the altera its not working. Find the below think I changed in the same driver.

________________________________________________________________________________________

line no : 548; file name : altera_avalon_lcd_16207.c ; function name : altera_avalon_lcd_16207_init();

original code :

/* Setup interface parameters: 8 bit bus, 2 rows, 5x7 font */

-lcd_write_command(sp, LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT | LCD_CMD_TWO_LINE);

changed code :

/* Setup interface parameters: 8 bit bus, 2 rows, 5x7 font */

+lcd_write_command(sp, LCD_CMD_FUNCTION_SET | LCD_CMD_TWO_LINE);

line no : 163 ; file name : altera_avalon_lcd_16207.c;function name : lcd_write_command();

IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, command);

+command = command << 4;

+IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, command);

line no : 198 ; file name : altera_avalon_lcd_16207.c; function name : lcd_write_data();

IOWR_ALTERA_AVALON_LCD_16207_DATA(base, data);

+data = data << 4;

+IOWR_ALTERA_AVALON_LCD_16207_DATA(base, data);

______________________________________________________________________________________

the above are the changes i done so far in the given HAL driver. but not its not working for me.

So plz any one can suggest how i can solve this issue?:(

1 Reply

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi everyone,

    I got the solution for the above one and find the patch for the same.

    --- src/altera_avalon_lcd_16207.c 2015-04-23 11:17:46.000000000 +0530

    +++ src/altera_avalon_lcd_16207.c 2016-09-06 15:30:57.331296200 +0530

    @@ -161,9 +161,11 @@

    /* Despite what it says in the datasheet, the LCD isn't ready to accept

    * a write immediately after it returns BUSY=0. Wait for 100us more.

    */

    - usleep(100);

    + usleep(1000);

    - IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, command);

    + IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, ( command & 0xf0 ));

    + command = command << 4;

    + IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, ( command & 0xf0 ));

    }

    /* --------------------------------------------------------------------- */

    @@ -197,7 +199,9 @@

    */

    usleep(100);

    - IOWR_ALTERA_AVALON_LCD_16207_DATA(base, data);

    + IOWR_ALTERA_AVALON_LCD_16207_DATA(base, ( data & 0xf0 ));

    + data = data << 4;

    + IOWR_ALTERA_AVALON_LCD_16207_DATA(base, ( data & 0xf0 ));

    sp->address++;

    }

    @@ -577,8 +581,11 @@

    usleep(1000);

    IOWR_ALTERA_AVALON_LCD_16207_COMMAND(base, LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT);

    - /* Setup interface parameters: 8 bit bus, 2 rows, 5x7 font */

    - lcd_write_command(sp, LCD_CMD_FUNCTION_SET | LCD_CMD_8BIT | LCD_CMD_TWO_LINE);

    + /* Setup interface parameters: 4 bit bus */

    + lcd_write_command(sp, LCD_CMD_FUNCTION_SET );

    +

    + /* Setup interface parameters: 4 bit bus, 2 rows, 5x7 font */

    + lcd_write_command(sp, LCD_CMD_FUNCTION_SET | LCD_CMD_TWO_LINE);

    /* Turn display off */

    lcd_write_command(sp, LCD_CMD_ONOFF);

    Thanks