The usage of bit is similar to sfr, except that sbit is a bit operation, which is used to assign a specific bit in an sfr to a variable, so that the program can use the variable to clear or set the bit.
sfr is used to assign a special function register of a microcontroller to a variable, so that the variable can refer to the register in subsequent programs.
The usage of sbit is similar to that of sfr, except that sbit is a bit operation, which is used to assign a specific bit in an sfr to a variable, so that the program can use the variable to clear or set the bit.
The special function register layout of STC series microcontrollers is as follows:
After looking at so many special function registers in Figure 1, you may have some confusion. We use sfr P0 = 0×80 to represent P0 and sfr SP = 0×81 to represent SP. There is no ambiguity. What is confusing is: if sbit P0_1 = 0×81 is used to represent the first bit of port P0, then what should I do if I want to represent the 0th bit of the SP register? If it is also defined as sbit SP_0 = 0×81, then there will be obvious ambiguity and the compiler cannot understand it. In fact, this problem does not exist. As can be seen from Figure 1, SFR can be divided into two areas: bit-addressable area and non-bit-addressable area. The register address of the bit-addressable area can be divided by 8, while the register address of the non-bit-addressable area does not meet this requirement. Therefore, sbit SP_0 = 0×81 in the example is invalid for the SP register and should be written as sfr SP=0x81.
For example: sbit P1^1=0x81;sfr SP=0x81;
Although they both refer to the same address 0×81, the compiler has completely different meanings. The former is a byte address because of the sfr keyword, while the latter is a bit address because of the sbit keyword, indicating a bit.
Previous article:Nuvoton N76E003AT20 multi-channel ADC acquisition method
Next article:A brief discussion on the use of macro definitions in single-chip microcomputer development
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- 【Construction Monitoring and Security System】Work Submission Post
- Live FAQ|Typical applications in the era of the Internet of Things
- CCS import routine for TM4C123x
- EEWORLD University Hall----Signal Integrity and High-Speed Digital Circuit Design
- Competition Schedule [Updated]
- Output impedance problem of parallel reference voltage
- Master Python web crawler core technology, framework and project practice PDF HD full version free download
- position2Go Review 2: Interlude
- Design of AC voltage measurement based on MSP430 microcontroller
- 【Beetle ESP32-C3】4. Luat-OS environment deployment