1.1 Introduction by lighting an LED
Using a single-chip microcomputer to light up an LED is almost the first experiment for every student learning single-chip microcomputers. So who lights it up and how does it light up? Note that there are two research objects involved here, the single-chip microcomputer and the LED. To know how the single-chip microcomputer lights up, you must first know why the LED lights up. This idea of studying the controlled object by analyzing the controlled object will be used repeatedly in the rest of this tutorial, so let's first bring it up to light up. Let's first look at why the LED lights up, that is, let's first understand the working principle of the LED. When there is current passing through (reaching a certain value, such as 5mA), the LED will light up. As for the further working principle, we will not pursue it. Those who are interested can check it out by themselves, which is not part of our discussion. According to this principle, we only need to connect one end of the LED (right side) to a 5V power supply and the left side of the LED to the ground, as shown in Figure 1, to generate a potential difference and conduct forward, then the LED will light up when there is current passing through it.
Figure 1: The LED is turned on, but it goes out quickly due to the high current.
But the LED will go out very quickly, why? When the LED is forward-conducting, the resistance is almost 0. According to Ohm's law, the current is infinite and the LED will burn out very quickly. Therefore, we need to add a current-limiting resistor to this circuit. How big should this current-limiting resistor be? Here we take the resistance of the LED as 0, the voltage as 5V, and the current as 5mA (the specific value depends on the parameters provided by the LED manufacturer you purchased). According to Ohm's law, the current-limiting resistor can be calculated to be 1K. In this way, the LED can continue to emit light, as shown in Figure 2.
Figure 2: A resistor is connected in series and the LED emits normally
So how do you turn off the LED? Just stop the current from flowing. How do you achieve this? Just make the potentials on both sides of the LED equal. So you only need to provide a high level of 5V on the left side of the LED, and the LED will turn off, as shown in Figure 3
Figure 3: Equal potential on both sides, LED off
We have completed the analysis of LED above. As mentioned before, we need to operate the control object (MCU) by analyzing the controlled object (LED). Now let's analyze how to operate the control object. First of all, we need to know what MCU is? According to the definition, MCU is a collection of digital circuits with certain programmable capabilities. So what is programmable? In layman's terms, it means to perform different tasks according to different instructions given to the microcontroller by people. Then it is easy to do. As shown in the figure below, the left side of the LED is connected to the P1.0 pin of the MCU. According to the previous analysis, just tell the MCU: "Turn your P1.0 pin output low level" (assuming that our microcontroller here outputs a high level of 5V and a low level of 0V. Because some microcontrollers have a high level of 3.3V). At this time, the LED will light up. If it outputs a high level, the LED will go out. In this way, the microcontroller controls the LED, as shown in Figure 4.
Figure 4 MCU controls LED
If you use human language to communicate with the MCU, the MCU cannot understand it. Therefore, the instructions you send to the MCU cannot be transmitted to the MCU. The MCU only recognizes 0 and 1. Then we immediately think of using 0 and 1 to communicate with the MCU, which is of course possible. In fact, early programs were written directly with 0 and 1. It is too painful for programmers to do this. The MCU recognizes it, but the programmer faints. If you don’t believe it, fill 0 and 1 on an A4 paper yourself. Regardless of what the meaning is, you will faint when you see it. This creates a problem. The MCU cannot understand human language, and it is inconvenient for humans to use the language of the MCU. Therefore, we take a step back and make a compromise. What to use? C language (early assembly language, we will talk about it later). Convert human language into C language, and then convert C language into machine language according to certain rules. The former is called development environment, and the latter is what we usually call compilation. You can completely understand it as translation. The result of compilation is the machine instructions recognized by the MCU. So how to transmit this instruction to the microcontroller? This process is called program burning, or program downloading. The tool used in the burning process is the burner. The machine instruction is transmitted to the microcontroller, but after power-on, the microcontroller starts to execute the instruction, thus achieving our purpose of controlling the device.
This example is very simple, but it gives the basic process of MCU development. First of all, we need to know the principle of working devices. Working devices are our ultimate goal, such as controlling LEDs for lighting; temperature sensors for measuring temperature; LCDs for displaying content, etc. MCUs are only a means or way to achieve the ultimate goal. Therefore, when using MCUs to control working devices, we must first understand how working devices work. Then, on this basis, different instructions (human language) are transmitted to the MCU according to the needs of the working devices. MCUs cannot understand human instructions, so they need to be translated into a language that the MCU can understand. Then the translated structure is transmitted to the MCU.
I have been talking so much before, mainly to explain the preliminary ideas of MCU development and the construction of MCU development environment for beginners. The main points are summarized as follows: 1. Start with the controlled object to study how to operate the control object. The so-called controlled object is actually the peripheral working device we want to use. It can be an LED, a temperature sensor, a stepper motor, etc. It is our ultimate goal, such as making the LED flash, measuring temperature, controlling the speed, etc. The best way to understand their working principles is to read the instructions provided by the manufacturer. For the control object (MCU), there are also many, 51, MSP430, AVR, PIC, etc. How to communicate with them, the same reason, check the chip manual (also official information). I repeatedly emphasize here because I see many beginners go to the online forum to post for help when they encounter problems, but they don’t know that the best way to solve the problem is to check the official information. 2. After understanding the relationship between the two objects, we start to build the MCU development environment, write instructions, compile instructions, and finally burn instructions.
Previous article:51 MCU environment construction-1.3 instruction download/burn software
Next article:CAN bus and Ethernet embedded gateway circuit design strategy
Recommended ReadingLatest update time:2024-11-15 12:57
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Three steps to govern hybrid multicloud environments
- Three steps to govern hybrid multicloud environments
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- EEWORLD University ---- Digital Circuit Design
- Allwinner heterogeneous multi-core AI intelligent vision V853 development board evaluation + ubuntu20 installation LiveSuit nanny-level tutorial
- 【NUCLEO-L552ZE Review】+ Various lighting patterns
- Summary: About 2.4G NRF24L01 wireless module
- After the holiday, I will give you a review~~
- DIY battery management + fully automatic electric fan
- Behind the Scenes: Perseverance Rover's "Seven Minutes of Terror"
- Capacitive sensor measurement system module circuit design precision amplifier circuit
- 【TI mmWave Radar Review】XWR14XX Data Path
- Disconnection detection