Timer0 is a function name, just randomly chosen
interrupt xx using y
The xx value after interrupt is the interrupt number, which means the interrupt port number to which this function corresponds. It is usually in 51.
0 External interrupt 0
1 Timer 0
2 External interrupt 1
3 Timer 1
4 Serial interrupt
In fact, when compiling, the entry address of your function is set to the jump address of the corresponding interrupt.
Using y The y here refers to the register group used by this interrupt function. There are generally 4 groups of registers r0-r7 in 51, a total of 32. If your terminal function and other programs do not use the same register group, the register group will not be pushed into the stack when entering the interrupt, and it will not be recalled when returning, saving code and time.
Note the following about the MCS-51 interrupt function:
(1) Interrupt functions cannot pass parameters. If an interrupt function contains any parameter declaration, a compilation error will occur.
(2) Interrupt functions do not have a return value. If you attempt to define a return value, you will not get the correct result. It is recommended to define the interrupt function as a void type to clearly indicate that there is no return value.
(3) Under no circumstances can an interrupt function be called directly, otherwise a compilation error will occur. This is because the return of the interrupt function is completed by the RETI instruction of the 8051 microcontroller, which affects the hardware interrupt system of the 8051 microcontroller. If the interrupt function is called directly without an actual interrupt, the operation result of the RETI instruction will result in a fatal error.
(4) If other functions are called in the interrupt function, the registers used by the called function must be the same as those of the interrupt function. Otherwise, incorrect results will occur.
(5) When the C51 compiler compiles the interrupt function, it will automatically add corresponding content at the beginning and end of the program, as follows: ACC, B, DPH, DPL, and PSW are pushed onto the stack at the beginning of the program and popped off the stack at the end. If the interrupt function does not have the using n modifier, R0~R1 must be pushed onto the stack at the beginning and popped off at the end. If the interrupt function has the using n modifier, the working register bank select bit in PSW must be modified after PSW is pushed onto the stack.
(6) The C51 compiler generates an interrupt vector from the absolute address 8m+3, where m is the interrupt number, which is the number after interrupt. The vector contains an absolute jump to the entry address of the interrupt function.
(7) The interrupt function is best written at the end of the file, and the extern storage type declaration is prohibited. Prevent other programs from calling it.
Previous article:The code keyword in C51
Next article:About the data types of data, idata, xdata, pdata, and code in Keil microcontroller programming
- Popular Resources
- Popular amplifiers
- Learn ARM development(14)
- Learn ARM development(15)
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
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
- 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
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Nonlinear distortion in Tx/Rx systems
- Write ADX112 driver from 0 (STM32)
- Diary of the trouble of building TMS320F28379D project with css6.0
- [Silicon Labs Development Kit Review] + Serial port printing Hall sensor Si7210 data
- USB Type C Display Mode with TPS65994AD and TUSB1046A
- Anlu SparkRoad Development Board Review (5) PLL IP and Frequency Counter
- Misumi data cable driver cannot be installed
- CH549EVT Development Board Test——Evaluation Summary
- Familiar Development Tools Support SoC FPGAs
- ADI Analog Dialogue magazine, if you are interested, come and get it~