The Six Important Parts of Microcontroller Learning Applications 1. Bus: We know that a circuit is always formed by connecting components through wires. In analog circuits, wiring is not a problem because the relationship between components is generally serial, and there are not many connections between components. However, computer circuits are different; they are centered around the microprocessor, and all components must connect to the microprocessor. The work between components must coordinate with each other, so many connections are needed. If we still connect each microprocessor and component individually like in analog circuits, the number of wires would be astonishingly high. Therefore, the concept of a bus is introduced in microprocessors, where each component shares the wiring. All eight data lines of the components are connected to eight common lines, effectively paralleling the components. However, this alone is not sufficient. If two components send data simultaneously, one being 0 and the other being 1, what will the receiver actually receive? This situation is not allowed, so control lines are used to manage this, ensuring that only one component sends data at any time (multiple components can receive simultaneously). The data lines of the components are referred to as the data bus, and all control lines of the components are referred to as the control bus. There are storage units in the internal or external memory and other components of the microcontroller, and these storage units must be assigned addresses to be used. The address assignment is also given in the form of electrical signals. Since there are many storage units, there are also many lines used for address assignment, which are called the address bus. 2. Data, Address, Instructions: The reason these three are grouped together is that their essence is the same—numbers, or sequences made up of ‘0’s and ‘1’s. In other words, addresses and instructions are also data. Instructions are a type of number defined by the designer of the microcontroller chip, with a strict one-to-one correspondence with the mnemonic instructions we commonly use, and they cannot be changed by the developer of the microcontroller. An address is the basis for finding internal and external storage units and input/output ports of the microcontroller. The address values of internal units are predetermined by the chip designer and cannot be changed, while external units can be determined by the microcontroller developer, but some address units must exist (as detailed in the program execution process). Data is the object processed by the microprocessor, varying in different application circuits. Generally, the processed data may fall into several categories: 1? Address (e.g., MOV DPTR, 1000H), which means sending address 1000H into DPTR. 2? Mode word or control word (e.g., MOV TMOD, #3), where 3 is the control word. 3? Constant (e.g., MOV TH0, #10H), where 10H is the timer constant. 4? Actual output value (e.g., connecting a colorful light to port P1, if all lights should be on, execute the instruction: MOV P1, #0FFH; if all lights should be off, execute the instruction: MOV P1, #00H), where both 0FFH and 00H are actual output values. For example, the character code used for LED is also an actual output value. Understanding the essence of addresses and instructions makes it easier to understand why programs may run off course and treat data as instructions during execution. 3. P0, P2, and the second function usage of P3: Beginners often find the second function usage of P0, P2, and P3 confusing, thinking there needs to be a switch process or an instruction to toggle between the second and original functions. In fact, the second function of each port is entirely automatic and does not require an instruction to switch. For instance, P3.6 and P3.7 are WR and RD signals, respectively. When the microcontroller is connected to RAM or external I/O ports, they are used for the second function and cannot be used as general I/O ports. As soon as the microprocessor executes the MOVX instruction, the corresponding signals will be sent from P3.6 or P3.7 without needing prior instruction. The statement ‘cannot be used as general I/O ports’ does not mean ‘cannot’ but rather that the user ‘will not’ use them as general I/O ports. You can completely arrange an instruction like SETB P3.7 in your code, and when the microcontroller executes this instruction, P3.7 will become high, but users typically avoid doing this as it often leads to system crashes. 4. Program Execution Process: After powering on and resetting, the program counter (PC) in the 8051 microcontroller starts with a value of ‘0000’, so the program always begins execution from the ‘0000’ cell. This means that there must be an instruction stored in the system ROM at cell ‘0000’. 5. Stack: The stack is an area used to store data. This area itself has no special properties; it is merely part of the internal RAM. What is special is the way data is stored and retrieved, known as ‘last in, first out’ (LIFO). The stack has special data transfer instructions, namely ‘PUSH’ and ‘POP’, and a special unit dedicated to it, the stack pointer SP. Every time a PUSH instruction is executed, SP automatically increments by 1; every time a POP instruction is executed, SP automatically decrements by 1. Since the value in SP can be changed by instructions, if the value of SP is altered at the beginning of the program, the stack can be set in a designated memory unit. For example, at the start of the program, using the instruction MOV SP, #5FH sets the stack to start from memory unit 60H. Generally, there is always an instruction at the beginning of the program to set the stack pointer, because at startup, the initial value of SP is 07H, causing the stack to start from unit 08H, and the area from 08H to 1FH is the working register area of 8031, which is frequently used, leading to data confusion. Different authors may have varying initialization instructions for the stack, reflecting their personal habits. Setting up the stack area does not mean that this area becomes special memory; it can still be used like regular memory, although programmers typically do not treat it as such. 6. Microcontroller Development Process: The development process mentioned here is not the typical task analysis described in general books. We assume that the hardware has already been designed and produced, and the next step is to write the software. Before writing software, some constants and addresses must be determined. In fact, these constants and addresses have already been directly or indirectly established during the design phase. For instance, once the wiring of a device is designed, its address is also determined. Once the function of a device is established, its control word is also determined. Then, using a text editor (like EDIT, CCED, etc.), the software is written. After writing, the source program file is compiled with a compiler, checking for errors until there are no syntax errors. Except for very simple programs, a simulator is generally used to debug the software until the program runs correctly. Once it runs correctly, the program can be written (permanently stored in EPROM). After the source program is compiled, a target file with the extension HEX is generated, which most programmers can recognize. This file can simply be loaded for writing. To give everyone an understanding of the entire process, here’s an example: Microcontroller Experiment Board ORG 0000H LJMP START ORG 040H START: MOV SP, #5FH ; Set Stack LOOP: NOP LJMP LOOP ; Loop END ; End