0
\$\begingroup\$

I'm trying to write a program in assembly to toggle the on-board LED of the Arduino MEGA2560 in assembly.

To do so I just have to indicate the direction of the pin (13 in this case which is PB7) as output and then set that pin as High or Low.

I understand that there are two registers related with this problem. one is the port's direction register (DDRB) and the register for the state of the pins (PORTB)

So I'm trying to understand what number or address those register have so I can assign values to them in assembly. I went into the C++ library in which those constants are defined (iomxx0.h) and for example DDRB is defined the following way:

#define DDRB    _SFR_IO8(0x04)
#define DDB7    7
#define DDB6    6
#define DDB5    5
#define DDB4    4
#define DDB3    3
#define DDB2    2
#define DDB1    1
#define DDB0    0

I'm curious about knowing if the register's address is 0x04? and if that is the case, what is _SFR_IO8() doing?

\$\endgroup\$
0
\$\begingroup\$

It is a macro to access AVR IO address space registers, and in that address space, register 4 seems to be DDRB. You might want to actually use the datasheet as the register reference, instead of digging the info from avr-libc headers.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.