HSERIN qualifier


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107

    Default HSERIN qualifier

    I have never used the DEC and HEX qualifiers in the HSERIN command.

    If I issue the command

    HSERIN [HEX X]

    Does that convert a received "A2" received as two ASCII characters into
    binary %10100010 and put that in the variable X?

    Or - does it just filter out any ASCII character that isn't in the range of "0" to "9" or "A" to "F" and save a "0" as 0x30 to X?

    Just what does it do?
    Charles Linquist

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Basically the modifiers tell PBP what to expect.
    With out a modifier PBP will treat the input as a Display Key:
    A2 will be broke into 65 and 50.
    Code:
    HSERIN [X] 
    HSEROUT [DEC X,13,10]
    The above will, if sent A2 will output to a terminal
    Code:
    65
    50
    13
    If the BIN modifier is used PBP will do nothing with A2 because A2 is not binary.
    If A1 or A0 is received with
    HSERIN [BIN X]
    Then
    HSEROUT [DEC X,13,10]
    will return
    1 or 0
    The A is ignored.
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Thanks!

    I already have a short routine that converts ASCII HEX into binary ("A" "2" = %10100010), but I thought if PBP did it automagically, I would use that routine instead. Oh well.
    Charles Linquist

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


    Did you find this post helpful? Yes | No

    Default

    It most certainly will.

    HSERIN [HEX2 X]

    Will receive "A2" as %10100010 or $A2.

    It's easiest to have a fixed length field.
    So 2 would be sent as "02".

    hth,
    DT

  5. #5
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Code:
         HSERIN [HEX X]
         HSEROUT [DEC X.7,13]
         HSEROUT [DEC X.6,13]
         HSEROUT [DEC X.5,13]
         HSEROUT [DEC X.4,13]
         HSEROUT [DEC X.3,13]
         HSEROUT [DEC X.2,13]
         HSEROUT [DEC X.1,13]
         HSEROUT [DEC X.0,13]
         HSEROUT ["BIN",13]
         HSEROUT [BIN X,13]
    Attached Images Attached Images  
    Dave
    Always wear safety glasses while programming.

  6. #6
    Join Date
    Sep 2005
    Location
    Campbell, CA
    Posts
    1,107


    Did you find this post helpful? Yes | No

    Default

    Thanks guys,

    The routine below is supposed to take comma-delimited strings and convert them to binary. It should handle the sequence 02,A,A2 for example, properly.

    Code:
    Preparser:
         HSERIN [Wait (":")]  ; wait for colon to start  
    GrabAscii:
    
          HSERIN 500,NoMoreInput,[ASCIN [Y]]   ; Load it into small array, first char goes into element zero
           
           IF ASCIN [Y] = "," THEN ; Found a comma   This will never be in element zero , but 
                                   ; may exist in element 1
                     
                     SELECT CASE Y
                         CASE 1
                            MSB = 0
                            LSB = ASCIN[Y-1]
                          CASE 2
                            MSB = ASCIN[Y-2]
                            LSB = ASCIN[Y-1]
                          CASE ELSE
                            HSEROUT ["INPUT ERROR"]
                              PAUSE 2500
                          END SELECT    
                     
                     GOSUB IHEX2BIN      
                      
                     OUTARRAY[Z] = ByteVal    ; load variable into array
                     Z = Z + 1
                     Y = 0                 ; Clear Y if we found a comma
            ENDIF
            Y = Y + 1
             
            Goto GrabAscii
            
                       
    NOMoreInput:
    
      ......
    
    
    ';**************************************************************
    '; Routine takes HEX Ascii chars 
    '; and converts to BIN
    '; Inputs MSB, LSB ("0" to "F")
    '; Outputs ByteVal 
    ';***************************************************************
    IHEX2BIN:
             LOOKDOWN MSB,["0123456789ABCDEF"],ByteValH
             LOOKDOWN LSB,["0123456789ABCDEF"],ByteValL
             ByteVal = (ByteValH << 4) + ByteValL
             RETURN
    ';***************************************************************


    It is nearly 4 A.M here in CA. Time to go to work and see how the code works!
    Charles Linquist

Similar Threads

  1. timeout of Hserin, goto, gosub or both?
    By flipper_md in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 28th October 2009, 18:43
  2. TMR0 interrupt and HSERIN
    By boban in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 2nd September 2008, 11:48
  3. 16F877a Interupt driven Hserin
    By RFsolution in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 3rd November 2006, 00:38
  4. Can a TMR interrupt stops HSERIN?
    By SergioRM in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 24th January 2006, 01:07
  5. Hserin
    By egberttheone in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 27th November 2004, 15:42

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