The calculation result should be from -10.0 to +10.9
then, i would like to display result like this : +xx.x or -xx.x
I would like to display 1 digit after comma : if i proceed like this, it it correct ?
But i don't know how to find out if result will be + or - signed ... i need to display the sign ( + or - ) in front of the result.
Code: Select all
char result_display[6] = " 00.0";
signed int z_read=0;
signed int result;
unsigned int c = 515;
unsigned int s = 163;
...
z_read = ADC_read(1); // get ADC value from 1st channel ( RA0 )
result = (((signed int)z_read - c) / s); // calculation
// Extract each digit from "g_int" result :
result_display[2] = result% 100+ 48; // example: result = 17.2 % 100 = 1, 1 + 48 = '7' - ASCII
LCD_Chr(4,1,48+result_display[2]); // Print character on LCD
result_display[1] = result% 10 + 48; // example: result = 17.2 % 10 = 7, 7 + 48 = '7' - ASCII
LCD_Chr_CP(48+result_display[1]); // Print character on LCD
LCD_Chr_CP('.'); // Print "." character on LCD
result_display[0] = result% 1 + 48; // example: result = 17.2 % 1 = 2, 2 + 48 = '2' - ASCII
LCD_Chr_CP(48+result_display[0]); // Print character on LCD
But maybe i declared " result " as float instead of signed int and then only show 1 digit after comma.
if so i don't know how to do that.
Can someone show me the way please ?