Four working modes and functions of T0 and T1 of mcs-51 single chip microcomputer and calculation of timing initial value

Publisher:GoldenHarmonyLatest update time:2017-10-13 Source: eefocusKeywords:mcs-51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Mode 0
When bit M1M0=00. T is a 13-bit counter, THi is the high 8 bits, and TLi is the low 5 bits. 

The design value is N, then the initial value of the count is X=2^13-N; 2^13=8192=2000H 

Example 1: Assume fosc=6MHz, and use T1 mode 0 for 10ms. Find the initial values ​​of TH1 and TL1. 

The design initial value is X; from the known conditions: 1 machine cycle=12/fosc=2us; 

10,000us=12/fosc*(2^13-X)us 

X=2^13-10000/2=8192-5000=3192=0C78H 

So: TL1=18H, TH1=63H 

2. Mode 1 

When bit M1M0=01. T is a 16-bit counter, THi is the high 8 bits, and TLi is the low 8 bits. 

If the design value is N, then the initial value of the count is X=2^16-N; 2^16==65536=10000H 

Example 2: Assume fosc=6MHz, and use T1 mode 1 for 100ms. Find the initial values ​​of TH1 and TL1. 

The initial value of the design number is X; from the known conditions, we get: 1 machine cycle=12/fosc=2us; 

100,000us=12/fosc*(2^16-X)us 

X=2^16-100000/2=65536-50000=15536=3CB0H. 

We get: TH1=3CH, TL1=0B0H 

3. Mode 2 

When bit M1M0=10. T is an 8-bit counter that automatically reloads the initial value. The count is in TLi. When TL overflows, not only TF=1, but also the value in TH is automatically sent to TL, and the value of TH remains unchanged. 

If the design value is N, then the initial value of the count is X=2^8-N; 2^8=256=100H. 

Example 3: If fosc=6MHz, and it is required to use T1 mode 2 for 500us, find the initial values ​​of TH1 and TL1. 

The initial value of the design number is X; from the known conditions, we get: 1 machine cycle = 12/fosc=2us; 

500us=12/fosc*(2^8-X)us 

X=2^8-500/2=256-250=6, 

so: TH1=6H, TL1=6H, in fact, just assign an initial value to TH. 

4. Mode 3 

When bit M1M0=11. Only T0 has mode 3. If T1 is set to mode 3, it will stop working. 

When T0 is in mode 3, TH0 and TL0 become two independent 8-bit counters; TL0 uses T0's control resources: GATE, C//T, TR0, TF0, /INT0 pin, etc., and can be used as an 8-bit timer/counter, while TH0 occupies T1's TR1 and TF1, and is a fixed 8-bit timer. At this time, T1 is controlled by the mode bit, mode 3 stops, and modes 0~2 are allowed to work, but TF1 is not set to 1 when the count overflows, that is, an interrupt request cannot be generated. In this case, T1 is generally used as a baud rate generator for the serial port.

Keywords:mcs-51 Reference address:Four working modes and functions of T0 and T1 of mcs-51 single chip microcomputer and calculation of timing initial value

Previous article:Write a single-chip counter program to count pulses
Next article:89C51 MCU timer/counter, P1 port programming example

Recommended ReadingLatest update time:2024-11-15 07:12

General description of MCS-51 program control instructions
Program control instructions are divided into three categories: "unconditional transfer", "call and return" and "conditional transfer". For program control instructions, you should understand: how the transfer address is generated and its transfer range. Note! The use of MCS-51 conditional branch instructions has
[Microcontroller]
The structure and working principle of MCS-51 microcontroller
1. Basic composition of MCS-51 microcontroller There are many kinds of MCS-51 single-chip microcomputer chips, such as 8051, 8031, 8751, 80c51, 80c31, etc. It consists of a central processing unit (CPU), clock circuit, program memory (ROM/EPROM), data memory (RAM), parallel I/O port (P0~P3), serial port, timer/cou
[Microcontroller]
The structure and working principle of MCS-51 microcontroller
MCS-51 microcontroller interrupt system (1)
When the CPU exchanges information with peripherals, there is a contradiction between a fast CPU and a slow peripheral. To solve this problem, the concept of interruption was developed.       A single-chip microcomputer can only process one task at a time. When multiple tasks require the single-chip microcomputer to p
[Microcontroller]
MCS-51 interrupt response process
MCS-51 interrupt response process:  1. Interrupt response conditions: At this point, we still feel magical about the computer's response to interrupts. We humans can respond to external events because we have multiple "sensors" - eyes and ears that can receive different information. How do computers do this? In fact,
[Microcontroller]
Writing a clock program using a timer based on the MCS-51 microcontroller (assembly)
1. Think carefully about the good idea Writing a clock program using a timer is a headache. Put aside other fancy functions and start with the most basic time display. The rest can be dealt with later. What we generally hope is that the clock can keep timing, call the display to show the current time when needed, an
[Microcontroller]
Writing a clock program using a timer based on the MCS-51 microcontroller (assembly)
Try to write a MCS-51 microcontroller program to calculate ∑i, I=1~100
Try to write a MCS-51 microcontroller program to calculate ∑i, I=1~100.  Reference microcontroller assembly language program:        org 000h        ljmp main        org 030h  main: mov 45h,#011h         mov 46h,#022h         mov 47h,#033h         mov 48h,#044h          mov 49h,#00h         mov r0,#45h         m
[Microcontroller]
Brief Introduction to MCS-51 MCU External Interrupt Software Programming
Introduction: MCS-51 microcontroller has multiple interrupt sources. Taking 8051 as an example, there are 5 interrupt sources, two external interrupts, two timing interrupts and one serial interrupt. In this section, we discuss external interrupt software programming. External interrupt is an interrupt caused by exter
[Microcontroller]
Brief Introduction to MCS-51 MCU External Interrupt Software Programming
Introduction to the pin functions of MCS-51 microcontroller
  40-pin dual in-line package (DIP). The 40 pins are divided into 3 categories according to their functions: (1) Power supply and clock pins: Vcc, Vss; XTAL1, XTAL2. (2) Control pins: PSEN*, EA*, ALE, RESET (i.e. RST). (3) I/O port pins: P0, P1, P2, P3, which are the external pins of 4 8-bit I/O ports. 2.
[Microcontroller]
Introduction to the pin functions of MCS-51 microcontroller
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号