WOSEN LIGHTING TECHNOLOGY LIMITED

WOSEN LIGHTING TECHNOLOGY LIMITED

Dom> Blog> Use the single-chip button to start and stop the led light program programming tutorial

Use the single-chip button to start and stop the led light program programming tutorial

February 27, 2023

MCU button start and stop led light program

#include

Void Delay(unsigned int t); sbit key=P3^2; // corresponding to the s19 button on the microcontroller development board

Void main (void)

{

While (1) / / after the function starts, it is always detecting whether the button is pressed

{

If(key==0) {

Unsigned char i; //Define an unsigned char type local variable i from 0 to 255

P0 = 0x7f; / / assign the initial value, the first light on the right lights up

For(i=0;i<8;i++) //Add a for loop, indicating that the program loop in the for loop is executed 8 times.

{

Delay (50000);

P0>>=1; // Move one bit to the right.

P0=P0|0x80; //After shifting right, the left end is automatically assigned 0, so the statement needs to be assigned 1

}

}

Else

{

P0=0x00;

}

} }

Void Delay(unsigned int t)

{

While(--t);

}

Skontaktuj się z nami

Author:

Ms. Mandy

Phone/WhatsApp:

+8613425434349

Wszystkie produkty
You may also like
Related Categories

Wyślij je do tym dostawcy

Przedmiot:
Email:
wiadomość:

Your message must be betwwen 20-8000 characters

  • Wyślij zapytanie

Copyright © 2024 WOSEN LIGHTING TECHNOLOGY LIMITED All rights reserved.

We will contact you immediately

Fill in more information so that we can get in touch with you faster

Privacy statement: Your privacy is very important to Us. Our company promises not to disclose your personal information to any external company with out your explicit permission.

Wysłać