Display Float on LCD – MPLAB XC8

Home Forums Microcontrollers PIC Microcontroller Display Float on LCD – MPLAB XC8

Tagged: , ,

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #10277
    sahu
    Participant

    How to display floating point values on LCD ? I am using MPLAB XC8 LCD Library.

    #10280
    Ligo George
    Keymaster

    You can display floating point values on LCD in following two methods.

    1. By converting floating point value to string and display that sting using Lcd_Write_String()
    2. By separating each digits and display that digit using Lcd_Write_Char() after converting it to character

    The second method is the best method but it will vary depending upon the length of values that to be displayed.

    #10281
    sahu
    Participant

    Please give me a example of first method.

     

    #10289
    Ligo George
    Keymaster

    Use sprintf() to convert floating point number to string :

    ........
    #include<stdio.h> 
    ......
    ...
    ...
    void main()
    {
      char s[16];
      float f;
      ........
      ....
      while(1)
      {
        ....
        ...
        ...
        sprintf(s, "Float = %f", f);
        Lcd_Set_Cursor(1, 1);
        Lcd_Write_String(s);
        ...........
        .....
      }
    }
    
    #10321
    sahu
    Participant

    Thank you Sir

    #10424
    sahu
    Participant

    what wrong with me `

    a = ADC_Read(0);
    involts =a*5000/255;
    delayMs(10);
    {
      Lcd_Clear();
      Lcd_Set_Cursor(1,1);
      Lcd_Write_String("Mains");
      /*
        Lcd_Set_Cursor(1,10);
        Lcd_Write_Char(involts%10 + 48);
        involts = involts/10;
        Lcd_Set_Cursor(1,9);
        Lcd_Write_Char(involts%10 + 48);
        involts = involts/10;
        Lcd_Set_Cursor(1,8);
        Lcd_Write_Char(involts%10 + 48);
      */
      sprintf(s, "Float = %f", involts);
      Lcd_Set_Cursor(1, 10);
      Lcd_Write_String(s);
      Lcd_Set_Cursor(1,13);
      Lcd_Write_String("VOLT");
    
    
    found error as
    

    lib\doprnt.c; 837. bad call to typeSub()
    `

    #10433
    Ligo George
    Keymaster
    • Try using the latest compiler
    • Make sure that you properly set the pic type in configuration
    • Try recreating the project after deleting all files
Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
>