does anyone have a routine to take say the binary value from an A/D pin and send it out over serial in hex, but as a decimal equivilent like the binary '00000001' would go out over serial as hex'31' ?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First for some clarity. All serial data is binary. There is no difference in what goes out the serial port uesing any of the three lines below.
Sersend 1, 65
Sersend 1, 0x41
Sersend 1, 'b01000001'
In al three cases the serial out data is the exact same series of 1' s and 0's
If the question is referring to reading an A/D pin, then sending serial data so that it displays on a terminal in hex format here's how I do it using a subroutine that converts a decimal byte value
to display as hex.
almost, but i need the hex to be the equivilent of the decimal, say the a/d reads 32 then i need the serial output to be '0x33' '0x32' so i get a "32" rather than '0x20'
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think it is a terminology issue, you are asking for the ASCII code not
HEX code.
There are several functions in BASIC to format numbers for printing,
unfortunately I don't have access to the GCB documentation at the moment
but look for a command like ASC().
almost, but i need the hex to be the equivilent of the decimal, say the
a/d reads 32 then i need the serial output to be '0x33' '0x32' so i get a
"32" rather than '0x20'
does anyone have a routine to take say the binary value from an A/D pin and send it out over serial in hex, but as a decimal equivilent like the binary '00000001' would go out over serial as hex'31' ?
Send it out in ASCII hex right?
You need to break it into bytes of tens and ones (base 16 though), then serial
print with the hex function.
http://gcbasic.sourceforge.net/help/_hex.html
Last edit: lhatch 2016-03-08
Look in the GCBasic Help under String Manipulations > Hex.
There is an example.
First for some clarity. All serial data is binary. There is no difference in what goes out the serial port uesing any of the three lines below.
Sersend 1, 65
Sersend 1, 0x41
Sersend 1, 'b01000001'
In al three cases the serial out data is the exact same series of 1' s and 0's
If the question is referring to reading an A/D pin, then sending serial data so that it displays on a terminal in hex format here's how I do it using a subroutine that converts a decimal byte value
to display as hex.
almost, but i need the hex to be the equivilent of the decimal, say the a/d reads 32 then i need the serial output to be '0x33' '0x32' so i get a "32" rather than '0x20'
I think it is a terminology issue, you are asking for the ASCII code not
HEX code.
There are several functions in BASIC to format numbers for printing,
unfortunately I don't have access to the GCB documentation at the moment
but look for a command like ASC().
Cheers
Chris
On Tue, Mar 8, 2016 at 8:59 PM, Ryan rmystique@users.sf.net wrote:
Just use SerPrint 1, (variable) to display the numerical 32 as "32"
This really has nothing to do with "hex"
Example:
Do
Variable = ReadAD(9)
SerPrint 1, Variable
Sersend 1,13
Sersend 1,10
wait 500 ms
Loop