Forum Discussion

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

Nios LCD Display

Dear friend ,

Somehow , I could not write text on LCD on DE2,is there any example code around.I can not find.

My pio and "hello from nios" is working but ,I can not make LCD work.

I need sample program.

13 Replies

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

    This is the main.c file of my project , please examine it , LCD still doesnt work ....I am screwed.. :((((

    Do I have a problem with this "DALT_USE_LCD_16207" I did not add that.

    /*

    * "Small Hello World" example.

    *

    * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on

    * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example

    * designs. It requires a STDOUT device in your system's hardware.

    *

    * The purpose of this example is to demonstrate the smallest possible Hello

    * World application, using the Nios II HAL library. The memory footprint

    * of this hosted application is ~332 bytes by default using the standard

    * reference design. For a more fully featured Hello World application

    * example, see the example titled "Hello World".

    *

    * The memory footprint of this example has been reduced by making the

    * following changes to the normal "Hello World" example.

    * Check in the Nios II Software Developers Manual for a more complete

    * description.

    *

    * In the SW Application project (small_hello_world):

    *

    * - In the C/C++ Build page

    *

    * - Set the Optimization Level to -Os

    *

    * In System Library project (small_hello_world_syslib):

    * - In the C/C++ Build page

    *

    * - Set the Optimization Level to -Os

    *

    * - Define the preprocessor option ALT_NO_INSTRUCTION_EMULATION

    * This removes software exception handling, which means that you cannot

    * run code compiled for Nios II cpu with a hardware multiplier on a core

    * without a the multiply unit. Check the Nios II Software Developers

    * Manual for more details.

    *

    * - In the System Library page:

    * - Set Periodic system timer and Timestamp timer to none

    * This prevents the automatic inclusion of the timer driver.

    *

    * - Set Max file descriptors to 4

    * This reduces the size of the file handle pool.

    *

    * - Check Main function does not exit

    * - Uncheck Clean exit (flush buffers)

    * This removes the unneeded call to exit when main returns, since it

    * won't.

    *

    * - Check Don't use C++

    * This builds without the C++ support code.

    *

    * - Check Small C library

    * This uses a reduced functionality C library, which lacks

    * support for buffering, file IO, floating point and getch(), etc.

    * Check the Nios II Software Developers Manual for a complete list.

    *

    * - Check Reduced device drivers

    * This uses reduced functionality drivers if they're available. For the

    * standard design this means you get polled UART and JTAG UART drivers,

    * no support for the LCD driver and you lose the ability to program

    * CFI compliant flash devices.

    *

    * - Check Access device drivers directly

    * This bypasses the device file system to access device drivers directly.

    * This eliminates the space required for the device file system services.

    * It also provides a HAL version of libc services that access the drivers

    * directly, further reducing space. Only a limited number of libc

    * functions are available in this configuration.

    *

    * - Use ALT versions of stdio routines:

    *

    * Function Description

    * =============== =====================================

    * alt_printf Only supports %s, %x, and %c ( < 1 Kbyte)

    * alt_putstr Smaller overhead than puts with direct drivers

    * Note this function doesn't add a newline.

    * alt_putchar Smaller overhead than putchar with direct drivers

    * alt_getchar Smaller overhead than getchar with direct drivers

    *

    */

    # include "sys/alt_stdio.h"

    # include <unistd.h>

    # include "system.h"

    # include "altera_avalon_pio_regs.h"

    # include <stdio.h>

    # include "alt_types.h"

    # include "altera_avalon_lcd_16207_regs.h"

    # include "altera_avalon_lcd_16207.h"

    # define LCD_WR_COMMAND_REG 0

    # define LCD_WR_DATA_REG 2

    void lcd_init(void);

    void lcd_test(void);

    int main()

    {

    alt_putstr("Hello from Nios II!\n");

    usleep(15000); /* Wait for more than 15 ms before init */

    lcd_init();

    lcd_test();

    while (1);

    return 0;

    }

    void lcd_init(void)

    {

    /* Set function code four times -- 8-bit, 2 line, 5x7 mode */

    IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE,0x38);

    usleep(4100); /* Wait for more than 4.1 ms */

    IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE,0x38);

    usleep(100); /* Wait for more than 100 us */

    IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE,0x38);

    usleep(5000); /* Wait for more than 100 us */

    IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE,0x38);

    usleep(100); /* Wait for more than 100 us */

    /* Set Display to OFF*/

    IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE,0x08);

    usleep(100);

    /* Set Display to ON */

    IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE,0x0C);

    usleep(100);

    /* Set Entry Mode -- Cursor increment, display doesn't shift */

    IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE,0x06);

    usleep(100);

    /* Set the Cursor to the home position */

    IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE,0x02);

    usleep(2000);

    /* Display clear */

    IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE,0x01);

    usleep(2000);

    }

    void lcd_test(void)

    {

    int i;

    char message[17] = "Hello World... ";

    char done[15] = "Done! ";

    /* Write a simple message on the first line. */

    for(i = 0; i < 16; i++)

    {

    IOWR_ALTERA_AVALON_LCD_16207_DATA(LCD_BASE,message);

    usleep(100);

    }

    /* count along the bottom row */

    /* set address */

    iowr_altera_avalon_lcd_16207_command(lcd_base,0xc0);

    usleep(1000);

    /* display count */

    for (i = 0; i < 10; i++)

    {

    iowr_altera_avalon_lcd_16207_data(lcd_base,(char)(i+0x30) );

    usleep(500000); /* wait 0.5 sec */

    }

    /* write "done!" message on first line. */

    /* set address */

    iowr_altera_avalon_lcd_16207_command(lcd_base,0x80);

    usleep(1000);

    /* write data */

    for(i = 0; i < 14; i++)

    {

    iowr_altera_avalon_lcd_16207_data(lcd_base,done);

    usleep(100);

    }

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

    Hello everybody,

    i have a problem to get my LCD running at my DE0-Nano-board. The LCD module is a TM164AAA http://pdf.datasheetcatalog.net/datasheets2/36/361888_1.pdf (http://pdf.datasheetcatalog.net/datasheets2/36/361888_1.pdf)

    I used Quartus and QSYS to add the LCD in the FPGA.

    In nios 2 I tried different examplecodes but nothing worked. I would be very pleased if you could have a short look on my simple code/files.

    I want to call the displayfunction in my mainfile. The files "display.h" , "display_1.h" and "display_2.h" are three different examplecodes.

    Please find attached some screenshots of my system and the three display-files.

    https://www.dropbox.com/s/q1yqr77xucjc0ld/hardware.jpg (https://www.dropbox.com/s/q1yqr77xucjc0ld/hardware.jpg)

    https://www.dropbox.com/s/660jtbpz57tyr2x/qsys.jpg (https://www.dropbox.com/s/660jtbpz57tyr2x/qsys.jpg)

    https://www.dropbox.com/s/iyfakq3nhugeyjt/system_h.jpg (https://www.dropbox.com/s/iyfakq3nhugeyjt/system_h.jpg)

    Thank you very much. I'm a newbie. Just want to see some characters on my LCD-screen...