## 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, add it to 36 records on the article, calculate 166 ÷ 34, and then subtract it from the previous work 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, a device can play the role of paper and pen; that is, the original title can memorize. Raw data and intermediate results and remember the various commands that enable the microcontroller to perform operations automatically. Such devices are 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 simultaneously. Therefore, it is necessary to set a “gate” for the controller’s action on the microcontroller, and when the operator needs it, let the new data entry. When the operator gets the final result, the result is output, and the intermediate product cannot “slip out” the microcontroller. 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 operation store’s intermediate result in mind. Or finally, the operator outputs through the “gateway.” After the controller interprets (decodes), it becomes various control signals to perform, such as addition, subtraction, multiplication, and 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, directs the reading (removing data), and writes (storing data) memory. The third type of information addresses 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 is 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 are provided in the MCU, and the basic structure thereof is similar to the example in (2) of the serial. So far, we already know the elemental composition of the microcontroller. 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 when performing calculations and control. Also, there is a so-called “interruption system.” This system has the function of a “communication room.” When the parameters of the control object of the single-chip computer reach a state that needs to interfere, What can notify the system 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 calculations and control. 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 stored 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 it is located and sending it to the computing unit;
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? An instruction corresponds to basic service; all the instructions that the MCU can execute are the instruction system of the MCU (Instruction Set), and the instruction systems of different types of MCU are other.
When using an 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 recognize and execute. The instruction program organized by the MCU user to solve their problems is called the Source Program. Instructions are usually divided into two parts: opcode (Opcode) and operand (Operand). The opcode indicates what operation the computer performs: 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 “recognizes” the binary code (0, 1). all instructions in the microcontroller system must represent 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 individual 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 mnemonic program 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, What must convert it into an application composed of binary machine code 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 MCU 8051 is composed of an arithmetic unit and a controller.
First, the operator
The operator center 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 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 of the service results with a carry (addition) or a borrow (subtraction) at the highest bit, otherwise 0.
2 The auxiliary carry flag AC. The semi-carry flag also 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 ACC’s operation has an even number of 1s (such as 11001100B, where there are four 1s), P is 0; otherwise, P=1.
Other bits of the PSW will introduce later. Since the PSW stores the state in the program’s execution, 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.
The second controller.
The controller is the nerve center 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 the memory ROM area 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 unit’s address where the direction is located. This circuit is the program counter PC. When the microcontroller starts executing the program, the PC is loaded with the first instruction address. Each time an instruction is fetched (for example, for a multi-byte instruction, each instruction byte is fetched), the PC’s content is automatically incremented by 1 to point to The address of the next instruction so that the instructions can execute sequentially. 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. The instruction code in the instruction register is then translated into various forms of control signals by the decoder. These signals combine with the microcontroller clock. The oscillator’s clock pulse 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 companies have a total of 256 lessons, 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 are the memory contents. The storage unit address of the memory and the storage unit’s contents 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 recognizes machine instructions consisting of “0” and “1” codes. The commands MOV A, #20H, written in the mnemonic mentioned above, are replaced by the machine-recognized 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 MCU’s memory. The mind is called the program memory. The program memory can place on-chip or off-chip, or What can set it on-chip simultaneously. Since the PC program counter is 16 bits, the program memory can use a 16-bit binary address to address 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.