当前位置:网站首页>Mcu-08 interrupt system and external interrupt application
Mcu-08 interrupt system and external interrupt application
2022-06-24 18:11:00 【LCH Nan'an】
reference :【 New reminder 】【 Blue Bridge Cup MCU 07】 Thoroughly understand 51 MCU interrupt system - - 21ic Electronic technology development forum
Interrupt definition :
You're chasing a TV show 《 The Brave Archer and His Mate 》, When I was fascinated , The phone rings , You pause the TV show , Answer the phone , In the process of answering the phone , The doorbell rang again , You put the phone down for a while , Go and open the door . If you are chasing a TV series Execute main program , So the phone is Interrupt source , When the phone rings, it's just Interrupt request , Pause TV is Site protection , Just answer the phone Interrupt response , The doorbell rang Higher level interrupt request , Go and open the door , That's it Break nesting . Come back after opening the door and talk on the phone , That is Interrupt return , After answering the phone, pause the TV play and open it Scene recovery .
There are two main ways of interaction between kernel and peripherals : polling and interrupt . Polling seems fair , But the actual efficiency is very low , And can't respond to emergencies in a timely manner ; The interrupt system makes the kernel have the ability to deal with emergencies .
Interrupts have a feature , You don't know when the interruption will happen . therefore , Each interrupt needs to have a Interrupt entry address , Has become a Interrupt vector . such , No matter when the interruption occurs , It has a definite starting point for program execution . After interrupt response , The program executed , We call it Interrupt service function , That is, this function is dedicated to the interrupt service .
Interrupt related register :
Interrupt related registers are 4 individual , Each register is OK Bit addressing Of , This brings convenience to the programming . among 2 One is the control register :IE register And IP register :

in addition 2 An interrupt request flag :TCON register And SCON register :

In general , There are two interrupt handling functions , One is Interrupt initialization function , The second is Interrupt service function . The initialization function is an ordinary function , The interrupt service function has Special format requirement :
<1> The interrupt function has no return value , Nor can it take parameters .
<2> The function name should be followed by a keyword interrupt, It shows that this is an interrupt service function .
<3> In keywords interrupt Keep up with Interrupt number , It indicates that this interrupt service function serves that interrupt .
Interrupt service function Format by :
void Function name () interrupt Interrupt number
{ ---- The body of the function ---- }
We're going to use a timer 0 For interval timing , Interrupt program architecture we C Language can write like this :

subject :

Circuit diagram :

Blue Bridge Cup MCU simulation schematic diagram : Blue Bridge Cup MCU simulation schematic diagram .pdsprj- Handout document resources -CSDN library
Code :
#include<reg52.h>
// Decoder definition
sbit HC138_C =P2^7;
sbit HC138_B =P2^6;
sbit HC138_A =P2^5;
//LED Definition
sbit L1 =P0^0;
sbit L8 =P0^7;
// Only control is used LED(Y4) The latch of
void SwitchHC138(unsigned char channel)
{
switch(channel)
{
case 4:
HC138_C= 1;
HC138_B= 0;
HC138_A= 0;
break;
case 5:
HC138_C= 1;
HC138_B= 0;
HC138_A= 1;
break;
}
}
void DelayL(unsigned int t)
{
while(t--);
while(t--);
}
//L1 Flicker function
void Working()
{
SwitchHC138(4);
L1 = 0; // Lighten up
DelayL(60000);
DelayL(60000);
L1 =1; // Extinguish
DelayL(60000);
DelayL(60000);
}
// ==========================
// Interrupt initialization
void Init_INT0()
{
IT0 = 1;
EX0=1;
EA=1;
}
// Interrupt service function ( Method 1 : Press the key L8 Lighten up , meanwhile L1 It will also light up )
//void Service1_INT0() interrupt 0
//{
// L8 = 0;
// DelayL(60000);
// DelayL(60000);
// L8 = 1;
// DelayL(60000);
// DelayL(60000);
//
//}
// ==========================
// Interrupt service function ( Method 2 : Use the flag quantity to light up L8, This method is based on Working After the function is executed, execute Light function )
unsigned char flag =0;
void Service2_INT0() interrupt 0
{
flag = 1;
}
void Light()
{
if(flag == 1)
{
L8 = 0;
DelayL(60000);
DelayL(60000);
L8 = 1;
DelayL(60000);
DelayL(60000);
}
flag =0;
}
// ==========================
void Init()
{
SwitchHC138(5);
P0 = 0x00;
DelayL(100);
SwitchHC138(4);
P0 = 0xff;
}
void main()
{
Init();
Init_INT0();
while(1)
{
Working();
Light();
}
}边栏推荐
- -Bash: wget: command not found
- Design topic: MATLAB UAV flight operation
- Install MySQL using Yum for Linux
- Explanation of MySQL indexing principle
- Service not found troubleshooting and resolution of error messages in the secondary development of the source code of the open source platform easydarwin
- EasyCVR国标协议接入的通道,在线通道部分播放异常是什么原因?
- How to start cloud native application development
- Regression testing strategy for comprehensive quality assurance system
- Quickly build MySQL million level test data
- It is often blocked by R & D and operation? You need to master the 8 steps before realizing the requirements
猜你喜欢
Issue 39: MySQL time class partition write SQL considerations

Project Management Guide: tips, strategies and specific practices
Millions of dollars worth of NFT were stolen in the attack, and Google issued an emergency warning to 3.2 billion users worldwide | February 21 global network security hotspot

Seven strategies for successfully integrating digital transformation

How can programmers reduce bugs in development?

Nine practical guidelines for improving responsive design testing

Six configuration management tools that administrators must know

It is often blocked by R & D and operation? You need to master the 8 steps before realizing the requirements

Nacos cluster starts throwing set of SQL_ SELECT_ LIMIT is not support

13 ways to reduce the cost of cloud computing
随机推荐
Cloud service selection of enterprises: comparative analysis of SaaS, PAAS and IAAs
About whether arm's large and small end mode is related to CPU or compiler
Millions of dollars worth of NFT were stolen in the attack, and Google issued an emergency warning to 3.2 billion users worldwide | February 21 global network security hotspot
Using easyjson to improve the efficiency of serialization transmission
Online sequence flow chart making tool
Do you charge for PDF merging software? Programmers make one by themselves
How to use rdbtools to analyze redis large keys
Users of the Tiktok open platform are authorized to obtain the user's fan statistics and short video data
2. Leveldb design principle -- LSM
Restcloud ETL extracting dynamic library table data
Business leaders compete for CIO roles
Four security issues of low code and no code development
[untitled]
Go language GC implementation principle and source code analysis
Can the money invested in financial products be withdrawn at any time?
【你真的会用ES吗】ES基础介绍(一)
[NLP] 3 papers on how Stanford team builds a better chat AI
专有云TCE COS新一代存储引擎YottaStore介绍
Complete Guide to web application penetration testing
How to decompile APK files