集成电路设计,单片机方案
Your current location : Home>News>Company news

Contact Us

Wuxi Xijie Microelectronics Co., Ltd

Mobile:151 6157 6380

E-mail:cathy@xjmcu.com

Website: www.xjmcu.com

Address:Floor 9, building A1, No. 777, Jianzhu West Road, Binhu District, Wuxi City, Jiangsu Province


The CPU of single chip microcomputer scheme 8051 is composed of arithmetic unit and controller

2022-01-19

The CPU of single chip microcomputer scheme 8051 is composed of arithmetic unit and controller.

1、 Arithmetic unit

The arithmetic unit takes Alu as the core, which completes binary arithmetic / logic operation, plus register TMP, accumulator ACC, register B, program status flag register PSW and Boolean processor. Accumulator ACC is an eight bit register, which is a frequently working register in CPU. During arithmetic and logic operations, the accumulator ACC often temporarily stores an operand (such as addend) before the operation, and saves its result (such as algebraic sum) after the operation. Register B is mainly used for multiplication and division operations. The flag register PSW is also an eight bit register, which is used to store some characteristics of the operation result, such as carry, borrow, etc. The specific meaning of each is as follows. PSW CY AC fo RS1 rs0 ov-p for users, the following four digits are concerned.

1 carry flag CY (psw7). It indicates whether the operation has carry (or borrow). If the operation result has carry (addition) or borrow (subtraction) in the high order, this bit is 1, otherwise it is 0.

2 auxiliary carry flag AC. Also known as half carry flag, it reflects whether the lower four bits of two eight digit operations have half carry, that is, whether the lower four bits add (or subtract) have carry (or borrow). If so, AC is in 1 state, otherwise it is 0.

3 overflow flag bit ov. MCS-51 reflects whether there is overflow in the operation result of signed number. If there is overflow, this bit is 1, otherwise it is 0.

4 parity flag P. Reflects the parity of the contents of the accumulator acc. if the operation result in ACC has an even number of 1 (e.g. 1100B, including 4 1), P is 0; otherwise, P = 1.

Other bits of PSW will be introduced later. Because PSW stores the status during program execution, it is also called program status word? There is also a bit logic processor (also known as Boolean processor) in the arithmetic unit. Its function will be explained when the bit instruction is introduced.

2、 Controller

The controller is the nerve center of CPU. It includes timing control logic circuit, instruction register, decoder, address pointer dptr, program counter PC, stack pointer SP, etc. Here, the program counter PC is a counter composed of 16 bit registers. To execute a program, the program must be loaded into an area of the memory ROM in order. When the single chip microcomputer acts, it should take out instructions one by one in order to execute them. Therefore, there must be a circuit that can find the unit address where the instruction is located. This circuit is the program counter PC. When the MCU starts to execute the program, it loads the address of an instruction into the PC. every time it takes out an instruction (if it is a multi byte instruction, every instruction byte is taken out), the content of the PC will automatically add 1 to point to the address of the next instruction, so that the instructions can be executed in sequence. Only when the program encounters transfer instruction, subroutine call instruction, or interrupt (described later), the PC will go to the required place. At the address specified by 8051 CPU and C, the instruction byte is taken out from the corresponding unit of ROM and stored 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 are combined with the clock pulse generated by the single chip microcomputer clock oscillator in the timing and control circuit to form a level and clock varying according to a certain time beat, That is, the so-called control information coordinates the data transmission, operation and other operations between registers within the CPU.

3、 Memory

Memory is another important part of MCU. Each storage unit corresponds to an address. There are 256 addresses in 256 units, which are represented by two hexadecimal numbers, that is, the address of the memory (00h ~ FFH). Each storage unit in the memory can store an eight bit binary information, which is usually represented by a two bit hexadecimal number, which is the content of the memory. The storage unit address of memory and the content of storage unit are two different concepts, which can not be confused.

1、 Program memory

