ASCii To HEX?


Closed Thread
Results 1 to 6 of 6

Thread: ASCii To HEX?

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: ASCii To HEX?

    Here is what I came up with today:

    Code:
    Grab_ELM:
        IF Ebit = 0 THEN                            ;Indicates 1st Nibble ASCii Character
            Ebyt0 = RCREG1                          ;Load Upper Nibble into Ebyt0
        ELSEIF Ebit = 1 THEN                        ;Indicates 2nd Nibble ASCii Character
            Ebyt1 = RCREG1                          ;Load Lower Nibble into Ebyt1
        ENDIF
        TOGGLE Ebit                                 ;Set Up to Load Lower Nibble, or Upper Nibble of Next Character
        IF Ebit = 1 THEN                            ;Just Loaded Upper Nibble, Still Need Lower Nibble
    @   INT_RETURN
        ELSE
    ;Combine HEX[Ebyt[0], Ebyt[1]]            
            IF (Ebyt0 => $30) AND (Ebyt0 <= $39) THEN   ;Characters 0 >> 9
                ElmIn = (Ebyt0 - $30) << 4          ;Shifts to Upper Nibble
            ELSEIF (Ebyt0 => $41) AND (Ebyt0 <= $46) THEN  ;Characters A >> F        
                ElmIn = (Ebyt0 - $37) << 4          ;Shifts to Upper Nibble
            ENDIF
            IF (Ebyt1 => $30) AND (Ebyt1 <= $39) THEN   ;Characters 0 >> 9
                ElmIn = ElmIn + (Ebyt1 - $30)       ;Adds to Upper Nibble
            ELSEIF (Ebyt1 => $41) AND (Ebyt1 <= $46) THEN  ;Characters A >> F
                ElmIn = ElmIn + (Ebyt1 - $37)       ;Adds to Upper Nibble
            ENDIF
        IF (ElmIn = $0D) OR (ElmIn = $20) THEN      ;Carriage Return or Space
    @   INT_RETURN                                  ;Ignore & Return
        ELSEIF (ElmIn <> $0D) AND (ElmIn <> $20) AND (ElmIn <> $3E) THEN
            Eval[ElmCt] = ElmIn
        ELSEIF ElmIn = $3E THEN                     ;">", End Of Transmission
            ELM_Rec = 0                             ;Can now send next Request
            ElmCt = 0                               ;Next BYTE In = New
            ElmDat = 1                              ;Must Decipher Eval[x]
            Ebit = 0                                ;Ensures 1st Character Loads into Ebyt0
    @   INT_RETURN                                  ;Return
        ENDIF
        ElmCt = ElmCt + 1                           ;Will Load Next Character
    @   INT_RETURN                                  ;Return
    At least I have variables to work with in a Hex format. From there I have other subroutines to dissect the content.

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: ASCii To HEX?

    I don’t think there’s any modifier that would pull out one byte being represented as a pair of bytes.
    There’s no neat way to deal with ASCII, but everything after the first return could be a part of the main program though.
    The main program knows by the state of Ebit when it’s supposed to act on the input just as the code above does.

  3. #3
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: ASCii To HEX?

    Not sure if there's a short cut, but the code I posted is working.

  4. #4
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: ASCii To HEX?

    Generally, it’s very beneficial for interrupts to be as short as possible.
    I’m not sure how BASIC interrupts work.
    Working is the main thing

Similar Threads

  1. hex dec ascii
    By l_gaminde in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 11th February 2015, 22:11
  2. Hex to Ascii to Decimal
    By khoog in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 31st July 2009, 06:27
  3. hex ascii help please
    By ffr58kk90 in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 29th December 2006, 22:09
  4. Converting ASCII to HEX
    By BobP in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 27th September 2006, 11:21
  5. ascii characters to hex
    By Peter1960 in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 26th January 2006, 05:06

Members who have read this thread : 0

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