A Brief Discussion on the RETI Instruction of 51 Single Chip Microcomputer

Publisher:BlossomBeautyLatest update time:2012-12-05 Source: 51hei Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Recently, a very strange problem occurred in the process of programming based on 51 single-chip microcomputers: "During the program execution, under the conditions of register EA=1, ET0=1, and TR0=1, the interrupt was not executed when TF0=1". Those who have experience in single-chip microcomputer interrupt programming know that when EA=1, ET0=1, and TF0=1 is satisfied, if there is no higher priority interrupt execution during this period, timer interrupt 0 will definitely generate an interrupt response. In the program I wrote, only timer interrupt 0 was used, and there was no priority problem for an interrupt. After checking my own program and comparing the interrupt programs in various textbooks, I found a problem in my program: due to the uncontrollability of the interrupt, it is uncertain to jump out of the interrupt and return to the main program, and because the program needs to jump to the specified address after the interrupt jumps out. In order to solve this problem, I directly used the unconditional jump instruction "LJMP ADR16" at the end of the interrupt, where ADR16 is the address where I want the program to run after the interrupt ends, without passing through the instruction "RETI". The problem was found, which means that the difference between my program and other programs is that it does not execute "RETI" but jumps out directly.

In order to solve the problem, I consulted a lot of information and textbooks on single-chip microcomputers. Almost all textbooks have the same definition of the role of the instruction "RETI": "After the interrupt program is completed, a RETI instruction must be executed. After executing this instruction, the CPU will take out the address stored in the stack and send it back to the PC, and then the program will continue to execute from the interruption point of the main program." If the role of "RETI" is only to "take out the address stored in the stack and send it back to the PC"; then can't I achieve the same effect of pushing the address by replacing it with the two instructions "POP DPH" and "POP DPL"? This can solve the stack overflow error caused by only pushing the stack instruction (automatically generated by the hardware) without popping the stack, but it cannot solve the "cannot enter the interrupt" problem mentioned at the beginning of the article. This makes me more convinced that the role of the instruction "RETI" introduced in the book is not complete. After consulting various materials and documents, I found a concept of "'priority effective' trigger" that was not mentioned in the textbooks and teachers when introducing single-chip microcomputer hardware and registers. The data points out that "according to the structural characteristics of 8051, its interrupt system contains two non-addressable "priority effective" triggers. One is used to indicate whether the CPU is executing a high-priority interrupt service program. When this trigger is 1, the system will block all interrupt requests; the other indicates whether the CPU is executing a low-priority interrupt service program. When this trigger is 1, it will block all interrupt requests except for high-priority ones. It can be seen that if you want to respond to interrupt requests of the same level or even lower level, you must clear the "priority effective" trigger. But this trigger is not addressable, so it cannot be cleared directly by software." Is the problem here? How is the "priority effective" trigger cleared? It is automatically executed by the hardware, so when is it executed? I will solve the problem with the problem. Suppose I can make the program jump to the original specified address "ADR16" after jumping out of the interrupt and satisfy the execution instruction "RETI". After repeated thinking, I used four instructions: "DEC SP"; "DEC SP"; "MOV DPTR, #ADR16"; "PUSH DPL"; "PUSH DPL" and "PUSH DPH" to replace them, and the problem was solved.

Summary: The interrupt instruction "RETI" as an interrupt jump instruction not only takes out the address stored in the stack and sends it back to the PC, so that the program can continue to execute from the interruption point of the main program, but also clears the "priority effective" trigger. This error also occurred in the program I made. Due to the clearing of the "priority effective" trigger, the second interrupt could not be entered (equivalent to the same priority application).

Postscript: The knowledge I used to solve this problem was from the textbook, but not entirely from the textbook. In this process, I used the knowledge I had learned to solve my own problem, and further introduced some new knowledge of the interruption process. I believe that the learning of new knowledge depends largely on the acquisition of new knowledge through the process of application, summary, deduction, etc. on the basis of the knowledge I have learned. This is also an ability of contemporary college students to apply knowledge and acquire new knowledge.

Reference address:A Brief Discussion on the RETI Instruction of 51 Single Chip Microcomputer

Previous article:Programming of Serial Communication between Two Single-Chip Microcomputers
Next article:How to use the built-in watchdog of 89S51 series microcontroller

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

Experiment 3: Table Lookup, Multi-branch (80C51 MCU Assembly Language Programming)
Suppose there is a table with the numbers: 00H, 11H, 22H...FFH. Put the lower 4 bits of the 00H unit on the chip into the 0000H outside the chip (the upper 4 bits of 0000H are 0), and put the upper 4 bits into the 0001H outside the chip (the upper 4 bits of 0001H are 0). According to the number in 0000H, take out the c
[Microcontroller]
8051 microcontroller for 8-channel LED analog branch control
1. The design problem uses the P1 port of 8051 as the input and the P0 port as the output, and connects 8 LED analog branch controls through 74LS244. When P1.0 is low level, one LED lights up; when P1.0 is high level and P1.1 is low level, all LEDs light up; when P1.0 and P1.1 are both high level, the LED presses four
[Microcontroller]
8051 microcontroller for 8-channel LED analog branch control
Design of 1s timer using external interrupt of C51 single chip microcomputer
The 51 single-chip microcomputer provides us with two timer interrupts, namely timer 0 and timer 1, and their corresponding priorities are 1 and 3 respectively. After the timer is turned on and its interrupt is allowed, the timer will start from the given initial value and increase by 1 in each instruction cycle until
[Microcontroller]
Design of 1s timer using external interrupt of C51 single chip microcomputer
51 MCU Learning 5-Independent Buttons and Matrix Keyboard
Episode 14   The principle of keyboard Keyboards are divided into coded keyboards (such as computer keyboards) and non-coded keyboards (identified by programs themselves). Non-encoded keyboards are divided into: independent non-encoded keyboards (independent keys), row-column non-encoded keyboards (4*4 array key
[Microcontroller]
51 MCU Learning 5-Independent Buttons and Matrix Keyboard
51 MCU——EEPROM
24C02: 256-byte EEPROM. Generally, EEPROM has a lifespan of 300,000 to 1 million times. Devices based on the I2C communication protocol. I2C is a communication protocol with strict communication timing logic requirements, while EEPROM is a device that only samples the interface of the I2C protocol and is connected to
[Microcontroller]
51 MCU Learning Notes (V)_C51 Implementation of MCU Serial Communication Simulation
1. Rendering     2. Virtual Serial Port Use VSPD virtual serial port tool to virtualize two serial ports for communication VSPD virtual serial port tool download: http://download.csdn.net/detail/leytton/7565589     3. Serial port debugging Open two serial port debugging tools, the first one opens
[Microcontroller]
51 MCU Learning Notes (V)_C51 Implementation of MCU Serial Communication Simulation
51 single chip microcomputer 8*8 dot matrix display
The display shows 0-9 numbers and text. Please follow the WeChat public account "Yisi Electronic Programming" to get it for free. Simulation diagram: Code:
[Microcontroller]
51 single chip microcomputer 8*8 dot matrix display
CH451 drives LED digital tube microcontroller C language example program
CH451 can drive 8-bit digital tubes at one time and communicate with the microcontroller in serial. It supports left shift, right shift, left cycle, right cycle, independent flashing, 16-level brightness control and other functions of the digital tube. It is a powerful assistant for the microcontroller to control multi
[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号