Several concepts that are difficult for microcontroller beginners to grasp

Publisher:Joyful444LifeLatest update time:2012-10-16 Source: 21ic Keywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Bus:
We know that a circuit is always made up of components connected by wires. In analog circuits, connecting wires 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. Each device shares 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 for address distribution. 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 sequences composed of strings of '0' and '1'. In other words, addresses and instructions are also data. Instructions are a kind of number specified by the designer of the microcontroller chip. It has a strict one-to-one correspondence with the commonly used instruction mnemonics 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 processed by the microprocessor and 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 (such as P1 port connected to the color light, to light up all the lights, then execute the instruction: MOV P1, #0FFH, to darken all the lights, then execute the instruction: 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. If you understand the nature of addresses and instructions, it is not difficult to understand why the program will run away during operation and why the data will be executed as instructions.

3. The second function usage of P0, P2 and P3:
Beginners are often confused about the second function usage of P0, P2 and P3, thinking 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 an external RAM or has an external I/O port, they function 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. or P3.7, without the need for prior instructions. 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 usually causes the system to crash (i.e. freeze).

4. Program execution process
After the microcontroller is powered on and reset, the value in the program counter (PC) in the 8051 is '0000', so the program always starts from the '0000' unit, that is to say: there must be a '0000' unit in the system 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 unique data transfer instructions, namely "PUSH" and "POP", and there is a special unit dedicated to it, namely the stack pointer SP. Whenever a PUSH instruction is executed, SP automatically increases by 1 (based on the original value), and whenever 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 SP value is changed at the beginning of the program, the stack can be set in the specified memory unit. For example, when a MOV SP, #5FH instruction is used at the beginning of the program, the stack is set in the unit starting from memory unit 60H. Generally, there are several instructions for setting the stack pointer at the beginning of a program. Because the initial value of SP is 07H when the computer is turned on, the stack starts from 08H and goes from 08H to 1FH. This area is exactly 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 matter of 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 described in general books. We assume that the hardware has been designed and made, and the next step is to write software. Before writing software, we must first determine some constants and addresses. In fact, these constants and addresses have been determined directly or indirectly during 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 the program to solidify it 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, to make everyone understand the whole process, let's give an example:
ORG 0000H
LJMP START
ORG 040H
START: MOV SP, #5FH; Set stack
LOOP: NOP
LJMP LOOP; Loop
END;

Keywords:MCU Reference address:Several concepts that are difficult for microcontroller beginners to grasp

Previous article:Design of operation indicator based on STC12C5616AD single chip microcomputer
Next article:Power-off protection circuit in single-chip microcomputer system

Recommended ReadingLatest update time:2024-11-16 23:52

[Self-study 51 single-chip microcomputer] 4---base conversion, C language variable types and operators
Conversion between different bases, C language variable types and operators, Keil Debug usage and application and the realization of running lights 1. Binary, decimal, hexadecimal conversion 1.1 Introduction to binary system Decimal system: Every ten digits has ten values: 0~9. Binary: Every binary digit has only tw
[Microcontroller]
[Self-study 51 single-chip microcomputer] 4---base conversion, C language variable types and operators
What kind of MCU can win the hearts of engineers (Part 4)
The secret behind ST's continued dominance in Cortex-M MCUs   MCU Model:   STMicroelectronics STM32 Product Family   Market size:   In 2007, ST first released the STM32 32-bit MCU product based on the ARM Cortex-M core. Since then, ST has been working hard to enrich and improve the STM32 MCU product system, an
[Analog Electronics]
What kind of MCU can win the hearts of engineers (Part 4)
Design of access control system based on AT89C2051 microcontroller
Circuit description: Safety is our biggest concern in daily life. Everyone feels that the security issue is very crucial, and the door and security in the home can be as safe as possible. For door access security we are therefore planning to provide security by introducing an electronic code lock system that includes
[Microcontroller]
Design of access control system based on AT89C2051 microcontroller
51 MCU serial communication principle and application
  In this section, we mainly talk about the working principle of the serial port on the microcontroller and how to set up the serial port through the program, as well as realize communication with the PC based on the given examples.   1. Principle Introduction   51 MCU has a full-duplex serial port inside. What is a f
[Microcontroller]
51 MCU serial communication principle and application
Study the operation of PIC microcontroller program under PICC compilation environment
PICC basically complies with the ANSI standard, but does not support recursive function calls. The main reason is the special stack structure of the PIC microcontroller. The stack in the PIC microcontroller is implemented by hardware, and its depth is fixed with the chip, so it is impossible to implement recursive alg
[Microcontroller]
Study the operation of PIC microcontroller program under PICC compilation environment
Analysis of Single Chip Microcomputer Application in Electronic Technology
    1. Characteristics and basic composition of single chip microcomputer     Compared with other embedded systems, the microcontroller is small in size, but highly integrated, with high reliability and control functions; it has low power consumption and uses low voltage, so it is very beneficial to the manufacture an
[Microcontroller]
National Technology and IAR start ecological cooperation, IAR integrated development environment fully supports N32 series MCU
IAR Embedded Workbench for Arm integrated development environment now fully supports application development based on industrial and automotive MCUs such as National Technology N32 G/L/WB/A Shanghai, China – June 13, 2023 – IAR, a global leader in embedded development software and services, recently
[Embedded]
National Technology and IAR start ecological cooperation, IAR integrated development environment fully supports N32 series MCU
Design of non-invasive visual pulse oximeter based on MSP430 series MCU
A pulse oximeter is a medical device used to monitor a patient's blood oxygen levels. The device measures blood oxygen levels and heart rate and generates an alarm when levels drop below a predetermined threshold. This type of monitoring is extremely useful for newborn babies and during surgical procedures. The
[Microcontroller]
Design of non-invasive visual pulse oximeter based on MSP430 series MCU
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号