Search code examples
cassemblyembeddedavravr-gcc

How to port pgm_read_byte macro (AVR-GCC) to Mircrochip C18 Compiler?


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;                   \
}))

Solution

  • 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?