Instruction timing of MCS-51 microcontroller

Publisher:创意探险Latest update time:2012-11-03 Source: 21ic Keywords:MCS-51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Timing is described using timing units. MCS-51 has four timing units: beat, state, machine cycle, and instruction cycle. We will explain each of them below.

  • Beat and state:
    We define the period of the oscillation pulse as the beat (represented by P for the convenience of description). After the oscillation pulse is divided by two, we get the clock signal of the entire microcontroller working system. The period of the clock signal is defined as the state (represented by S). Such a state has two beats. The beat corresponding to the first half of the cycle is defined as 1 (P1), and the beat corresponding to the second half of the cycle is defined as 2 (P2).
  • Machine cycle:
    MCS-51 has a fixed machine cycle, which stipulates that a machine cycle has 6 states, represented by S1-S6, and one state contains two beats, so a machine cycle has 12 beats. We can remember S1P1, S1P2...S6P1, S6P2. A machine cycle contains a total of 12 oscillation pulses, that is, the machine cycle is 12-divided by the oscillation pulse. Obviously, if a clock frequency of 6MHz is used, a machine cycle is 2us, and if a clock frequency of 12MHz is used, a machine cycle is 1us.
  • Instruction cycle:
    The time required to execute an instruction is called the instruction cycle. MCS-51 instructions are single-byte, double-byte, and triple-byte, so their instruction cycles are not the same, that is, the machine cycles they require are different, and may include one to four machine cycles (we will explain these contents in the following chapters).

MCS-51 instruction timing:
In the MCS-51 instruction system, instructions can be divided into single-byte instructions, double-byte instructions and three-byte instructions according to their length. The time required to execute these instructions is different, that is, the machine cycles they require are different, and there are the following forms:

  • Single byte instruction single machine cycle
  • Single byte instruction double machine cycle
  • Two-byte instruction single machine cycle
  • Two-byte instruction, two machine cycles
  • Three-byte instruction double machine cycle
  • Single-byte instructions take four machine cycles (such as single-byte multiplication and division instructions)

The following figure is the instruction timing diagram of the MCS-51 series microcontroller:



The figure above shows the timing of single-cycle and double-cycle instruction fetch and execution. The ALE pulse in the figure is the selection signal for latching the address. Obviously, each time this signal appears, the microcontroller performs a read instruction operation. It can be seen from the timing diagram that this signal is obtained after the clock frequency is divided by 6. In one machine cycle, the ALE signal is valid twice, the first time during S1P2 and S2P1, and the second time during S4P2 and S5P1.
Next, we will explain several typical instruction timings.

  • Single-byte single-cycle instruction:
    A single-byte single-cycle instruction only performs one read instruction operation. When the second ALE signal is valid, PC does not increase by 1, so the original instruction is still read, which is an invalid read operation.
  • Double-byte single-cycle instructions:
    For this type of instruction, both ALE signals are valid, but when the first ALE signal is valid, the opcode is read, and when the second ALE signal is valid, the operand is read.
  • Single-byte two-cycle instruction:
    Two machine cycles require four read instruction operations, but only one read operation is valid, and the next three read operations are invalid operations.
    There is a special case for single-byte two-cycle instructions, such as MOVX. When executing such instructions, the instruction is first read from the ROM, and then the external data memory is read or written. The opcode of the first read instruction in the first machine cycle is valid, while the second read instruction operation is invalid. In the second instruction cycle, the external data memory is accessed. At this time, the ALE signal has no effect on its operation, that is, there will be no more read instruction operation.

In the timing diagram on the previous page, we only described the instruction reading status, but did not draw the instruction execution timing, because each instruction contains specific operands, and the types of operands are too diverse to list here. Interested readers can refer to relevant books. [page]

External program memory (ROM) read timing



