Displaying a float number on LCD

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi,

   

My project is to display, in different formats, the results of the A/D conversion. I cannot display the result in decimal format (floating point).

   

My resources are:

   

PSOC Creator 3.3.

   

PSOC4: CY8CKIT-049-42XX-(CY8C4245AX483)

   

LCD: RC1602B

   

I wrote the ”-u_printf_float”  as a custom command line for the Linker tool.

   

The LCD is displaying only ”ADC”, at position (0,0).

   

Thank You!

   

The main file is bellow:

   

#include <project.h>
#include <stdio.h>
int main()

    int32 conversie;
    char cuvant [16];
    float32 val,vin ;
    
    CyGlobalIntEnable; /* Enable global interrupts. */
    ADC_Start();
    ADC_StartConvert();
    ADC_IsEndConversion(ADC_WAIT_FOR_RESULT);
    
    LCD_Start();
    LCD_Position(0,0);
    LCD_PrintString("ADC");
       
    for(;;)
    { 
    conversie = ADC_GetResult16(0);
    val = ADC_CountsTo_Volts(0,conversie);    
    sprintf(cuvant,"%1.4f       ",val);
    LCD_Position(1,0);
    LCD_PrintString(cuvant);
   
    
    vin = (float32)conversie * 1024/32768;
    sprintf(cuvant,"%1.3f       ",vin);
    LCD_Position(1,6);
    LCD_PrintString(cuvant);
   
   
    
    LCD_Position(0,6);  
    LCD_PrintNumber(vin);
    
    LCD_Position(0,10);
    LCD_PrintInt16(conversie);
    
    LCD_Position(1,11);
    LCD_PrintInt16(vin);
    
      
    CyDelay(1000);
    }
}

   

/* [] END OF FILE */

0 Likes
4 Replies
himam_31
Employee
Employee
50 likes received 25 likes received 10 likes received

Hello,

   

Can you increase the stack size inn .cydr->System_>Stack Size.

   

 

   

Thanks,

   

Hima

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

It is not the stack size, but the heap size. Set it to at least 0x0200.

   

 

   

Bob

0 Likes
Anonymous
Not applicable
        Thanks for both, Bob(0x0200) and Hima(0x0800). IT is working now.   
0 Likes

When using GCC, you also may need to set the floating point library in the linker options

0 Likes