Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

string to hex/string problem

Status
Not open for further replies.

eng.hasan.power

Member level 1
Joined
Mar 30, 2006
Messages
39
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,597
hello everyone,



im facing a problem, im sending a HEX values to the PC, put the PC program display it as string, BUT i want it as HEX, i cant change the PC part, because its displaying other information too, it will be easier for me if i change the TI code,

for example,

i want to send 0xEA on the screen i received it as ê,,, i want to see it as EA

i did like that

tempTXFrame= 0xEA;
ltoa(tempTXFrame,TCPTemp);

TXFrame[0] = 0x41;
TXFrame[1] = TCPTemp[0];
TXFrame[2] = TCPTemp[1];

////////////////////////

it suppose i receive 6561 but i receive on the screen 23 ?????? i think im using the wrong function, im newbie with strings

any advice will be great, thanks all

Hasan
 

Try:

sprintf(TCPTemp,"%c%x",0x41,tempTXFrame);

This should create a string "TCPTemp" with position [0] holding 0x42 and subsequent locations holding the hex characters from tempTXFrame.
You can then send the string by sending TCPTemp[0], [1]. [2] and so on as characters.

Brian.
 

thanks bunch Brain,
but i used it like that,
tempTXFrame= 0xea;
sprintf(TCPTemp,"%x",tempTXFrame);
TXFrame[1] = TCPTemp[0];
TXFrame[2] = TCPTemp[1];

///////////
but i received a warning,
>> warning: creating .sysmem section with default size of 400 (hex) words.

Use -heap option to change the default size.
im using C2000 DSP family, btw,

greetings, and thanx again
hasan
 

Maybe the 'sprintf' function is too large to link in the available memory space. It caters for all kinds of radix conversion so it is a large function.

Try this method instead. I haven't tried it myself to verify it works,

TxFrame[1] = ((tempTxFrame & 0xF0) >> 4) + '0'; // move MSB to LSB and add ASCII zero
if(TxFrame[1] > '9') TxFrame[1] += 7; //adjust for hex characters
TxFrame[2] = (tempTxFrame & 0x0F) + '0';
if(TxFrame[2] > '9' TxFrame[2] += 7;

If I got this right, you split the hex value into an upper and lower part. The upper part is made ASCII by shifting it to the lower part and adding the value for ASCII zero, so hex zero becomes '0'. If the original value was above 9 it must have been A to F so add another 7 to skip over the ASCII symbols and make 0x0A in to character 'A'.
The same is done for the lower half of the byte but without shifting it.

Brian.
 
grazie mille,
thanks aloot,,its working gr8, really appreciated :)
Greetings have a gr8 day,
Hasan
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top