I want to convert hex to dec using PIC. Thing that I want to do is that:
I have 2 byte (like 27 and 0F) in two register in PIC (A_REG=27,B_REG=0F). Converting of 270F to decimal result is 9999. I want to write this convertion result to PIC's registers ( C_REG=99, D_REG=99 )
If u want to conver hex to decimal to make it output on an lcd u can use pic basic like the following code ,but if u want to convert it for any other application u can use Klug's method of dividing by 10 (if u can post your idea i would help u more)
hexa var Word , This would make the two registers as 32bit
main:
lcdout dig4 hexa , This would output 4 digit decimal number
end
Hope this is what u r thinking of & that it helped u
#define L1 H'0210'
#define L2 H'0A'
LIST P=16F877
#include <p16F877.inc>
ORG 0X00
VERI EQU H'20'
SAY EQU H'21'
SAY1 EQU H'22'
SAY2 EQU H'23'
BANKSEL PORTA
movlw L1 - (L1/L2)*L2
MOVWF VERI
movlw (L1/L2)-((L1/L2)/L2)*L2
movwf SAY
movlw (L1/L2/L2)-((L1/L2)/L2/L2)*L2
movwf SAY1
movlw (L1/L2/L2/L2)
movwf SAY2
GOTO $
END
But in these codes, i guess the compiler (MPLAB) calculate the results. If I load to a microcontoller, how to make it count. In my device, L1 is changeable. So, it can't calculate 16 bit data.
In my application, I must use 4 digit number (hex) for coverting. Therefore, I couldn't use the codes that you gave. I have fould an app note from microchip. (AN526) I will try these codes(for 16 bit converting). I hope it works.