Serin Help - ASCII to Decimal


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2009
    Posts
    8

    Default Serin Help - ASCII to Decimal

    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.
    Last edited by Dino308gt4; - 12th October 2009 at 17:16.

  2. #2
    Join Date
    Nov 2005
    Location
    Perth, Australia
    Posts
    429


    Did you find this post helpful? Yes | No

    Default

    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.
    "I think fish is nice, but then I think that rain is wet, so who am I to judge?" - Douglas Adams

  3. #3
    Join Date
    May 2008
    Location
    Italy
    Posts
    825


    Did you find this post helpful? Yes | No

    Default

    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.
    All progress began with an idea

  4. #4
    Join Date
    Oct 2009
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    That makes perfect sense (both replies). Thank you for your help!

  5. #5
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    Or maybe ...
    Code:
    Byte1 var Byte
    Byte2 var Byte
    
    SERIN2  1, 16780,[Byte1, DEC3 Byte2]
    DT

  6. #6
    Join Date
    Oct 2009
    Posts
    8


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Darrel Taylor View Post
    Or maybe ...
    Code:
    Byte1 var Byte
    Byte2 var Byte
    
    SERIN2  1, 16780,[Byte1, DEC3 Byte2]
    I'll try this. Thank you.

Similar Threads

  1. Hex to Ascii to Decimal
    By khoog in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st July 2009, 05:27
  2. Convert long binary number to ASCII Decimal
    By Joe Rocci in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 9th July 2009, 13:58
  3. SERIN in acii, hex, decimal?
    By sccoupe in forum mel PIC BASIC Pro
    Replies: 15
    Last Post: - 10th March 2009, 21:28
  4. Problem with PBP interrupt and Serin, please help
    By rgregor in forum mel PIC BASIC
    Replies: 0
    Last Post: - 22nd August 2006, 19:02
  5. Conversion of 10-bit word into ASCII
    By Barry Johnson in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 16th January 2005, 14:26

Members who have read this thread : 1

You do not have permission to view the list of names.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts