MCS-51 MCU Timing

Publisher:美好回忆Latest update time:2013-01-24 Source: 21IC Keywords:MCS-51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Timing: MCU timing refers to the time sequence of control signals that should be issued when the MCU executes instructions. The temporal relationship between these control signals is the CPU timing. It is a series of pulse signals with a time sequence.

There are two types of timings issued by the CPU: one is used to control the functional components within the chip, which is the concern of chip designers and has little meaning to users. The other is used to control off-chip memory or I/O ports, which need to be sent to the outside of the chip through the control pins of the device. This part of the timing is crucial to analyzing the principles of hardware circuits and is also the principle followed by software programming, which needs to be carefully mastered.

Extended reading: What is the timing of a microcontroller?

2. Clock cycle, machine cycle and instruction cycle

1. Clock cycle: also known as oscillation cycle. Refers to the oscillation source cycle that provides timing signals for the microcontroller. It is the smallest timing unit.

The higher the frequency of the oscillation source, the faster the microcontroller operates.

The clock cycle is divided into two beats, P1 and P2. In the first half of each clock cycle, the P1 signal is valid, and the CPU usually completes arithmetic and logical operations at this time; in the second half of each clock cycle, the P2 signal is valid, and data between internal registers generally occurs in this state.

2. Machine cycle: It is defined as the time required to achieve a specific function. Machine cycles are named according to their functions, such as instruction fetch machine cycle, etc.

The machine cycle time of MCS-51 is constant, which is 12 crystal oscillator cycles or 6 state cycles. It is divided into S1P1, SIP2; S2P1, S2P2; etc.

3. Instruction cycle: the time to execute one instruction.

According to the execution time of instructions, it can be divided into: single cycle, double cycle and four cycles (there are only two instructions, multiplication and division).

Clock cycle, machine cycle and instruction cycle are all timing units of single-chip microcomputer. Machine cycle is the basic timing unit for single-chip microcomputer to calculate other time values ​​(such as baud rate, timer timing, etc.).

If the external crystal oscillator of MCS-51 is 12MHz, then:

Clock period = = =0.167us;

Machine cycle = = =1us;

Instruction cycle = (1~4) = (1~4) = 1~4us.

Example: If the microcontroller clock frequency is 12MHz, calculate the timer initial value required for a 2ms timing. (Assume the timer works in mode 1, that is, the modulus is 2.jpg)

Analysis: MCS-51 has two 8-bit counters. Each time a machine cycle comes, the counter increases by 1. When the counter increases from 0FFFFH to 0000H, the timer automatically generates an overflow request. Therefore, the maximum timing time of mode 1 is Tmax= 2.jpg×T0, where T0 is the time of a machine cycle. Since the frequency of the clock cycle is 12MHz, here 1.jpg.

Tmax= 2.jpg×T0=65536×1us=65.536ms.

Now we need to generate a 2ms timing time, so we must put a certain initial value x in the counter in advance, so that:

(216-x)T0=2ms.

untie:1.jpg

( 2.jpg-x)T0=2ms=2×10-3s

X= 2.jpg- =216-2×103=63536=F830H.

Note:

How to quickly convert decimal numbers, binary numbers, and hexadecimal numbers

1. If the decimal number is less than 256, divide this number by 16 to get the quotient and remainder. If the decimal quotient is written in binary form, it is the upper 4 bits of the binary. If the decimal remainder is written in binary form, it is the lower 4 bits of the binary. Together, it is the converted 8-bit binary number. Similarly, if the decimal quotient is written in hexadecimal form, it is the hexadecimal representation of the upper 4 bits of the binary, and if the decimal remainder is written in hexadecimal form, it is the hexadecimal representation of the lower 4 bits of the binary, and together they are the converted hexadecimal representation.

2. If the decimal number is greater than 256 and less than 65536, divide this number by 256 to get the quotient and remainder, and then divide the quotient and remainder by 16 respectively. After the quotient is divided by 16, the quotient and remainder are obtained again. This quotient and remainder are in decimal form. When written in hexadecimal, they are the hexadecimal form of the upper 4 bits of the upper 8 bits and the lower 4 bits of the upper 8 bits. Dividing the remainder by 16 also gives the quotient and remainder. This quotient and remainder are also in decimal form. When written in hexadecimal, they are the hexadecimal form of the upper 4 bits of the lower 8 bits and the lower 4 bits of the lower 8 bits.

Example: Find the binary and hexadecimal versions of the following decimal numbers.

(1)212; (2)65365

Solution: (1)

212/16=13……4

