12
From the structure diagram, we can see that the 51 MCU has 5 interrupts, namely external interrupt 0 (INT0), external interrupt 1 (INT1), timer interrupt 0 (T0), timer interrupt 1 (T1) and serial port interrupt (TX/RX). There are two priorities, and the priority order in an interrupt group from high to low is INT0, T0, INT1, T1, TX/RX.
Partial Interrupt Register 12
1. Interrupt Enable Control Register (IE)
EX0: External interrupt 0 enable bit;
ET0: Timer/Counter T0 interrupt enable bit;
EX1: External interrupt 1 enable bit;
ET1: Timer/Counter T1 interrupt enable bit;
ES: Serial port interrupt enable bit;
EA: CPU interrupt enable (always enable) bit.
All of the above are enabled by 1 and disabled by 0.
2. Timer/controller control register TCON
IT0: External interrupt 0 trigger mode control bit
When IT0=0, it is level trigger mode (low level is valid)
When IT0=1, it is edge trigger mode (falling edge is valid)
IE0: External interrupt 0 interrupt request flag bit (automatically completed by hardware)
IT1: External interrupt 1 trigger mode control bit (same as IT0)
IE1: External interrupt 1 interrupt request flag bit (same as IE1)
TF0: Timer/counter T0 overflow interrupt request flag bit
TF1: Timer/counter T1 overflow interrupt request flag bit
3. Interrupt priority control register (IP)
PX0: External interrupt 0 priority setting bit
PT0: Timer/counter T0 priority setting bit
PX1: External interrupt 0 priority setting bit
PT1: Timer/counter T1 priority setting bit
PS: Serial port priority setting bit All
of the above are 1 for high priority and 0 for low priority.
4. Timer/counter working mode register TMOD
GATE-gate control bit.
GATE=0, the start and stop of the timer/counter are only controlled by TRX (X=0,1) in the TCON register.
GATE=1, the start and stop of the timer counter are controlled by the level status of TRX (X=0,1) in the TCON register and the external interrupt pin (INT0 or INT1).
C/T—Timer and counter mode selection bit.
C/T=1, counter mode; C/T=0, timer mode.
M1M0—Working mode selection bit.
Before using the interrupt, turn on the general interrupt, turn on the interrupt enable bit you use, set the interrupt trigger mode for the external interrupt, and configure the corresponding registers for other interrupts. If multiple interrupts are used, configure the interrupt priority.
The format of the interrupt service function:
The writing method of the interrupt service program
void function name () interrupt interrupt number [using workgroup]
{
interrupt service program content
}
These are basically the interrupts of 51 single-chip microcomputer. Here is an example.
Use the falling edge to trigger INT0 (P3.2), and then let P1^0 output 0; 12
Main Program
include "intrins.h"includesbit LED = P1^0 ;void Int0 (void) interrupt 0{ LED = 0 ; }void Init_INT(void) { EA = 1; // Enable general interrupt EX0 = 1; //Open external interrupt 0 IT0 = 1; // Edge trigger}void main() { Init_INT(); //Interrupt initialization while(1) { } }123456789101112131415161718192021222324252627
Simulation with signal function
signal void test(void) { while(1) { port3 = 0xff ; swatch(0.02); port3 = 0xfB ; swatch(0.1) ; port3 = 0xff ; swatch(0.02); _break_ = 1 ; } }1234567891011121314151617
The simulation waveform is as follows, the upper one is the external interrupt signal, and the lower one is the P1^0 output signal.
Previous article:Method of triggering external interrupt of STC15 MCU only on rising edge
Next article:Using interrupt mode to realize serial port data sending and receiving in 51 single chip microcomputer
Recommended ReadingLatest update time:2024-11-16 13:48
- Popular Resources
- Popular amplifiers
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
- Single chip microcomputer control technology (Li Shuping, Wang Yan, Zhu Yu, Zhang Xiaoyun)
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
- [EETalk] Why do smart homes not use ZigBee but are keen on Bluetooth and Wi-Fi?
- Selection of the discharge resistor of the X capacitor
- Help on ADN8834 burning out
- Double 11 development board recommendation: MSP430 LaunchPad
- Characteristics and research analysis of wireless communications with examples
- 【RT-Thread Reading Notes】Reading Notes for Chapters 1~4
- A look inside the U.S. Army's counter-artillery radar system
- Qorvo Broadband Access CATV and FTTH Product Selection Guide
- Use MOS tube or triode?
- Award-winning live broadcast | Power supply, motor, electronic control, new energy vehicle power design technology is coming