1. Bus : We know that a circuit is always made up of components connected by wires. In analog circuits, wiring is not a problem because the devices are generally in serial relationship and there are not many wires between the devices. However, computer circuits are different. They are based on microprocessors. All devices must be connected to the microprocessor and the work between the devices must be coordinated with each other, so a lot of wires are needed. If the microprocessor and the device are connected separately as in analog circuits, the number of wires will be amazing. Therefore, the concept of bus is introduced in microprocessors. All devices share the wires. All 8 data lines of all devices are connected to 8 common lines, which is equivalent to connecting all devices in parallel. However, this is not enough. If two devices send data at the same time, one is 0 and the other is 1, then what does the receiver receive? This situation is not allowed, so it is necessary to control through control lines to make the devices work in time-sharing mode. Only one device can send data at any time (multiple devices can receive data at the same time). The data line of the device is called the data bus, and all the control lines of the device are called the control bus. There are storage units inside the microcontroller or in external memory and other devices. These storage units must be assigned addresses before they can be used. The assigned addresses are of course given in the form of electrical signals. Since there are many storage units, there are also many lines used for address allocation. These lines are called address buses.
2. Data, address, and instruction : The reason why these three are put together is that the essence of these three is the same - numbers, or a sequence of '0' and '1'. In other words, addresses and instructions are also data. Instruction: A number specified by the designer of the microcontroller chip. It has a strict one-to-one correspondence with the instruction mnemonics we commonly use and cannot be changed by the developer of the microcontroller. Address: It is the basis for finding the internal and external storage units and input and output ports of the microcontroller. The address value of the internal unit has been specified by the chip designer and cannot be changed. The external unit can be determined by the microcontroller developer, but some address units must be there (see the execution process of the program for details). Data: This is the object processed by the microprocessor. It is different in various application circuits. Generally speaking, the data being processed may be in the following situations:
1. Address (such as MOV DPTR, #1000H), that is, address 1000H is sent to DPTR.
2. Mode word or control word (such as MOV TMOD, #3), 3 is the control word.
3. Constant (such as MOV TH0, #10H) 10H is the timing constant.
4. Actual output value (e.g., if you want to connect colored lights to the P1 port, and want all lights to be bright, execute the command: MOV P1, #0FFH, if you want to want all lights to be dark, execute the command: MOV P1, #00H) Here, 0FFH and 00H are both actual output values. Another example is the font code used for LED, which is also the actual output value.
Once you understand the nature of addresses and instructions, it is not difficult to understand why the program may run wild during execution and why data may be executed as instructions.
3. How to use the second function of P0, P2 and P3 When starting to learn, people are usually confused about how to use the second function of P0, P2 and P3. They think that there must be a switching process between the second function and the original function, or an instruction. In fact, the second function of each port is completely automatic and does not require instructions to switch. For example, P3.6 and P3.7 are WR and RD signals respectively. When the microprocessor is connected to RAM or has an external I/O port, they are used as the second function and cannot be used as a general I/O port. As long as the microprocessor executes the MOVX instruction, the corresponding signal will be sent from P3.6 or P3.7, and there is no need to use instructions in advance. In fact, "cannot be used as a general I/O port" does not mean "cannot" but (the user) "will not" use it as a general I/O port. You can arrange a SETB P3.7 instruction in the instruction, and when the microcontroller executes this instruction, P3.7 will also become a high level, but users will not do this because it often causes the system to crash (i.e. freeze).
4. Program execution process After the microcontroller is powered on and reset, the value of the program counter (PC) in the 8051 is '0000', so the program always starts from the '0000' unit. In other words, the '0000' unit must exist in the system's ROM, and there must be an instruction stored in the '0000' unit.
5. Stack The stack is an area used to store data. This area itself has nothing special. It is just a part of the internal RAM. What is special is the way it stores and retrieves data, which is the so-called "first in, last out, last in, first out". The stack has special data transfer instructions, namely "PUSH" and "POP", and there is a special unit dedicated to it, namely the stack pointer SP. Every time a PUSH instruction is executed, SP automatically increases by 1 (based on the original value), and every time a POP instruction is executed, SP automatically decreases by 1 (based on the original value). Since the value in SP can be changed by instructions, as long as the value of SP is changed at the beginning of the program, the stack can be set in the specified memory unit. For example, at the beginning of the program, a MOV SP, #5FH instruction is used to set the stack in the unit starting from memory unit 60H. Generally, there is always an instruction to set the stack pointer at the beginning of a program. Because when the computer is turned on, the initial value of SP is 07H, so the stack starts from unit 08H and goes backwards. The area from 08H to 1FH is the second, third, and fourth working register area of 8031, which is often used, which will cause data confusion. When different authors write programs, the initialization instructions for the stack are not exactly the same. This is a problem of the author's habit. When the stack area is set, it does not mean that the area becomes a special memory. It can still be used like a normal memory area, but programmers generally do not use it as a normal memory.
6. The development process of single-chip microcomputer The development process mentioned here is not the one that starts from task analysis as mentioned in general books. We assume that the hardware has been designed and made, and the following is the work of writing software. Before writing software, we must first determine some constants and addresses. In fact, these constants and addresses have been directly or indirectly determined in the design stage. For example, when the connection of a device is designed, its address is also determined. When the function of the device is determined, its control word is also determined. Then use a text editor (such as EDIT, CCED, etc.) to write the software. After writing, use a compiler to compile the source program file and check for errors until there are no syntax errors. Except for very simple programs, the software is generally debugged by an emulator until the program runs correctly. After running correctly, you can write to the chip (solidify the program in the EPROM). After the source program is compiled, a target file with the extension HEX is generated. Generally, the programmer can recognize files in this format. As long as this file is loaded, the chip can be written. Here, in order to give everyone an understanding of the whole process, an example is given:
Table 1
ORG 0000H
LJMP START
ORG 040H
START:
MOV SP, #5FH; set stack
LOOP:
NOP
LJMP LOOP ; Loop
END; End
Table 2
:03000000020040BB
:0700400075815F000200431F
Table 3
02 00 40 FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF FF. FF FF FF FF FF FF FF FF FF FF FF FF FF FF 75 81 5F 00 02 00 43
Table 1 is the source program, Table 2 is the HEX file obtained after assembly, and Table 3 is the target file converted from the HEX file, that is, the file finally written into the EPROM, which is converted by the programmer or by programs such as HEXBIN. Those who have learned manual assembly should not have difficulty in finding the one-to-one correspondence between Table 3 and Table 1. It is worth noting that there is a long string of 'FF' starting from 02 00 40 to 75 81, which is the result of the pseudo instruction: ORG 040H.
7. Simulation and Simulator Simulation is a very important part of the MCU development process. Except for some very simple tasks, simulation is generally required in the product development process. The main purpose of simulation is to debug the software. Of course, with the help of the simulator, some hardware debugging can also be performed. A MCU application circuit board includes the MCU part and the application circuit designed to achieve the purpose of use. Simulation is to use the simulator to replace the MCU part of the application circuit board (called the target machine) to test and debug the application circuit part. There are two types of simulation: CPU simulation and ROM simulation. The so-called CPU simulation refers to the method of replacing the CPU of the target machine with the simulator, and the simulator supplies various signals and data to the application circuit part of the target machine for debugging. This kind of simulation can run the program through multiple methods such as single-step running and continuous running, and can observe the changes inside the MCU, which is convenient for correcting errors in the program. The so-called ROM simulation is to replace the ROM of the target machine with the simulator. When the CPU of the target machine is working, the program is read from the simulator and executed. This kind of emulation actually treats the emulator as an EPROM, but it saves the trouble of erasing and writing, and there are not many debugging methods. Often these are two different types of emulators, that is, an emulator cannot do both CPU emulation and ROM emulation. If possible, of course, CPU emulation is better. The above is my understanding of the microcontroller. If there is anything wrong, please give me more advice. Post your opinion.
Previous article:51 MCU Tutorial from Scratch - 27 Matrix Keyboard Interface Technology and Program Design
Next article:51 MCU Tutorial from Scratch—— 29 MCU Music Programming
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- A newbie needs help. What are the sensors that can detect tiny distances?
- [NXP Rapid IoT Review] + First impressions
- 【Xianji HPM6750】Review and unboxing
- Who is proficient in medical regulations? To make medical devices or medical equipment, you need to understand or be proficient in the following regulations
- Live broadcast today at 10:00 AM | Omron relay/switch/connector solutions for photovoltaic inverters/energy storage systems
- How difficult is it to produce domestic automotive-grade MCU?
- Recently I made a [51 MCU building block graphical Chinese programming software/C language code generator/circuit simulation]
- Regarding the use of serial ports for ESP32 MicroPython - Thanks!
- Qorvo Design Tools - The Go-to Resource for RF Projects
- FPGA Learning