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.
事实却不像keil说的那样。
.H
//串行口特殊功能寄存器
sfr SCON = 0x98;
sbit SM0 = SCON^7;
sbit SM1 = SCON^6;
sbit SM2 = SCON^5;
sbit REN = SCON^4;
sbit TB8 = SCON^3;
sbit RB8 = SCON^2;
sbit TI = SCON^1;
sbit RI = SCON^0;
sfr SBUF = 0x99;
sfr S2CON = 0x9a;
#define S2SM0 0x80
#define S2ST4 0x40
#define S2SM2 0x20
#define S2REN 0x10
#define S2TB8 0x08
#define S2RB8 0x04
#define S2TI 0x02
#define S2RI 0x01
sfr S2BUF = 0x9b;
|