1. External structure of single chip microcomputer
If you get a chip and want to use it, you must first know how to connect it. The chip we use is called 89C51. Let's take a look at how to connect it.
1. Power supply: This is of course essential. The microcontroller uses a 5V power supply, with the positive pole connected to pin 40 and the negative pole (ground) connected to pin 20.
2. Oscillator circuit: The microcontroller is a sequential circuit that must provide a pulse signal to work properly. An oscillator has been integrated inside the microcontroller. Use a crystal oscillator and connect it to pins 18 and 19. Just buy a crystal oscillator and a capacitor and connect them. Just connect them as shown in Figure 1.
3. Reset pin: Connect it as shown in Figure 1. As for what reset means and why it is necessary to reset, it is introduced in the microcontroller function.
4. EA pin: The EA pin is connected to the positive power supply terminal. At this point, a single-chip microcomputer is connected, and when the power is turned on, the single-chip microcomputer starts to work.
Of course, you don't necessarily need an 89c51. In fact, any chip in the 8051 series can be used. For example, 89s51, 89c52
etc.
Figure 1
2. Task Analysis
Our first task is to use the microcontroller to light up a light-emitting diode (LED). Obviously, this LED must be connected to a pin of the microcontroller, otherwise the microcontroller cannot control it. So which pin should it be connected to? In addition to the 5 pins just used, there are 35 pins on the microcontroller. We connect this LED to pin 1. (See Figure 1, where R1 is the current limiting resistor)
According to the connection method in this diagram, when pin 1 is at a high level, the LED will not light up, and only when pin 1 is at a low level, the LED will light up. Therefore, we need to be able to control pin 1, that is, we need to be able to make pin 1 change to a high or low level as required. Since we want to control pin 1, we have to give it a name. We can't just call it pin 1, right? What name should we call it? INTEL, the company that designed the 51 chip, has already named it P1.0. This is a rule and cannot be changed by us.
Now that we have a name, how do we make it 'high' or 'low'? To tell someone to do something, we just need to say it, which is called issuing a command. To tell a computer to do something, we also need to send a command to the computer. The command that the computer can understand is called a computer instruction. The instruction to make a pin output a high level is SETB, and the instruction to make a pin output a low level is CLR. Therefore, if we want P1.0 to output a high level, we just need to write SETB P1.0, and if we want P1.0 to output a low level, we just need to write CLR P1.0.
Now we have a way to make the computer output high or low level of P1.0, but how can we make the computer execute this instruction? We can't just tell the computer and leave it at that. To solve this problem, there are still several steps to go. First, the computer cannot understand instructions such as SETB CLR. We have to translate the instructions into a way that the computer can understand, and then let the computer read it. What can the computer understand? It only understands one thing - numbers. Therefore, we have to change SETB P1.0 to (D2H, 90H) and CLR P1.0 to (C2H, 90H). As for why these two numbers are used, this is also stipulated by the designer of the 51 chip - INTEL, and we will not study it. The second step is, after obtaining these two numbers, how to let these two numbers enter the internal of the microcontroller? This requires the help of a hardware tool "programmer". Of course, if you use our Yitian version development kit or XP development kit, then you have both the programmer and the test board, and you only need to program.
This is our first step in microcontroller programming. It may seem simple, but it is of great significance to you. Yes, you are programming: (
Open the Chinese version of uvw51e we introduced earlier; refer to its usage instructions; write the program,
We set its name to: 001led. Finally, burn the generated 001led.hex into the 89s51 of our Yitian version kit
Then change the chip into the test socket, and we can see that the p1.0 light is on.
Look at this picture, it shows the 8 lights of our Yitian version development kit P1.0-P1.7
Note that he can switch the port externally through the row of switches next to it.
At this point, some friends may ask: Why do we need to use a single chip microcomputer to make such a simple problem so complicated? If we connect a battery, won’t the light turn on?
That's right, but this is programming. If we don't want p1.0 to light up, but want p2.0 to light up, then just write clr p2.0, and you don't need to use a soldering iron to change the line. In this way, we can see that the connection of the hardware circuit has not been changed. As long as the content written into the microcontroller is changed, the output effect of the circuit can be changed.
It can be seen that problems that are very difficult to implement with hardware can be easily solved with a single-chip microcomputer. Therefore, it is necessary for every hardware engineer to master the single-chip microcomputer technology.
3. Analysis of the internal structure of the MCU
Let's think about a question. When we write an instruction into the microcontroller in the programmer, and then remove the microcontroller, the microcontroller can execute the instruction. Then the instruction must be saved somewhere in the microcontroller, and this place can still keep the instruction from being lost after the microcontroller loses power. What is this place? This place is the read-only memory inside the microcontroller, namely ROM (READ ONLY MEMORY). Why is it called read-only memory? Didn't we just write two numbers in it? It turns out that the ROM in 89C51 is an electrically erasable ROM, called FLASH ROM. We just used a programmer to write to the ROM under special conditions by an external device. Under normal working conditions of the microcontroller, it can only be read from that side, and data cannot be written in, so we still call it ROM.
Previous article:From the world of radio to the world of microcontrollers
Next article:The second experiment - using a single chip microcomputer to light up a flashing LED
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Those who want to learn ROS system should read this (video teaching materials are updated continuously...)
- A large number of books have been released after graduation, including C/C++, Linux, algorithms, and other books. They are on sale now. Only 3 days left
- IWR1642Boost people counting DEMO program operation process
- I would like to ask the experts to introduce the generation of 2HZ in detail. Now the buzzer circuit 2HZ does not work! ! ! ! ! !
- Why doesn't the CPU top cover use silver, which has better heat dissipation?
- Summary of low power consumption STM32L151+RTC wake-up application
- LLC design information collection (for learning only)
- Do the read and write registers of the ds2438 coulomb meter have a lifespan?
- Raspberry Pi based smartphone
- Share WB-Serial Port Debugging Assistant