HSER revisited


Closed Thread
Results 1 to 5 of 5

Thread: HSER revisited

  1. #1
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305

    Default HSER revisited

    I need to send and receive bytes in a hex format. Is it as simple as HSEROUT $aa, $bb, $cc etc etc?
    And to receive bytes in hex is just HSERIN HEX B0, B1, B2 ?

    Now if I want to send out an incoming byte but swap the first and last characters around - example recieve $ab and send back $ba, how would I split up the byte and reverse it and send it back again?
    Do I need to split the byte upon receipt or save it to a variable and split the variable?

  2. #2


    Did you find this post helpful? Yes | No

    Default HSER observations

    I have had mixed success with HSERIN and HSEROUT. You certainly MUST set the defines for HSER_TXSTA, HSER_RCSTA and baud rate. I think you also need to manually clear framing and overrun errors for complete success. Maybe also to tie the input high or low with 4k7. I never found out why the command was unreliable and so I gave up on HSER and went for SERIN/OUT and SERIN2/OUT2 which are software UARTS. They take a little more code and time but they have been absolutely reliable in my usage.

    I also send and receive HEX from time to time. I use the bit masking technique.

    Assume the 8 bit value for A has been received by your favourite serial input routine, such as SERIN. Further assume the upper 4 bit nibble is B and the lower 4 bit nibble is C

    Find the upper nibble
    B = A >> 4 ' here the lower four bits 'fall off' and the new incoming upper bits are zeros.
    More properly perhaps
    B = A >> 4 & %00001111

    Isolate the lower nibble
    C = A & %00001111 'here the upper4 bits are masked to zeros

    To build a new A in the reverse hex/nibble order to that received.

    A = (C << 4) | B 'this is the bitwise addition of the upper and lower 4 bits to make a new 8 bit byte.


    HTH
    BrianT

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Using the HEX modifiers with HSERIN/HSEROUT works just like it's shown in the manual.

    Here's an example of receiving .HEX files from a PC serial connection;
    http://www.microengineeringlabs.com/...bp/progeex.bas

    Reversing the upper & lower nibbles is really simple with a single line of assembler.

    X VAR BYTE
    X = $AB

    @ SWAPF _X,F ; Swap upper & lower nibbles in X. Now X = $BA.
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Feb 2004
    Location
    Michigan, USA
    Posts
    305


    Did you find this post helpful? Yes | No

    Default

    OK, so lets say I'm being sent $ab and I need it to be placed in a variable a0.

    HSERIN [HEX4 a0]

    This will place the hex value of $ab into a0, correct?

    What if I'm recieving several bytes such as $aa $ab $ac $ad etc etc and I want them in a1 a2 a3 a4 etc?

    HSERIN [HEX4 ao, a1, a2, a3, a4]
    or do I need multiple lines?
    HSERIN [HEX4 a0]
    HSER [HEX4 a1] etc etc.

  5. #5
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jmgelba View Post
    This will place the hex value of $ab into a0, correct?
    Should do it.

    What if I'm recieving several bytes such as $aa $ab $ac $ad etc etc and I want them in a1 a2 a3 a4 etc?
    HSERIN [HEX4 ao, a1, a2, a3, a4]
    or do I need multiple lines?
    HSERIN [HEX4 a0]
    HSER [HEX4 a1] etc etc.
    Your first example would almost work, except it should be like this:
    HSERIN [ HEX2 a0, HEX2 a1, HEX2 a2 ]
    HEX2 for bytes
    HEX4 for words
    And multiple lines/statements would work too.

Similar Threads

  1. HSER Problems
    By Kaldurenik in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 15th October 2007, 08:33
  2. Bargraph Revisited..Erm well not maybe
    By Sean_Goddard in forum Off Topic
    Replies: 2
    Last Post: - 22nd July 2007, 11:50
  3. Model Train controller - revisited
    By malc-c in forum mel PIC BASIC Pro
    Replies: 32
    Last Post: - 8th May 2007, 09:40
  4. Interrupts Revisited
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th August 2005, 18:57
  5. Serial Pic to Pic using HSER
    By Chadhammer in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 11th March 2005, 23:14

Members who have read this thread : 1

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

Posting Permissions

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