Forum: Mikrocontroller und Digitale Elektronik gepackte BCB Zahl => Binär (8bit)


von Fiffi (Gast)


Lesenswert?

Hallo,

ich suchte eine Routine welche eine gepackte BCD Zahl in eine binär
Zahl wandelt.

Bsp.:  0x99 => 0x63
  0x10 => 0x0A

Ich habe die App Note 204 von Atmel gefunden, welche aber nicht
funktioniert !:


;*********************************************************************** 
****
;*
;* "BCD2bin8" - BCD to 8-bit binary conversion
;*
;* This subroutine converts a 2-digit BCD number (fBCDH:fBCDL) to an
;* 8-bit number (tbin).
;*
;* Number of words  :4 + return
;* Number of cycles  :3/48 (Min/Max) + return
;* Low registers used  :None
;* High registers used  :2 (tbin/fBCDL,fBCDH)
;*
;* Modifications to make the routine accept a packed BCD number is
indicated
;* as comments in the code. If the modifications are used, fBCDH shall
be
;* loaded with the BCD number to convert prior to calling the routine.
;*
;*********************************************************************** 
****

;***** Subroutine Register Variables

.def  tbin  =r16    ;binary result
.def  fBCDL  =r16    ;lower digit of BCD input
.def  fBCDH  =r17    ;higher digit of BCD input

;***** Code

BCD2bin8:
;----------------------------------------------------------------------- 
---
;|        ;For packed BCD input, add these two lines
;|  mov  tbin,fBCDH  ;copy input to result
;|  andi  tbin,$0f  ;clear higher nibble of result
;----------------------------------------------------------------------- 
---

BCDb8_0:subi  fBCDH,1    ;fBCDH = fBCDH - 1
  brcs  BCDb8_1    ;if carry not set
;----------------------------------------------------------------------- 
---
;|        ;For packed BCD input, replace the above
;|        ;two lines with these.
;|  subi  fBCDH,$10  ;MSD = MSD - 1
;|  brmi  BCDb8_1    ;if Zero flag not set
;----------------------------------------------------------------------- 
---
  subi  tbin,-10  ;    result = result + 10
  rjmp  BCDb8_0    ;    loop again
BCDb8_1:ret      ;else return




//////////////////////////////////////////////////////////////////////

Hier nun meine eigene Routine (von der App Note abgeleitet ...):

bcd2bin8:
  mov  tbin, fBCDH          // copy input to result
  andi  tbin, 0x0f          // clear higher nibble of result
  andi  fBCDH, 0xf0          // clear lower nibble of the input

bcd2bin8_1:
  cpi  fBCDH, 0
  breq  bcd2bin8_2          // if no upper digit

  subi  fBCDH, 0x10          // MSD = MSD - 1
  subi  tbin, -10          // result = result + 10
  rjmp  bcd2bin8_1          // loop again

bcd2bin8_2:
  ret



Versteht von euch jemand den Sinn der folgenden Zeile?

brmi  BCDb8_1    ;if Zero flag not set



Gruß

Fiffi

von Sebastian Wille (Gast)


Lesenswert?


von Fiffi (Gast)


Lesenswert?

Hallo Sebastin,

ich suche keine Routine mehr, da meine funktioniert !

Unter dem Link sind nur 16 bit Routinen zu finden.
Außerdem würde ich die Routinen nicht gerade als effizient bezeichnen
!
( es wird mit 10 multipliziert ...)


Ich versuche zu verstehen was sich Atmel dabei gedacht hat, bzw. warum
es nicht funktioniert !


Gruß

Fiffi

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.