So you tried this:

asm volatile("sbi 0x18,0x07;");

Which works. When you do the same thing but replace the address of the port by its macro name, like this:

asm volatile("sbi PORTB,0x07;");

you get a compilation error: "Error: constant value required".

PORTB is a precompiler definition included in the processor specific file included in avr/io.h. As you may know, the precompiler will not touch strings and PORTB, instead of 0x18, gets passed to the assembler. One way to avoid this problem is:

asm volatile("sbi %0, 0x07" : "I" (_SFR_IO_ADDR(PORTB)):);

Back to FAQ Index.