51 MCU Study Notes (IV)_Interrupt System

Publisher:caijtLatest update time:2016-05-17 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Related concepts
  • Interrupt source: The event that caused the interrupt
  • Interrupt request: The interrupt source makes a request to the CPU for processing
  • Breakpoint: The pause point of the program when an interrupt occurs
  • Interrupt response: The process by which the CPU pauses the current program and responds to an interrupt request
  • Interrupt handler: A program that handles an interrupt source
  • Interrupt processing: CPU executes the relevant interrupt processing program
  • Interrupt return: the process of returning to the breakpoint

The difference between interrupts and subroutines

Calling is somewhat similar, but the two are different concepts.

 

  • The source is different. Interrupts are generated by external interrupt sources and are unpredictable and random, such as throwing exceptions. Subroutines are called by the main program.
  • The responses are different. The interrupt system needs to protect the breakpoints and context, while the subroutine only needs to save the breakpoints.
  • The functions are different. The interrupt program mainly handles CPU external asynchronous events, and the subroutine call serves the main program.

Interrupt Type

  • External interrupt source: generated by external hardware resources. Up and down edge trigger and high and low level trigger.
  • Timing interrupt source: timer/counter overflow trigger.
  • Serial port interrupt source: triggered by sending or receiving completion information during serial communication.

TCON interrupt flag

 

  • IE1: External interrupt 1 request flag.
  • IT1: External interrupt 1 trigger mode selection bit. When IT1=0, it is low level trigger mode; when IT1=1, it is falling edge trigger mode.
  • IE0: External interrupt 0 request flag.
  • IT0: External interrupt 0 trigger mode selection bit. When IT0=0, it is low level trigger mode; when IT0=1, it is falling edge trigger mode.

 

SCON interrupt flag

  • RI: After receiving the information on the serial interface, the hardware automatically sets RI=1 and the CPU responds to the interrupt. Note that it will not automatically clear RI=0 and needs to be set by software
  • TI: After the serial interface completes sending information, the hardware automatically sets TI=1 and the CPU responds to the interrupt. Note that it will not automatically clear TI=0 and needs to be set by software

 

General steps for interrupt initialization

1. Determine the working mode (i.e. assign a value to TMOD);
2. Preset the initial value of timing or counting (the initial value can be directly written into TH0, TL0 or TH1, TL1);
3. Enable the interrupt of the timer/counter as needed (directly assign a value to the IE bit);
4. Start the timer/counter (if it is specified to be started by software, TR0 or TR1 can be set to "1"; if it is specified to be started by the external interrupt pin level, a start level needs to be added to the external pin. When the start requirements are met, the timer starts counting or timing according to the specified working mode and initial value).

 

 

Interrupt enable flag

 

 

  • EX1: External interrupt 1 enable bit;
  • EX0: external interrupt 0 enable bit; 
  • ET1: Timer/Counter T1 interrupt enable bit; 
  • ET0: Timer/Counter T0 interrupt enable bit;
  • ES: serial port interrupt enable bit; 
  • EA: CPU interrupt enable (always enable) bit.

 

Interrupt priority flags

0 is low priority, 1 is high priority
  • PS: Serial interface interrupt priority setting bit
  • PT1: Timer/Counter Interrupt 1 Interrupt Priority Setting Bit
  • PT0: Timer/Counter Interrupt 0 Interrupt Priority Setting Bit
  • PX1: External interrupt 1 interrupt priority setting bit
  • PX0: External interrupt 0 interrupt priority setting bit

51 MCU interrupt number


  • External interrupt 0 (INT0), the corresponding interrupt number is 0, the interrupt entry address is 0003H
  • Timer/Counter 0 (T1), corresponding to interrupt number 1, interrupt entry address 000BH
  • External interrupt 1 (INT1), interrupt number 2 entry address 0013H
  • Timer/Counter 1 (T1) Interrupt Number 3 Entry Address 001BH
  • Serial port (RI/TI) interrupt number 4 Entry address 0023H
  • These five are AT89S51, 52 also has the following
  • Timer/Counter 2 (T2) interrupt number 5, entry address 002BH

  1. Function name()interrupt 0 {} //Corresponding to external interrupt 0;
  2. Function name ()interrupt 1 {} //Corresponding to timer/counter 0 interrupt;
  3. Function name()interrupt 2 {} //Corresponding to external interrupt 1;
  4. Function name ()interrupt 3 {} //Corresponding to timer/counter 1 interrupt;
  5. Function name ()interrupt 4 {} //Corresponding to serial port interrupt;
There are 5 types of interrupts, with priority from top to bottom; [Quoted from Baidu Knows link]

 


Reference address:51 MCU Study Notes (IV)_Interrupt System

Previous article:Renesas MCU Learning Notes (1) Basic Configuration
Next article:51 MCU Study Notes (VI)_Serial Port Interrupt Communication + Timer 2 Serial Port Interrupt

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号