当前位置:网站首页>SCM learning notes: interrupt learning
SCM learning notes: interrupt learning
2022-06-30 04:43:00 【ToDoNothing】
1. What is interruption , The principle of interruption
Interrupt is set to enable the single chip microcomputer to have real-time processing of external or internal random events , The existence of interrupt function , It greatly improves the ability of MCU to deal with external or internal events .
In order to make it easier for everyone to understand the concept of interruption , Let's start with a life example : You turn on the fire , Boil a pot of water . Then go and do the laundry , In the process of washing clothes , Suddenly I heard the kettle send out the alarm of boiling The sound , At this time , You stop washing clothes , Turn off the fire immediately , Then pour boiling water into the thermos , Completion of irrigation After boiling water , You go back and continue washing clothes . There is actually an interruption in this process . For single chip microcomputer , Interruption means CPU Dealing with an event A when , Another incident happened B, request CPU Deal with quickly ( Interruption occurs );CPU Temporarily stop the current work ( Interrupt response ), turn and go Handling events B( Interruption of service ); stay CPU Put the event I After processing , Back to the original event A By Continue processing events where interrupted A( Interrupt return ), This process is called interruption .
With the application of computer technology , It has been found that interrupt technology not only solves the problems of fast host and slow host I/O Data transmission problem of equipment , It also has the following advantages : ① Time sharing operation .CPU It can be divided into multiple I/O Equipment services , Improve the utilization of the computer ; ② Real time response .CPU Be able to handle random events of application system in time , The real-time performance of the system is greatly increased strong ;③ High reliability .CPU Have the ability to deal with emergencies such as equipment failure and power failure , So that the system Improved reliability .
2.STC89C5X Interrupt in series single chip microcomputer
STC89C5X Series MCU provides 8 An interrupt request source , They are : External interrupt O(INTO)、 External interrupt 1(INT1)、 External interrupt 2(INT2)、 External interrupt 3(INT3)、 Timer 0 interrupt 、 Timer 1 interrupt 、 Timer 2 interrupt 、 A serial port (UART) interrupt .
Now let's 51 SCM must have 5 An interrupt to introduce , Its internal structure block diagram is as follows :
(1). Interrupt allow control

(2). Interrupt request flag TCON

(3). Interrupt priority

(4). Interrupt number

(5). Interrupt response condition

Code representation :
EA=1;// Turn on the main interrupt switch
EX0=1;// Open external interrupt 0
IT0=0/1;// Set the trigger mode of external interrupt
void int() interrupt() using 1
{
// Function code
}
3. Button control is realized through external interrupt LED Turn off and on the lights
(1) Circuit design
External interrupt 0 Corresponding to MCU p3.2 mouth , External interrupt 1 Corresponding to MCU p3.3 mouth , So here we use p3.2 Connect button K1, And then d1 Connect to P2.0, As shown in the figure below :
Code design :
/************************************************************************************** Experimental phenomena : After downloading the program , operation K3 Press the key to make D1 State inversion Wiring instructions : ( The specific wiring diagram can be seen in the corresponding experiment of the development strategy “ Experimental phenomena ” chapter ) 1, Single chip microcomputer -->LED& Traffic light module P20-->D1 2, Single chip microcomputer --> Independent key module P32-->K3 matters needing attention : ***************************************************************************************/
#include "reg52.h" // This file defines some special function registers of MCU
typedef unsigned int u16; // Declare and define data types
typedef unsigned char u8;
sbit k3=P3^2; // Define keys K3
sbit led=P2^0; // Definition P20 The mouth is led
/******************************************************************************* * Letter Count name : delay * The functionality : The time delay function ,i=1 when , About time delay 10us *******************************************************************************/
void delay(u16 i)
{
while(i--);
}
/******************************************************************************* * Letter Count name : Int1Init() * The functionality : Set external interrupt 1 * transport Enter into : nothing * transport Out : nothing *******************************************************************************/
void Int0Init()
{
// Set up INT0
IT0=1;// Jump along the departure mode ( Falling edge )
EX0=1;// open INT0 The interrupt allows .
EA=1;// Open total interrupt
}
/******************************************************************************* * Letter Count name : main * The functionality : The main function * transport Enter into : nothing * transport Out : nothing *******************************************************************************/
void main()
{
Int0Init(); // Set external interrupt 0
while(1);
}
/******************************************************************************* * Letter Count name : Int0() interrupt 0 * The functionality : External interrupt 0 The interrupt function of * transport Enter into : nothing * transport Out : nothing *******************************************************************************/
void Int0() interrupt 0 // External interrupt 0 The interrupt function of
{
delay(1000); // Delay chattering
if(k3==0)
{
led=~led;
}
}
The effect is as follows :
边栏推荐
- BeanFactory创建流程
- 深度学习------不同方法实现Inception-10
- 【Paper】2015_ Coordinated cruise control for high-speed train movements based on a multi-agent model
- What is an optocoupler circuit and what should be paid attention to in actual use?
- Difference between request forwarding and redirection
- QT 6.3.1conan software package release
- Threadlocal
- Implementation of one interview question one distributed lock every day
- Fair lock and unfair lock
- [control] multi agent system summary. 4. control agreement.
猜你喜欢

Interprocess communication

Window10 jar double click to run without response

Geotrustov wildcard

Universal Studios Singapore: a good place for a one-day parent-child tour in Singapore

Connect to the database and run node JS running database shows that the database is missing
![[fpga] implementation of IIC read / write EEPROM](/img/6a/36e9355058a90d98cffafcbaa1930b.png)
[fpga] implementation of IIC read / write EEPROM

Use of thread pool

Sailing experience not to be missed in New York Tourism: take you to enjoy the magnificent city scenery from different perspectives

Wildcard SSL certificate issuing time

IIS request SSL certificate
随机推荐
Read / write lock example
Enter the date format string as the production date of the commodity, and enter the shelf life (days); Calculate the number of days until today before the expiration date of the product. 1. Change the
SSL update method
Servlet lifecycle
How to renew an SSL certificate
QT 6.3.1conan software package release
Foreign SSL certificate
Code cloud fatal: authentication failed for
OneNote production schedule
基于servlet+jsp+mysql实现的工资管理系统【源码+数据库】
破局存量客群营销,试一下客户分群管理(含聚类模型等实操效果评估)
Salary management system based on servlet+jsp+mysql [source code + database]
基于SSM框架茶叶商城系统【项目源码+数据库脚本+报告】
Bean creation process and lazy init delay loading mechanism
Webots learning notes
【Paper】2020_ Research on defense and evaluation strategy of heterogeneous UAV formation_ Zuojiankai
【Paper】2016_ A Learning-Based Fault Tolerant Tracking Control of an Unmanned Quadrotor Helicopter
Blocking queue example
Redis implements SMS login function (I) traditional session login
Fair lock and unfair lock