Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Converting hex to dec with PIC

Status
Not open for further replies.

optech

Member level 1
Joined
Dec 19, 2004
Messages
37
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
407
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 )

How can I do that?

Thanks.....
 
Do you need to make it in Assembler or C?

Anyway you need to make a chain of remainders after dividing to 10.

In your example:

0x270F % 0x0A=9
(0x270F / 0x0A) % 0x0A = 9
((0x270F / 0x0A) / 0x0A) % 0x0A = 9
(((0x270F / 0x0A) / 0x0A) / 0x0A ) % 0x0A = 9
 

Salam,

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
 

Thanks for your answers. I have wrote a asm code.

Code:
#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.
 

look for digbyte macro, which calculates byte digits, and stores in Dig1, Dig2, and Dig3 variables.

**broken link removed**

Added after 2 minutes:
 

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.

May be it will be useful for anybody:
https://ww1.microchip.com/downloads/en/AppNotes/00526e.pdf
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top