PDA

View Full Version : Serin Help - ASCII to Decimal



Dino308gt4
- 12th October 2009, 17:07
I've Googled till my fingers bled, but still can't get this to work. I'm reading serial data from a Windows XP machine in the following format: "F100". I'm using serin on a 16f877. The data is being sent as characters from the Window machine.

<code>
Byte1 var Byte
Byte2 var Byte

Serin 1,N2400, Byte1, Byte2
</code>

I want to read Byte1 as "F", and Byte2 as decimal 100. I can read the "F", but I'm not sure how to get the 100 as a number. I've tried # and []. Should be easy right? So far I'm failing miserably!

Can anyone help? Thank you in advance.

Kamikaze47
- 12th October 2009, 17:55
if the pc is sending the ascii characters F 1 0 0 then it is actually sending four bytes.

you can either receive all four and then use some math to translate the characters 1 0 0 into a decimal 100, or if you can change what the PC is sending, you can send F d since ascii d is decimal 100.

aratti
- 12th October 2009, 17:59
In order to receive "F100" you need 4 bytes "F" "1" "0" "0" , so try

Byte1 var Byte
Byte2 var Byte
Byte3 var Byte
Byte4 var Byte

Serin 1,N2400, Byte1, Byte2, Byte3, Byte4

Al.

Dino308gt4
- 12th October 2009, 18:01
That makes perfect sense (both replies). Thank you for your help!

Darrel Taylor
- 12th October 2009, 22:17
Or maybe ...

Byte1 var Byte
Byte2 var Byte

SERIN2 1, 16780,[B]DEC3 [/COLOR]Byte2]

Dino308gt4
- 12th October 2009, 23:00
Or maybe ...

Byte1 var Byte
Byte2 var Byte

SERIN2 1, 16780,[B]DEC3 [/COLOR]Byte2]

I'll try this. Thank you.