This and others from the PIC Micro-controller Base conversion techref page at: http://204.210.50.240/techref/default.asp?url=microchip/base.htm All credit to Scott Dattalo, everybody email him and bug him to come back to the PICList... (just kidding) You'll need to modify it slightly to separate tens from ones. Binary to BCD (packed) From: Scott Dattalo ;******************************** ;binary_to_bcd - 8-bits ; ;Input ; bin - 8-bit binary number ;Outputs ; hundreds - the hundreds digit of the BCD conversion ; tens_and_ones - the tens and ones digits of the BCD conversion binary_to_bcd: CLRF hundreds SWAPF bin, W ADDWF bin, W ANDLW 00001111b SKPNDC ADDLW 0x16 SKPNDC ADDLW 0x06 ADDLW 0x06 SKPDC ADDLW -0x06 BTFSC bin,4 ADDLW 0x16 - 1 + 0x6 SKPDC ADDLW -0x06 BTFSC bin, 5 ADDLW 0x30 BTFSC bin, 6 ADDLW 0x60 BTFSC bin, 7 ADDLW 0x20 ADDLW 0x60 RLF hundreds, F BTFSS hundreds, 0 ADDLW -0x60 MOVWF tens_and_ones BTFSC bin,7 INCF hundreds, F James Newton mailto:jamesnewton@geocities.com phone:1-619-652-0593 http://techref.homepage.com NOW OPEN (R/O) TO NON-MEMBERS! Members can add private/public comments/pages ($0 TANSTAAFL web hosting) -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Edson Brusque Sent: Wednesday, December 22, 1999 12:50 PM To: PICLIST@MITVMA.MIT.EDU Subject: Fast byte to BCD routine! Hello PICsters! I'm needing a fast routine to break-down a byte to three digits: before: input = 137; after: output2 = 7; output1 = 3; output0 = 1; It doesn't have to be small, but it have to be FAST. I'm thinking about doing it with a BIG lookup-table. Anyone have a better idea? Maybe a hybrid routine (table+calculations). Best regards and thanks for all your help, Brusque ___________________________________________________________________________ | | || |\| | || || |\|\ Edson :-^= Brusque | | || ||| | || || |||| brusque@flynet.com.br | |_||_||| |_||_||_|||| Musician, Programmer, Developer, Electronics | \_\\_\|| \_\\_\\_\||| Blumenau / SC / Brazil / South America | | | | | | | || Earth / Solar System / Milk Way |__|__|__|__|__|__|__|| Giro In'Italia homepage: www.flynet.com.br/giro \__\__\__\__\__\__\__\| C.I.Tronics Lighting Designers: www.citronics.com.br ---------------------------------------- ICQ# 15937748 --------------------- Founder of the CUMP mailing list subscribe-cump@egroups.com Founder of the SoundFont mailing list soundfont-subscribe@onelist.com ----------------------------------------------------------------------------