Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++

Nios LCD Display

Altera_Forum
Honored Contributor II
2,354 Views

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.
0 Kudos
13 Replies
Altera_Forum
Honored Contributor II
1,274 Views

See Chapter 9 "Optrex 16207 LCD Controller Core": 

 

http://www.altera.com/literature/ug/ug_embedded_ip.pdf 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
1,274 Views

Thats written in datasheet ; " An Avalon Memory-Mapped (Avalon-MM) slave interface that provides access to 4 registers " 

 

That Avalon Memory-Mapped (avalon MM) slave should be added in SOPC builder. 

 

I did not put any avalon slave to my system while I am defining system.I just add following  

 

*Nios CPU 

*PIO 

*Onchip Memory 

*JTAG_UART 

*Systemid 

*LCD Dsiplay 

 

So Is there anything that I forgot? 

Do I need extra stuff to add in SOPC, for access LCD. 

 

And in nios ,How can I initialize LCD , I can not find init function .
0 Kudos
Altera_Forum
Honored Contributor II
1,274 Views

 

--- Quote Start ---  

 

Do I need extra stuff to add in SOPC, for access LCD. 

 

And in nios ,How can I initialize LCD , I can not find init function . 

--- Quote End ---  

 

 

The LCD component provides read/write access to the LCD registers. Those registers are described in the Optrex LCD manual. The LCD manual also describes the initialization sequence. 

 

http://www.optrex.com/pdfs/dmcman_full.pdf 

 

I have not used the SOPC LCD controller, so I don't know what software support they offer.  

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
1,274 Views

Dave thank you for reply , But I want to say that , I want to define System in SOPC builder , 

 

I just want to use pio's and lcd . 

 

I tried pio's and acheived how ever now I want to try lcd , 

 

Is anyone tell me step by step.  

 

And I want to write test code in NIOS.
0 Kudos
Altera_Forum
Honored Contributor II
1,274 Views

 

--- Quote Start ---  

I want to define System in SOPC builder , 

 

I just want to use pio's and lcd . 

 

I tried pio's and acheived how ever now I want to try lcd , 

 

Is anyone tell me step by step.  

 

And I want to write test code in NIOS. 

--- Quote End ---  

 

 

The steps are; 

 

1) Define an SOPC system containing; NIOS II + PIO + LCD 

 

2) Write code to access the PIO and LCD at the addresses defined by the SOPC system. 

 

The values of the data you have to write to the LCD to first initialize it, and then create text on it, is described in the Optrex manual. 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
1,274 Views

 

--- Quote Start ---  

The steps are; 

 

1) Define an SOPC system containing; NIOS II + PIO + LCD 

 

2) Write code to access the PIO and LCD at the addresses defined by the SOPC system. 

 

The values of the data you have to write to the LCD to first initialize it, and then create text on it, is described in the Optrex manual. 

 

Cheers, 

Dave 

--- Quote End ---  

 

 

 

and what should I add to system On chipMemory , JTAG and whatelse I need , Do I need to add avalon slave?
0 Kudos
Altera_Forum
Honored Contributor II
1,274 Views

 

--- Quote Start ---  

and what should I add to system On chipMemory , JTAG and whatelse I need 

 

--- Quote End ---  

 

 

If you want to use your processor, sure you need memory for it. Just follow one of the "My First NIOS" tutorials that Altera/Terasic provide with their kits. 

 

 

--- Quote Start ---  

 

Do I need to add avalon slave? 

--- Quote End ---  

 

 

PIO and LCD are Avalon slaves. 

 

You need to take the time to go through the tutorials to understand what an SOPC or Qsys system design is. 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
1,274 Views

Hi cesimkaol, 

 

I have build a system with the following components: 

clk_source, Nios II Processor, lcd_character, Pio for led; onchip_memory, jtag_uart and an DDR2. The DDR2 is not neccasary but you have to take a look at your on-chip memory size and the size of your C-Code. 

You can find an example how to program a LCD from optrex in the following doc 

DOT MATRIX CHARACTER LCD MODULE USER’S MANUAL from here:  

 

www.optrex.com/siteimages/litcentral/dmcman_full.pdf. 

 

In that doc is a description about the LCD registers and how to control tham. It help me a lot. 

Be also aware that you have the right Pin Assignments for your LCD(see right here:  

 

www.alteraforum.com/forum/showthread.php?t=4610&nojs=1&gsa_pos=4&wt.oss_r=1&wt.oss=lcd character)  

 

If you don´t have it your display make crazy things. 

 

I hope this hint will help you.
0 Kudos
Altera_Forum
Honored Contributor II
1,274 Views

LCD_ON is pin L4 and when I create system , I use system on block diagram I added system and connect pins ,there is just LCD_EN,LCD_RW,LCD_RS pins , where is the LCD_ON pin and LCD_BLON pins,or pin L4 and K2 are directly assigned to system wwhile system generated , according to lcd mocule verilog code , also there is not input for LCD_ON and LCD_BLON , just examine below ... 

 

 

 

//Legal Notice: (C)2011 Altera Corporation. All rights reserved. Your 

//use of Altera Corporation's design tools, logic functions and other 

//software and tools, and its AMPP partner logic functions, and any 

//output files any of the foregoing (including device programming or 

//simulation files), and any associated documentation or information are 

//expressly subject to the terms and conditions of the Altera Program 

//License Subscription Agreement or other applicable license agreement, 

//including, without limitation, that your use is for the sole purpose 

//of programming logic devices manufactured by Altera and sold by Altera 

//or its authorized distributors. Please refer to the applicable 

//agreement for further details. 

 

// synthesis translate_off 

`timescale 1ns / 1ps 

// synthesis translate_on 

 

// turn off superfluous verilog processor warnings  

// altera message_level Level1  

// altera message_off 10034 10035 10036 10037 10230 10240 10030  

 

module lcd ( 

// inputs: 

address, 

begintransfer, 

clk, 

read, 

reset_n, 

write, 

writedata, 

 

// outputs: 

LCD_E, 

LCD_RS, 

LCD_RW, 

LCD_data, 

readdata 

 

output LCD_E; 

output LCD_RS; 

output LCD_RW; 

inout [ 7: 0] LCD_data; 

output [ 7: 0] readdata; 

input [ 1: 0] address; 

input begintransfer; 

input clk; 

input read; 

input reset_n; 

input write; 

input [ 7: 0] writedata; 

 

wire LCD_E; 

wire LCD_RS; 

wire LCD_RW; 

wire [ 7: 0] LCD_data; 

wire [ 7: 0] readdata; 

assign LCD_RW = address[0]; 

assign LCD_RS = address[1]; 

assign LCD_E = read | write; 

assign LCD_data = (address[0]) ? 8'bz : writedata; 

assign readdata = LCD_data; 

//control_slave, which is an e_avalon_slave 

 

endmodule 

 

 

//module generated by SOPC builder.
0 Kudos
Altera_Forum
Honored Contributor II
1,274 Views

 

--- Quote Start ---  

where is the LCD_ON pin and LCD_BLON pins 

 

--- Quote End ---  

 

 

These are board-specific (not all LCD interfaces need them). You can control them using a PIO component. 

 

Cheers, 

Dave
0 Kudos
Altera_Forum
Honored Contributor II
1,274 Views

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); 

 

}
0 Kudos
Altera_Forum
Honored Contributor II
1,274 Views

Now its working , thank you dave .

0 Kudos
Altera_Forum
Honored Contributor II
1,274 Views

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...
0 Kudos
Reply