This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Display value in 20x4 LCD with TM4C 123GXL

My objective is to display a variable value in 20x4 LCD that variable value will get sourced
either from adc or some communication like uart,CAN so i was trying with just
a variable x defined 5 which i want to display

i am using  usprintf function
but it is giving error of expression is missing

let me know if m missing something or understanding is wronge




Code snippet



#include <stdint.h>
#include <stdbool.h>
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/gpio.h"
#include "driverlib/sysctl.h"
#include "utils/ustdlib.h"



// initilization of global variable

uint32_t X=5;
char X1[3]={0};

void main(void)
{
    SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_XTAL_16MHZ|SYSCTL_OSC_MAIN);      // Setting the System Clock 40Mhz

    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);    // Enable GPIO Port F
    SysCtlDelay(6);                                   // 450ns approx
    SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);    // Enable GPIO Port B For LCD Lines
    SysCtlDelay(6);                                   // 450ns approx

    // Check if the peripheral access is Enabled.
       while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOF))
       {
       }
       while(!SysCtlPeripheralReady(SYSCTL_PERIPH_GPIOB))
       {
       }

       GPIOPinTypeGPIOOutput(GPIO_PORTB_BASE,GPIO_PIN_0|GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3| GPIO_PIN_4| GPIO_PIN_5| GPIO_PIN_6| GPIO_PIN_7);
       GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE,GPIO_PIN_1|GPIO_PIN_2|GPIO_PIN_3);  //Red,Blue,Green Gpio Pin as a Output Pin
       GPIOPinWrite(GPIO_PORTB_BASE, GPIO_PIN_2, 0x0);      //  R/W Low, Enable LCD Data Write
       LcdInit();    // LCD Configuration
       X=5;

      // Loop forever.
      while(1)
       {
         
             displaystrn(2,3,"Tiva=");
            usprintf(X1,"%u",X);        //usprintf(char * restrict s, const char * restrict format, ...);
            displaystrn(2,3,X1);
            delay_ms(1000);
            LcdClear();
            delay_ms(1000);
       }    // End of Infinite Loop

}     // End of Main Function

  • sorry for correction

    while(1)
    {
    //X=5;
    displaystrn(2,3,"Tiva= "); //
    usprintf(X1,"%u",X); //usprintf(char * restrict s, const char * restrict format, ...);
    displaystrn(2,9,X1);
    delay_ms(1000);
    LcdClear();
    delay_ms(1000);
    } // End of Infinite Loop
  • Hello Gourav,

    Did you add the ustdlib.c in compilation flow? Please paste the CCS compilation console log if the error is for compilation and linking.
  • Hi Amit

    Thanks ,yes by adding this the error has gone i can able to display. after reading this function details it can only display %d ,%c,.. and so on format except %f (to display float value like 2.5 ......... )
    Is there any other function for float that i can used ???
  • Hello Gaurav,

    You would need to use fractional display using %d operator as is given in the examples for sensor hub in TivaWare. The trick is to use %03d.%03d and use the calculated integer and fractional value.