Atmel CAVR-4 Manual De Usuario
![Atmel](https://files.manualsbrain.com/attachments/0369829915bda09f9c2e00fb805a7753579683b5/common/fit/150/50/8d2bf08978ec3e5bc63f4343ac5e91ce8d0e40045619fa520d910d64af8f/brand_logo.png)
CAVR-4
Part1. Using the compiler
Efficient coding for embedded applications
133
Protecting the eeprom write mechanism
A typical example of when it can be necessary to use the
_ _monitor
keyword is when
protecting the eeprom write mechanism, which can be used from two threads (for
example, main code and interrupts). Servicing an interrupt during an EEPROM write
sequence can in many cases corrupt the written data.
example, main code and interrupts). Servicing an interrupt during an EEPROM write
sequence can in many cases corrupt the written data.
ACCESSING SPECIAL FUNCTION REGISTERS
Specific header files for a number of AVR derivatives are included in the AVR IAR
C/C++ Compiler delivery. The header files are named
C/C++ Compiler delivery. The header files are named
ioderivative.h
and define the
processor-specific special function registers (SFRs).
In IAR Embedded Workbench, enable the bit definitions by selecting the option
General Options>System>Enable bit definitions in I/O include files.
General Options>System>Enable bit definitions in I/O include files.
SFRs with bitfields are declared in the header file. The following example is from
iom128.h
:
_ _io union
{
unsigned char PORTE; /* The sfrb as 1 byte */
struct
{
unsigned char PORTE_Bit0:1,
PORTE_Bit1:1,
PORTE_Bit2:1,
PORTE_Bit3:1,
PORTE_Bit4:1,
PORTE_Bit5:1,
PORTE_Bit6:1,
PORTE_Bit7:1;
};
} @ 0x1F;
By including the appropriate include file to your code, it is possible to access either the
whole register or any individual bit (or bitfields) from C code as follows:
whole register or any individual bit (or bitfields) from C code as follows:
/* whole register access */
PORTE = 0x12;
/* Bitfield accesses */
PORTE.PORTE_Bit0 = 1;
You can also use the header files as templates when you create new header files for other
AVR derivatives. For details about the @ operator, see Located data, page 46.
AVR derivatives. For details about the @ operator, see Located data, page 46.