Christopher Cole wrote: > Josh Koffman wrote: >> Hi all. I'm thinking of a project where I'll have a 9 bit >> binary number, and I'll want to display it on a 3 digit >> 7 segment display. To do this I'll need to extract the >> hundreds, tens, and ones digits from the number... > > For this, I would use the "Shift and Add-3 Algorithm" to do the conversion you need: > > http://www.engr.udayton.edu/faculty/jloomis/ece314/notes/devices/binary_to_BCD/bin_to_BCD.html That algorithm is not well suited for PICs, it will take a very long time. It's much better to make use of the hardware multiplier. Djula ;********************************************************************************************** ;CONVERT 10-BIT BINARY TO THREE DECIMAL DIGITS (28 cycles, 25 program memory) ;Input word: Digits+1:Digits ;Output digits: Digits+2:Digits+1:Digits ;Trashes: PRODH, PRODL ;********************************************************************************************** Bin_To_Dec_999 movlw d'41' ;Multiply by 0.01 (41/4096) mulwf Digits+1 ; movff PRODL, Digits+2 ; mulwf Digits ; movf PRODH, w ; addwf Digits+2, w ; mullw 0x10 ;Lose the lower 8 bits and shift movf PRODH, w ;result 4 bits left (divide by 4096) movwf Digits+2 ;Save result mullw d'100' ;and then multiply it by 100 movf PRODL, w ; subwf Digits, f ;Subtract from original movf PRODH, w ;to get subwfb Digits+1, f ;remainder movf Digits, w ;Split remainder (0-99) to two decimals mullw D'205' ; movlw D'32' ;Multiply by 0.1 mulwf PRODH ;(205/256 * 32/256) movf PRODH, w ; movwf Digits+1 ;Save result mullw D'10' ;and then multiply it by 10 movf PRODL, w ;Subtract from original subwf Digits, f ;Save remainder return ;Done -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist