In the 8051 series microcontrollers, the first 32 bytes of the internal RAM are divided into 4 groups, each with 8 registers. The names of the 8 registers in each group are R0-R7. By setting two bits in the PSW register, you can choose which of the 4 groups of registers to use.
Register sets are very useful when handling interrupts or using real-time operating systems. You can use different register sets when entering an interrupt or switching tasks, without saving the contents of the 8 registers to the stack. When exiting an interrupt or returning to the original task, you only need to switch back to the original register set.
Specify the register bank to be used by a function:
void rb_function (void) using 3 { . . . }
Using is followed by a number 0-3. Symbolic expressions are not allowed to replace the numeric constant. The using keyword can only be used when defining a function. It is not allowed when declaring a function prototype.
A function declared using has the following characteristics:
1) At the function entry, the currently used register set is saved to the stack;
2) The specified register group is set;
3) Before the function exits, the original register set is restored;
The following shows the usage of using. Please pay attention to the codes at the function entry and exit in the generated assembly program:
C program: 1 2 external bit alarm; 3 int alarm_count; 4 extern void alfunc (bit b0); 5 6 void falarm (void) using 3 { 7 1 alarm_count++; 8 1 alfunc (alarm = 1); 9 1 } Generated assembler: 0000 C0D0 PUSH PSW /* At the function entry, save the original register group to the stack */ 0002 75D018 MOV PSW,#018H /* Switch to new register bank */
0005 0500 R INC alarm_count+01H 0007 E500 R MOV A,alarm_count+01H 0009 7002 JNZ ?C0002 000B 0500 R INC alarm_count 000D ?C0002: 000D D3 SETB C 000E 9200 E MOV alarm,C 0010 9200 E MOV ?alfunc?BIT,C 0012 120000 E LCALL alfunc
0015 D0D0 POP PSW /* Before exiting the function, switch to the original register group */ 0017 22 COURT
Functions whose return values are stored in registers cannot use using.
Even if the same register set is used, a using function cannot return a bit type value.
Using is usually used when defining interrupt service functions. We can specify different register groups for different interrupt service functions, which can reduce stack operations and improve program running efficiency.
Previous article:Keil C51 LST file
Next article:Keil C51's Seventeenth Keyword Extension to C Language: sbit
Recommended ReadingLatest update time:2024-11-16 21:24
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- Siemens Motion Control Technology and Engineering Applications (Tongxue, edited by Wu Xiaojun)
- How to read electrical control circuit diagrams (Classic best-selling books on electronics and electrical engineering) (Zheng Fengyi)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- 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
- Newbies, please read here: Newbie Guide, Points System, Monthly Reward System, Contact Management, Must-Read Questions, Quick View of Posts
- Software requirements for legally controlling microcontrollers remotely via Android phones
- How to Meet the Testing Challenges of Multi-Antenna Systems
- Award-winning live broadcast: STMicroelectronics SiC products and industrial application guide, please watch at 10:00 on September 10~
- Texas Instruments' new synchronous boost converter TPS61288 is an ideal solution for wireless speaker boost converters
- A new user uses Quartus for the first time
- Some unclear points about self-oscillation
- Insulation paths and insulation types
- Top four domestic automotive chips
- ST extends long-term supply commitment for SPC56 automotive MCU to promote automotive electronics innovation