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
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
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
- 【GD32L233C-START Review】MODBUS Test
- Configuration of character overlay chip 90092
- The normalized epidemic situation is still exploited by the virus
- Life Tips
- Drive Operating System
- Introduction to ARM SWD Protocol
- Introduction to the mobile station development board: ultra-low power python board
- USB to JTAG
- MSP430F5529 Power Management Module
- DSP28335 SCI communication problem summary and problem summary