Robot's brain - single chip (four)

xiaoxiao2021-03-06  75

The brain-single-chip microcontroller (4) single-chip microcontroller is working properly, and the program needs to be prepared in advance, then put the program into the memory, then execute the program by the CPU. The program is composed of instructions, the basic composition of the instruction is an opcode and an operand. The single-chip microcomputer variety, how to indicate the operation code and operand when designing, there is a respective regulations, and the instruction code is different, so the entire directive of the selected microcontroller must be the so-called "instruction system", there is Sufficient understanding. Although individual series of microcontrollers have different instruction systems, there is also their commonality. Master a single-chip instruction system that can function to other series of microcontrollers. The MCS-51 single-chip microcomputer is widely used, and there are many derived varieties. It is representative, so here is the composition and application of the "instruction" as an example of the MCS-51 series.

1, MOV A, # 20h This instruction indicates that the number of 20h is sent into the accumulator A (a special function register). 2, Add A, 70h This command represents content (also numbers) in the 70H unit of the content (# 20h) sent in the accumulator A and the address of the address in the memory (also a number), by arithmetic logic unit (English abbreviation is ALU) is added and the result is retained in A. Here, the MOV, ADD, etc. are called operational codes, and A, # 20h, 70h, etc. are all called operands. In assembly language programs, the opcode is usually abbreviated by English word, which helps to remember, so it is also known as assistance. If MOV is the abbreviation of English word Move, the meaning of movement is contained; and the ADD is English word, which is interested in adding. Therefore, it is more convenient to master the meaning of the microcontroller instruction to the user who knows English. There are a variety of representations, such as the above # 20h, called immediate, that is, 20h is the real operand. 70h is the address of a unit in the memory, in which the operand (such as 3ah), the ADD A, 70h is not added to the contents of 70 h and A, but from the memory 3AH taken out in the 70H unit plus the contents in A. It is known that you want to find the actual number of operands, sometimes you want to turn a curve, even a few bends, this process is called addressed, the MCS-51 has a total of 7 addressing methods, and now the following: First, immediate addressing: The number of operands are written in the instruction, and the operation code is placed in the program memory. Put the "#" number in front of the number to indicate that the address is addressed immediately, such as # 20h. Second, register addressing: The operand is placed in the register, and the address of the operand is represented directly in the command of the register. For example, MOV A, R0 belongs to register addressing, and the content of the R0 register is sent to the accumulator A. Third, the direct addressing: The operand is placed in a unit of the single-chip inner RAM, and the address of the unit is directly written directly in the instruction. 70h in the ADD A, 70H of the previous example. Fourth, register indirect addressing: The operand is placed in a unit of the RAM, and the address of the unit is placed in the register R0 or R1. If the address of the RAM is greater than 256, the address is stored in the 16-bit register DPTR (data pointer), at which time the register is pre-@ symbol to represent this indirect addressing. Such as MOV A, @ r0. Others include address addresses, relative addressing, bit addressing, etc., and later introduce. Some people may ask, give the actual number of operands directly in the directive, isn't it simple, clear? Why do you still use several other addressing methods? This is because it is difficult to give the operand when the program is compiled. If the temperature is controlled by the microcontroller, the given control temperature (e.g., 20 ° C) is sometimes necessary to change the ambient temperature, while the ambient temperature changes, it is obviously not given in the program instruction, only through a certain way, An input / output port, then placed in a register, this must be used to address register. For arithmetic operations, the average value of each class is to calculate the average of each class, if each student is edited, and directly give the students directly, then seek average, obvious Too troublesome.

Here you can edit a general program for average score, and send each student's score to each unit of the memory, you can take direct addressing, one program is available for each student, isn't it more convenient? Therefore, the more addressed methods, the more convenient, flexible, and the scope of application is. Addressing if you find someone, if you are looking for mobile phones, BP machines, landline phones, etc., it is easy to find him, the microcontroller is the same, the more addressed, the more convenient to find the operand, the function of the microcontroller The stronger. In the previous introduction of the addressing method of the 51 series of microcontrollers, some registers, accumulators A, general registers R0 ~ R7, data pointers, general purpose registers, etc. When the instructions are introduced later, the data is to be transferred between these registers, the memory, or operate. Therefore, the programming can be familiar with the internal structure of the microcontroller. 8051 The internal overall overall structure of the single-chip microcontroller is as follows: 8-bit CPU, on-chip oscillator 4K byte ROM, 128 byte RAM 21 Special function registers 32 root I / O line Address 115k byte external data, program 2 16-bit timers in storage, counter interrupt structure: having two priorities, five interrupt sources a full-duplex serial port bit addressing (you can find a bit of content) function, suitable for standby A bit processor for logical operations. In addition to 128 bytes of RAM, 4K byte ROM and interrupts, serial ports and timer modules, there are 4 groups of I / O ports P0 ~ P3, and the remaining is all of the CPUs. The 4kROM is converted to EPROM is the structure of 8751, such as block diagram of the ROM / EPROM section is 8031, if the ROM is replaced with a Flash memory or EEPROM, or save some I / O, 51 series can be obtained. A block diagram of a single-chip microcontroller such as 89C51, AT89C2051. The individual parts of the single-chip microcomputer are organically connected to the interior bus.

转载请注明原文地址:https://www.9cbs.com/read-108780.html

New Post(0)