G'day, all I'm starting to do some serial comms stuff between my latest project and either a modem or terminal. The existing serial buss that I am using right now talks between a number of similar nodes (up to 63) and a communications controller that actually interfaces the serial buss to the outside world. Everything works quite well right now so far as node to node or node to comm controller is concerned. Now I get to tie the whole thing to the outside world. This requires hex to ascii conversion and ascii to hex conversion. I've spent the day coming up with some routines and would like a sanity check on what I've done so far. I've got 3 routines so far: HEXASCII, ASCIIHEX, UPCASE. They all seem to work okay; I'm just looking for better or neater ways of doing them. LIST P=16C71,F=INHX8M,X=ON,R=HEX INADR EQU 0 OPTINIT EQU b'00000111' CNTR1 EQU 20 CNTR2 EQU 21 CNTR3 EQU 22 CNTR4 EQU 23 ORG 00H goto COLDBOOT HEXASCII ;Convert hex nybble to ascii character ;*********** ;written by Dwayne Reid ;* enters with: hex nybble (0-F) in w ;* uses subroutines: none ;* registers: w ;* bits/flags: none ;* returns: ascii character in w ;* andlw b'00001111' ;lower nybble only addlw 6 ;0-9 or A-F? skpndc ;dc==1 if larger than 9 addlw 7 ;adjust A-F addlw (0x30-6) ;add offset to convert to ascii return ASCIIHEX ;Convert ascii character to hex nybble ;*********** ;written by Dwayne Reid ;* enters with: ascii character in w ;* uses subroutines: none ;* registers: w ;* bits/flags: C ;* returns: hex nybble (0-F) in w, C=0 & w=0 if error ;* ;00-2f:c=0 30-39:c=1 3a-40:c=0 41-46:c=1 47-60:c=0 61-66:c=1 67-ff:c=0 addlw -(0x3A) ;value higher than 9? skpnc ;note: 1 higher than 9 because of >= goto A2H_1 ;too high: try next test addlw 0x0A ;value lower than 0? (span is 0-9 ==.10) skpnc ; return ;value is in range of 0 - 9h: done! A2H_ERR clrc clrw return ;error: ascii character is not 0-9 or a-f A2H_1 ;upper case A-F (41h-46h) addlw -((0x47)-(0x3A));value higher than F? skpnc ;note: 1 higher than F because of >= goto A2H_2 ;too high: try next test addlw 0x6 ;value lower than A? (span is A-F ==.6) skpnc ; goto A2H_LET ;value is in range of A - Fh: add offset goto A2H_ERR A2H_2 ;lower case a-f (61h-66h) addlw -((0x67)-(0x47));value higher than f? skpnc ;note: 1 higher than f because of >= goto A2H_ERR ;too high: error addlw 0x6 ;value lower than a? (span is a-f ==.6) skpc ; goto A2H_ERR A2H_LET ;w contains 0-5 representing a-f addlw 0x0A ;add offset to make hex A-F setc return UPCASE ;Convert lower case ascii character to upper case ;*********** ;Written by Dwayne Reid ;* enters with: any character from 00 - FF in w ;* uses subroutines: none ;* registers: w ;* bits/flags: none ;* returns: original value in w EXCEPT ascii a-z converted to A-Z ;* ;A-Z is 41h-5Ah; a-z is 61h-7Ah. Range of a-z is 7A-61==19 addlw -(0x7B) ;value higher than z? skpnc ;note: 1 higher than 7A because of >= goto UCaseX1 ;too high: restore w and exit addlw 0x1A ;value lower than a? (span is a-z ==.26) skpc ; goto UCaseX2 ;too low: restore w and exit addlw 0x41 ;value is in range of 00 - 19h: add offset return ;done! UCaseX2 addlw -(0x1A) ;restore original value UCaseX1 addlw 0x7B ;restore original value return COLDBOOT clrf CNTR1 clrf CNTR2 LOOP movfw CNTR1 ;test UPCASE call UPCASE movwf CNTR2 movfw CNTR1 ;test HEXASCII call HEXASCII movwf CNTR3 movfw CNTR1 ;test ASCIIHEX call ASCIIHEX movwf CNTR4 BREAKPT nop incf CNTR1,F goto LOOP END Ideas, opinions? Thanks! Dwayne Reid Trinity Electronics Systems Ltd Edmonton, Alberta, CANADA (403) 489-3199 voice (403) 487-6397 fax