Summary of MCU interrupts

Publisher:VS821001Latest update time:2016-09-21 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
1. TMOD: Timer counter mode register



M1M0: There are four working modes for the timer/counter, which are controlled by M1M0. 2 bits are exactly four combinations.

1. Working mode 1 

Working mode 1 is a 16-bit timer/counter mode. Set M1M0 to 01. Other characteristics are the same as working mode 0.

Working mode 2 
Before introducing this mode, let us think about a question: In the last class, we mentioned the problem of arbitrary counting and arbitrary timing. For example, I want to count 1000 numbers, but the 16-bit counter has to count to 65536 before it is full. What should I do? After discussion, we came up with a solution to use a preset number. First put 64536 in the counter, and then 1000 pulses. Isn't that enough? Yes, but what should we do after the count is full? You know, counting is always repeated. After the count is full on the pipeline, the next count will start immediately. Will the next count still be 1000? When the counter is full and overflows, the value in the counter becomes 0 (for reasons, please refer to the explanation in the previous course). Therefore, the next time the counter will overflow after it reaches 65536, which does not meet the requirements. What should we do? Of course, the solution is very simple, that is, to execute a program every time an overflow occurs (this is usually necessary, otherwise why would there be an overflow?). In this program, the preset number 64536 can be sent to the counter. Therefore, whether the working mode 0 or 1 is used, a reset of the preset number must be performed after the overflow. Of course, it takes time to do the work. Generally speaking, this time is nothing, but in some occasions, we still have to care about it, so there is a third working mode - the working mode of automatically reloading the preset number.

Since the preset number needs to be automatically loaded, the preset number must be placed in a place, otherwise what should it be placed in? So where is the preset number placed? It is placed in the upper 8 bits of T (0/1). So, won't the upper 8 bits not be able to participate in the counting? Yes, in working mode 2, only the lower 8 bits participate in counting, while the upper 8 bits do not participate in counting and are used to store the preset number. In this way, the counting range is much smaller. Of course, there is always a price to pay for doing anything. The key is to see whether it is worth it. If I don’t need to count so many numbers at all, then I can use this method. See Figure 4. Whenever the count overflows, the switch between the upper and lower 8 bits of T (0/1) will be turned on, and the preset number will enter the lower 8 bits. This is done automatically by hardware and does not require manual intervention.

Usually this mode of operation is used for baud rate generators (we will explain it in the serial interface). When used for this purpose, the timer is to provide a time base. There is no need to do anything after the count overflows. There is only one thing to do, which is to reload the preset number and start counting again, and there should be no delay in the middle. It can be seen that this task is best completed by working mode 2.

Working mode 3 
Under this mode of operation, timer/counter 0 is split into two independent timers/counters. Among them, TL0 can constitute an 8-bit timer or counter working mode, while TH0 can only be used as a timer. We know that when used as a timer or counter, it needs to be controlled. When overflow occurs after counting, an overflow mark is required. T0 is divided into two, so two sets of control and overflow marks are required. Where do they come from? TL0 still uses the original T0 mark, while TH0 borrows the mark of T1. In this

case, T1 is unmarked and control is available, right? Yes. In general, only when T1 is running in working mode 2 (when used as a baud rate generator), T0 is allowed to work in mode 3.

Timing/counting range of timer/counter

Working mode 0: 13-bit timing/counting mode, so it can count up to 2 to the 13th power, that is, 8192 times. Working mode 1:

16-bit timing/counting mode, so it can count up to 2 to the 16th power, that is, 65536 times.

Working modes 2 and 3 are both 8-bit timing/counting modes, so it can count up to 2 to the 8th power, that is, 256 times.

Preset value calculation: subtract the required number of counts from the maximum count amount.

C/T: As we said before, the timer/counter can be used for timing or counting. It is up to us to decide what to use it for, or we, the programmers, can decide. If C/T is 0, it is used as a timer (the switch is turned up), and if C/T is 1, it is used as a counter (the switch is turned down). By the way: a timer/counter can be used for timing or counting at the same time, but not at the same time. This is very common knowledge. Almost no textbooks will mention this, but many beginners will be confused by this. 

GATE: Look at the picture. When we choose the timing or counting working mode, the timing/counting pulse may not reach the counter end. There is also a switch in the middle. Obviously, if this switch is not closed, the counting pulse cannot pass. So when does the switch pass? There are two cases: 

1. GATE = 0. Analyze the logic. GATE is 1 after negation. It enters the OR gate. The OR gate always outputs 1, which has nothing to do with the other input terminal INT1 of the OR gate. In this case, the opening and closing of the switch depends only on TR1. As long as TR1 is 1, the switch is closed and the counting pulse can pass smoothly. If TR1 is equal to 0, the switch is open and the counting pulse cannot pass. Therefore, whether the timing/counting works depends only on TR1. 

GATE = 1. In this case, the switch on the counting pulse path is not only controlled by TR1, but also by the INT1 pin. Only when TR1 is 1 and the INT1 pin is also high, the switch is closed and the counting pulse can pass. This feature can be used to measure the width of the high level of a signal. Think about it, how to measure it? 
 

II. TCON: Timer counter control register



1. Interrupt request source: 

