avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Pointer to byte in code.


From: E. Weddington
Subject: Re: [avr-gcc-list] Pointer to byte in code.
Date: Thu, 15 Jul 2004 10:37:04 -0600

On 15 Jul 2004 at 21:56, Royce & Sharal Pereira wrote:

> Hi,
> is thare a way to access a byte in ROM besides the macro __LPM(address)?

If you mean the program memory (flash), then no, you have to use macros. But 
there are other macros that have public names. Technically, anything starting 
with an underscore is reserved for the "implementation"; in this case, avr-
libc.
 
> How does one define a pointer to a byte in ROM?
> 
> For eg, should'nt the function:
> 
> void get_byte(PGM_P src)
>     {
>         while(*src)
>             PORTB= *src++;
>     }
> 
> generate the lpm instruction automatically?

No, because the GCC compiler knows nothing about multiple memory spaces, e.g. 
Harvard Architecture chips such as the AVR.
 
> How to implement the above?
> 

#include <avr/io.h>
#include <avr/pgmspace.h>
#include <inttypes.h>

void get_byte(PGM_P src)
{
    uint8_t data;

    data = pgm_read_byte(src++);
    while(data)
    {
        PORTB = data;
        data = pgm_read_byte(src++);
    }
    return;
}



reply via email to

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