Cx51 User's GuideCx51 Introduction Compiling Programs Language Extensions Keywords Memory Areas Program Memory Internal Data Memory External Data Memory Far Memory SFR Memory Memory Models Small Model Compact Model Large Model Memory Types bdata code data far idata pdata xdata Data Types Special Function Registers sfr sfr16 sbit Bit-Addressable Objects bit Standard C Types void char int enum float double Type Modifiers signed unsigned short long Type Qualifiers const volatile Storage Classes auto register extern static Absolute Variable Location Pointers Generic Pointers Memory-Specific Pointers Pointer Conversions Abstract Pointers Function Declarations Parameters and the Stack Parameters and Registers Return Values Memory Models Register Banks Register Bank Access Interrupt Functions Reentrant Functions Alien (PL/M-51) Function Real-Time Function Tasks Preprocessor Advanced Programming 8051 Derivatives Error Messages Library Reference Appendix
The sfr16 type defines a 16-bit special function register (SFR). It is used as follows:
sfr16 name = address;
Some 8051 derivatives have 16-bit SFRs thare are created using consecutive addresses in SFR memory to specify 16-bit values. For example, the 8052 uses addresses 0xCC and 0xCD for the low and high bytes of timer/counter 2 respectively. The Cx51 Compiler provides the sfr16 data type to access two 8-bit SFRs as a single 16-bit SFR.
Access to 16-bit SFRs using sfr16 is possible only when the low byte immediately precedes the high byte (little endian) and when the low byte is written last. The low byte is used as the address in the sfr16 declaration. For example:
sfr16 T2 = 0xCC; /* Timer 2: T2L 0CCh, T2H 0CDh */ sfr16 RCAP2 = 0xCA; /* RCAP2L 0CAh, RCAP2H 0CBh */
In this example, T2 and RCAP2 are declared as 16-bit special function registers.
The sfr16 declarations follow the same rules as outlined for sfr declarations. Any symbolic name can be used in an sfr16 declaration. The address specification after the equal sign ('=') must be a numeric constant. Expressions with operators are not allowed. The address must be the low byte of the SFR low-byte, high-byte pair.
Related Knowledgebase Articles
of your data.