If 13 is written as D in hexadecimal, and 4 is written as 4 in hexadecimal, then the hexadecimal number is:

212=D4(H)

If 13 is written as binary, it is 1101, and 4 is written as binary, it is 0100, then converted into binary:

212=11010100(B).

(2)

65365/256=255……85

(The quotient divided by 16 is the high 8 bits, and the remainder divided by 16 is the low 8 bits)

255/16=15……15

(The quotient is the high 4 bits of the high 8 bits, and the remainder is the low 4 bits of the high 8 bits)

Write the quotient 15 in hexadecimal as F, and write the remainder 15 in hexadecimal as F, so the hexadecimal of the upper 8 bits is: FFH;

85/16=5……5

(The quotient is the high 4 bits of the low 8 bits, and the remainder is the low 4 bits of the low 8 bits)

The quotient 5 is written as hexadecimal 5, and the remainder 5 is written as hexadecimal 5, so the hexadecimal of the lower 8 bits is: 55F.

The high 8 bits and the low 8 bits together are the hexadecimal form of this decimal number:

65365=FF55(H).

Converted to binary: 65365=FF55(H)=111111111010101010(B).

Keywords:MCS-51 Reference address:MCS-51 MCU Timing

Previous article:Design of a practical eight-channel level measuring instrument based on 89C52 single chip microcomputer
Next article:How to use 51 single chip microcomputer related software and experimental board

Recommended ReadingLatest update time:2024-11-16 14:40

What you should know about the timer/counter of MCS-51 microcontroller
1. If the frequency of the crystal oscillator used is 3MHz, and the timer/counter works in mode 0, 1, or 2, what are the maximum timing times? 2. When a timer/counter is used as a timer, who provides its counting pulses? What factors are related to the timing time? 3.When the timer/counter is used in counter mode,
[Microcontroller]
Accessing the I/O Port of MCS-51 Single Chip Computer
MCS-51 microcontrollers usually have four 8-bit I/O ports. The data written to each port is written into the latch of the corresponding port, but there are two ways to read each port: read the latch and read the pin. 1 Read-Modify-Write Operation Pn (referring to P0, P1, P2, P3) is a special identifier in 5
[Microcontroller]
Accessing the I/O Port of MCS-51 Single Chip Computer
MCS-51 single-chip computer instruction system "read-modify-write" mode instructions
The 51 MCU has four 8-bit parallel interfaces. Due to the characteristics of the internal structure, the parallel interface has different capabilities when outputting 0 and 1. When outputting 0, the capability is strong, but when outputting 1, the capability is very poor. For the P0 port, an external pull-up resistor
[Microcontroller]
MCS-51 MCU I2C Simulation Software Package
Note: The machine cycle of a common M51 microcontroller = 12 clock cycles, and the machine cycle of f020 = clock cycle For nop instructions, F020 is a clock cycle. For example, the f020 crystal is 22.1184M, which is about 45ns.   /*The function uses software delay to generate SCL pulses, so some modifications m
[Microcontroller]
MCS-51 MCU I2C Simulation Software Package
What is a stack? How to set up the stack of MCS-51 microcontroller?
When programming, a last-in-first-out RAM area is often needed to save the CPU scene. This last-in-first-out buffer is called a stack. In principle, the stack of the MCS-51 microcontroller is located in any area of ​​the internal RAM, but it is usually located between 31H and 7FH, and the top of the stack is pointed
[Microcontroller]
Design and implementation of frequency measurement based on MCS-51 series single chip microcomputer
    There are many methods for measuring the frequency of periodic waves, but most of them are to calculate the frequency indirectly through measurement. This article introduces the use of the widely used MCS-51 series single-chip microcomputer to measure the frequency of periodic waves, and uses LED to intuitively di
[Microcontroller]
Design and implementation of frequency measurement based on MCS-51 series single chip microcomputer
In-depth Study on Soft Reset of MCS-51 System
introduction Reset is the initialization operation of the microcontroller. Its function is to put the microcontroller and other components in the system into a certain initial state and start working from this state. The reset logic of the standard MCS-51 is relatively simple, and can only be expanded ex
[Microcontroller]
In-depth Study on Soft Reset of MCS-51 System
MCS-51 MCU Practical Subroutine Library 7
25) Label: FTOD Function: Converts a floating point number into a double-byte fixed point number Entry condition: Formatted floating-point operand in . Exit information: OV=1 overflow, OV=0 conversion success: The absolute value of the fixed-point number is in (double byte), the sign is in bit 1FH, F0=1 is an inte
[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号