Forum Discussion

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

NIOS 2 alt_up_charactor_lcd to display variables C program

hey guys i need help with this i know how write to the LCD display, i just don know how to get my variables to display if you check my code you will see what i mean.

# include "altera_up_avalon_character_lcd.h"# include "altera_up_avalon_character_lcd_regs.h"
int main(){
/* other part of program
*
*
*here
*
*
*/
static int percent; 
percent = (rddata * 100)/511; // rddatta is from other part of code 
alt_up_character_lcd_dev * char_lcd_dev;
char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/LCD");
alt_up_character_lcd_init(char_lcd_dev);
alt_up_character_lcd_string(char_lcd_dev,"% reflection "); //first line of text to display
alt_up_character_lcd_set_cursor_pos(char_lcd_dev,13,0);// move cursor to where i want to place variable percent
/* this is where i need help, hw do i display my variable??
*is the format i need something like this
*
*alt_up_character_lcd_write(char_lcd_dev, percent);
*
*/
https://www.alteraforum.com/forum/attachment.php?attachmentid=6535

4 Replies

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

    You can use a function such as sprintf() to convert your value to a character string, and then write this string to the LCD using alt_up_character_lcd_string().

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

    Using snprintf() is generally better than sprintf() since it guarantees that you won't write beyond the end of the buffer.

    However, both of those functions will need the entire stdio library code (about 70k) in your image.

    If it isn't there already (eg you are using one of the 'small' BSP templates - or whatever they are called) and you are trying to fit the code into internal memiry, then you might have to do the numeric convertions yourself.

    That is hard, for decimal just repeatedly divide and remainder by 10 and add each remainder to '0', then output the characters in reverse order.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    okay, so i havekind of read up on sprintf

    this is what my code has now

    
    # include <stdio.h>
    # include "altera_up_avalon_character_lcd.h"
    # include "altera_up_avalon_character_lcd_regs.h"
    int  rddata;
    char buff ;
    int value ;
    //rddata recieved from other part of code
    //
    //    HERE
    //
    //end other part of code
    value=sprintf (buff, "%d", (rddata*100)/511 );
    alt_up_character_lcd_dev * char_lcd_dev;
    char_lcd_dev = alt_up_character_lcd_open_dev ("/dev/LCD");
    alt_up_character_lcd_init(char_lcd_dev);
    alt_up_character_lcd_string(char_lcd_dev,"reflection = ");
    alt_up_character_lcd_set_cursor_pos(char_lcd_dev,13,0);
    c(char_lcd_dev, "%s", buff);
    

    i get the error in the last line "too many arguments to function alt_up_character_lcd_string"

    how do i format this?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    never mind guys alittle extra perseverance got me through.. thanks for the quick responses and the valuable help.