LCD

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

cross mob
eeEn_4618901
Level 4
Level 4
5 likes given First like received First like given

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
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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
Level 9
Level 9
Distributor - Marubun (Japan)
First comment on blog Beta tester First comment on KBA

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