Home > Microcontroller > A little summary of the operating principles of single-chip microcomputer

A little summary of the operating principles of single-chip microcomputer

Source:互联网Publisher:宋元浩 Keywords: Microcontroller Updated: 2023/01/04

A single-chip microcomputer integrates a central processing unit (CPU), storage, input, writing and output on a chip. It can be said that a single-chip microcomputer is a microcomputer, but its functions are different compared with the computers we usually use. The computer used is so powerful.

The computer can run applications one by one, and the microcontroller can write executable files according to the engineers' instructions to achieve various functions. So, how does the microcontroller know what instructions to execute and what actions to take? How are our instructions recognized by the microcontroller? Understanding this process can deepen your understanding of microcontrollers.

First of all, let’s start with the composition of the CPU. The CPU is composed of transistors, which are semiconductor devices. If the diode is the most common semiconductor device. Current can only flow from the positive pole to the negative pole, and is blocked in the reverse direction.

diode

Transistors form gate circuits through various combinations: AND gate, OR gate, NOT gate, XOR gate... Gate circuits, also known as logic gates, are the basis of digital circuits. Common gate circuits and their truth tables:

truth table

AND gate circuit

7bb6e69e87a58b70a773d4c3ab5c5025.pngThe AND gate circuit can be imagined as two series switches controlling a light bulb. Only when both switches are closed at the same time will the light bulb be lit. The switch represents the on and off of the transistor, and the lighting and extinguishing of the light bulb represents the high and low levels of the circuit output.

Other gate circuits are also composed of various transistors. Different inputs and writes have different outputs, forming various functions. Various gate circuits become a CPU through complex combinations. Secondly, the CPU is used to complete various complex calculations.

Adder

With the CPU, we use it to calculate an arithmetic problem for primary school students, 1+1=2, to see how it is calculated. Starting from a simple adder, the adder consists of a half adder.

Half adder:

A half adder consists of an AND gate and an XOR gate. Regardless of the carry value from the low-order carry, there are only two inputs and two outputs.

half adder

1+1=2, 2 is represented as 0010 in binary. In the half adder: the XOR gate inputs and writes different levels (not high or low at the same time), the output is high, that is, 1+0 or 0+1, and the output is 1. When both inputs are written as 1, the output is 0, the output of the AND gate is 1, which is a carry. Be able to abstract it into a black box.

half adder

Full adder:

A full adder can be formed from two half adders.

full adder

When adding multiple digits, a half adder can be used to sum the lowest digits and give the carry number. The addition of the second bit has two numbers to be added (B and carry CO), and a carry number (A) sent from the previous low bit. Adding these three numbers gives us the radical sum (full sum) and the carry number. It can also be abstracted.

full adder

If you want to calculate the addition of multiple digits, you need multiple full adders and other gate circuits to combine into a more complex adder. The operation of subtraction can be broken down by addition:

Subtraction: 10 - 5 = 10 + (-5), which must be done through inversion, complement and other operations.

Other operators are also composed of related gate circuits, and the relevant knowledge will not be expanded here.

It is not difficult to conclude from the adder that the operation of the CPU is the input, writing and output of high and low levels of various gate circuits. The high level is 1 and the low level is 0. Our ordinary decimal numbers are converted into binary numbers for input and writing. , output binary number.

register

The addition of two numbers is done using a combination of full adders. What if it is the addition of multiple numbers? If 1+2+3+4+5+……+100, how to complete it?

Looking at this problem according to our calculation process, we first take out the first two numbers and add them, and then add the obtained sum to the third number, and then add it up to 100, and then convert it to the microcontroller to complete. Then we need to add all the The sum added is placed in a memory so that it can be retrieved during each addition, and the sum added each time is saved for use in the next addition. This is where registers are used.

Register-1 stores the numbers from 1 to 100, and register-2 stores the result of each addition. Calculate the addition of 1-100. The initial value of register-2 is 0. Take the numbers in register-1 and add the results of register-2 in sequence:

1+0=1,

2+1=3,

3+3=6,

4+6=10……

Latches:

But how do registers help us save data? This requires the help of a latch. Two NOR gates form the simplest latch.

save data

Latches

