gabo1024
Joined: 02 Apr 2012 Posts: 1
|
problem with itoa and atoi |
Posted: Mon Apr 02, 2012 1:35 pm |
|
|
Hi, i have used this configuration for multiple usarts:
Code: |
#use rs232(baud=9600,parity=n,xmit=PIN_A2,rcv=PIN_A3,bits=8,stream=display)//conexion a display
#use rs232(baud=9600,parity=e,xmit=PIN_C1,rcv=PIN_C2,bits=7,stream=balanza)//conexion a balanza
#use rs232(baud=9600,parity=e,xmit=PIN_A0,rcv=PIN_A1,bits=7,stream=pc)//conexion a PC
|
I receive this datagram in ASCII code: "02905" or 30,32...35 in hex, for example.
I need convert this datagram to decimal, process(divide for 100 or 1000) for later sending for others ports balanza, or pc.
as I can do ? |
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 02, 2012 2:30 pm |
|
|
The atol() function (ASCII to long) requires a string as the input. The
ASCII digits must be in an array, and the digits must have a 0x00 byte at
the end. The array must be large enough to hold the ASCII numbers, and
the 0x00 byte.
If the ASCII digits don't have a 0x00 byte at the end, then you must
write code to put it there.
The atol() function can convert a signed decimal ASCII number from
-32768 to 32767, into a 'signed int16' value in CCS. |
|