piclist 2001\04\06\232039a >
Thread: Rounding to closest 1's multiple, code enclosed :)
www.piclist.com/techref/microchip/devices.htm?key=pic
flavicon
face BY : Djula Djarmati email (remove spam text)



Here is another version for 24bit mod 10 for 14bit core:

Mod10   movfw LO                +ADs-Calculates HI:MED:LO mod 10
       andlw 0x0f              +ADs-Output (0-9) is in W
       movwf Tmp               +ADs-Bits 3:0 normal weight 8421
       swapf LO,w              +ADs-
       call CalcNbl            +ADs-Bits 7:4 -+AD4- weight 8426
       movfw MED               +ADs-
       call CalcNbl            +ADs-Bits 11:8 -+AD4- weight 8426
       swapf MED,w             +ADs-
       call CalcNbl            +ADs-Bits 15:12 -+AD4- weight 8426
       movfw HI                +ADs-
       call CalcNbl            +ADs-Bits 18:15 -+AD4- weight 8426
       swapf HI,w              +ADs-
       call CalcNbl            +ADs-Bits 23:19 -+AD4- weight 8426
       swapf Tmp,w             +ADs-24 bits shrinked to 7 in Tmp
       call CalcNbl            +ADs-Shrink more to 5 bits
       movfw Tmp               +ADs-
       skpndc                  +ADs-Bit4+AD0-1? (digit carry)
       addlw 6                 +ADs-yes, 8421 to 8426 for bit4
       addlw -10               +ADs-Bits 3:0 are ok now
       skpdc                   +ADsAPA-10?
       addlw 10                +ADs-yes, restore old value
       andlw 0x0f              +ADs-clear upper bits
       return

CalcNbl andlw 0x0f              +ADs-Take care of 8426 weight scheme
       addwf Tmp,f             +ADs-for a nibble, first add 8421
       andlw 1                 +ADs-Mask bit 0
       movlw 5                 +ADs-Prepare addition
       skpz                    +ADs-Nibble bit0+AD0-1?
       addwf Tmp,f             +ADs-yes, add 5 to get 8426
       return


Djula

--
http://www.piclist.com hint: To leave the PICList
KILLspampiclist-unsubscribe-requestspamspammitvma.mit.edu


<00ae01c0bf11$741730c0$1804f0d5@djula> 7bit

See also: www.piclist.com/techref/microchip/devices.htm?key=pic
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) Rounding to closest 1's multiple, code enclosed :)

month overview.

new search...