51 MCU Environment Construction-1.1 Introduction by lighting an LED

Publisher:光速思考Latest update time:2016-03-29 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
Chapter 1 51 MCU Environment Construction

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.

Reference address:51 MCU Environment Construction-1.1 Introduction by lighting an LED

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

MCU C language programming: K1-K4 controls LED shift
/* Name: K1-K4 controls LED shift Note: When K1 is pressed, the LED at port P0 moves up one position;   #FormatImgID_0#     */ When K2 is pressed, the LED at port P0 moves down one position; When K3 is pressed, the LED at port P2 moves up one position; When K4 is pressed, the LED at port P2 moves dow
[Microcontroller]
MCU C language programming: K1-K4 controls LED shift
How to test LEDs with a multimeter
QA& Q: How to test LED This article will introduce some basic knowledge about LEDs and how to test LEDs. Basic knowledge of LED An LED (light emitting diode) is a semiconductor diode (a pn junction) that emits light when positive current flows from the anode to the cathode of the LED. The anode is represented by "+"
[Test Measurement]
How to test LEDs with a multimeter
Buck regulator using optical feedback to control white LEDs
Lighting using LEDs has become more popular due to the availability of high-power, high-efficiency white (and other color) LEDs. Since LEDs are current-controlled devices, the typical control circuit is to adjust the current through the LED to maintain consistent brightness. To make the best use of the power, users of
[Analog Electronics]
Buck regulator using optical feedback to control white LEDs
LED digital tube experimental procedure
DISPBUF EQU 50H; 50H, 51H, 52H, 53H are display buffer  LED1 EQU P2.0; the first digital tube bit control  LED2 EQU P2.1; the second digital tube bit control  LED3 EQU P2.2 ;The third digit of the digital tube is controlled  LED4 EQU P2.3 ;The fourth digit of the digital tube is controlled  LED5 EQU P2.4  LED6 EQU P2.
[Microcontroller]
Summary of stm32 KEY control LED
The learning of stm32 is to understand how to configure the software, first understand the hardware connection, and then combine them; #include "stm32f4xx.h" #include "led.h" #define KEY0 GPIO_ReadInputDataBit(GPIOE,GPIO_Pin_4) // Read the IO status here and use the IO port of stm32 as input #define KEY1 GPIO_Re
[Microcontroller]
Low-cost 1W high-power LED practical driver
  High-power LEDs have higher luminous efficiency and service life than fluorescent lamps. People should install a heat sink according to the actual usage. At present, the retail price of domestic 3W white light LED is 15 yuan, but because the quality of 3W high-power LED is not reliable enough, it is not suitable for
[Power Management]
Low-cost 1W high-power LED practical driver
Arm2440 - Detailed explanation of Nand flash boot mode (LED program as an example)
I have been studying arm on and off for 2 months. Now I feel that I understand the boot process of arm in Nand flash mode. Now I come here to record it to express my extremely happy mood. Without further ado, while I still remember the feelings during the learning process, I will go straight to the point. As we all kn
[Microcontroller]
Design of simplified LED dot matrix system based on PSoC
Abstract: This paper introduces the difference between the traditional LED display design method controlled by single-chip microcomputer and the LED display design method based on PSoC technology, and expounds the advantages of PSoC technology in the design of LED dot matrix display system. Taking the LED dot matrix d
[Analog Electronics]
Design of simplified LED dot matrix system based on PSoC
Latest Microcontroller Articles
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号