Microcontroller Test 1: Light up a LED

Publisher:SerendipityJoyLatest update time:2024-08-30 Source: eepwKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

If you get a chip and want to use it, you must first know how to connect it. The chip we use is called 89S52. Let's see 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 timing circuit that must provide a pulse signal to work properly. The oscillator has been integrated inside the microcontroller, using a crystal oscillator, connected to pins 18 and 19. Just buy a crystal oscillator and a capacitor and connect them. Just connect them according to Figure 1.
3. Reset pin: Connect according to the method 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 microcontroller is connected, and the microcontroller starts working after power is turned on.


Of course, you don't necessarily need an 89S52. In fact, we can use any chip in the 8051 series, such as 89s51, 89c52, etc.

Our first task is to use a 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. Connect this LED to pin 1. (See Figure 1, where R2 is a current-limiting resistor)
According to the connection method in this figure, 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, pin 1 must be controllable, that is, it must be able to make pin 1 become high or low 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 you want P1.0 to output a high level, just write SETB P1.0, and if you want P1.0 to output a low level, just write CLR P1.0.


Now there is a way to make the computer output P1.0 high or low, but how can the computer execute this instruction? You can't just tell the computer and leave it alone. To solve this problem, there are still a few steps to take.


First, computers cannot understand instructions such as SETB CLR. We have to translate the instructions into a way that computers can understand, and then let the computer read them. What can computers understand? They only understand 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 getting these two numbers, how to get these two numbers into the microcontroller? This requires the help of a hardware tool "programmer" or "ISP download cable" (the microcontroller supports online programming, and the ISP download cable can be used, which is more convenient and quick). Of course, if you use our microcontroller development test application board, then you have both the programmer and the test board, and you only need to program. The ISP download cable and test board download program interface are shown in Figures 2 and 3.

This is the first step to microcontroller programming. It may seem simple, but it is of great significance to you. Yes, you are programming: (
Open WAVE software; write the program,

We set its name to: sy1.asm; finally, burn the generated sy1.hex into the 89S52 of the microcontroller test development board. At this time, you can see that the p1.0 light is on.

This picture shows the 8 light-emitting diodes on the experimental development board. Note that it can be switched through a jumper switch next to it (light-emitting diode and LED display switch)!


At this time, 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 you 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, you can see that the connection of the hardware circuit has not been changed. As long as you change the content written into the microcontroller, you can change the output effect of the circuit.

It can be seen that problems that are very difficult to implement with hardware can be solved easily and quickly with a single-chip microcomputer.


Keywords:MCU Reference address:Microcontroller Test 1: Light up a LED

Previous article:Using the T0 and T1 timing counter functions of the AT89S51 microcontroller
Next article:Answers to Common Exercises on MCS-51 MCU Timer/Counter

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号