Searching \ for '[PIC]: "itoa" routines? (16F870)' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/devices.htm?key=16F
Search entire site for: '"itoa" routines? (16F870)'.

Exact match. Not showing close matches.
PICList Thread
'[PIC]: "itoa" routines? (16F870)'
2001\07\26@011907 by Nick Veys

flavicon
face
Hi all.  I'm in a bit of a tangle with some A/D input!  I've been
wrestling with a way to do this all night, which means I haven't thought
of anything new, and won't!  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... I have tried subtract and compare methods but they're huge and
sloppy and I fear incorrect.  Has anyone tackled this?  My LCD output
function spits out what is in W, I would *like* an "itoa"-like function
that would break my 8-bit variable into 2 variables holding each digit,
so I can then spit it out, but I am at a loss on how to do this
effectively!  (btw: my 100-line jump table didn't work out so well
either! ;)

spam_OUTnickTakeThisOuTspamveys.com | http://www.veys.com/nick

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\07\26@013830 by Vasile Surducan

flavicon
face
I've done this using a standard bin to bcd routine from piclist. You may
adjust a little the slope ( if you need ) by playing with references of
your microcontroller. If your LM outputs the correct voltage for measured
temperature ( in your favorite measuring sistem), no table look or other
software tricks are required.
Even for kelvin to celsius conversion, with some resolution loss you may
apply same hardware trick. From farenheit to celsius I don't know...
Vasile

On Thu, 26 Jul 2001, Nick Veys wrote:

{Quote hidden}

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\07\26@091921 by Nick Veys

flavicon
face
Well, it's nice because my input only needs to me multiplied by
(500/512) = .97 so I'm just going to forget about it (this isn't a
precision project by any means)...  What exactly did the bin -> bcd
routines give you?  Input: 45 -> Output 0x45 ?  This would be handy then
I could just jump off those two digits individually...

nickspamKILLspamveys.com | http://www.veys.com/nick


> {Original Message removed}

2001\07\26@092355 by Lawrence Lile

flavicon
face

Here's an ItoA in C, are you working in C or Assembler?


/*
*    itoa(n,s) - convert n to characters in s
*
*/
itoa(int n, char *s)
{
   int sign;
   char *ptr;
   ptr = s;
   if ((sign = n) < 0)        /* record sign  */
       n = -n;                        /* make n positive  */
   do {                             //  generate digits in reverse order
       *ptr++ = n % 10 + '0';    /* get next digit  */
   } while ((n = n / 10) > 0);    /*  delete it  */
   if (sign < 0)
       *ptr++ = '-';
   *ptr = '\0';
   reverse(s);
}
/*
* reverse(s) - reverse string in place
*
*/
reverse(char *s)
{
   char *j;
   int c;
   j = s + stlen(s) - 1;
   while (s < j)
   {
       c = *s;
       *s++ = *j;
       *j-- = c;
   }
}

--Lawrence Lile

{Quote hidden}

2001\07\26@095846 by Scott Dattalo

face
flavicon
face
On Thu, 26 Jul 2001, Nick Veys wrote:

> Well, it's nice because my input only needs to me multiplied by
> (500/512) = .97 so I'm just going to forget about it (this isn't a
> precision project by any means)...  What exactly did the bin -> bcd
> routines give you?  Input: 45 -> Output 0x45 ?  This would be handy then
> I could just jump off those two digits individually...
>

www.piclist.com/techref/microchip/math/radix/b2ah-8b2a-sd.htm
http://www.piclist.com/techref/microchip/math/radix/index.htm

--
http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads


2001\07\26@192325 by Mike Mansheim

flavicon
face
> ...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


2001\07\26@194836 by Nick Veys

flavicon
face
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 :(

EraseMEnickspam_OUTspamTakeThisOuTveys.com | http://www.veys.com/nick


> {Original Message removed}

2001\07\27@063124 by Gennette, Bruce

flavicon
face
How about a brute force approach ?

splittens
       movlw   255             ;setup at 1 below 0
       movwf   tens
       movf    number,w        ;copy original number
       movwf   units           ;into units
checktens
       incf    tens,f  ;=0 first time thru
       movlw   10
       subwf   units,f ;reduced by 10 until
       btfsc   status,c        ;below 0 or
       goto    adjustit
       btfsc   status,z        ;hits 0, get out,
       goto    checktens       ;or not, so try again
       goto    gotit
adjustit
       movlw   10              ;gone too low, so
       addwf   units,f ;fix up the units
gotit

itoa
       movlw   48              ;to convert the integers to ASCII
       addwf   tens,f  ;add the ASCII value for "0"
       addwf   units,f ;to the integers

bye.

{Original Message removed}

More... (looser matching)
- Last day of these posts
- In 2001 , 2002 only
- Today
- New search...