当前位置:网站首页>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);
}
}
边栏推荐
- 学编程的八大电脑操作,总有一款你不会
- MPLS experiment
- 凡人修仙学指针-1
- Caching mechanism of leveldb
- FAQs and answers to the imitation Niuke technology blog project (III)
- Summary of multiple choice questions in the 2022 database of tyut Taiyuan University of Technology
- [hand tearing code] single case mode and producer / consumer mode
- There is always one of the eight computer operations that you can't learn programming
- Quickly generate illustrations
- 【九阳神功】2018复旦大学应用统计真题+解析
猜你喜欢
C语言入门指南
[during the interview] - how can I explain the mechanism of TCP to achieve reliable transmission
甲、乙机之间采用方式 1 双向串行通信,具体要求如下: (1)甲机的 k1 按键可通过串行口控制乙机的 LEDI 点亮、LED2 灭,甲机的 k2 按键控制 乙机的 LED1
FAQs and answers to the imitation Niuke technology blog project (I)
Tyut Taiyuan University of technology 2022 introduction to software engineering summary
仿牛客技术博客项目常见问题及解答(二)
魏牌:产品叫好声一片,但为何销量还是受挫
优先队列PriorityQueue (大根堆/小根堆/TopK问题)
西安电子科技大学22学年上学期《基础实验》试题及答案
一段用蜂鸣器编的音乐(成都)
随机推荐
Questions and answers of "Fundamentals of RF circuits" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
Mortal immortal cultivation pointer-2
Custom RPC project - frequently asked questions and explanations (Registration Center)
Tyut Taiyuan University of technology 2022 introduction to software engineering summary
FAQs and answers to the imitation Niuke technology blog project (I)
View UI Plus 發布 1.3.1 版本,增强 TypeScript 使用體驗
【九阳神功】2017复旦大学应用统计真题+解析
学编程的八大电脑操作,总有一款你不会
西安电子科技大学22学年上学期《射频电路基础》试题及答案
C语言实现扫雷游戏(完整版)
Voir ui plus version 1.3.1 pour améliorer l'expérience Typescript
View UI Plus 发布 1.3.1 版本,增强 TypeScript 使用体验
(原创)制作一个采用 LCD1602 显示的电子钟,在 LCD 上显示当前的时间。显示格式为“时时:分分:秒秒”。设有 4 个功能键k1~k4,功能如下:(1)k1——进入时间修改。
7. Relationship between array, pointer and array
4.分支语句和循环语句
西安电子科技大学22学年上学期《基础实验》试题及答案
【毕业季·进击的技术er】再见了,我的学生时代
2. C language matrix multiplication
[during the interview] - how can I explain the mechanism of TCP to achieve reliable transmission
(超详细onenet TCP协议接入)arduino+esp8266-01s接入物联网平台,上传实时采集数据/TCP透传(以及lua脚本如何获取和编写)