After the key is pressed for the first time, the buzzer sounds;
After pressing the key for the second time, the buzzer stops.
#include sbit beep=P1^5; sbit key=P3^1; unsigned int mode; //define a mode void delay(unsigned int i) { while(i--); } void voice() { if(mode) { beep=~beep; delay(100); //Changing the delay can make the buzzer emit different sounds } else { beep=0; } } void main() { while(1) { voice(); if(key==0) { delay(1000); if(key==0) { mode=!mode; while(!key); } } } }
Previous article:51 single chip matrix button controls the digital tube to display 0~F
Next article:51 single chip LED water light
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Huawei's Strategic Department Director Gai Gang: The cumulative installed base of open source Euler operating system exceeds 10 million sets
- Download from the Internet--ARM Getting Started Notes
- Learn ARM development(22)
- Learn ARM development(21)
- Learn ARM development(20)
- Learn ARM development(19)
- Learn ARM development(14)
- Learn ARM development(15)
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- MAX40026 280ps High-Speed Comparator
- A novice asks for advice on the MSP430 interrupt flag PxIFG
- ST MEMS sensor official Chinese technical documentation summary (continuously updated)
- What is 5G Super Uplink?
- Outsourcing of small brushless sensor driver
- Single-ended forward converter
- Bootloader issue of CH579
- SPI to USB CDC
- Battery Pack SOC
- Strange phenomenon of screen display and USB!