I'm porting the T6963-based LCD driver from AVR-GCC to the microchip C18 compiler. I have seen the macro "pgm_read_byte": does anyone know how to port this macro?
UPDATE
From here I can see the implementation of the macro
#define pgm_read_byte(address_short)
pgm_read_byte_near(address_short)
...
#define pgm_read_byte_near(address_short) __LPM((uint16_t)(address_short))
...
#define __LPM(addr) __LPM_enhanced__(addr)
...
#define __LPM_enhanced__(addr) \
(__extension__({ \
uint16_t __addr16 = (uint16_t)(addr); \
uint8_t __result; \
__asm__ \
( \
"lpm %0, Z" "\n\t" \
: "=r" (__result) \
: "z" (__addr16) \
); \
__result; \
}))
According to the link you posted, the macro is defined as:
#define pgm_read_byte(address_short) pgm_read_byte_near(address_short)
#define pgm_read_byte_near(address_short) __LPM((uint16_t)(address_short))
Those macros should be portable without any problems, they're simply aliasing the names of other functions/macros. What specifically are you having trouble with? What have you tried so far, and what went wrong?
AVR is Harvard architecture and pgm_read_ macros serves to access AVR's flash memory which resides in an other address space than RAM.
On a target with a linear address space you can just use the pointers to access the data:
#if defined (__GNUC__) && defined (__AVR__)
#include <avr/pgmspace.h>
#else
#include <stdint.h>
#define PROGMEM /* empty */
#define pgm_read_byte(x) (*(x))
#define pgm_read_word(x) (*(x))
#define pgm_read_float(x) (*(x))
...
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With