Direct write to literal register

Does anybody know how to directly access uC registers in arduino code? I need to read/write to 2 registers on the atmega16u2.
thanx, mike

Surely you jest. You can, literally, take examples from the AVR datasheet, paste them into a sketch, and there is a high probability they will compile and work correctly.

The point of the AVR family is to be C / C++ friendly.

if (PORTB == 0) { // read
  PORTD = 0; // write
}

:roll_eyes:

but those are in assembler code, and besides, i can't find any in the DS. ATmega8U2 ATmega16U2 ATmega32U2 Datasheet (microchip.com)

yeah but it's not the regular ports i'm trying to access, it's the registers for the analog comparator

https://ww1.microchip.com/downloads/en/DeviceDoc/doc7799.pdf#page=71
Page 71

Access method doesn't change for any register! :hushed:

ok i didn't know i could use the regular register labels to do that.
thanx :slight_smile:

This is possible because the definition header is automatically included. :wink:

ok, didn't know that. :+1:

If you look in the Arduino source code you'll see that direct register access is heavily used. That's the great advantage of open-source, its not a secret, once you know to read the source code.

thanx that's a good idea