[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [avr-gcc-list] Using PSTR()
From: |
David Kelly |
Subject: |
Re: [avr-gcc-list] Using PSTR() |
Date: |
Tue, 29 Mar 2005 08:09:13 -0600 |
On Mar 29, 2005, at 2:05 AM, Bjarne Laursen wrote:
return( PSTR("01234567890ABCDEF")[u] );
PSTR puts the string in flash, but the compiler knows nothing about
that when using the pointer. You must the use pgm_read_byte().
something like (not tested):
return( pgm_read_byte(PSTR("01234567890ABCDEF")+u));
Sorry about that, I had mail problems which dropped my original reply
to myself, and then blocked some other mail until last night.
Quite often I've found once possibly making a fool of myself in public
asking such a question, that after sleeping on it I wake up with the
correct solution. The disassembly of what I'm using is essentially what
Bjarne said altho I typed a goof (extra zero) in the string Bjarne
copy/pasted from my original message:
Problem solved like this:
0000093c <ntohex>:
//
// Binary Nybble to Hex ASCII
// A bit convoluted for efficiency on AVR
//
unsigned char
ntohex(unsigned char n)
{
return( pgm_read_byte(PSTR("0123456789ABCDEF")+(n&0xf)) );
93c: 99 27 eor r25, r25
93e: 8f 70 andi r24, 0x0F ; 15
940: 90 70 andi r25, 0x00 ; 0
942: fc 01 movw r30, r24
944: e4 57 subi r30, 0x74 ; 116
946: ff 4f sbci r31, 0xFF ; 255
948: 84 91 lpm r24, Z
}
94a: 99 27 eor r25, r25
94c: 08 95 ret
--
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.