Intel® FPGA University Program
University Program Material, Education Boards, and Laboratory Exercises
Announcements
Intel Support hours are Monday-Fridays, 8am-5pm PST, except Holidays. Thanks to our community members who provide support during our down time or before we get to your questions. We appreciate you!

Need Forum Guidance? Click here
Search our FPGA Knowledge Articles here.

DE2 LCD display

Altera_Forum
Honored Contributor II
1,897 Views

I'm trying to debug a code I've written, but I'm having trouble figuring out the values of some of my parameters while using the Altera Debug Client. I'm using the Altera DE2 board and I was hoping to display some results on the LCD screen 

I found in verilog this command: DE2LCDDriver(parameter) 

 

How would i convert that to C or C++?? 

 

Thanks!
0 Kudos
8 Replies
Altera_Forum
Honored Contributor II
109 Views

does anyone have a copy of this library? 

alt_up_character_lcd.h
Altera_Forum
Honored Contributor II
109 Views

#ifndef __ALTERA_UP_AVALON_CHARACTER_LCD_H__ 

# define __ALTERA_UP_AVALON_CHARACTER_LCD_H__ 

 

# include <stddef.h> 

 

# include "sys/alt_dev.h" 

# include "sys/alt_alarm.h" 

# include "sys/alt_warning.h" 

 

# ifdef __cplusplus 

extern "C" 

# endif /* __cplusplus */ 

 

/* 

* Device structure definition. Each instance of the driver uses one 

* of these structures to hold its associated state. 

*/ 

typedef struct alt_up_character_lcd_dev { 

/// @brief character mode device structure  

/// @sa Developing Device Drivers for the HAL in Nios II Software Developer's Handbook 

alt_dev dev; 

/// @brief the base address of the device 

unsigned int base; 

} alt_up_character_lcd_dev; 

 

// system functions 

/** 

* @brief Initialize the LCD by clearing its display 

* @param lcd -- struct for the LCD Controller device  

**/ 

void alt_up_character_lcd_init(alt_up_character_lcd_dev *lcd); 

 

// file-like operation functions 

int alt_up_character_lcd_write_fd(alt_fd *fd, const char *ptr, unsigned int len); 

 

// direct operation functions 

/** 

* @brief Open the character LCD device specified by <em> name </em> 

* @param name -- the character LCD name. For example, if the character LCD name in SOPC Builder is "character_lcd_0", then <em> name </em> should be "/dev/character_lcd_0" 

* @return The corresponding device structure, or NULL if the device is not found 

**/ 

alt_up_character_lcd_dev* alt_up_character_lcd_open_dev(const char* name); 

 

/** 

* @brief Write the characters in the buffer pointed to by <em> ptr </em> to 

* the LCD, starting from where the current cursor points to  

* @param lcd -- struct for the LCD Controller device  

* @param ptr -- the pointer to the char buffer 

* @param len -- the length of the char buffer 

* @return 0 for success 

**/ 

int alt_up_character_lcd_write(alt_up_character_lcd_dev *lcd, const char *ptr, unsigned int len); 

 

/** 

* @brief Set the cursor position 

* @param lcd -- struct for the LCD Controller device  

* @param x_pos -- x coordinate ( 0 to 15, from left to right ) 

* @param y_pos -- y coordinate ( 1 for the first row, 2 for the second row ) 

* @return 0 for success 

**/ 

int alt_up_character_lcd_set_cursor_pos(alt_up_character_lcd_dev *lcd, unsigned x_pos, unsigned y_pos); 

 

/** 

* @brief Shift the cursor to left or right 

* @param lcd -- struct for the LCD Controller device  

* @param x_right_shift_offset -- the number of spaces to shift to the right. If the offset is 

* negative, then the cursor shifts to the left. 

* @return 0 for success 

**/ 

int alt_up_character_lcd_shift_cursor(alt_up_character_lcd_dev *lcd, int x_right_shift_offset); 

 

/** 

* @brief Shift the entire display to left or right 

* @param lcd -- struct for the LCD Controller device  

* @param x_right_shift_offset -- the number of spaces to shift to the right. If the offset is 

* negative, then the display shifts to the left. 

* @return 0 for success 

**/ 

