Pigi_102
Member level 2
- Joined
- Nov 14, 2007
- Messages
- 46
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1,286
- Activity points
- 1,722
Stucked on studid string conversion ( C inside )
Hi all,
I'm facing a stupid problem on converting from string to integer.
I have a string ( like "123" ) and need to interpreter his value, char by char reading backword and looking up his display value in an array ( to lit a 7 segment display by using a 4094 driver.
I already have a code working in C on my linux machine, and a working code for a really old Pic C compiler, but translating in CCS it does not work.
Here some snippet:
In the previous code I had:
and was working, but in CCS it does not.
In linux the code is almost the same :
Can you help me understand what I'm doing wrong ?
Thanks
Pigi
Hi all,
I'm facing a stupid problem on converting from string to integer.
I have a string ( like "123" ) and need to interpreter his value, char by char reading backword and looking up his display value in an array ( to lit a 7 segment display by using a 4094 driver.
I already have a code working in C on my linux machine, and a working code for a really old Pic C compiler, but translating in CCS it does not work.
Here some snippet:
Code:
char digit[10]=
{
0b01111110, // 0
0b00010010, // 1
0b10111100, // 2
0b10110110, // 3
0b11010010, // 4
0b11100110, // 5
0b11001110, // 6
0b00110010, // 7
0b11111110, // 8
0b11110010 // 9
} ;
void display(char * content, int howmany){
char Bytem;
char p[2];
while ( (howmany+1) > 0 ) { // for every byte in buffer
p[0] = content[howmany--]; // read from last char in string backword
p[1] = '\0';
Bytem = digit[atoi(p)];
/* here the 4094 routine */
}
void main () {
while ( 1 )
display ( "123", 3);
display ( "456", 3);
// and so on
}
}
In the previous code I had:
Code:
int i=0;
while ( (howmany+1) > 0 ) {
i = (char) content[howmany--] - 0x80;
Bytem = digit[i];
/* here the 4094 routine */
}
and was working, but in CCS it does not.
In linux the code is almost the same :
Code:
while ( (howmany+1) > 0 ) {
i = (char) content[howmany--] - '0';
Bytem = digit[i];
Can you help me understand what I'm doing wrong ?
Thanks
Pigi