Playing with Arduino

A page to record my playing with Arduino
garretlab
__LPM_enhanced__()

__LPM_enhanced__()

Abstract

The __LPM_enhanced() is an assembler code that reads a byte of data stored in a specified address(PROGMEM area).

Source Code

The __LPM_enhanced() is defined in hardware/tools/avr/avr/include/avr/pgmspace.h as below.

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

The lpm, short for Load Program Memory, is a instruction that reads a byte of data from PROGMEM area. It substitue a data at addr for __result, then returns the __result.

Version

Arduino 1.0.5



Turn on JavaScript to display a menu.

Playing with Arduino
Copyright © 2012 garretlab all rights reserved.
inserted by FC2 system