On Sep 18, 2005, at 11:11 PM, Vincent Trouilliez wrote:
Okay, I got your dot_two() working (the another_dot_two() has one last
fatal error that I can't figure out yet).
Yeah well, still not bad for code written in bed on laptop in the
email editor.
I tested it in all fairness. That is, I modified the printf hack from
printf ("%d.%03d", x / 1000, x % 1000), to
printf ("%d.%02d", x / 100, x % 100)
So that the functionality is the same as dot_two().
Doing this, printf doesn't take 13ms anymore, but 10ms.
And your dot_two() takes... 6ms ! That's a whole 40% faster, not bad
indeed !!! :o)
Your putchar() (or whatever) writes to an LCD? So how long does it
take to latch a character into the LCD?
Another way I thought to write the code without utoa() was something
like this (no I haven't tried this one either):
char buffer[4];
uint8_t i;
strncpy_P( buffer, PGM_P("000"), 3 );
i = 2;
while(x) {
buffer[i--] = x%10 + '0';
x = x/10;
}
putchar(buffer[0]);
putchar('.');
putchar(buffer[1]);
putchar(buffer[2]);
In the above I find myself wishing for the FORTH /mod operator. Avr-
gcc calls exactly the same routine for division or modulo and stores
the desired result. In assembly we could store both but I don't see
how to get at both from C. Is possible the compiler could optimize it
but plain -O didn't in recent tests.
--
David Kelly N4HHE, [EMAIL PROTECTED]
========================================================================
Whom computers would destroy, they must first drive mad.
_______________________________________________
AVR-GCC-list mailing list
AVR-GCC-list@nongnu.org
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list