当前位置:网站首页>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();
}
}边栏推荐
- Design topic: MATLAB cellular automata personnel evacuation
- Project Management Guide: tips, strategies and specific practices
- He "painted" what a smart city should look like with his oars
- Seven strategies for successfully integrating digital transformation
- Three indicators to help you measure the effectiveness of digital transformation
- Use BPF to count network traffic
- How does the video platform import the old database into the new database?
- Erc-721 Standard Specification
- Etching process flow for PCB fabrication
- [can you really use es] Introduction to es Basics (I)
猜你喜欢

Top ten popular codeless testing tools
![[NLP] 3 papers on how Stanford team builds a better chat AI](/img/f1/1c2ff31a728152395618800600df45.jpg)
[NLP] 3 papers on how Stanford team builds a better chat AI

Nacos cluster starts throwing set of SQL_ SELECT_ LIMIT is not support
What if the database table structure changes? Smartbi products support one click synchronization

Complete Guide to web application penetration testing

Five skills of selecting embedded programming language

(Video + graphics) introduction to machine learning series - Chapter 11 support vector machines

How can programmers reduce bugs in development?

Etching process flow for PCB fabrication

How to decompile APK files
随机推荐
[untitled]
-Bash: wget: command not found
Common GCC__ attribute__
Selection (032) - what is the output of the following code?
Leveldb source code analysis -- writing data
What if the database table structure changes? Smartbi products support one click synchronization
How to decompile APK files
Use py-mysql2pgsql to synchronize MySQL data to Greenplum
Rapidssl getting started SSL certificate
Solutions for RTSP video streaming played by several browsers
投资理财产品的钱能随时取出来吗?
Provide secure and convenient Oracle solutions for smart contract developers
He "painted" what a smart city should look like with his oars
你知道CMDB吗?
Using easyjson to improve the efficiency of serialization transmission
13 skills necessary for a competent QA Manager
Digital transformation informatization data planning and technology planning
SQL basic tutorial (learning notes)
Comparison of similarities and differences between easynvr video edge computing gateway and easynvr software versions
Easygbs video platform TCP active mode streaming exception repair