您好,欢迎访问三七文档
I新疆农业大学科学技术学院课程设计报告课程名称:单片机原理与应用学生姓名:梁保军完成时间:2015年7月2日II系(部)机电工程系专业班级农电122班课程实训题目简易电子琴设计姓名梁保军组别同组实训者梁保军杨涛指导教师吴毅实训时间2015.6.15至2015.7.2指导教师评语指导教师签名:______年____月____日实训成绩III摘要本次设计为简易电子琴设计,利用8051单片机内定时器和I|O端口,设计一台简易电子琴,能通过按键进行简单的乐曲演奏。每个不同的音符对应着不同的频率,利用单片机内部定时器TO结合I|O端口来产生不同频率的方波信号改变TO的计数值即可改变不同的音符。关键词:8501单片机音符频率内部定时器IV目录一、概述···················································································································11.1课题设计目的及其意义······················································································11.2课题设计的任务与主要内容················································································1二、基本组成和原理·····································································································12.1音乐相关知识··································································································12.2简易电子琴基本原理及其框图···········································································32.2.1基本思想································································································32.2.2硬件框图································································································32.2.3软件设计流程图·······················································································43.1元器件清单及其电路图······················································································43.2单片机89C51的简介·························································································53.3键盘电路········································································································63.4振荡电路········································································································73.5复位电路········································································································73.6音频放大电路··································································································8四、系统软件的设计···································································································94.1系统的软件主程序····························································································94.2系统的软件的调试仿真···················································································12总结·······················································································································13参考文献·················································································································14附录·······················································································································15附录1简易电子琴PCB二维图···············································································15附录2简易电子琴PCB三维图···············································································151基于单片机简易电子琴一、概述1.1课题设计目的及其意义单片机(单片微型计算机)是大规模集成电路技术发展的产物,具有高性能、高速度、体积小、价格低廉、稳定可靠等特点。单片机的应用相当广泛,从平常的家用电器到航空航天系统和国防军事、尖端武器都能找到它的身影。因此,单片机的开发应用已成为高科技和工程领域的一项重大课题。随着社会的发展进步,人们的生活水平也逐步提高,音乐已经成为了我们生活中很重要的一部分,在工作和学习之余,欣赏音乐不仅使身心得到放松,同时也提高人们的精神品质和个人素养。当代,爱好音乐的年轻人越来越多,也有不少人自己练习弹奏乐器,作为业余爱好和一种放松的手段,鉴于一些乐器学习难度大需花费太多精力,且其价格太过于高昂,使得一部分有这种想法的人不得不放弃这种想法,而电子琴又是一种新型的键盘乐器,它是现代电子科技与音乐结合的产物,价格相对便宜,能够满足一般爱好者的需求,因此,在现代音乐中扮演着重要的角色。故简易电子琴的研制具有一定的社会意义。1.2课题设计的任务与主要内容本文的主要内容是用AT89C51单片机为核心控制元件,设计一个简单的电子琴。以单片机作为主控核心,与键盘、扬声器等模块组成核心主控制模块,在主控模块上设有16个按键和扬声器。定时器按设置的定时参数产生中断,由于定时参数不同,就会发出不同频率的脉冲,不同频率的脉冲经喇叭驱动电路放大滤波后,就会发出不同音调。先根据要求设计硬件电路和编写相应的程序,然后进行仿真调试,最后细心焊接硬件电路图,将程序烤入芯片中,最终达到设计目的。本系统运行稳定,其优点是硬件电路简单,软件功能完善,控制系统可靠,性价比较高等,具有一定的实用和参考价值。具体实现的功能:按下音符键可以发出相应的音符。二、基本组成和原理2.1音乐相关知识在人类还没有产生语言时,就已经知道利用声音的高低、强弱等来表达自己的思想和感情。声带、琴弦等物体振动时会发出声波,声波通过空气传播进入人耳,人们就听到了声音。声音有噪音和乐音之分振动有规律的声音是乐音,音乐中所用的声音主要是乐音。2乐音听起来有的高、有的低,这就叫做音高。音高是由发声物体振动频率的高低决定的,频率高声音就高,频率低声音就低。音持续时间的长短即时值,一般用拍数表示。休止符表示暂停发音。一首音乐是由许多不同的音符组成的,而每个音符对应着不同的频率,这样就可以利用不同的频率组合,加以拍数对应的延时,构成音乐。如果单片机要自己播放音乐就必须考虑到节拍的设置。对于AT80C51而言要产生一定频率的方波一般是先将某口线输出高电平,延迟一段时间后再输出低电平。通过改变延迟时间可以改变单片机的输出频率。单片机的延时主要有两种方式,即软件延时和使用定时/计数器延时。其中软件延时不是很精确,而电子琴电路由于每个音符的频率值要求比较严格,因此我们选用定时/计数器延时。由于本课程设计是由用户通过键盘输入弹奏乐曲的,所以节拍由用户掌握,不由程序控制。因此,我们只需弄清楚音乐中的音符和对应的频率,利用单片机的定时/计数器来产生方波频率信号即可。要产生相应的音频脉冲,只需要计算出某音频的周期,再除以2。利用计数器计时半周期,计满时使P2.0反向,然后重复计时再反向。本例中,单片机工作在12MHz时钟,使用定时器/计数器T0,工作模式为1,改变计数初值TH0、TL0就可产生不同频率的脉冲信号。例如低3MI音,频率为330Hz,其周期T=1/f=1/330=3030us,计数值N=3030/2=1515,所以每计数1515次P2.0反向。计数初值T=65536-N=64021。C调的各音符频率与计数值T的对照表如表1所示。表1C调各音符频率与计数值T对照表音符频率(HZ)简谱码(T值)音符频率(HZ)简谱码(T值)低1DO26263628#4FA#74064860#1DO#27763731中5SO78464898低2RE29463853#5SO#83164934#2RE#31163928中6LA88064968低3M33064021#693264994低4FA34964103中7SI98865030#4FA#37064185高1DO1046650583低5SO39264260#1DO#110965085#5SO#41564331高2RE117565110低6LA44064400#2RE#124565134#646664463高3M131865157低7SI49464524高4FA139765178中1DO52364580#4FA#148065198#1DO#55464633高5SO156865217中2RE58764684#5SO#166165235#2RE#62264732高6LA176065252中3M65964777#6186565268中4FA69864820高7SI1967652832.2简易电子琴基本原理及其框图2.2.1基本思想简易的电子琴系统主要是采用AT89C51单片机,单片机工作于12MHZ的时钟频率,使用其定时/计数器T0,工作模式为1,设计4*4键盘矩阵,设置成16个音,可随意弹奏想要表现的音乐,因为单片机产生的音频脉冲没有足够的驱动能力,所以用三极管放大电路实现音频的放大,保证扬声器能产生所要实现的音符声音。2.2.2硬件框图42.2.3软件设计流程图本设计采用AT89C51单片机作为核心处理器件
本文标题:简易电子琴设计
链接地址:https://www.777doc.com/doc-2096393 .html