The program is a series of commands that control the action of the computer. The single chip microcomputer only knows the machine instructions composed of "0" and "1" codes. As mentioned above, the commands mov A and 20h written with mnemonics are replaced with codes 74h and 20h recognized by the machine: (written in binary, they are 01110100b and 00100000b). Before the single chip microcomputer deals with problems, the compiled programs, tables and constants must be compiled into machine code and stored in the memory of the single chip microcomputer. The memory is called program memory. The program memory can be placed inside or outside the chip, or can be set inside and outside the chip at the same time. Since the PC program counter is 16 bits, the program memory can use 16 bit binary address. Therefore, the address of internal and external memory can range from 0000H to ffffh. The internal 4K byte ROM of 8051 occupies the lower 4K bytes from 0000H to 0fffh. At this time, the address number of the program memory expanded outside the chip should start from 1000h. If 8051 is used as 8031 and does not want to use the on-chip 4krom and all the off-chip memory, the address number can still start from 0000H. However, at this time, the {31} pin (i.e. EA pin) of 8051 should be kept low. When EA is high, the user uses the internal ROM within the range of 0000H to 0fffh. When it is greater than 0fffh, the MCU CPU automatically accesses the external program memory.

2、 Data storage

The data memory of single chip microcomputer scheme is composed of read-write memory RAM. Its large capacity can be extended to 64K to store real-time input data. There are 256 units of internal data memory in 8051, of which 00h ~ 7FH are internal random access memory RAM and 80h ~ FFH are special register areas. In practical use, we should first make full use of the internal memory. From the perspective of use, it is very important to understand the structure and address allocation of the internal data memory. Because they will be often used in learning instruction system and programming in the future. The address of 8051 internal data memory is 256 bytes from 00h to FFH. The space is divided into two parts, in which the address of internal data RAM is 00h ~ 7FH (i.e. 0 ~ 127). The addresses used as special function registers are 80h ~ FFH. In this 256 bytes, there is also a so-called "bit address" area, which can be addressed not only by bytes, but also by "bits". The data that needs bit operation can be stored in this area. Four groups of working registers are arranged from 00h to 1fh, each occupying 8 ram bytes, which are recorded as R0 ~ R7. The group of registers to be selected is selected by RS1 and rs0 in the above flag register. Different register groups can be selected by putting different binary numbers on these two bits.

3、 Special function register

The address range of special function register (SFR) is 80h ~ FFH. In MCS-51, except for the program counter PC and four working register areas, the other 21 special function registers are in this SFR block. Five of them are double byte registers, which occupy a total of 26 bytes. See attached table 2 for the symbols and addresses of each special function register. Among them, bit addressable with * sign. The special function register reflects the status of 8051, which is actually the status word and control word register of 8051. PSW for CPU is a typical example. These special function registers are generally divided into two categories, one is related to the pin of the chip, and the other is used for the control of on-chip functions. The special function registers related to the chip pins are P0 ~ P3. They are actually four eight bit latches (one for each I / O port). Each latch is attached with a corresponding output driver and input buffer to form a parallel port. MCS-51 has four such parallel ports P0 ~ P3, which can provide 32 I / O lines. Each line is bidirectional, and most of them have the second function. Among the other registers used for chip control, the functions of accumulator a, flag register PSW and data pointer dptr have been mentioned earlier, while the functions of other registers will be further introduced in the relevant parts later

Instruction system and addressing mode of single chip microcomputer scheme

In order to operate normally, the single chip microcomputer needs to compile a program in advance, put the program into the memory, and then the CPU executes the program. The program is composed of instructions. The basic components of instructions are opcodes and operands. There are many kinds of single chip microcomputer. There are their own regulations on how to represent the operation code and operand in the design, and the instruction code is also different. Therefore, we must have a sufficient understanding of all the instructions of the selected single chip microcomputer, that is, the so-called "instruction system". Although each series of single chip microcomputer has different instruction systems, it also has its commonality. Mastering the instruction system of a single chip microcomputer can play a role of analogy to other series of single chip microcomputer. MCS-51 single chip microcomputer is widely used and has many derived varieties. Therefore, taking MCS-51 series instruction system as an example, this paper explains the composition and application of "instruction".

1、MOV A,#20H 

This instruction means that the number 20h is sent to accumulator a (a special function register).

2、ADD A,70H 

This instruction means that the contents in accumulator a (20h sent in the above example) and the contents in the memory unit with address 70h (also a number) are added through the arithmetic logic unit (English abbreviation ALU), and the result is retained in a. Here, MOV, add, etc. are called opcodes, while a, 20h, 70h, etc. are called operands. In assembly language programs, the operation code is usually abbreviated from English words, which is helpful for memory, so it is also called mnemonic. For example, MOV is the abbreviation of the English word move, which contains the meaning of moving; Add is an English word, which means addition. Therefore, for users who know a little English, it is more convenient to master the meaning of MCU instructions. There are many representations of operands. For example, 20h above is called an immediate number, that is, 20h is the real operand. 70h is the address of a unit in the memory. In this unit, the operand (for example, 3ah) is placed. Add a and 70h do not add the contents of 70h and a, but add the contents of 3ah and a from the memory 70h unit. It can be seen from the above that in order to find the actual operand, sometimes it is necessary to turn a corner or even turn several corners. This process is called addressing. MCS-51 has seven addressing modes, which are introduced as follows:

1、 Immediate addressing:

The operand is written in the instruction and placed in the program memory together with the opcode. Put the sign "in front of the immediate number to indicate that the addressing mode is immediate addressing, such as 20h.

2、 Register addressing:

The operand is placed in a register, and the address of the operand is directly represented by the name of the register in the instruction. For example, MOV A and R0 belong to register addressing, that is, the contents of R0 register are sent to accumulator a.

3、 Direct addressing:

The operand is placed in a unit of the internal RAM of the single chip microcomputer, and the address of the unit is written directly in the instruction. As add a in the previous example, 70h in 70h.

4、 Register indirection:

The operand is placed in a unit of ram, and the address of the unit is placed in register R0 or R1. If the address of ram is greater than 256, the address is stored in the 16 bit register dptr (data pointer). At this time, the @ symbol is added before the register name to represent this indirect addressing. Such as mov a, @ R0. Others include index addressing, relative addressing, bit addressing, etc., which will be introduced in detail later. Some people may ask, isn't it simple and clear to give the actual operand directly in the instruction? Why use other addressing methods? This is because it is difficult to give operands at once when programming. If the temperature is controlled by single chip microcomputer, the given control temperature (such as 20 ℃) needs to be subtracted from the ambient temperature from time to time, and the ambient temperature changes from time to time. Obviously, it cannot be given in the program instruction. Only by a certain way, it can be sent to an input / output port and stored in a register, which must use register addressing. In addition, if you want to carry out arithmetic operation, you need to calculate the average value of the students' scores in each class. If you compile a program for each student's subjects, directly give the students' scores in the program, and then calculate the average value, it is obviously too troublesome. Here we can compile a general program for average score, and send each student's score into each unit of the memory. At this time, direct addressing can be adopted. A program can be used by each student. Isn't it more convenient? Therefore, the more addressing methods, the more convenient and flexible the programming is, and the wider the scope of application is.

Addressing is like looking for someone. If the person to be found has a variety of contact methods such as mobile phone, BP machine and landline phone, it is easy to find him. The same is true for single chip microcomputer. The more addressing methods, the more convenient it is to find operands, and the stronger the function of single chip microcomputer. When introducing the addressing mode of 51 series single chip microcomputer, we often encounter some registers, accumulator a, general registers R0 ~ R7, data pointer dptr and memory in the single chip microcomputer. When instructions are introduced later, data will be transferred or operated between these registers and memories. Therefore, programming needs to be familiar with the internal structure of MCU.

The internal overall structure of 8051 single chip microcomputer and its basic characteristics are as follows:

8-bit CPU, on-chip oscillator

4K byte ROM, 128 byte RAM

21 special function registers

32 I / O cables

Addressable 64K bytes of external data and program storage space

2 16 bit timers, counters

Interrupt structure: it has two priorities and five interrupt sources

A full dual port serial port

Bit addressing (i.e. finding the content of a bit) function, which is suitable for bit processor for logical operation by bit. In addition to 128 byte ram, 4K byte ROM and interrupt, serial port and timer module, there are four groups of I / O ports P0 ~ P3, and the rest is all the composition of CPU. Replacing 4krom with EPROM is the structure of 8751. If the ROM / EPROM part is removed, it is the block diagram of 8031. If the ROM is replaced with flash memory or EEPROM, or some I / O is omitted, we can get the block diagram of 51 series derived varieties, such as 89C51, AT89C2051 and so on.

All parts of the single chip microcomputer are organically connected through the internal bus. After learning the basic knowledge of the single chip microcomputer above, you should have a general understanding of the single chip microcomputer.


Copyright © Wuxi Xijie Microelectronics Co., LTD. All rights reserved苏ICP备18012310号-1 Mainly engaged inMicroelectronics,Integrated circuit design,Single chip solutions, Welcome to inquire! Service support:无锡网站建设