当前位置:网站首页>A piece of music composed by buzzer (Chengdu)
A piece of music composed by buzzer (Chengdu)
2022-07-06 13:38:00 【axu_ nine hundred and ninety thousand seven hundred and seven】
The code and simulation can be downloaded through the following link
Resource link : Click to download Download free
Simulation diagram

The buzzer adopts passive buzzer speaker, You can change the pronunciation frequency by timing the timer .
By querying the frequency corresponding to the scale , Make different timing , Produce different frequencies . Then match the score , You can play music .
The operation is relatively simple .
#include<reg51.h>
sbit P10=P1^0;
sbit P17=P1^7;
void delay(unsigned char k){
unsigned char h,i,j;
for(h=0;h<k;h++){
for(i=0;i<25;i++){
for(j=0;j<20;j++);
}
}
}
/**delay Method introduction * Functional specifications : * It can be used for program delay * The delay duration is determined by the incoming parameters * The unit of the passed in parameter is ms * Such as the input “1” For delay 1ms * And so on */
void speaker(unsigned int SSC,unsigned int fre){
unsigned int j=fre;
TMOD=0x11;
TR0=1;
TR1=1;
EA=1;
ET0=1;
ET1=1;
P10=1;
TH0=SSC/256;
TL0=SSC%256;
TH1=60928/256;
TL1=60928%256;
while(j>0){
while(TF1==0){
while(TF0==0){
;
}
TR0=0;
TH0=SSC/256;
TL0=SSC%256;
P10=~P10;
TR0=1;
TF0=0;
}
TH1=60928/256;
TL1=60928%256;
TF1=0;
j--;
TF1=0;
}
j=fre;
}
void musician(unsigned int tone,unsigned int duration){
unsigned int box1[]={
0,63628,63835,64021,64103,64260,64400,64524,
// low 1(1) low 2(2) low 3(3) low 4(4) low 5(5) low 6(6) low 7(7)
64580,64680,64750,64800,64898,64968,65030,
// in 1(8) in 2(9) in 3(10) in 4(11) in 5(12) in 6(13) in 7(14)
65058,65110,65160,65178
// high 1(15) high 2(16) high 3(17) high 4(18)
};
unsigned int box2[]={
0,/*1*/30,/*2*/60,90,/*4*/120,150,/*6*/150,210,240,270,300,
// Time value
//0.1S(1)~1S(10)
};
speaker(box1[tone],box2[duration]);
P10=1;
delay(20);
}
void main(){
while(P17==0){
musician(12,6);
musician(12,2);
musician(10,2);
musician(12,2);
musician(13,4);
musician(13,2);
musician(10,4);
musician(9,2);
musician(8,2);
musician(5,1);
musician(6,1);
musician(8,2);
musician(9,2);
musician(10,2);
musician(9,2);
musician(10,6);
musician(12,6);
musician(12,2);
musician(10,2);
musician(12,2);
musician(13,4);
musician(13,2);
musician(10,4);
musician(9,2);
musician(8,2);
musician(5,1);
musician(6,1);
musician(8,2);
musician(9,2);
musician(12,2);
musician(9,2);
musician(8,6);
musician(12,2);
musician(10,2);
musician(9,2);
musician(8,6);
musician(5,4);
}
}
边栏推荐
- Arduino+ water level sensor +led display + buzzer alarm
- Solution: warning:tensorflow:gradients do not exist for variables ['deny_1/kernel:0', 'deny_1/bias:0',
- 【九阳神功】2016复旦大学应用统计真题+解析
- Database operation of tyut Taiyuan University of technology 2022 database
- Floating point comparison, CMP, tabulation ideas
- Thoroughly understand LRU algorithm - explain 146 questions in detail and eliminate LRU cache in redis
- 4. Binary search
- [au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP
- [the Nine Yang Manual] 2019 Fudan University Applied Statistics real problem + analysis
- 5月27日杂谈
猜你喜欢

5. Download and use of MSDN

C language to achieve mine sweeping game (full version)

3.输入和输出函数(printf、scanf、getchar和putchar)

强化学习系列(一):基本原理和概念

fianl、finally、finalize三者的区别

MySQL锁总结(全面简洁 + 图文详解)

(ultra detailed onenet TCP protocol access) arduino+esp8266-01s access to the Internet of things platform, upload real-time data collection /tcp transparent transmission (and how to obtain and write L

Data manipulation language (DML)

Change vs theme and set background picture

更改VS主题及设置背景图片
随机推荐
Floating point comparison, CMP, tabulation ideas
[during the interview] - how can I explain the mechanism of TCP to achieve reliable transmission
西安电子科技大学22学年上学期《信号与系统》试题及答案
[modern Chinese history] Chapter 9 test
C language Getting Started Guide
Quickly generate illustrations
The latest tank battle 2022 - full development notes-3
Comparison between FileInputStream and bufferedinputstream
MySQL中count(*)的实现方式
Arduino+ water level sensor +led display + buzzer alarm
2.C语言初阶练习题(2)
5. Function recursion exercise
优先队列PriorityQueue (大根堆/小根堆/TopK问题)
The latest tank battle 2022 full development notes-1
4.二分查找
Pit avoidance Guide: Thirteen characteristics of garbage NFT project
Conceptual model design of the 2022 database of tyut Taiyuan University of Technology
FAQs and answers to the imitation Niuke technology blog project (III)
[au cours de l'entrevue] - Comment expliquer le mécanisme de transmission fiable de TCP
MPLS experiment