Circuit Diagram:
uchar t;
uchar i;
P1 = 0xff;
Reference address:Four key pronunciations designed by single chip microcomputer
Program implementation functions:
To achieve four buttons to emit different tones, the code is as follows:
#include
#define uchar unsigned char
#define uint unsigned int
sbit BEEP = P3^7; //Assign P3.7 interface to BEEP (connect to speaker)
sbit K1 = P1^4; //Assign P1.4 interface to K1
sbit K2 = P1^5; //Assign P1.5 interface to K2
sbit K3 = P1^6; //Assign P1.6 interface to k3
sbit K4 = P1^7; //Assign the p1.7 interface to K4
//Delay
void DelayMS(uint x)
{
while(x--)
{
for(t=0;t<120;t++);
}
}
void Play(uchar t)
{
for(i=0;i<100;i++)
{
BEEP = ~BEEP; //Invert once every half cycle
DelayMS(t); //delay
}
BEEP = 0;
}
void main()
{
while(1)
{
if(K1==0) Play(1);
if(K2==0) Play(2);
if(K3==0) Play(3);
if(K4==0) Play(4);
}
}
Previous article:LED display count
Next article:Single chip microcomputer designed circular lighting
- Popular Resources
- Popular amplifiers
Recommended Content
Latest Microcontroller Articles
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- 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
MoreDaily News
- 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
Guess you like
- EEWORLD University ---- Embedded Linux Development Introduction Video
- What is a smart WiFi module? What are the types and functions of wireless router gateway control modules?
- Case! EMI rectification of power supply
- Reasons for choosing 4-20mA for flow meter
- I want to ask why this motor cannot start? The voltage from B+ to B- is normal, but after starting, the voltage from B+ to M- jumps and the motor vibrates.
- Summary of equivalent circuits of common electronic components
- Comparison of several MicroPython IDEs
- [RVB2601 Creative Application Development] @fxyc87 RVB2601-Snake Game
- AD7190 Issues
- Pingtouge Xuantie VirtualZone: Security extension based on RISC-V architecture