51 microcontroller learning-button control LED

Publisher:CuriousObserverLatest update time:2022-12-14 Source: zhihu Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Press the button once and the LED light will flash once.


#include

void Delay(unsigned int xms) //@12.000MHz

{

unsigned char i, j;

while(xms)

{

i = 2;

j = 239;

do

{

while (--j);

} while (--i);

xms--;

}

}


void main()

{

//P2=0xFE;

while(1)

{if(P3_1==0)

       {

Delay(20);

while(P3_1==0);

Delay(20);

P2_0=~P2_0;

        }

}

}


Press once to change once

2. Press the button once and the LED will shift once.


#include


void Delay(unsigned int xms) //@12.000MHz

{

unsigned char i, j;

while(xms--)

{

i = 2;

j = 239;

do

{

while (--j);

} while (--i);

}

}


void main()

{

unsigned char i=0;

P2=~0x01;

while(1)

{

if(P3_1==0)

{

Delay(20);

while(P3_1==0);

Delay(20);

i++;

if(i>=8)

i=0;

P2=~(0x01< /*i++;

P2=~i;*/

}

if(P3_0==0)

{

Delay(20);

while(P3_0==0);

Delay(20);

if(i==0)

i=7;

else

i--;

P2=~(0x01< /*i++;

P2=~i;*/

}

}

}


Press once to shift once


Reference address:51 microcontroller learning-button control LED

Previous article:51 single chip microcomputer - digital tube display
Next article:51 microcontroller - memory (1)

Recommended ReadingLatest update time:2024-11-16 12:25

ARM Assembly Example - Button LED (Loop)
Assembly programming is a very good entry point for learning hardware. Although it is more convenient to write programs in C, if you want to truly understand a piece of hardware, you still have to work hard on the architecture and assembly instructions. Below is a basic ARM assembler program that presses a key and d
[Microcontroller]
LED lighting market is going to take off, reliable driver power is the key
    In addition to the high cost, another major obstacle that prevents LED lighting from entering large-scale commercial applications today is the mismatch of power supply life and insufficient reliability. In short, the real bottleneck for large-scale application of LED lighting (especially LED street lights) lies in
[Power Management]
arm7 Litian Electronics lpc2148 GPIO 2 single-channel LED control experiment
Note: This development board of Litian Electronics is different from Zhou Ligong's LPC2131. On Zhou Ligong's development board, you can use a jumper stick to choose whether to use the 595 driver. When Zhou Ligong conducted the GPIO output experiment - single-channel LED control experiment in his textbook, he directly
[Microcontroller]
arm7 Litian Electronics lpc2148 GPIO 2 single-channel LED control experiment
Highly Efficient 28 V, 3.3 A LED Driver Design for LED Street Light Applications
As LEDs continue to improve in almost every aspect of performance and cost, LED lighting is being used in an increasingly wide range of applications, among which LED street lights are a focus of industry attention. As the leading supplier of high-performance silicon solutions for energy-efficient electronic products,
[Power Management]
Highly Efficient 28 V, 3.3 A LED Driver Design for LED Street Light Applications
Apple's MacBook Air and iPad Pro series all use mini-LED, to be released in 2022
According to DigiTimes, Apple's next-generation MacBook Air will be equipped with a mini-LED screen and will be launched in 2022. DigiTimes previously said that the MacBook Air will be equipped with a mini-LED screen in the future, but the media has reiterated this statement, citing industry sources as saying that App
[Mobile phone portable]
2416 Development Record 3: Simple LED Driver and Application
Having written the helloworld driver, let’s write some real drivers. The simplest one is the LED driver.  Refer to the mini2440 LED driver writing method. Write a hybrid driver (for the first simple driver, there are many benefits) Driver source code The source code of the driver is as follows: #include  #includ
[Microcontroller]
Analysis of "Process Capability Index" in LED Chip Production
In the production process of chips, they will go through many processes such as doping, layering, lithography and heat treatment, and each step must meet extremely demanding physical property requirements. However, even the most mature process has variations between different locations, between different wafers, betwe
[Power Management]
Analysis of
A brief discussion on the design of LED display screen in switching power supply
     The switching power supply for LED is a single-output AC-DC external power supply powered by the grid power supply and with a rated voltage not exceeding 600V. The environment of outdoor LED switching power supplies is more severe than that of indoor ones, so it is more representative to select outdoor LED switc
[Power Management]
A brief discussion on the design of LED display screen in switching power supply
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

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号