None of the sources on the piclist page worked for me so I just ended up writing my own decimal -> BCD function off an algorithm I found on some EE class on a university home page, works great! :) I'd post it if it wasn't so tailored to my own project :( nick@veys.com | www.veys.com/nick > -----Original Message----- > From: pic microcontroller discussion list > [mailto:PICLIST@MITVMA.MIT.EDU] On Behalf Of Mike Mansheim > Sent: Thursday, July 26, 2001 6:21 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: Re: [PIC]: "itoa" routines? (16F870) > > > > ...I have an 8bit number, only ranging 99 >= N >= 0 so it > will only be > > 2 digits. I need to find a way to output it to my LCD... > > Not sure this will help, but just in case... > pseudo-code for what you want to do: > > lcd_digit1 = a2d_result / 10 > lcd_digit2 = a2d_result - (lcd_digit1 * 10) > > in you're working in C, this is trivial. > in asm, multiply by 10 is simple (x*8) + (x*2), but divide by > 10 is not so simple. There is a lot of stuff in the source > code section of piclist.com for basic multiplying and > dividing, and (under conversions) all kinds of clever stuff > for converting binary to decimal, which is really what you > want to do. If you're not familiar with this type of stuff, > 'BCD' means binary coded decimal, and just means each byte of > the result contains a digit of the input number. For example, > if the input is one byte, say B9h (185 decimal), the output > bytes will be 01, 08, 05. 'BCD packed' just means each digit > is stored in a nibble, so there are two digits per byte > (because the range for the digits is 0-9, and a nibble - 4 > bits - can hold 0-15). You can grab the digit in the upper > nibble via 'swapf' or dividing by 16. > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > > > -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads