The single machine, also called a single microcontroller, is not a chip that completes a logical function, but integrates a computer system into a chip. The equivalent of a mini-computer, as compared to computers, is only missing i/o equipment on a single machine. In summary: a chip becomes a computer. It is small, of light quality, cheap and facilitates learning, application and development. At the same time, learning to use a single machine is the best option to understand computer principles and structures。
The use of single-piece machines has become extensive, such as smart instrumentation, real-time engineering control, communication equipment, navigation systems, household appliances, etc. Once a single machine is used, products can be used to upgrade, often with the adjective — “smart”, such as an intelligent washing machine — in front of the product name
Thumbnail of single-piece cycle relationships

1. Clock cycle
Clock cycle: the oscillation cycle, which is the countdown of the crystal oscillation of the external single machine, e. G., a 4mhz crystal vibration, which is 0. 25us (1/4 mhz)
In a clock cycle, the cpu completes a minimum action. So it's the smallest, most basic unit of time in the computer。
The mcs-51 clock cycle is also called the oscillation cycle and the oscillation cycle, which is the basic time unit of a single machine. An oscillation cycle is defined as a beat (in p) and two beats as a state cycle。
The cycle of a single clock signal (expressed in s) generated by the pulse of the oscillator following the split frequency of the clock circuit is referred to as the state cycle. Thus, a state cycle s consists of two beats, the previous one-hour cycle being called the p1 beat and the subsequent one-hour cycle being called the p2。
Tosc = (1/fosc) for the oscillation of the clock. For a crystal vibration frequency of 12 mhz, the oscillation cycle tosc = (1/12us)。
2. Status cycle
In 8051, the status cycle consists of two clock cycles; one clock cycle is referred to as a beat (p) and two clock cycles as a state cycle (s). It's twice the clock cycle。
3. Machine cycle
In computers, in order to facilitate management, the process of implementing a directive is often divided into several stages, each of which completes a task. For example, the taking of instructions, memory reading, memory writing, etc., each task is called a basic operation. The time required to complete a basic operation is called the machine cycle. In general, a machine cycle consists of several s cycles (state cycles)。
The 8051 series single machine consists of one machine cycle with six s cycles (state cycle). As mentioned earlier, a clock cycle is defined as a beat (in p), two beats are defined as a state cycle (in s), and the machine cycle of the 8051 single machine consists of six status cycles, i. E. A machine cycle = 6 states = 12 clock cycles. Calculates the clock cycle x cycles. If the single machine is a 12-cycle, then the machine cycle is tx12. Assuming a crystal vibration frequency of 12m and a single machine of 12 cycles, the machine cycle is 1us。
For example, a single machine with 24m crystal vibrating, one of his machine cycles = 12/24m seconds; a single machine cycle of the 52 series equals 12 clock cycles. The 52-piece machine is a 12-t single-formulator, i. E., a frequency of 12 minutes, at a crystal-fibration frequency of 12 mhz. 12m is converted from frequency to frequency from t=1/f, i. E. A machine cycle to 1us。
4. Command cycle
It is defined as the time required to implement an instruction. Usually, instructions containing a machine cycle are called single-cycle instructions, such as the mov, clr, etc. Commands containing two machine cycles are called double-cycle commands. There are also four-cycle directives。

The most reliable is to check the form. I found a summary online of a pattern that should be judged in order, with the former principle taking precedence over the latter (predominantly 2 to 6) and checking sequentially which is satisfied, which falls into which category:
1, mul, div: 4-cycle directive only
2. Directives containing dptr and pc are two-year
3. All absolute jump and condition transfer instructions are two-year
4. All instructions, including the a register, are single-cycle
Anl and orl are the 2nd-cycle commands for 5-bit operational instructions
6. All instructions with immediate address are 2-cycle except inc direct and dec direct
7. All remaining are single-cycle directives。
Timer works. System clocks
System clock: the system clock is the frequency that cpu commands run, and this is the real frequency of the cpu。
All the work within a single machine is based on the same trigger signal source generated by the crystallization that synchronizes the coordinated steps. We refer to this signal as a system clock, which is typically generated by a crystallized clock, but the clock does not necessarily equal a crystallized frequency, may be smaller than a crystallized frequency, and may be greater than a crystallized frequency, depending on how much is determined by the unit's internal structure, the normal situation and the crystallized frequency will have an integer relationship. The system time range is the benchmark for the working rhythm of the entire single machine, which is activated once in every time it oscillates。

Generally, single machines have only one clock. External crystal shocks are used, not internal rcs, not external crystal shocks. The oscillator oscillates and produces periodic waves. The frequency of a single wave plays a regular one-time job, the faster it works, the slower it works。
With the above concepts in mind, it is possible to understand correctly the work of the timer, which in 8051f310 units has three timers. If the timer 1 works under mode 1, such as working mode 1, is a 16-bit timer with a maximum value of 65535, and when added at one time (= 65536), there will be a spill and a break, so if we want it to count 1,000, then the time limit is 65536-1000, with the result being 64536, which is given to th, tl, because it is 16, so that the height is 645536/256 and the lower is 6456。
Besides, how long is every count? When we usually take the 12m, one cycle is just 1us, counting 1,000 units is 1 ms, because the standard 51 unit is 12-hour cycle (stc has 6-hour and 1-hour methods). Well, if we're 12m, it's better to count. If it's something else, we'll take it out. For example, it's 6m, and then 12/6 = 2, and each count is 2us, so you have to count 1 ms for just 500。
The starting value of the timer is related to the mode of work of the timer and to the frequency of the crystal. A machine cycle tcy = crystal oscillation frequency x12, count n = fixed time t/ machine cycle tcy, then the opening value is x = 65536-n, and the resulting number is only hexadecimal. Here's an example of how timer o works, which, if it's another way of working, can't be 65535. Working mode 0 is 8192, mode 2, 3 is 256. Here's a formula:
Th = (65536-time/(12/ft))/256
Of these, time is 100 ms (to take 100,000us) and ft is a crystallization frequency. This style can be simplified
Th = (65536-time*ft/12)/256
Tl = (65536-time*ft/12) %6
In one book, we also see this calculation of the time threshold:
Th0 = - (50235/256); // reload 100 ms at beginning of time
Tl0 = - (50235%6); // 6m crystal used here
Here's the 6m crystal, with a delay of 100 ms, so the principle is that 6m is 2us, 100 ms is counted at 50,000 times。
The primary value of the timer is then 65536-50000 = 15536, with 16 in 3cb0. This is the value to be given to th(=3c) and tl(=b0)。
Th0 =- (50235/256); it's actually this type of th0 = 0x100-(50235/256); in 51, the negative number, the result of which is its value-inverse +1, or it can be reduced by 0x100 (256 of the decimal). The result is 3c。




