HOME / Technology / The MCU composition

The MCU composition

What is the most critical part of the MCU to automate the calculation?
We use the plan disk as an example to calculate an arithmetic problem. Example: 36+163×156-166÷34. Now to perform the calculation, you first need an abacus, followed by paper and pen. We record the problem to calculate; then the first step is to figure 163 × 156, the result of adding it to 36 records on the paper, then calculate 166 ÷ 34, and then subtract it from the previous result, then Get the final result.

Now, we use the MCU to complete the above process. It must first have the part that replaces the abacus for calculation. This is the “operator”. Secondly, there must be a device that can play the role of paper and pen; that is, the original title can memorise. Raw data and intermediate results, but also to remember the various commands that enable the microcontroller to perform operations automatically. Such devices referred to as “memory.” Also, there is a need for a controller that can replace human action, which can issue various control signals according to a given command, so that the entire calculation process can perform step by step. However, it is not enough to have these three parts. The original data and commands should be input, and the results of the calculations must be output. They need to be performed in order, sometimes waiting. In the above example, when calculating 163 × 156, the number 36 cannot enter the operator at the same time. Therefore, it is necessary to set a “gate” for the action of the controller on the microcontroller, and when the operator needs it, let the new data entry. Or, when the operator gets the final result, the result is output, and the intermediate result cannot “slip out” the microcontroller. Such a “gate” circuit that manages input and output data in a certain way is called a “port” in a single chip microcomputer. In a single-chip microcomputer, basically three types of information are flowing, one type is data, that is, various raw data (such as 36, 163 in the above example), intermediate results (such as quotient 4 of 166÷34, remainder 30, etc.), Programs (collections of commands), etc. In this way, the external device enters the MCU through the “port” and stores it in the memory. During the operation process, the data is read from memory into the arithmetic unit for calculation, and the intermediate result of the operation store in mind. Or finally, the operator outputs through the “gateway”. The various commands (programs) that the user wants to execute by the microcontroller are also sent to the controller by the memory in the form of data. After the controller interprets (decodes), it becomes various control signals to perform such as addition, subtraction, multiplication, and In addition to multiple commands for functions. Therefore, this kind of information is called a control command, that is, the controller controls the arithmetic unit to perform operations and processing step by step, and controls the reading (removing data) and writing (storing data) of the memory. The third type of information is address information, which is used to tell the operator and controller where to fetch the command to bring data, where to store the result, and which port to input and output information.

The memory divided into two types: a read-only memory and a read-write memory. The former stores fixed and fixed programs and constants, and the latter stores’ data that may change at any time. As the name implies, once the read-only memory is stored, it can only be read and cannot change (EPROM, E2PROM, etc. ROM can be replaced and written in a certain way – editor’s note). The read and write memory can store or read data at any time.

People often combine the operator and controller into a central processing unit – the CPU. In addition to the calculation, the MCU also needs to complete the control function. So it is inseparable from counting and timing. Therefore, a timer and a counter provided in the single chip microcomputer, and the basic structure thereof is similar to the example in (2) of the serial. So far, we already know the basic composition of the microcontroller. That is, the microcontroller is composed of a central processing unit (i.e., an arithmetic unit and controller in the CPU). A read-only memory (usually represented as a ROM), and a read-write memory ( Also known as random memory is generally expressed as RAM), input/output port (also divided into the parallel port and serial port, revealed as I / O port) and so on. There is a clock circuit inside the MCU so that the MCU can perform rhythmically when performing calculation and control. Also, there is a so-called “interruption system”. This system has the function of “communication room”. When the parameters of the control object of the single-chip computer reach a state that needs to interfere, the system can be notified to the CPU through the “communication room”. The CPU takes appropriate countermeasures based on the priorities of the external events.

MCU instruction system and assembly language program

