当前位置:网站首页>一段用蜂鸣器编的音乐(成都)
一段用蜂鸣器编的音乐(成都)
2022-07-06 09:20:00 【axu_990707】
代码和仿真可通过如下链接下载
资源链接: 点击下载 下载免费
仿真图示
蜂鸣器采用无源蜂鸣器speaker,可以通过定时器定时从而改变发音频率。
通过查询音阶对应的频率,制作出不同的定时,产生不同的频率。然后配合曲谱,即可奏乐。
操作较为简单。
#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方法使用介绍 *功能说明: *可以作程序延时使用 *延时时长由传入的参数决定 *传入参数的单位为ms *如输入“1”代表延时1ms *以此类推 */
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,
//低1(1) 低2(2) 低3(3) 低4(4) 低5(5) 低6(6) 低7(7)
64580,64680,64750,64800,64898,64968,65030,
//中1(8) 中2(9) 中3(10) 中4(11) 中5(12) 中6(13) 中7(14)
65058,65110,65160,65178
//高1(15) 高2(16) 高3(17) 高4(18)
};
unsigned int box2[]={
0,/*1*/30,/*2*/60,90,/*4*/120,150,/*6*/150,210,240,270,300,
//时值
//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);
}
}
边栏推荐
- 【九阳神功】2020复旦大学应用统计真题+解析
- 魏牌:产品叫好声一片,但为何销量还是受挫
- IPv6 experiment
- [Topic terminator]
- fianl、finally、finalize三者的区别
- Service ability of Hongmeng harmonyos learning notes to realize cross end communication
- arduino+DS18B20温度传感器(蜂鸣器报警)+LCD1602显示(IIC驱动)
- 关于双亲委派机制和类加载的过程
- Share a website to improve your Aesthetics
- String class
猜你喜欢
fianl、finally、finalize三者的区别
TYUT太原理工大学2022数据库题库选择题总结
受检异常和非受检异常的区别和理解
Cookie和Session的区别
7. Relationship between array, pointer and array
System design learning (III) design Amazon's sales rank by category feature
3. Number guessing game
(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
System design learning (I) design pastebin com (or Bit.ly)
MySQL Database Constraints
随机推荐
View UI Plus 发布 1.3.1 版本,增强 TypeScript 使用体验
7. Relationship between array, pointer and array
TYUT太原理工大学往年数据库简述题
5. Download and use of MSDN
Inheritance and polymorphism (Part 2)
[Topic terminator]
Cloud native trend in 2022
Differences and application scenarios between MySQL index clock B-tree, b+tree and hash indexes
Questions and answers of "basic experiment" in the first semester of the 22nd academic year of Xi'an University of Electronic Science and technology
【九阳神功】2020复旦大学应用统计真题+解析
最新坦克大战2022-全程开发笔记-1
5. Function recursion exercise
六种集合的遍历方式总结(List Set Map Queue Deque Stack)
List set map queue deque stack
魏牌:产品叫好声一片,但为何销量还是受挫
Quickly generate illustrations
最新坦克大战2022-全程开发笔记-2
ROS machine voice
MySQL Database Constraints
MySQL中count(*)的实现方式