Results 1 to 3 of 3

Thread: How to Initialize Char LCD using PIO (De0-Nano)

  1. #1
    Join Date
    Dec 2016
    Posts
    3
    Rep Power
    1

    Default How to Initialize Char LCD using PIO (De0-Nano)

    Hello to the whole forum, this is my very first thread so please be kind with me(=

    I'm trying to drive a char LCD using my de0 nano but no results yet..

    My lcd is a 5v unit but since I need just to write to it I guess it wont be a problem, except for a bit weak logic 1 but according to data sheet it should work.

    I tried the altera university core for 16 x 2 char LCD but since I must keep the reduced drivers enabled this seems not the right option to save memory, anyway this core was able to properly initialize the LCD so I must have made some coding/timing error.

    In my new implemntation I drive it with 2 separate PIO, one for RS, R/W, En + one for Data.

    The PIO_LCD_COMMAND drives the 3bit output bus (msb is RS, RW, lsb is En), then the PIO_LCD_DATA drives the lcd bidirectional data bus.

    Here's the LCD data sheet if it may help: http://www.farnell.com/datasheets/20...068.1473273391

    Here below I've attached my initialization code, I hope someone might help! Much thanks guys

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_LCD_DATA_BASE , ALTERA_AVALON_PIO_DIRECTION_OUTPUT);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x00);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b000);




    usleep(16000);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b001);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x30);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b000);
    usleep(4500);


    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b001);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x30);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b000);
    usleep(200);


    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b001);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x30);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b000);
    usleep(200);




    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b001);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x38);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b000);
    usleep(200);




    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b001);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x08);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b000);
    usleep(200);


    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b001);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x01);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b000);
    usleep(200);




    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b001);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x06);
    usleep(100);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE,0 b000);

    usleep(200);

  2. #2
    Join Date
    Dec 2016
    Posts
    3
    Rep Power
    1

    Default Re: How to Initialize Char LCD using PIO (De0-Nano)

    Hi I've been able to initialize it correctly.

    I didn't set the biport output direction for all data pins.

    No I fixed it:

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_LCD_DATA_BASE , 0b11111111);

    Anyway I try to print some char after the initialization but no result, here's the code I used to print a char:

    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x80);
    usleep(1);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b001);
    usleep(2);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b000);
    usleep(200);

    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x41);
    usleep(1);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b101);
    usleep(2);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b100);
    usleep(200);

    I take some wide timing since I wanted to be sure the unit has time to do its internal operation.

  3. #3
    Join Date
    Dec 2016
    Posts
    3
    Rep Power
    1

    Default Re: How to Initialize Char LCD using PIO (De0-Nano)

    Everything solved, now I can print char and do stuff.

    The second issue was caused by wrong timing.

    The Clear Display command is quite slow and it take 1.52ms to be done, so I Changed usleep(2000).

    As I said I've taken super wide delays since I wanted to avoid timing issue.

    This is my working/corrected code, I hope it may help someone:

    IOWR_ALTERA_AVALON_PIO_DIRECTION(PIO_LCD_DATA_BASE , 0b11111111);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x00);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b000);


    usleep(16000);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x38);
    usleep(1);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b001);
    usleep(2);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b000);
    usleep(4500);

    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x38);
    usleep(1);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b001);
    usleep(2);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b000);
    usleep(200);

    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x38);
    usleep(1);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b001);
    usleep(2);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b000);
    usleep(200);


    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x38);
    usleep(1);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b001);
    usleep(2);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b000);
    usleep(200);


    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x0E);
    usleep(1);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b001);
    usleep(2);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b000);
    usleep(200);


    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x01);
    usleep(1);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b001);
    usleep(2);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b000);
    usleep(2000);


    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x06);
    usleep(1);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b001);
    usleep(2);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b000);
    usleep(200);


    //data to test lcd


    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_DATA_BASE, 0x41); // A
    usleep(1);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b101);
    usleep(2);
    IOWR_ALTERA_AVALON_PIO_DATA(PIO_LCD_COMMAND_BASE, 0b100);
    usleep(2);
    Last edited by Herva; December 29th, 2016 at 01:22 AM.

Similar Threads

  1. using char-lcd in linux
    By wangweike in forum Linux Forum
    Replies: 15
    Last Post: September 26th, 2010, 08:24 AM
  2. Char Buffer UP IP
    By marsi in forum University Program
    Replies: 1
    Last Post: February 23rd, 2010, 01:30 AM
  3. write char in DE2 SRAM
    By mikeren in forum General Altera Discussion
    Replies: 5
    Last Post: October 28th, 2009, 03:36 AM
  4. char takes 4 bytes?
    By mountain8848 in forum Linux Forum
    Replies: 4
    Last Post: November 9th, 2005, 06:21 PM
  5. char driver
    By pankajsharma in forum Linux Forum
    Replies: 1
    Last Post: May 25th, 2005, 05:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •