PIC elado

VFX info at vfx.hu
Mon Apr 28 19:55:52 CEST 2003


Hali!

Mar nem is tudom mi volt az eredeti feladat, de itt az ATMEL app.note:

;***************************************************************************
;*
;* "bin2BCD16" - 16-bit Binary to BCD conversion
;*
;* This subroutine converts a 16-bit number (fbinH:fbinL) to a 5-digit
;* packed BCD number represented by 3 bytes (tBCD2:tBCD1:tBCD0).
;* MSD of the 5-digit number is placed in the lowermost nibble of tBCD2.
;* 
;* Number of words:25
;* Number of cycles:751/768 (Min/Max)
;* Low registers used:3 (tBCD0,tBCD1,tBCD2)
;* High registers used  :4(fbinL,fbinH,cnt16a,tmp16a)
;* Pointers used:Z
;*
;***************************************************************************

;***** Subroutine Register Variables

.equAtBCD0=13;address of tBCD0
.equAtBCD2=15;address of tBCD1

.deftBCD0=r13;BCD value digits 1 and 0
.deftBCD1=r14;BCD value digits 3 and 2
.deftBCD2=r15;BCD value digit 4
.deffbinL=r16;binary value Low byte
.deffbinH=r17;binary value High byte
.defcnt16a=r18;loop counter
.deftmp16a=r19;temporary value

;***** Code

bin2BCD16:
ldicnt16a,16;Init loop counter
clrtBCD2;clear result (3 bytes)
clrtBCD1
clrtBCD0
clrZH;clear ZH (not needed for AT90Sxx0x)
bBCDx_1:lslfbinL;shift input value
rolfbinH;through all bytes
roltBCD0;
roltBCD1
roltBCD2
deccnt16a;decrement loop counter
brnebBCDx_2;if counter not zero
ret;   return

bBCDx_2:ldir30,AtBCD2+1;Z points to result MSB + 1
bBCDx_3:
ldtmp16a,-Z;get (Z) with pre-decrement
;----------------------------------------------------------------
;For AT90Sxx0x, substitute the above line with:
;
;decZL
;ldtmp16a,Z
;
;----------------------------------------------------------------
subitmp16a,-$03;add 0x03
sbrctmp16a,3;if bit 3 not clear
stZ,tmp16a;store back
ldtmp16a,Z;get (Z)
subitmp16a,-$30;add 0x30
sbrctmp16a,7;if bit 7 not clear
stZ,tmp16a;store back
cpiZL,AtBCD0;done all three?
brnebBCDx_3;loop again if not
rjmpbBCDx_1


More information about the Elektro mailing list