Typical application: sbit P0_0=P0^0; // defines P0_0 as the first bit of port P0 for bit operation.
Usage:
In C language, if you write P1.0 directly, the C compiler cannot recognize it, and P1.0 is not a legal C language variable name, so you have to give it another name, here it is called P1_0, but is P1_0 the same as P1.0? You think so, but the C compiler doesn't think so, so you have to establish a connection between them. Here, the Keil C keyword sbit is used to define it. There are three uses of sbit:
The first method: sbit bit variable name = address value
The second method: sbit bit variable name = SFR name ^ variable bit address value
The third method: sbit bit variable name = SFR address value ^ variable bit address value
The following three methods can be used to define OV in PSW:
sbit OV=0xd2 (1) Description: 0xd2 is the bit address value of OV
sbit OV=PSW^2 (2) Note: PSW must be defined first using sfr
sbit OV=0xD0^2 (3) Note: 0xD0 is the address value of PSW
Therefore, here we use sbit P1_0=P1^0; to define the symbol P1_0 to represent the P1.0 pin. If you want, you can also use a name like P10, as long as you change it accordingly in the following program.
sbit and bit:
sbit must be defined at the outermost, that is, it must be defined as an external variable. sbit defines the bit of SFR (special function register)
sbit is more like a type definition than a variable definition.
sbit: just an illustrative note
A bit can be defined externally or internally.
Reference link: http://baike.baidu.com/link?url=R_fzVbhmSpnJIcMdnyH1kJFNiJRW2wMLb-zjl9gr-Ht779OltInqwjJpibGxATyR7pLLTOMI4EQLNLaOCKZ1iK
Previous article:51 single chip microcomputer——_crol_
Next article:Design and implementation of an intelligent street lamp energy-saving controller
Recommended ReadingLatest update time:2024-11-16 04:21
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
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- After adding shutdown and low power consumption, stm32 will run away after working for 8-9 hours
- [Silicon Labs Development Kit Review] +6-axis inertial sensor ICM-20648
- Welcome our new moderator, Azuma Simeng~~
- Thanks to all the staff of Electronic Engineering Forum
- TI DSP--Memory space allocation and designation
- Reward (1000RMB) 3-output Hall speed sensor chip selection and external circuit design
- How to set up the Qt program to start automatically on the Sinlinx A64 development board
- Four aspects to understand the internal loss of switching power supply
- [Good memory is not as good as bad writing] 1. F1 MDK transplantation FreeRTOS practice record 2-CUBE generation project
- National Undergraduate Electronic Design Competition Paper Album