Earlier, we talked about the input and output functions of the 51 microcontroller. Today we will talk about something different, external interrupt testing.
First of all, we have to talk about the role of interruptions in dealing with internal and external random events and responding to emergencies. While the CPU is executing the program, if an external emergency event occurs, the CPU stops its work to handle the emergency event. After processing, it returns to the place where it was originally interrupted and continues working. It's like receiving a phone call while eating, going out to answer the phone and then sitting back at the table to eat. Stopping what you were doing and doing other things in the middle is an interruption.
The interrupt function of the 51 microcontroller is relatively simple. You only need to configure the corresponding registers to complete the initialization.
In this article, the external interrupt is tested using button P3.2 because its port has the second function of external interrupt.
Before configuring the interrupt structure of the 51 microcontroller, you need to look at the internal structure diagram. You can see that there are IE, IP, TCON and other registers to control the interrupt function.
Different registers have different functions. Each register has 8-bit configuration bits, which are responsible for different functions. Among them, the most important external interrupts are the IE and TCON registers. For details, you can read the 51 microcontroller data manual, which will provide detailed introduction.
The detailed code is as follows:
#include sbit ExternalInterruptPin = P3^2; // External interrupt pin definition void ExternalInterrupt_Init() { IT0 = 1; // Set external interrupt 0 to falling edge trigger mode EX0 = 1; // Enable external interrupt 0 EA = 1; // Global interrupt enable } void ExternalInterrupt_Service() interrupt 0 { // Process logic in the interrupt service routine // ... } void main() { ExternalInterrupt_Init(); while (1) { //Other logic in the main loop // ... } } Among them, void ExternalInterrupt_Service () interrupt 0 One line is the 51 microcontroller interrupt service function, which has been designed by the semiconductor manufacturer. We only need to use it according to regulations, unless we are working on the kernel, we will not consider the design issues. There are many other interrupt functions as shown below. Just choose different functions according to different ports and functions: Note: The so-called falling edge is the edge that changes from high level to low level, that is, the time when the transition occurs.
Previous article:Simulation design of intelligent desk lamp for infrared detection and light detection based on 51 microcontroller
Next article:Punch controller based on AT89S51 microcontroller
- 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
- Do I need to set the pull-up or pull-down resistor of the port for output?
- There are 20 prizes left to be drawn: Watch the video "Avoiding Common AC-DC Design Pitfalls" and win a prize
- What should electronics beginners learn? What are the topics worth learning? And in what order should they learn them?
- Use STVP to encrypt and remove write protection for STM8
- What is interval timer mode?
- The third stage of automatic wiring results in the realization of full-scale or partial automatic copper plating
- Power supply dynamic response test, what kind of waveform is qualified?
- Python is 30 years old
- Some low-frequency 32.768kHz crystal oscillators of MSP430F169 do not oscillate. What's the situation?
- What is a diode used for?