ON 20030213@5:17:49 PM at page:
http://www.piclist.commicrochip/math/radix/b2bu-16b5d.htm
JMN-EFP-786 James Newton published post 37665.6993634259
If you convert this routine to work with PIC18, invert addition and decrement instruction in normalization code. Replace btfss 3,0
by btfss STATUS, C, ACCESS
Original code :
addwf Ones,f ; B0 += 10
decf Tens,f ; B1 -= 1
btfss 3,0
Modified code :
decf Tens,f ; B1 -= 1
addwf Ones,f ; B0 += 10
btfss STATUS, C, ACCESS
Do it for all digits...
|Delete 'P-' before: '' but after: '
This is a useful algorithm. I think PIC programmers have to very inventive to code so efficiently with so few instructions and available program memory.
However, one comment that bears consideration:
Why not leave the ASCII for the HIGH nibble in W, and then output the LOW nibble ASCII into a variable called CHAR_LO.
You need to rename CHAR_HI to CHAR_LO , and to change the second instruction in the sequence
from swapf CHAR_HI,W
to swapf CHAR_LO,F
and of course alter the comments accordingly
Other than that, it should all be OK
Consider where the ASCII hex representation of the byte is likely to be used, i.e. as output to a terminal / screen connected by UART or other character-by-character means.
You need to transmit the text with the ASCII hex for the most significant nibble first, so it makes more sense to leave that in W at the end of the routine.
e.g. movf MY_BYTE,W
call hex2ascii ; the conversion routine
call send ; your serial TX routine, with char in W
movf CHAR_LO,W
call send ; your serial TX routine, with char in W
If you tried to do a similar thing with the existing routine, you'd need to save the LOW nibble hex value somewhere (in anothe RAM address) temporarily while moving the high one back into W for transmission. You are far more likely to write a generic "send" routine assuming the character is in W.
Cheers
Jason Armistead
|Delete 'P-' before: '' but after: '