int alt_up_character_lcd_shift_display(alt_up_character_lcd_dev *lcd, int x_right_shift_offset); 

 

/** 

* @brief Erase the character at the specified coordinate  

* @param lcd -- struct for the LCD Controller device  

* @param x_pos -- x coordinate ( 0 to 15, from left to right ) 

* @param y_pos -- y coordinate ( 1 for the first row, 2 for the second row ) 

* @return 0 for success 

**/ 

int alt_up_character_lcd_erase_pos(alt_up_character_lcd_dev *lcd, unsigned x_pos, unsigned y_pos); 

 

/* 

* Macros used by alt_sys_init  

*/ 

# define ALTERA_UP_AVALON_CHARACTER_LCD_INSTANCE(name, device)  

static alt_up_character_lcd_dev device =  

{  

{  

ALT_LLIST_ENTRY,  

name##_NAME,  

NULL, /* open */  

NULL, /* close */  

NULL, /* read */  

alt_up_character_lcd_write_fd,  

NULL, /* lseek */  

NULL, /* fstat */  

NULL, /* ioctl */  

},  

name##_BASE,  

 

# define ALTERA_UP_AVALON_CHARACTER_LCD_INIT(name, device)  

{  

alt_up_character_lcd_init(&device);  

alt_dev_reg(&device.dev);  

 

 

# ifdef __cplusplus 

# endif /* __cplusplus */ 

 

# endif /* __ALTERA_UP_AVALON_CHARACTER_LCD_H__ */
Altera_Forum
Honored Contributor II
109 Views

Hope The Above Helps....

Altera_Forum
Honored Contributor II
109 Views

Here I am posting some very rudimentary code that shows one way to drive the LCD display in the DE2 (very rudimentary code ....) 

 

# include <stdio.h># include <unistd.h># include "system.h"# include "DE2_pio_regs.h"# include "altera_up_avalon_character_lcd.h" 

 

int main() 

int in, out; 

alt_up_character_lcd_dev * lcd; 

int len; 

 

len =15; 

lcd = alt_up_character_lcd_open_dev(CHARACTER_LCD_0_NAME ); 

// i 've found CHARACTER_LCD_0_NAME in the system.h file 

 

alt_up_character_lcd_set_cursor_pos(lcd, 0, 1); 

alt_up_character_lcd_write(lcd, "SOO REALLY COOL", len); 

alt_up_character_lcd_set_cursor_pos (lcd, 0, 2); 

alt_up_character_lcd_write(lcd, "... TWICE SO ..", len); 

 

[....] 

 

 

 

Hope this helps others.... 

 

alfa 

 

PS I am using Nios II IDE 8.0 and and Quartus/SoPC builder 8.0sp1. 

As I was learning how to do this i figured out that the name of some include files has changed. 

For instance: 

altera_up_avalon_character_lcd.h 

 

used to be: 

alt_up_character_lcd.h 

 

Has anyone else noticed?
Altera_Forum
Honored Contributor II
109 Views

@foleyme (http://www.alteraforum.com/forum/member.php?u=3960

i'm trying connect keyboard to FPGA ( kit DE2 like you) and display on LCD green..can you give me verilog code of DE2LCDDriver(parameter)?I realy need it :)
Altera_Forum
Honored Contributor II
109 Views

you can use the LCD16207. 

that will work.
Altera_Forum
Honored Contributor II
109 Views

hello everybody, i'm trying to display time and date on LCD ( board DE2 Altera) by VHDL code, can you help me with the code ? please, i'm a beginer. thanks you very much

Altera_Forum
Honored Contributor II
109 Views

I keep hitting this 'obsolete' thread... just FYI, as of Quartus 13.0sp1 the library is 'altera_avalon_lcd_16207.h'  

 

Looking over that and the other docs should help...# include "altera_avalon_lcd_16207.h"# include "altera_avalon_lcd_16207_regs.h" 

 

then you just treat it like a 'mostly avalon' device... 

 

IORD_ALTERA_AVALON_LCD_16207_STATUS(baseAddress); 

IOWR_ALTERA_AVALON_LCD_16207_DATA(base, data); 

 

However... the LCD needs quite a few 'waits'... so don't try to do a lot of IOWR's in a quick sequence.. put in some waits.. try starting wtih 100usec between them to start.
Reply