piclist 2001\02\05\153601a >
Thread: Code Challenge: Range check and convert Hex
face picon face BY : jamesnewton@TakeThisOuTpiclist.com

This code is tested and working on an SX. The Mchip translation follows. You
may have to tweak the +1's and -1's to get it to work on a PIC. If anybody
bothers to test it, I'll add the MChip version to the PICList code library.

;SXKey version
device  SX28L, turbo, STACKX_OPTIONX

       mov NextChar, #$FF
       mov temp, NextChar

;routine starts here
       mov w, #'F'
       mov w, temp - w
       jc :Bad

       mov w, #'0'-1
       mov w, temp - w
       jnc :Bad

       mov w, #'@'+1
       sub temp, w
       mov w, #('@' - ':') + 1
       add temp, w
       jc :BadRestore

       mov w, #(':' - '0')
       sb temp.7
        mov w, #('A' - '@')+1
       add temp, w
       jmp :Good

       mov w, #':'-1
       add temp, w
       jmp :Next
       djnz NextChar, :Loop

;MChip verion

NextChar Res d'1' ; Just used to test routine

temp  Res d'1' ; Temporary variable

org 0

            MOVLW 0xFF
            MOVWF NextChar
            MOVF NextChar,w
            MOVWF temp

;routine starts here
            MOVLW 'F'
            SUBWF temp,w
            BTFSC status,c
            GOTO start_Bad

            MOVLW '0'-1
            SUBWF temp,w
            BTFSS status,c
            GOTO start_Bad

            MOVLW '@'+1
            SUBWF temp
            MOVLW ('@'-':')+1
            ADDWF temp
            BTFSC status,c
            GOTO start_BadRestore

            MOVLW ':'-'0'
            BTFSS temp,d'7'
            MOVLW ('A'-'@')+1
            ADDWF temp
            GOTO start_Good

            MOVLW ':'-1
            ADDWF temp
            GOTO start_Next
            DECFSZ NextChar
            GOTO start_Loop

James Newton (PICList Admin #3)
spamBeGonejamesnewtonTakeThisOuTspampiclist.com 1-619-652-0593
PIC/PICList FAQ: http://www.piclist.com or .org

{Original Message removed}
<000401c08fb3$615d5b40$0600a8c0@efplus.com> 7bit

In reply to: <13211869063.20010131065758@yahoo.com>
See also: www.piclist.com/techref/microchip/ios.htm?key=rang
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Code Challenge: Range check and convert Hex

month overview.

new search...