(1) External interrupt request source: that is, external interrupt 0 and 1, which are introduced through external pins. There are two pins on the microcontroller, named INT0 and INT1, that is, P3.2 and P3.3. There are four bits in the internal TCON that are related to external interrupts.

IT0: INT0 trigger mode control bit, which can be set and reset by software. IT0=0, INT0 is low-level trigger mode, IT0=1, INT0 is negative jump trigger mode. The difference between these two modes will be discussed later.

IE0: INT0 interrupt request flag. When there is an external interrupt request, this bit will be set to 1 (this is done by hardware). After the CPU responds to the interrupt, IE0 is cleared to 0 by hardware

. The purpose of IT1 and IE1 is the same as IT0 and IE0.

(2) Internal interrupt request source

TF0: Timer T0 overflow interrupt flag. When T0 counts overflow, TF0 is set by hardware. When the CPU responds to the interrupt, TF0 is cleared to 0 by hardware.

TF1: Similar to TF0.

TI, RI: Serial port send and receive interrupts

III. Interrupt enable register IE

In the MCS-51 interrupt system, the enable or disable of interrupts is controlled by the 8-bit interrupt enable register IE that can be bit-addressed on the chip. See the table below

EA

master switch
 X
 X
 ES

serial port interrupt enable
 ET1

timer 1 interrupt enable

 
 EX1

external interrupt 1 interrupt enable
 ET0

Timer 0 interrupt enable
 EX0

External interrupt 0 interrupt enable
 

EA is the master switch. If it is equal to 0, all interrupts are not allowed.

ES-Serial port interrupt enable

ET1-Timer 1 interrupt enable

EX1-External interrupt 1 interrupt enable.

ET0-Timer 0 interrupt enable

EX0-External interrupt 0 interrupt enable

IV. Interrupt priority register IP

The interrupt priority is set high by the interrupt priority register IP. If a bit in IP is set to 1, the corresponding interrupt is high priority, otherwise it is low priority.

 

X
 X
 X
 PS

Serial port
 PT1

Timer 1
 PX1

External interrupt 1
 PT0

Timer 0
 PX0

External interrupt 0
 

The request address of the five interrupt sources

External interrupt 0: 0003H

Timer 0: 000BH

External interrupt 1: 0013H

Timer 1: 001BH

Serial port: 0023H
Keywords:MCU Reference address:Summary of MCU interrupts

Previous article:Difficulties to pay attention to in developing single chip microcomputer products
Next article:Commonly used address latch chips in single-chip microcomputer systems: 74LS373 74hc373

Recommended ReadingLatest update time:2024-11-23 06:16

MCU C Language Tutorial: Appendix 3 Operator Precedence and Associativity
Operator precedence and associativity
[Microcontroller]
MCU C Language Tutorial: Appendix 3 Operator Precedence and Associativity
Renesas unveils next-generation automotive SoC and MCU processor product roadmap
Future product lineup includes R-Car SoC using advanced chiplet integration technology and automotive MCUs based on Arm® cores November 8 , 2023 , Beijing, China - Renesas Electronics, a global semiconductor solutions provider , today unveiled its next-generation system-on-chip (SoC) and microcontroller
[Embedded]
Renesas unveils next-generation automotive SoC and MCU processor product roadmap
51 MCU (V) - GPIO lights up an LED
1. Introduction to LED control Light-emitting diodes are a type of semiconductor diode that can convert electrical energy into light energy, often abbreviated as LED. Like ordinary diodes, light-emitting diodes are composed of a PN junction and also have unidirectional conductivity. When a forward voltage is applied t
[Microcontroller]
51 MCU (V) - GPIO lights up an LED
Image acquisition system realized by FIFO chip and single chip microcomputer
Introduction In the microcontroller application system, it is quite difficult to completely store an image of 30 fps and 640×480 pixels due to the limitations of image acquisition speed, program memory and data memory addressing space. This paper uses a high-performance 16-bit Freescale microcontroller to directly ac
[Microcontroller]
Image acquisition system realized by FIFO chip and single chip microcomputer
Configuration of Field Programmable Gate Array Based on Single Chip Microcomputer
1 Introduction Before the emergence of large-scale programmable logic devices, soldering the device on the circuit board was the last step in designing a digital system. When there were problems in the design and they were solved, the designer often had to redesign the printed circuit board. The design cycle w
[Microcontroller]
Research on the Design of 8-bit Microcontroller Architecture
1. Introduction Since the emergence of microcontrollers in the 1970s, they have developed rapidly and been widely used in the past 30 years. With the rapid development of microelectronics technology, microcontrollers have been widely used in household appliances, computing and peripherals, communications, indus
[Microcontroller]
PIC Microcontroller Study Notes
1. Status register STATUS 2. Implement indirect addressing registers INDF and FSR 3. Registers PCL and PCLATH related to the program counter PC 4. Power control register PCON PIC microcontroller instruction system PIC16F87X has 35 instructions, all of which are single-byte instructions w
[Microcontroller]
PIC Microcontroller Study Notes
Design of AVR single chip LED display screen with scrolling text and images
LED dot matrix blocks have the advantages of high brightness, uniform light emission, good reliability, and easy assembly, and can form display screens of various sizes. At present, LED display screens have been widely used in text display and have achieved good results, but most of them can only display scrolling tex
[Power Management]
Design of AVR single chip LED display screen with scrolling text and images
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号