The main components of the MCU have been described above, and these parts constitute the hardware of the MCU. The so-called equipment (Hardware) is the entity that can be seen and touched. However, with such a device, there is only the possibility of implementing computing and control functions. To be able to perform calculations and control, the MCU must also have software (Software). The software mainly refers to various programs. It works only if the right program is “filled in” (stored) into the microcontroller. Therefore, the MCU can automatically perform calculation and control. It is precisely because people implement the steps of calculation and control step by step in the form of commands, that is, an instruction (Instruction) is pre-stored in the memory, and the CPU controls the MCU. Next, the instructions are taken out one by one and translated and executed. In the simple operation of adding two numbers, when the number of services required has a store in the memory, the following steps are required:
The first step: take the first number from its storage location (Location) and send it to the operator.
The second step: taking the second number from the storage unit in which is located, and sending it to the computing unit;
The third step: adding;
Step 4: Send the result of the addition to the specified.
All of these numbers, numbers, additions, registers, etc. are all operations. We write down the various services that require the computer to execute in the form of commands. But how can you identify and perform these operations? By the instruction system assigned to it by the designer when designing the microcontroller. An instruction corresponds to basic service; all the instructions that can be executed by the MCU are the instruction system of the MCU (Instruction Set), and the instruction systems of different types of MCU are different.
When using a MCU, the problem to be solved should compile into a series of instructions in advance. These instructions must be instructions that the selected microcontroller can recognise and execute. The instruction program organised by the MCU user to solve their problems is called the Source Program. Instructions usually divided into two parts: opcode (Opcode) and operand (Operand). The opcode indicates what operation the computer performs, that is, the function of the instruction; the operand suggests the address of the participating service or the address of the operand (i.e., the place number where the operand is stored). Because the microcontroller is a programmable device, it only “recognises” the binary code (0, 1). all instructions in the microcontroller system must represent in binary code. For example, in Intel’s MCS-51 series MCU.the instruction code of the accumulator from the memory to the CPU (in the operator, the unique register that participates in the operation and stores the operation result) is 74H, accumulating The code of the device content plus immediate is 24H, plus the quick code, the system that the accumulator sends to the internal RAM is F6H~F7H. These instructions are binary coded machine code in hexadecimal. The word length of the MCS-51 MCU is 8 bits. Sometimes, it is not enough to use a byte to complete some operations. Therefore, there are single-byte instructions and multi-byte instructions in the instruction system.
The machine code consists of a series of 0s and 1s. It has no apparent features, is not easy to remember, is difficult to understand, and is prone to errors. Therefore, it is challenging to use it directly to write programs. Therefore, people use some mnemonics (Mue monic) – usually the English abbreviation of the instruction function instead of the opcode, such as the MCS-51 medium transfer commonly used MOV (Move abbreviation), addition with Add (Addition abbreviation ) as a mnemonic. In this way, each instruction has distinct motion characteristics, is easy to remember and understand, and is not prone to error. A program written with a mnemonic is called an assembly language program. However, the program written by the mnemonic is easy for people to understand, but the single-chip microcomputer only knows the binary machine code. Therefore, for the single-chip microcomputer to “read” the assembly language program, it must be converted into an application composed of binary machine code. It is called “assembly”. The assembly can be done using a manual look-up table, or using a PC via a so-called “cross-assembler”. Once the user program consisting of machine code “enters” the microcontroller and then “starts” the microcontroller, it can execute the tasks specified by the input program.

MCU–51 CPU and memory

The CPU of the single chip microcomputer 8051 is composed of an arithmetic unit and a controller.

First, the operator
The operator centre on the binary arithmetic/logical operation unit ALU, plus the register TMP, the accumulator ACC, the register B, the program status flag register PSW, and the Boolean processor. The accumulator ACC is an eight-bit register that is the most frequently used register in the CPU. When performing arithmetic and logic operations, the accumulator ACC tends to temporarily store an operand (such as an addend) before the process, and then save the result (such as algebraic sum). Register B mainly use for multiplication and division operations. The flag register PSW is also an eight-bit register that is used to store some characteristics of the operation result, such as whether there is carry or borrow. The specific meaning of each of them is as follows. PSW CY AC FO RS1 RS0 OV – P For the user, the most concerned is the following four.
1 Carry flag CY (PSW7). It indicates whether the operation has a carry (or borrow). This bit is one if the result of the service has a carry (addition) or a borrow (subtraction) at the highest bit, otherwise 0.
2 The auxiliary carry flag AC. Also known as the semi-carry flag, it reflects whether the lower four bits of the two octet operations have a semi-carry, that is, the lower four bits add (or subtract) whether there is a carry (or borrow) if any, AC is one state, Otherwise 0.
3 Overflow flag OV. MCS-51 reflects whether the operation result of the signed number has overflowed. When there is overflow, this bit is 1. Otherwise, it is 0.
Four parity flag P. Reflects the parity of the accumulator ACC content. If the result of the operation in the ACC has an even number of 1s (such as 11001100B, where there are four 1s), then P is 0, otherwise, P=1.
Other bits of the PSW will introduce later. Since the PSW stores the state in the execution of the program, it is also called the program status word. The arithmetic unit also has a logical processor (also called a Boolean processor) that performs logical operations by bits. Its function will explain when introducing the bit instruction.

Second, the controller.

The controller is the nerve centre of the CPU and includes a timing control logic circuit, an instruction register, a decoder, an address pointer DPTR and a program counter PC, a stack pointer SP, and the like. Here, the program counter PC is a counter composed of 16-bit registers. For a microcontroller to execute a program, the program must preload into an area of ​​the memory ROM in order. When the MCU is operating, it should complete by taking out the instructions in sequence. Therefore, there must be a circuit that can find the address of the unit where the direction located. This circuit is the program counter PC. When the microcontroller starts executing the program, the PC loaded with the address of the first instruction. Each time an instruction is fetched (for example, for a multi-byte instruction, each instruction byte is fetched), the content of the PC is automatically incremented by 1 to point to The address of the next instruction so that the instructions can execute sequentially. Only when the program encounters a branch instruction, a subroutine call instruction, or an interrupt (described later), the PC goes to where it is needed. 8051 CPUC specified address, the instruction byte is taken from the corresponding unit of the ROM and placed in the instruction register. Then, the instruction code in the instruction register is translated into various forms of control signals by the decoder. These signals combine with the microcontroller clock. The clock pulse generated by the oscillator is combined with the timing and control circuit to form a level and a watch that changes in a certain period, that is, so-called control information, and coordinates data transfer, calculation, and the like between the registers in the CPU.

Third, the memory

Memory is another vital component of the microcontroller. Figure 6 shows a memory structure with a storage capacity of 256 units. Each of the storage units corresponds to an address, and 256 units have a total of 256 addresses, represented by two hexadecimal numbers, that is, the address of the memory (00H to FFH). Each memory location in mind can store eight-bit binary information, usually represented by two hexadecimal numbers, which is the contents of the memory. The storage unit address of the memory and the contents of the storage unit are two different concepts and cannot be confused.

A program is a series of commands that control the motion of a computer. The microcontroller only recognises machine instructions consisting of “0” and “1” codes. The commands MOV A, #20H, written in the mnemonic as mentioned above, are replaced by the machine-recognised laws 74H, 20H: (written as binaries are 01110100B and 00100000B). Before the MCU processes the problem, the programmed program, table, and constant must be assembled into the machine code and stored in the memory of the MCU. The mind is called the program memory. The program memory can place on-chip or off-chip, or it can be set on-chip simultaneously. Since the PC program counter is 16 bits, the program memory can use with a 16-bit binary address to the addresses of the internal and external memories can be up to 0000H to FFFFH. The 8051 has 4k bytes of ROM inside, which occupies the lowest 4k bytes from 0000H to 0FFFH. At this time, the program memory address number of the off-chip expansion should start from 1000H. If the 8051 is used as 8031, you do not want to use the on-chip 4kROM. , all use off-chip memory, the address number can still start from 0000H. However, at this time, the {31} pin of the 8051 (i.e., the EA pin) should be kept low. When EA is high, the user uses the internal ROM in the range of 0000H to 0FFFH. After greater than 0FFFH, the microcontroller CPU automatically accesses the external