About MCU C interrupt function

Publisher:BlissfulHikerLatest update time:2015-07-02 Source: 51heiKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Define interrupt service function
 
Function type function name (formal parameters) interrupt n [using n]
Interrupt Number Interrupt Source Interrupt Vector
  0 External interrupt 0 0003H
  1 Timer/Counter 0 000BH
  2 External interrupt 1 0013H
  3 Timer/Counter 1 001BH
  4 Serial port 0023H
The interrupt keyword is indispensable. It tells the compiler that this function is an interrupt service function.
n indicates the interrupt number used. The value range of n is 0-31, but the specific interrupt number depends on the chip model, such as
AT89C51 actually uses interrupts 0 to 4. Each interrupt number corresponds to an interrupt vector, the specific address is 8n+3,
After the interrupt source responds, the processor will jump to the address where the interrupt vector is located to execute the program. The compiler will generate a
Unconditional jump statement jumps to the address where the interrupt service function is located to execute the program. The following table shows the interrupt vector and the interrupt vector of the 51 chip.
Disconnected number.
 
Qmt above has roughly introduced the definition of interrupt function to you. It is worth mentioning that the interrupt function type is void, which means that the interrupt function cannot have a return value. This point should be made clear, so do not try to let the interrupt function give you a return value. In addition, there are no parameters in the brackets after the function name... This also needs to be noted that the interrupt function cannot pass parameters.
 
The dot after interrupt is the interrupt number. Let me explain using to you.
 
This is a keyword extended by the C51 compiler. It is used to select different register groups in the 80c51 microcontroller. As you know, there are 4 groups of R0-R7, so the number after using is a number in the range of 0-3. If using is not required, the compiler will automatically select a group of registers as absolute register access.
Using has a certain impact on the code.
Let me give you a simple example. You can think about it.
If you define 
void time0() interrupt 1 using 1
Suppose we call a delay() in the interrupt; this delay has a delay effect.
Then, we need to make sure that we are using the same set of registers, otherwise, confusion will occur.
Do you understand what I mean?
 
So, I suggest you not to use using when it is not necessary. However, you can try this keyword.
 
I wish you good luck in your studies.
 
LX efenwu:
In short, 51 has 4 groups of general registers, R0~R7. When we use them, we never specify which R0 is used, and the compiler will automatically select a group of general registers as absolute address access. In C language, when we write a function, such as a delay function, the variables used in it are using R0-R7 after disassembly, so can you be sure which group of registers you are using?
So, using using can select the register bank to use, but at the same time, you must be especially careful when "switching". If you call other programs in the interrupt program, the register bank switching problem will occur.
Actually, there are other things to note about using. Because it is troublesome to use, I never use this keyword. This is why I don't recommend you to use using. The compiler will choose a group by itself.
 
So just define an interrupt function like this:
void FuncName() interrupt lvl
Where lvl is the priority number of the interrupt.
Keywords:MCU Reference address:About MCU C interrupt function

Previous article:How to write modular C programs in KEIL
Next article:My experience of learning microcontrollers for three or four days

Recommended ReadingLatest update time:2024-11-16 16:40

51 MCU-button part (1)
Program function: The first three digits of the digital tube display a stopwatch, which runs from 000 to 999 at a speed of 1% second. When an independent keyboard is pressed, the stopwatch stops and continues to run after the hand is released. (Design the watch using a timer).  1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
[Microcontroller]
Several points to note when using the I/O port of AVR microcontroller
Introduction: Several precautions for using the I/O port of AVR microcontroller 1. Correctly set the DDRx direction register before performing read and write operations on the I/O port. 2. The initial state of the I/O port after reset is all input working mode, the internal pull-up resistor is invalid, and the ext
[Microcontroller]
51 single-chip microcomputer, assembly language, key operation control
Hardware circuit: P1.0 ~ P1.5 are connected to 6 external LEDs, called D1 ~ D6 respectively, which emit light at low level. P0.0 ~ P0.3 are connected to 4 external buttons, called K1 ~ K4 respectively. P3.2 ~ P3.3 are connected to 2 external buttons, called K5 ~ K6 respectively. Control by assembly language prog
[Microcontroller]
What are the characteristics and advantages of PIC microcontrollers?_pic method introduction
  What are the characteristics and advantages of the PIC series of microcontrollers?   Since I came into contact with PIC microcontrollers in 1995, I have been keen on the development and application of this type of microcontroller. Many friends asked me: What are the advantages of PIC? Maybe you will also have such q
[Microcontroller]
Use git to manage MCU project files developed by KEIL5
Prerequisites It is convenient to use KEIL5 to develop stm32. Many useless files will be generated in the process of program compilation and connection. For example, after a STM32 project is compiled normally, the size of the entire project is: After using keilkill.bat provided by Zhengdian Atom to delete useless fi
[Microcontroller]
Use git to manage MCU project files developed by KEIL5
Design of ultrasonic distance measurement alarm system based on single chip microcomputer
  With the continuous improvement of the requirements of intelligent building security systems and the continuous improvement of people's safety awareness, indoor anti-theft has gradually attracted people's attention. In response to this situation, this paper designs an ultrasonic ranging alarm system that can be used
[Microcontroller]
Design of ultrasonic distance measurement alarm system based on single chip microcomputer
Learning some related knowledge about microcontroller memory
Following the content of the previous issue, we will continue to understand the memory of microcontrollers and learn some related knowledge. There are two combination schemes of on-chip ROM and off-chip ROM. The first scheme is that the ROM inside the 51 microcontroller has a total of 4K. 4K is its storage capacity. I
[Microcontroller]
Learning some related knowledge about microcontroller memory
A summary of 51 MCU knowledge to see how much you know
The function signal generator based on 51 single-chip microcomputer uses the single-chip microcomputer AT89C52 to generate four waveforms: sawtooth wave, triangle wave, sine wave, and square wave by programming method, and then converts the digital signal into analog signal through D/A converter DAC0832, filters and a
[Power Management]
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
Guess you like

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号