Writing of MCU interrupt function

Publisher:自由探索Latest update time:2017-01-10 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

interrupt m modifier

The C51 interrupt function must be modified by this modifier. In C51 programming, when the interrupt m modifier is used in the function definition, the system converts the corresponding function into an interrupt function during compilation, automatically adds the program header and trailer, and automatically arranges it in the corresponding position in the program memory according to the 51 system interrupt processing method.

In this modifier, the value of m is 0~31, and the corresponding interrupt conditions are as follows:

0——External interrupt 0

1——Timer/Counter T0

2——External interruption 1

3——Timer/Counter T1

4——Serial port interrupt

5——Timer/Counter T2

Other values ​​are reserved.

The C51 compiler generates an interrupt vector from the absolute address 8m+3, where m is the interrupt number, which is the number after interrupt. The vector contains an absolute jump to the entry address of the interrupt function.

[Example] Write an interrupt service program to count the number of interrupts of external interrupt 0

 

1 int  x=0;2 void  int0()  interrupt 0  using 13 {4   x++;5 }

 

using n modifier

The modifier using n is used to specify the working register group used within this function, where n is a value between 0 and 3, indicating the register group number. This modifier can be omitted, and the system automatically selects the register group number after it is omitted.

Note the following about the interrupt function:

(1) Interrupt functions cannot pass parameters. If an interrupt function contains any parameter declaration, a compilation error will occur.

(2) The interrupt function has no return value. If you attempt to define a return value, you will not get the correct result. It is recommended to define the interrupt function as a void type to clearly indicate that there is no return value.


Keywords:MCU Reference address:Writing of MCU interrupt function

Previous article:Program to test timer 0
Next article:51 MCU SRF register

Recommended ReadingLatest update time:2024-11-16 15:48

Detailed steps to explain the high-impedance state using 51 microcontroller
The P0 port of the 51 microcontroller works in the ordinary IO port mode and is a bidirectional IO port. When working in the second functional state, it is a standard bidirectional IO port. Since the output of the bidirectional IO port is required to output high and low levels, a complementary push-pull circuit is usu
[Microcontroller]
Detailed steps to explain the high-impedance state using 51 microcontroller
External interrupts of microcontrollers (Part 2)
Preface: Microcontroller Interrupt System (I) The 80C51 microcontroller provides two external interrupt ports: INT0 (P3.2) and INT1 (P3.3) pin inputs. These two pins are function-multiplexed pins, which can be used as ordinary V0 ports or external interrupt input pins. The following is an explanation of the external
[Microcontroller]
External interrupts of microcontrollers (Part 2)
【PIC microcontroller】-- LCD related knowledge
00 Write in front This series of articles is from a teacher who has served as a teaching assistant for the PIC microcontroller course. I mainly explained the contents of several experimental classes to my junior students. Here I record some of the knowledge learned in class. This series of articles mainly introduces
[Microcontroller]
【PIC microcontroller】-- LCD related knowledge
51 MCU interrupt priority and interrupt nesting
Introduction: To put it simply, the old 51 MCU (80C51 series) has 5 interrupt sources, 2 priorities, and can implement two-level interrupt service nesting. Now many extended 51 MCUs have 4 priorities (or more) and more interrupt sources. Before talking about interrupts, let me first define priority. If you understan
[Microcontroller]
Introduction to PIC series microcontrollers
1) The biggest feature of PIC is that it does not simply pile up functions, but starts from reality, attaches importance to the performance and price ratio of products, and develops multiple models to meet different levels of application requirements.  Initial 8-bit microcontroller: PIC12C5XXX/16C5X series  PIC16C5X
[Microcontroller]
51 MCU Experiment - Hexadecimal Counter
1. Experimental topic: Use P0.0- P0.03 to design a hexadecimal counter that automatically counts between 0-15, and each number lasts 0.2s. The code uses SWITCH statements and for loops to implement the hexadecimal counter design. The LED lights connected to the four IO ports count in the binary change sequence of 0000
[Microcontroller]
51 MCU Experiment - Hexadecimal Counter
Design scheme of laser rangefinder performance detection based on AVR microcontroller
The author has designed a comprehensive performance testing device for laser rangefinders based on AVR microcontroller. With the help of this device, digital testing of ranging accuracy, ranging capability, ranging logic, single pulse energy, etc. of laser rangefinders of different models can be completed, which gre
[Microcontroller]
Design scheme of laser rangefinder performance detection based on AVR microcontroller
Things to note when developing and debugging a single-chip microcomputer
    1. Use a single-chip computer without external bus     ·It is the most orthodox MCU usage mode     ·Consistent with the original intention of small, simple, reliable and cheap single-chip microcomputer design     Bus-enclosed products are the most reliable     2. Use MCU C language programming     * C la
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号