Altera_Forum
Honored Contributor
14 years agoHow to "printf" to my 16207 Optrex lcd controller ?
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