To put it simply, this unit remembers the previous input and write of 1 on the S terminal. It is not until we set the R terminal to 1 that the output terminal Q changes back to 0.

Secondly, adding a control terminal G and an input and write terminal D to this simple latch becomes a D latch:

D latch

It has two input and write terminals, one for signal control G, one for input and write data signal D, and one for output Q. Its function is to transfer the value of D to Q when G is valid, which is the latching process.

trigger:

Combining two D latches together becomes a D flip-flop (DATA flip-flop). A flip-flop, also called a bistable gate, is a digital logic circuit that can operate in two states. Flip-flops maintain their state until they receive an input write pulse, also known as triggering. Common flip-flops include: RS flip-flop, D flip-flop, JK flip-flop, etc., among which D flip-flop is the most commonly used.

trigger

When latch-1 controls G as a valid signal, the input and write of D is transmitted to the input and write of latch-2, but the control signal of latch-2 is not valid at this time, so latch-2 The output Q of latch-1 has not changed; when the control G of latch-1 becomes invalid and the control signal of latch-2 becomes valid, the output Q of latch-2 changes, which is the D of the flip-flop. The input and write is transmitted to Q, and D remains unchanged without input and write.

Sequential circuit:

Let’s take a look at the accumulation process from 1 to 100. If the storage speed of register-1 and register-2 are different, or the arithmetic unit’s access is not coordinated, that is, register-2 has not had time to store, or register-1 has not been taken out. If a number is involved in the operation, the operation will be wrong this time, and it will affect the next operation. This impact will be magnified to the subsequent results indefinitely, and the microcontroller also has many peripherals that need to run synchronously. At this time A unified command is needed to synchronize the actions of various departments, when to do what, and which step has been achieved.

sequential circuit

This conductor is the clock. The clock circuit generates a pulse signal to the circuit. It can be considered that when a pulse signal is given, each part of the microcontroller will move and the circuit will be refreshed. This achieves unified action. The front D latch and the G input and writing terminal of the D flip-flop are the clock pulse signal input and write, which controls the G input and write signal, thereby controlling the output of Q, or remembering the Q value. This is what memory originally looked like.

At this point, we know that a register is a sequential logic circuit, but this sequential logic circuit only includes storage circuits. The storage circuit of the register is composed of a latch or a flip-flop, which is used to temporarily store the data and operation results involved in the operation.

A latch or flip-flop can store 1-bit binary number, so N latches or flip-flops can form an N-bit register, generally 8-bit registers, 16-bit registers, etc. It is widely used in various digital systems and computers.

Run program

With the previous foreshadowing, let's try to analyze how the code is recognized by the microcontroller and converted into function output.

First, the engineer writes the code logic, and then compiles it into an executable program for the microcontroller. This executable program actually turns into a binary number composed of 0 and 1 arranged according to a certain rule, and then writes it into the microcontroller using a burner. .

The inside of the microcontroller is composed of various combinations of the gate circuits we learned earlier. The gate circuits are also composed of semiconductor devices. These semiconductor PN junctions are special fuses. Inside the blank microcontroller are fuses arranged in a matrix. During the burning process, the 0's in the program are blown and the 1's are turned on. After programming, the microcontroller has logic functions.

Program execution process: read program instructions from the program storage area - analyze the instructions - execute the instructions.

Reading instructions: fetching the corresponding instructions based on the address of the program calculator (PC) and sending them to the instruction register.

Analyze instructions: Take out the instruction opcode in the instruction register and decode it to analyze its instruction properties. If the instruction is to get the addend in our previous addition operation, find the address of the addend.

Execution of instructions: It is nothing more than converting a binary code into a digital signal (high and low levels), operating a logic gate circuit, and inputting and writing output just like our adder. Output the result of the logic gate operation and output the relevant pin level of the microcontroller high or low.

That is to say, when the microcontroller is powered on and turned on, the microcontroller is in the initial state. It can be considered that the program calculator (PC) has the first instruction address in the initial state. Under the action of the sequential circuit, it is sent to the instruction register, analyzes the instruction, executes the instruction, and outputs Function, cycle like this. The microcontroller automatically enters the execution process.

Of course, the process of running a single-chip microcomputer is very complicated. Here is just a brief personal understanding and summary.


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号