Sorry, you are wrong! Why? Due to weird sublw because of after sublw you have 0 if you had 9 and 9 if you had 0. So the result will be bogus. Imre On Thu, 11 Jun 1998, James Cameron wrote: > Clewer,Brian wrote: > > > move the byte to W > > > swap nibbles (swapf) > > > and with 0x0f > > > or with 0x30 > > > send that byte > > > > > > move the byte to W again > > > and with 0x0f > > > or with 0x30 > > > send that byte > > This is ok if you use the numbers 0 to 9 but it doesn't work if you > > need HEX values from A to F. > > Any more ideas? > > Yeah, you're right. Good observation. > > Okay, time to factor out the nibble to hex ASCII digit stuff into > it's own subroutine ... > > hex ; convert nibble to ascii hex > andlw 0x0f ; keep only the right bits > movwf tmp1 ; save it for later > sublw 0x09 ; subtract from nine > movf tmp1,w ; bring it back (leave carry alone) > btfsc status,c ; test result of subtraction > ; (maybe it's btfss, not sure!) > addlw 0x37 ; adjust to A-F > return > hex_0 > addlw 0x30 ; adjust to 0-9 > return > > byte > movwf tmp2 ; save the byte for later > swapf tmp2,w ; grab the high nibble back > call hex ; encode high nibble as hex ascii > call send ; send the byte in w to serial port > movf tmp2,w ; fetch the byte again > call hex ; encode low nibble > call send ; send the byte in w to serial port > return > > I've not tested that. > It's probably wrong somewhere. > I'm a beginner. > Did it work? ;-) > > -- > James Cameron (james.cameron@digital.com) > Digital Equipment Corporation (Australia) Pty. Ltd. A.C.N. 000 446 800 > >