Two buttons to control the LED program:
/*
* @Author: Wang Yunlong
* @Date: 2020-02-23 12:48:51
* @Last Modified by: Wang Yunlong
* @Last Modified time: 2020-02-23 15:37:24
*/
#include #define LED P0; //Set LED pin sbit KEY1 = P3^4; //Set key 1 pin sbit KEY2 = P3^5; //Set key 2 pin void LightLed1(); //Lighting mode 1 void LightLed2(); //Lighting mode 2 void delay(unsigned int n); //n ranges from 0 to 65535 unsigned char table1[15] = {0x7E,0xBD,0xE7,0x00,0xFF,0xDB,0xBD,0x7E,0x00,0xFF,0x00,0xFF}; unsigned char table2[] = {0xFE,0xFD,0xE7,0xEF,0xDF,0xBF,0x7E,0xFF,0x00,0xFF,0x7F,0xBF,0xDF,0xDF,,0xEF,0xF7,0xFB,0xFD,0xFE,0xFF,0x01}; void main()//two buttons { while(1) { if(KEY1==0) //key 1, press detection { delay(5); //delay 5ms if(KEY1==0) { LightLed1(); } while(!KEY1)//Release detection } if(KEY2==0) //Key 2 { delay(5); if(KEY==0) { LightLed2(); } while(!KEY2); } } } void delay(unsigned int n) //n ranges from 0 to 65535 { unsigned char i; unsigned int j; for(i = 0;i<183;i++) { for(j = 0;j ; } } } void LightLed1()//Lighting method without identifier, for() loop { unsigned char i; for(i = 0;i<15;i++) { LED = table1[i]; delay(1000); } } void LightLed2()//Lighting method with identifier, while() loop { unsigned char i = 0; while(table2[i]!=0x01) { LED = table2[i]; delay(1000); i++; } } Method 1 and method 2 are two different ideas: Method 1: for() loop: stop by the number of elements in the array Method 2: while() loop, stopped by identifier in array
Previous article:51 MCU Learning Notes——6. Interrupt method to configure timer
Next article:51 MCU Learning Notes——3. Several different ways of lighting LED (array form) and key detection, delay debounce
- Popular Resources
- Popular amplifiers
- A review of learning-based camera and lidar simulation methods for autonomous driving systems
- First Clinical Experience with Retrospective Flash Glucose Monitoring (FGM) Analysis in South Africa
- Fundamentals of Massive MIMO
- LED Street Light Design 150W Power Supply Design Guide Using FL7930B and FAN7621S
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Study on TMS570LS3137
- AT32F425-Evaluation Report-Upper Computer Development 04
- The quickest way to set the plug-in through-hole pin pad of a multi-layer board to appear on only one side in Altium Designer
- Can 'ice' be used as a semiconductor material?
- 【NUCLEO-L552ZE Review】- 8 : TrustZone
- 【Qinheng Trial】8. FlashROM
- The Agilent oscilloscope cannot be started and keeps stopping at the self-test position. What should I do?
- ESP32-C3 development board for 9.9 yuan with free shipping
- Design method of high-speed graphics frame storage using DSP+FPGA architecture
- Why can the defined pointer be used as an array?