sfr
The sfr type defines a special function register (SFR). It is used as follows:
sfr name = address;
Where
name is the name of the SFR.
address is the address of the SFR.
SFRs are declared in the same fashion as other C variables. The only difference is that the type specified is sfr rather than char or int. For example:
sfr P0 = 0x80; /* Port-0, address 80h */
sfr P1 = 0x90; /* Port-1, address 90h */
sfr P2 = 0xA0; /* Port-2, address 0A0h */
sfr P3 = 0xB0; /* Port-3, address 0B0h */
P0, P1, P2, and P3 are the SFR name declarations. Names for sfr variables are defined just like other C variable declarations. Any symbolic name may be used in an sfr declaration.
The address specification after the equal sign ('=') must be a numeric constant. Expressions with operators are not allowed. Classic 8051 devices support the SFR address range 0x80-0xFF. The NXP 80C51MX provides an additional extended SFR space with the address range 0x180-0x1FF.
Note
sfr variables may not be declared inside a function. They must be declared outside of the function body. sfr variables are always volatile. The compiler will not optimize accesses to this type of variables.