STC89C52 microcontroller lights up the LED light

Publisher:蓝天飞行Latest update time:2022-10-18 Source: csdnKeywords:STC89C52 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Light up the LED light

1. What is LED

The full name of LED is semiconductor light-emitting diode. It is made of semiconductor materials and is a light-emitting device that directly converts electrical energy into light energy and electrical signal into optical signal. It is characterized by low power consumption, high brightness, bright colors, vibration, and long life. It has the advantages of long life (80,000-100,000 hours of normal light emission) and cold light source, making it a true "green lighting".

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-3t4DG9VG-1604912650705) (img/LEDlight.png)]

2. LED working parameters

The symbol of LED (Light Emitting Diode) in the circuit diagram is:

It has the basic characteristics of a diode: forward conduction and reverse blocking. To light up the LED, operating current needs to flow from the forward direction.


The working voltage drop of ordinary light-emitting diodes is: 1.6~2.1V.

Working current: 1~20mA.

With the passing current of the LED in the picture, we can follow Ohm's law I (current) = U (voltage) / R (resistance)

It can be calculated as 3mA.

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-EFxHmT1r-1604912650709) (img/LEDWorkingParameter.png)]

3. Schematic analysis

[The external link image transfer failed. The source site may have an anti-leeching mechanism. It is recommended to save the image and upload it directly (img-aFK0cizd-1604912650713) (img/LEDPrincipleAnalysis.png)]

4. C language knowledge

Keywords: sbit

Function: bit definition

General format: sbit identifier = address value;


For example: sbit LED1 = P1^0;

Note: The "P" in P1 in the address value must be a capital P


5. Write code

1. Turn on LED1

#include // Reference 51 header file


sbit LED1 = P1^0; // P must be uppercase to control the red light


void main(){ // After the program is compiled, the main function itself will loop

LED1 = 0; // When set to 0, input a low level and the first light of the microcontroller will light up.     

// LED1 = 1; // When set to 1, input a high level, the first light of the microcontroller will go out

}


Rendering:

Insert image description here

2. Turn on LED1, 3, 5, and 7, and turn off LED2, 4, 6, and 8;

#include

void main(){ // main function itself will loop

while(1){ // Generally, when executing a program, you need to write a while loop body to execute the code.

P1 = 0XAA; // 1010 1010   // Make LED1, 3, 5, 7 light up

}


Rendering:

Insert image description here

Keywords:STC89C52 Reference address:STC89C52 microcontroller lights up the LED light

Previous article:Light up the LED light (STC89C52RC chip)
Next article:ISIS 7 Professional Simulation - Keyed Water Lamp

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号