2014-05-24 07:27 AM
Hi, i have a bmp085 bosch pressure&temp sensor, wich i want to show my data in format 4 degree
The raw readings are ok, i have the following code goinguint8_t tlsb;
uint8_t tmsb;
uint16_t temp;
char txt[10];
tmsb=i2c_rdack(I2C1);
tlsb=i2c_rdNack(I2C1);
temp=(tmsb<<8)+tlsb;
sprintf(txt,''%d'',temp); // converts int to string
char *ch1;
char *ch2;
char *ch3;
ch1=&txt[0];
ch2=&txt[1];
ch3=&txt[2];
UB_LCD_2x16_String(0,1,txt); // if i use only this, it shows me 254 value, wich is corect since i have 4 degree
but i wanna split the chars so i can add comma''.'', the result i wanted to be like this
UB_LCD_2x16_String(0,1,ch1); // displays first digit ( 2)
UB_LCD_2x16_String(0,1,ch2); // displays second digit (5)
UB_LCD_2x16_String(0,1,''.''); // displays only a dot (.)
UB_LCD_2x16_String(0,1,ch3); // displays the last digit (4)
The problem is at the pointing trough the txt char array. I`m not so familiar to standard c, used only mikroc builtin libs. Have any idea how to point
Thanks
#string #c-learning #c-string
2014-05-24 08:12 AM
sprintf(txt,''%d.%d'',temp/10,temp%10); // converts 10x int to string
xx.x
2014-05-24 11:28 AM
The the thing you need to remember is that a ''string'' in 'C' means ''an array of characters terminated by a NUL''
char txt[10];
char *ch1;
char *ch2;
char *ch3;
:
ch1=&txt[0];
ch2=&txt[1];
ch3=&txt[2];
So what this actually gives you, in a function expecting a
string, is a set of
strings starting at different points through the original string.
If txt is the string ''123'', then
ch1 isthe string ''123'';
ch2 isthe string ''23'';
ch3 isthe string ''3''.
''I`m not so familiar to standard c, used only mikroc builtin libs''
I can't imagine that this would be any different?
Here's some standard 'C' learning resources:
http://blog.antronics.co.uk/2011/08/08/so-youre-thinking-of-starting-with-c/
2014-05-25 07:19 AM
Not related to the display issue but
temp=(tmsb<<8)+tlsb;
Should be
temp=((uint16_t)tmsb<<8)+tlsb;
as tmsb is only 8 bits