[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [avr-gcc-list] Pgmspace.h Use

From: Ron
Subject: RE: [avr-gcc-list] Pgmspace.h Use
Date: Thu, 11 Aug 2005 21:40:20 +1000

> > As Brano suggested, a macro is about as close as you can get. Not 
> > _quite_ what you want, but close:
> >
> > #define array(i)    pgm_read_byte(&Array[i])
> > const prog_char Array[7] = {0x10,0x20,0x30,0x40,0x50,0x60,0x70};
> >
> >   y = array(4);
> This is what I did:
> unsigned char
> ntohex(unsigned char n)
> {
>      return( pgm_read_byte(PSTR("0123456789ABCDEF")+(n&0xf)) ); }
> -- 
> David Kelly N4HHE, address@hidden 

Because compatibility was the issue, my suggestion was to replace access
to the array with a function. With avrgcc's -os and inline there is very
little runtime cost:

    y = Array(i);

inline uint8 Array(int i)
#ifdef __AVR__
    return pgm_read_byte(&array[i]);
    return array[i];

Interesting to imagine the syntax of a flash and eep aware C. Presumably
you would just need to declare where the type instance is stored and the
compiler handles all subsequent access under the covers. Something like:

const _fl Array[7] = {0x10,0x20,0x30,0x40,0x50,0x60,0x70};


reply via email to

[Prev in Thread] Current Thread [Next in Thread]