Figure 8051 external program memory read timing diagram. It can be seen from the figure that P0 port provides the low 8-bit address and P2 port provides the high 8-bit address. Before the end of S2, the low 8-bit address on P0 port is valid. After that, the low 8-bit address signal appears on P0 port, but the instruction data signal. Of course, there is a buffer transition time between the address signal and the instruction data signal. This requires that the low 8-bit address signal must be latched during S2. At this time, the ALE selection pulse is used to control the latch to latch the low 8-bit address. The P2 port only outputs the address signal, but there is no instruction data signal. The address signal is valid throughout the machine cycle, so there is no need to latch this address signal. To read instructions
from the external program memory, two signals must be controlled. In addition to the above-mentioned ALE signal, there is also a PSEN (external ROM read selection pulse). It can be clearly seen from the above figure that PSEN is valid from S3P1 until the address signal is sent out and the data of the external program memory is read into the CPU. Then the second read instruction operation is executed from S4P2.

External data memory (RAM) read timing



The above figure shows the 8051 external data memory read and write timing diagram. The instructions to be executed are read from the ROM, and the CPU's access to the external data storage is to read or write data to the RAM, which belongs to the instruction execution cycle. It is worth mentioning that read or write are two different machine cycles, but their timing is similar. We only analyze the RAM read timing.
The previous machine cycle is the instruction fetch stage, which reads the instruction data from the ROM, and then the next cycle begins to read the contents of the external data memory RAM.
After S4 ends, the address to be read from the RAM is first placed on the bus, including the low 8-bit address A0-A7 on the P0 port and the high 8-bit address A8-A15 on the P2 port. When the RD strobe pulse is valid, the RAM data is read into the CPU through the P0 data bus. The ALE signal of the second machine cycle still appears, and an external ROM read operation is performed, but this time the read operation is an invalid operation.
When writing to the external RAM, the CPU outputs WR (write strobe signal) to write the data to the external memory through the P0 data bus.
Keywords:MCS-51 Reference address:Instruction timing of MCS-51 microcontroller

Previous article:Two methods of 51 single chip microcomputer output PWM
Next article:C8051F320 and its USB interface application

Recommended ReadingLatest update time:2024-11-16 15:58

Notes on assembly operators based on the MCS-51 kernel
Data transfer instructions: MOV accesses internal data storage MOVX accesses external data storage MOVC accesses ROM storage XCH Whole byte exchange XCHD Nibble swap (lower four bits) PUSH Set the contents pointed to by the stack pointer register SP (push the word onto the stack) POP pops the word out of the stack; SW
[Microcontroller]
Interrupt sources and interrupt vectors of mcs-51 microcontroller
1. External interrupt 0, 1; caused by the level signals of pins /INT0, /INT1 respectively.  2. Timer/ Counter 0, 1; caused by the overflow of T0, T1 respectively.  3. Serial port sending, receiving; caused by sending a byte or receiving a byte.  There are 5 interrupt sources in total.  4. Timer/Counter 2; caused b
[Microcontroller]
Design of data collection and information analysis system based on LabVIEW and MCS-51 microcontroller
1. LabVIEW part design 1.1VISA Introduction LabVIEW provides a powerful VISA library. VISA (Virtual Instrument Software Architecture) - virtual instrument software specification, is the general name for the standard I/O function library and related specifications used for instrument programming. The VISA library resid
[Test Measurement]
Design of data collection and information analysis system based on LabVIEW and MCS-51 microcontroller
Electrical Control Circuit Wiring Fault Diagnosis System Based on MCS-51 Single Chip Microcomputer
0 Introduction In the teaching of electrical control courses, regular training projects mainly include the installation, wiring and debugging of three-phase asynchronous motor inching control circuit, continuous operation control circuit, forward and reverse control circuit, forward start and reverse stop c
[Microcontroller]
Electrical Control Circuit Wiring Fault Diagnosis System Based on MCS-51 Single Chip Microcomputer
Timing watering circuit designed and made by single chip microcomputer
This timed watering device composed of the MCS-51 series single-chip microcomputer can water the flowers and plants on a regular basis, solving your worries when you go out. 1. Functions to be completed by the circuit The basic requirement for the circuit is to complete daily timed watering, taking into acc
[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号