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++
12599 Discussions

How to "printf" to my 16207 Optrex lcd controller ?

Altera_Forum
Honored Contributor II
1,795 Views

Hi there, 

 

I've spent lots of time on this, but S.O.L.. cant solve this one. 

 

I am trying to output a string of texts (sometimes with integer variable) to my LCD controller using printf() (or similar) through NIOS 2, using Eclipse IDE. 

 

I can verify my connection is good, and my LCD and NIOS 2 works fine too, as i can use the HAL to manually initialize the LCD, delay, and also to output text like the following;  

 

/////////////////////////////////////////////////////////////////////////////////////// 

void lcd_init(void){ 

IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE, 0x38); 

usleep(1000); 

IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE, 0x0C); 

usleep(1000); 

IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE, 0x01); 

usleep(1000); 

IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE, 0x06); 

usleep(1000); 

 

/////////////////////////////////////////////////////////////////////////// 

void lcd_print(char *pText){ 

int i=0; 

 

while(pText!='\0') // loop until the eof 

switch(ptext

case '\f':IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE, 1); 

usleep(2000); 

break; 

case '\n':IOWR_ALTERA_AVALON_LCD_16207_COMMAND(LCD_BASE, 0xC0); 

usleep(1000); 

break; 

default: IOWR_ALTERA_AVALON_LCD_16207_DATA(LCD_BASE, pText[i] ); 

usleep(1000); 

break; 

 

i++; // get ready for the next character in the string 

} // end of while 

return; 

///////////////////////////////////////////////////////////////////////////////// 

 

 

I wrote these functions, it works well, but it does not take any variable like the following; 

lcd_print("the number is: %d", A) .  

my function can only output pure ASCII character.  

 

I found some example online that could potentially do this, shown in the following; 

 

////////////////////////////////////////////////////////// 

 

FILE* fp; 

fp= fopen("LCD_NAME", "w"); 

 

if (fp == NULL) { 

fprintf(stderr, "open failed\n"); return 0; 

 

fprintf(fp, "The time now is %d", time); 

 

////////////////////////////////////////////////////////////// 

 

I can't make this code work. my question is WHY?? 

I don't understand how this code can work, as it does not initialize, and it does not contain any delay. Can anyone correct this? 

 

 

 

Thank you. 

 

Michael
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
585 Views

In Nios II software build tools (Eclipse), make a new program from example. I am sure there is LCD routine in Web Server example since it shows IP address in the LCD, but You can check board diagnostics or other examples containing LCD control source.

0 Kudos
Altera_Forum
Honored Contributor II
585 Views

 

--- Quote Start ---  

In Nios II software build tools (Eclipse), make a new program from example. I am sure there is LCD routine in Web Server example since it shows IP address in the LCD, but You can check board diagnostics or other examples containing LCD control source. 

--- Quote End ---  

 

 

Hi,  

 

My LCD routine works now. As you said, i used the code from a template file. But i dun quite understand the template file. 

Do you know how this line works??  

 

FILE* fp; 

fp= fopen(LCD_DISPLAY_NAME, "w"); 

 

am i writing to the internal physical memory of the LCD module?? otherwise where is this file located at? 

 

 

regards, 

Michael
0 Kudos
Reply