-1

I'm using CY8CKIT-050 PSOC 5LP development kit and I have this code:

#include "project.h"
#include<stdio.h>

int main(void)
{
    CyGlobalIntEnable; /* Enable global interrupts. */

    float32 test;

    LCD_Start();

    for(;;)
    {
        test = 0.1;
        sprintf(lineStr, "Test: %.2f", test);

        LCD_Position(1u, 0u);
        LCD_PrintString("                    ");

        LCD_Position(1u, 0u);
        LCD_PrintString(lineStr);

    }

But when I connect the LCD to the board, it doesn't appear 0.1, but 0.. However, when test=0.0, it apears Test: 0.000000.

I hope someone can help me. Thank you for your responses.

Josemi
  • 121
  • 5

2 Answers2

3

It looks like test is defaulting to an integer datatype, unless you have declared it otherwise in one of your header files. Your real literal, 0.1, is being truncated (i.e. floored, rounded-down) to integer 0.

You must declare test to be a floating-point datatype.

Elliot Alderson
  • 31,521
  • 5
  • 30
  • 67
0

[Referring to an earlier version of the question text.]

"Test: 0." contains 8 characters (not including the nul at the end) - is this the width of your LCD?

Try using LCD_PrintString("0123456789ABCDEF"); and see how many characters are displayed.

srl100
  • 179
  • 4