At 11:50 98.06.11 PDT, you wrote: >James Cameron wrote: > >>Clewer,Brian wrote: >>> My problem is that I have an 8 bit byte and I need to convert it >>> into two printable chars to send to my PC. E.g.. 00111001 would be >>> 39 (in hex). I need to send the two chars 3 and 9 to my PC. >> >> 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 >> >>Hey, I enjoyed that. Uh oh. ;-) > >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? > Well, maybe its worth to take a look at the following code snipset. I extracted the idea from an old program, and wrote these pieces in a hurry, but I think they might be usefull. [] Jorge F : --- Table generation: Generates a retlw table for the translation from hex(4bit) to ASCII HEX_ASC_TAB macro local i=0 while i < 10 retlw i i+=1 endw local i=65 ; Change 65 to 97 while i<71 ; and 71 to 103 if you want lowercase letters retlw i i+=1 endw endm [snip] ; ---- Translation routine Convert addwf pc,f HEX_ASC_TAB [snip] ; --------- Convertion ; IN_BYTE -> data to be converted ; OUT_ASC_1 -> Converted high nibble ; OUT_ASC_2 -> Converted lowe nibble ... swapf IN_BYTE,W ; get high nibble in W andlw 0x0f call Convert ; get ASCII in W movwf OUT_ASC_1 ; store result movlw 0x0f ; get low nibble in W andwf IN_BYTE,W call Convert ; get ASCII in W movwf OUT_ASC_2 ; store result ... =============================================================== cumprimentos / best regards Jorge Ferreira mailto://jorgegf@mail.telepac.pt ------ Make sure brain is in gear before engaging mouth ------- ===============================================================