In the Microcontroller C language programming, two keywords SFR and sbit are expanded.
SFR (abbreviation for the special function Register of the special function Register), Sbit (special function Register bit), differs from defining a general int, char type variable, which defines not a variable, but a reference to a special function register, which may be called an alias.
The single-chip header file <reg51.h> defines 21 special function registers, all of which are 8-bit registers, and each bit of some registers is defined with Sbit:
SFR P0 = 0x80;
SFR P1 = 0x90;
SFR P2 = 0xA0;
SFR P3 = 0xb0;
SFR PSW = 0xD0;
SFR ACC = 0xE0;
SFR B = 0xF0;
SFR SP = 0x81;
SFR DPL = 0x82;
SFR DPH = 0x83;
SFR PCON = 0x87;
SFR TCON = 0x88;
SFR tmod = 0x89;
SFR TL0 = 0x8A;
SFR TL1 = 0x8b;
SFR TH0 = 0x8c;
SFR TH1 = 0x8d;
SFR IE = 0xa8;
SFR IP = 0xb8;
SFR SCON = 0x98;
SFR sbuf = 0x99;
SFR is defined as a 8-bit register, Sbit is defined as a bit register, and the individual thinks it is possible to interpret this definition as defining a constant pointer to always point to 0x80, the special register, the following definition method;
Const unsigned char *pp = 0x80;
Of course, this method of definition does not fully conform to the above statement, and *PP is limited to the write operation, that is, pp points to the address is identified as a constant, and PP is still a variable, in fact, in addition to using SFR and sbit definition, other definitions are considered unsafe and is limited to write operations. Finally, when defining the pointer, only when the array is defined:
Char a[];
The address pointer A is a constant pointer, while the other pointers are variables;
---------------------
Lorain_lynies
Source: CSDN
Original: 52013611?utm_source=copy
Copyright NOTICE: This article is for bloggers original article, reprint please attach blog link!
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
MCU keywords SFR and sbit understanding