electronics forum

Rules | Recent posts | topic RSS | Search | Register  | Log in

How can i convert 16 bit number to decimal ?


Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> How can i convert 16 bit number to decimal ?
Author Message
SphinX



Joined: 25 Jan 2002
Posts: 1069
Helped: 28
Location: EGYPT


Post30 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 Sad Crying or Very sad Wink
Sphinx
Back to top
Google
AdSense
Google Adsense




Post30 Mar 2004 16:19   

Ads




Back to top
SphinX



Joined: 25 Jan 2002
Posts: 1069
Helped: 28
Location: EGYPT


Post30 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


Post30 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


Post30 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


Post31 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


Post31 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
Arabic versionBulgarian versionCatalan versionCzech versionDanish versionGerman versionGreek versionEnglish versionSpanish versionFinnish versionFrench versionHindi versionCroatian versionIndonesian versionItalian versionHebrew versionJapanese versionKorean versionLithuanian versionLatvian versionDutch versionNorwegian versionPolish versionPortuguese versionRomanian versionRussian versionSlovak versionSlovenian versionSerbian versionSwedish versionTagalog versionUkrainian versionVietnamese versionChinese version
Post new topic  Reply to topic    EDAboard.com Forum Index -> Microcontrollers -> How can i convert 16 bit number to decimal ?
Page 1 of 1 All times are GMT + 1 Hour
Similar topics:
(8051) how to convert a 16 bit hex number to dec number? (1)
how to convert signed decimal to unsigned decimal? (7)
converting decimal number to something i can disp (9)
how to convert binary to BCD or decimal in assembly (4)
How to convert a number string to several integer? (1)
How to efficiently convert the 32-bit data into 8-bit data? (13)
How can we pass a decimal value in the module Verilog (7)
Represent decimal number as bits in verilog (3)
Need to convert hex to decimal (8051) (5)
convert from hexa to decimal in unix (1)


Abuse || Administrator || Moderators || Support us || sitemap
topic RSS