51 MCU Self-study Notes (IV) - Lighting up LED lights and running lights

Publisher:binggegeLatest update time:2021-07-28 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

LED Light

LED stands for semiconductor light emitting diode, which is made of semiconductor materials. It is a light-emitting device that directly converts electrical energy into light energy and electrical signals into light signals. It has the characteristics of low power consumption, high brightness, bright colors, vibration resistance, long life (normal light emission time is 80,000-100,000 hours), cold light source, etc. It is a real "green lighting". Actual picture:

insert image description here

The symbol of LED in the circuit diagram is:

insert image description here

It has the basic characteristics of a diode, that is, it conducts in the forward direction and is cut off in the reverse direction. To light up the LED, an operating current needs to flow in the forward direction.


The operating voltage drop of different LED lights is different. The operating voltage drop range of ordinary light-emitting diodes is: 1.6-2.1V. The operating current is: 1-20mA.


Light up the LED in the microcontroller

Schematic diagram of LED module in single chip microcomputer:

insert image description here

By observing the circuit schematic, it can be concluded that to light up the small LED light on the development board, you only need to control the P2 port to output a low level (that is, assign a value of "0" to the P2 port).


1. Light up all LED lights on the microcontroller

code show as below:


#include


sbit LED1 = P2^0;

sbit LED2 = P2^1;

sbit LED3 = P2^2;

sbit LED4 = P2^3;

sbit LED5 = P2^4;

sbit LED6 = P2^5;

sbit LED7 = P2^6;

sbit LED8 = P2^7;


void main()

{

  LED1 = 0;

  LED2 = 0;

  LED3 = 0;

  LED4 = 0;

  LED5 = 0;

  LED6 = 0;

  LED7 = 0;

  LED8 = 0;

}


The results are as follows:

insert image description here

2. The LED light flashes

Code:


#include


unsigned int i;


void main()

{

  while(1)

  {

    P2 = 0;

    i = 65535;

    while(i--);

    P2 = 0xff;

    i = 65535;

    while(i--);

  }

}


3. Flowing lights

Code:


#include

#include


#define uint unsigned int

#define uchar unsigned char


uchar temp;

void delay(uint z)

{

  uint x,y;

  for(x = z;x > 0;x--)

     for(y = 114;y > 0;y--)

}


void main()

{

   temp = 0xfe;

   P2 = temp;

   delay(100);

   while(1)

   {

      temp = _crol_(temp, 1);

      P2 = temp;

      delay(100);

   }

}



Reference address:51 MCU Self-study Notes (IV) - Lighting up LED lights and running lights

Previous article:51 MCU Self-study Notes (V) - Buzzer
Next article:51 MCU Self-study Notes (Part 3) - Basics of Electronic Circuits

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components
Guess you like

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号