What is a microcontroller? According to the internet: “A microcontroller is a device that integrates a CPU, memory (RAM, ROM, EPROM), and various I/O interfaces (timers, counters, parallel I/O ports, etc.) on a single silicon chip, functioning like a computer, also known as a single board computer, microcontroller, or embedded controller.” I think this statement is very good, but here I want to say more.
I don’t understand/(ㄒoㄒ)/~~
So, let’s first talk about microcontrollers and remember one thing: the pins of a microcontroller can receive or emit high and low levels. The principle seems to be “not seeking large scale, but aiming for small and complete.” n(*≧▽≦*)n
The left image is a physical picture of the 51 microcontroller, and the right image is a pin diagram. What are pins? Pins, also known as leads, are the connections that extend from the internal circuit of the integrated circuit (chip) to the external circuit. That is the small white rectangles in the left image. We first need to control ourselves with our thoughts and not wonder what is inside this black block; we just need to know that these pins can receive or emit high and low levels. The received levels can influence the output, and the output can also affect the input. To understand the mystery of the mutual influence between the two, we need to know the principles of this black block. For those who are just getting acquainted with microcontrollers, let’s first get to know the visible components. Pins. Pin 20 connects to the negative terminal, and pin 40 connects to the positive terminal; this is for power supply, with 5V voltage being the best. Ports P1 and P2 have a total of 16 pins; they are the same, both output or receive the so-called high and low levels. Pin P3 is quite busy; it not only has the same functions as P1 and P2 but also has a second function, which I won’t discuss now. Port P0 is somewhat deficient; it needs to be provided with driving force to function like P1, and this driving force is called a pull-up resistor. Of course, this design serves a purpose, but I won’t elaborate on that for now. The ports we mainly use are these P ports.
Learning C language or Java, the first thing is to say “hello world”; similarly, when learning microcontrollers, the first task is to light up a lamp. We learned how to do this in middle school: take one or two batteries, connect one end of the lamp to the negative terminal and the other end to the positive terminal, and it will light up. Just like this.
Now we want to use a microcontroller to light a lamp; first, let’s talk about this lamp, which we call an LED, or light-emitting diode (I remember at first I didn’t know LED meant light-emitting diode (⊙﹏⊙)). We all know about diodes, which have unidirectional conductivity, as shown in the diagram below.
Connect A to the positive terminal and B to the negative terminal, and it will conduct. If reversed, it won’t work; of course, you can forcibly break it, making it cease to exist. Now, what about light-emitting diodes? As the name suggests, when A is connected to the positive terminal and B to the negative terminal, it conducts and the light turns on; otherwise, it won’t light up. Here, we have new terms to describe the positive and negative terminals: high level and low level. In physical terms, the positive terminal refers to the end with a higher potential (voltage) in the power source, while the negative terminal is the opposite. High level corresponds to the positive terminal, while the negative terminal corresponds to the low level. When we talk about “level,” the dictionary explains it as being parallel to the horizontal plane or reaching a certain height in some aspect, extending to mean the comparative conclusion of things under the same conditions.
Look at this picture; water flows from a high elevation to a lower one. Water flows from a high level to a low level. Now, think about high level and low level, and it will all become clear. Electric charges flow from high level to low level, just like flowing from the positive terminal to the negative terminal. That’s the principle. In digital systems, we use 1 to represent high level and 0 to represent low level. Why? Using 0 to represent high level is also possible, but doesn’t it feel awkward that 0 is larger than 1? Next, let’s talk about light-emitting diodes; see the diagram below.
When A is at high level and B is at low level, it lights up. So what does this have to do with microcontrollers? Remember how I said earlier? The pins of the microcontroller can receive or emit high and low levels. Therefore, when the high level connected to A is provided by the microcontroller, and B is connected to the negative terminal, the light will turn on. If A is connected to an external high level and B is connected to the low level emitted by the microcontroller, the light will also turn on. In fact, these two connection methods are also called common anode and common cathode, which we will discuss later. So how does the microcontroller emit high and low levels? This requires software to achieve. I am using Keil 3; I won’t elaborate on how the software works~( ̄0 ̄)/. I must say that any program written without looking at the circuit diagram is nonsense, so let’s assume the LED is connected to pin P1.1. #include<reg52.h> To know what this header file does is simple: select the header file, right-click, and select open document #include<reg52.h> to see some content.
For more comments from netizens, please click Read Original below.
Recent Exciting Content Recommendations:
Rectification Discussion (1)
Rectification Discussion (2)
Rectification Discussion (3)