3.11 __io Keyword
The IAR __io
keyword specifies that the object aliases memory mapped SFRs and
that access will be performed on the AVR's IO registers. This keyword is used for
accessing SFRs at addresses below 0x100.
Suggested Replacement
There are several MPLAB XC8 attributes that perform similar tasks to this keyword, but there are some differences in their usage and effect.
Use one of__attribute__((io_low(n)))
,
__attribute__((io(n)))
or
__attribute__((address((n))))
, depending on the desired address
of the SFR, where n
is the mapped address in data memory. If the
SFR is in the bit-addressable IO range (IO memory address 0x0-0x1F), then use the
io_low
attribute. If the SFR is in the IN/OUT range (IO memory
address 0x20-0x3F), then use the io
attribute; otherwise, use the
address
attribute.The compiler will use the in
and/or out
instructions whenever possible to access the
symbol.
Caveats
An object specified with this IAR keyword is assigned memory, like with any ordinary definition; however, this keyword ensures that this memory is in the I/O memory space. By comparison, MPLAB XC8 does not assign memory to the symbol that uses these attributes, assuming that the symbol represents a peripheral register. The symbol defined with this attribute is merely equated with an address.
A warning will be issued if the declaration for a symbol using either the
io
or io_low
attributes is not
volatile
.
Examples
__io int userMode;
to MPLAB
XC8 codes similar
to:// declare userMode as being at the specified address in upper I/O memory
volatile int userMode __attribute__((io(0x42)));
// or declare userMode as being in the lower area in I/O memory
volatile int userMode __attribute__((io_low(0x28)));
// or declare userMode as being at the specified address in I/O memory
volatile int userMode __attribute__((address(0x50)));
Further Information
See the Attributes section in the MPLAB XC8 C Compiler User's Guide for AVR MCUs for more information on these attributes.