| Author |
Message |
SphinX
Joined: 25 Jan 2002 Posts: 1069 Helped: 28 Location: EGYPT
|
30 Mar 2004 16:19 bin16 2 bcd microchip |
|
|
|
|
Hi,
In my work we need to convert 16 bit number to decimal using ATMEL.
Ex. This number 65535 ----> R0=6 R1=5 R2=5 R3=3 R4=5
I need just an idea only.
I know a method for 8 bit conversion but what about 16 bit number.
Please help me or i will be fired
Sphinx
|
|
| Back to top |
|
 |
Google AdSense

|
30 Mar 2004 16:19 Ads |
|
|
|
|
|
|
| Back to top |
|
 |
SphinX
Joined: 25 Jan 2002 Posts: 1069 Helped: 28 Location: EGYPT
|
30 Mar 2004 16:28 how to convert 16 bit to 8 bit atmel |
|
|
|
|
Hi,
I found a routine using PIC at
http://www.piclist.com/techref/microchip/math/radix/b2a-16b4a-ng.htm
But there are strange instruction
skpc
skpnc
IFNDEF known_zero
What these instructions do?
Thanx
|
|
| Back to top |
|
 |
Gorilla
Joined: 13 Jan 2003 Posts: 92 Helped: 9
|
30 Mar 2004 16:33 decimal to 16 bit converter |
|
|
|
|
Look for binary to BCD conversion algorithms, there are a lot of examples online.
By the way: 'ATMEL' does not say a lot about the architercture you are using. They sell MARC4, 8051, AVR and ARM based cores...
Anyway, here is one example in 8051 assembly:
http://www.8052.com/codelib/bintoasc.asm
|
|
| Back to top |
|
 |
SphinX
Joined: 25 Jan 2002 Posts: 1069 Helped: 28 Location: EGYPT
|
30 Mar 2004 16:58 16 bit number to decimal |
|
|
|
|
Hi Gorilla,
:multi: THANX VERY MUCH. :multi:
We use 8051 mcu.
SphinX
|
|
| Back to top |
|
 |
svicent
Joined: 11 Jul 2001 Posts: 413 Helped: 23
|
31 Mar 2004 14:43 Re: How can i convert 16 bit number to decimal ? |
|
|
|
|
Hi SphinX
This is my 8051 version to convert 16 bit number to decimal:
; FUNCTION: BIN2BCD
; BYTES: 27
; CYCLES: 327
; INPUT: R6 (Msb) and R7 (Lsb) (binary_16_bits)
; OUTPUT: R3 (Msb), R4 and R5 (Lsb) (PACKET BCD)
; Destroy: R2, R6, R7, A, and PSW
;
; ALGORITM:
;
; BCD = 0;
; COUNT = 16; // (TO PROCESS 16 BITS)
; do {
; BIN16 = BIN16 * 2
; BCD = BCD * 2 + CARRY
; COUNT = COUNT - 1
; } while (COUNT != 0);
;
BIN2BCD:
CLR A ; BCD = 0
MOV R5,A
MOV R4,A
MOV R3,A
MOV R2,#16 ; TO PROCESS 16 BITS
BIN_10:
MOV A,R7 ; BIN16 = BIN16 * 2
ADD A,R7
MOV R7,A
MOV A,R6
ADDC A,R6 ; CARRY = MSB of BIN16
MOV R6,A
MOV A,R5 ; BCD = BCD * 2 + CARRY
ADDC A,R5
DA A
MOV R5,A
MOV A,R4
ADDC A,R4
DA A
MOV R4,A
MOV A,R3
ADDC A,R3
DA A
MOV R3,A
DJNZ R2,BIN_10
RET
Best regards.
|
|
| Back to top |
|
 |
artem
Joined: 22 May 2003 Posts: 1652 Helped: 91 Location: Turan
|
31 Mar 2004 18:56 How can i convert 16 bit number to decimal ? |
|
|
|
|
Hi SphinX
There were few topics related to hex to bcd conversion . But especially for ATMEL there is Atmel's written high efficiency routines for BCD arithmetics (see application notes for AVR on www.atmel.com ) . Those are written in asm and execute faster than C implementation .
|
|
| Back to top |
|
 |