cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 5, 3 & 1

eeEn_4618901
Contributor

Hi;

When I use the sensorread function it says 9A on the screen. How do I print the result in decimal?

void sensorRead()

{

  int8  sensorRead=(-20-((205 - spi_read(0x26))/ 2));

     LCD_Position(0u,4u);

     LCD_LCD_LCD_PrintInt8(sensorRead);

    CyDelay(300);

// LCD_ClearDisplay();

}

LCD_PrintNumber(spi_read(0x26));==> LCD Output    42

  LCD_PrintDecUint16(spi_read(0x26));  ==> LCD Output    42

  LCD_PrintHexUint16(spi_read(0x26));  ==> LCD Output    2A

0 Likes
1 Solution
MotooTanaka
Esteemed Contributor

Hi,

From what you wrote both LCD_PrintNumber() and LCD_PrintDecUint16() are printing in decimal.

as 2A in hex is 42 in decimal.

If you want to have control over format, maybe you can try...

#define STR_LEN 32 // choose appropriate number for your usage

char str[STR_LEN] ;

int8 sensorRead ;

...

sensorRead = -20-((205 - spi_read(0x26))/2) ; // I just referenced your formula

snprintf(str, STR_LEN, "%d", sensorRead) ; // you can have something like "value = %d" for the format

LCD_PrintString(str) ;

...

moto

View solution in original post

1 Reply
MotooTanaka
Esteemed Contributor

Hi,

From what you wrote both LCD_PrintNumber() and LCD_PrintDecUint16() are printing in decimal.

as 2A in hex is 42 in decimal.

If you want to have control over format, maybe you can try...

#define STR_LEN 32 // choose appropriate number for your usage

char str[STR_LEN] ;

int8 sensorRead ;

...

sensorRead = -20-((205 - spi_read(0x26))/2) ; // I just referenced your formula

snprintf(str, STR_LEN, "%d", sensorRead) ; // you can have something like "value = %d" for the format

LCD_PrintString(str) ;

...

moto

View solution in original post