Arduino: Understanding the Internals

/* pin = Arduino Mapped Pin Name, ex. Digital pin 22: pin = 22 */
void digitalWrite(uint8_t pin, uint8_t val)
    uint8_t timer = digitalPinToTimer(pin);
    uint8_t bit   = digitalPinToBitMask(pin);
    uint8_t port  = digitalPinToPort(pin);

    volatile uint8_t *out;
    out = portOutputRegister(port);

    uint8_t oldSREG = SREG;

    if (val == LOW) {
        *out &= ~bit;
    } else {
        *out |= bit;
    SREG = oldSREG;

SREG (Status Register) und Globale Interrupts aktivieren: SREG -Register

extern const uint8_t PROGMEM digital_pin_to_port_PGM[];

#define digitalPinToPort(P) ( pgm_read_byte( digital_pin_to_port_PGM + (P) ) )
#define pgm_read_byte(address_short)    pgm_read_byte_near(address_short)
#define pgm_read_byte_near(address_short) __LPM((uint16_t)(address_short))

Was pgm_read_byte() macht bzw. wie es in Assembler ├╝bersetzt wird: Source von pgm_read_byte

const uint16_t PROGMEM port_to_mode_PGM[] = {

Accessing data past 64k boundary on atmega1280

Leave a Reply

Your email address will not be published. Required fields are marked *