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.
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:
AND gate circuit
The 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.
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.
Full adder:
A full adder can be formed from two half adders.
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.
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.
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:
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.
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.
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.
- Improved circuit diagram of 8050 transistor emitter drive relay
- Data transmission modulator/demodulator composed of SST8803 and UM3758-108A
- Computer USB port to mobile phone interface conversion circuit
- Interface circuit composed of 8255A and single chip microcomputer
- Using 89C2051 to make a four-way digital display water level controller circuit
- Sharing the process of making a single-chip integrated digital clock
- Use PC’s RS232 port to control LED lights
- Microcomputer motherboard reset part circuit diagram
- 3 IO scan 16 buttons
- Hard disk control circuit and original program
- Some notes on electronic design
- Reset circuit design of the smallest microcontroller system
- Dual audio decoding electronic circuit
- Design of infrared communication circuit based on single chip microcomputer
- Microcontroller control circuit
- Stepper motor drive circuit composed of LB1836M
- Negative voltage generation circuit diagram
- Microcontroller measurement circuit
- Optoelectronic interface circuit between single-channel DA chip DAC0832 and microcontroller
- Typical circuit for connecting MAX1101 and microcontroller