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 is a 16-bit timer/counting 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 (if the initial value is 0, it will become 0001H after counting 1, and 0FFFFH after counting 65535. It will become 65536 after counting again. It overflows, and all bits are 0, and then an interrupt is requested. So it can count 65536, although it overflowed the last time.), what should we 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 it? Yes, but what should we do after the counter is full? You know, counting is always repeated. When the pipeline is full, 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 (why, you can refer to the explanation in the previous course), so the next time it will overflow after the counter reaches 65536, which does not meet the requirements. What should we do? Of course, the solution is very simple, that is, execute a program every time it overflows (this is usually necessary, otherwise why overflow?). In this program, you can do something to send the preset number 64536 into the counter. Therefore, using working mode 0 or 1, you must reset the preset number after overflow. Of course, it takes time to do this work. Generally speaking, this time is nothing, but there are some occasions where 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 reloaded, the preset number must be placed in a place, otherwise what should it be placed in? So where should the preset number be 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 the counting, while the upper 8 bits do not participate in the counting, and are used to store the preset number, so the counting range is much smaller. Of course, there is always a price to pay for doing anything, and 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. Look at 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 control, and overflow after full count requires an overflow mark. T0 is divided into two, so two sets of control and overflow marks are needed. Where do they come from? TL0 still uses the original T0 mark, while TH0 borrows the mark of T1. In this way, T1 is unmarked and control is available, right? Yes.
In general, only when T1 runs 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 mode 2 and working mode 3 are both 8-bit timing/counting modes, so the maximum count can be 2 to the 8th power, or 256 times.
Preset value calculation: subtract the required count times 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 programmer, 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 either timing or counting at the same time, but not at the same time. This is very common sense. 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 = 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 through. 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.
(1) External interrupt request source: that is, external interrupts 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
Request address of five interrupt sources
External interrupt 0: 0003H
Timer 0: 000BH
External interrupt 1: 0013H
Timer 1: 001BH
Serial port: 0023H
Previous article:Analysis of pull-up resistors for 51 MCU drive capability
Next article:Proteus and Keil Cx51 microcontroller simulation (flowing light)
Recommended ReadingLatest update time:2024-11-16 19:55
- Popular Resources
- Popular amplifiers
- 西门子S7-12001500 PLC SCL语言编程从入门到精通 (北岛李工)
- MCU C language programming and Proteus simulation technology (Xu Aijun)
- 100 Examples of Microcontroller C Language Applications (with CD-ROM, 3rd Edition) (Wang Huiliang, Wang Dongfeng, Dong Guanqiang)
- Fundamentals and Applications of Single Chip Microcomputers (Edited by Zhang Liguang and Chen Zhongxiao)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- How to Make DSP Digital Oscillator Generate Phase-Shifted Sine Wave
- One-to-two high power relay
- CC2640 Button Battery Powered Design Tips
- A new energy company in Beijing is recruiting algorithm and HIL engineers
- Review summary: Free review of Pingtouge scenario-based Bluetooth Mesh gateway development kit
- MOSFET capacitor
- 5G small base station construction technology article sharing
- May 19 live broadcast review: MPS, Nexperia and Tektronix gathered to discuss the key points of new energy power design
- R329 Development Board Application - Operation Image (2)
- IOT desk lamp software design