您好,欢迎访问三七文档
当前位置:首页 > 电子/通信 > 综合/其它 > 基于单片机的电子琴发声控制系统
2011年11月25日摘要本设计是基于单片机的模拟电子琴发声控制系统,该控制系统的主要控制部件是AT89S52,晶振频率为11.0592MHz,发声部件为蜂鸣器,显示部件为七段数码管,十个按键作为输入端。设计内容:设置8个音符按键发出1(do)、2(re)、3(mi)、4(fa)、5(so)、6(la)、7(xi)、1(do),为一组八度音阶;设置1个按键调节音调高低(低八度音阶为一组,中八度音阶为一组,高八度音阶为一组),通过识别按键的次数来调出一组八度音阶,供人们演奏,在按键按下的同时由数码管输出对应的音阶数值;另外设置一个播放按键,当判断按键按下时,自动播放内存的音乐,可以随时中断音乐。设计方法:软件部分由扫描按键发声并显示和音乐自动播放两部分构成,故本设计通过判断一个按键的两种状态而在两个部分之间进行切换,每种状态对应一个指定部分,从而保证两种状态的正常切换。按键的扫描采用4*2矩阵形式,节省了输出端口。硬件部分的设计主要包括按键排列、数码管显示和蜂鸣器部分,本设计P1口用作对按键的扫描,P2口用作数码管显示,所以矩阵按键和数码管的排列均就近I/O口焊接,布局合理。数码管显示部分通过限流电阻接P2口,无译码器,考虑到输出的数值,本部分设计由软件部分实现指定数值输出。蜂鸣器通过PNP型三极管8550接P3口,8550可以实现音频的放大。蜂鸣器与数码管就近排列,以达到输出一致的效果。设计成果:按照本设计的设计理念,设计成功!该控制系统能准确实现按键扫描,音符、音阶的调用准确无误,同时能显示音符和音阶数值,但受数码管限制,无法同时显示音符1和高一阶音符1(本设计中以8代替);能实现按键控制音乐的自动播放,当检测到控制按键按下时,即可启动音乐自动播放。本设计简单实用,方便操作,系统稳定,编程简单,能满足单片机初学者对单片机技术的追求,也能满足音乐初学者学习乐器的的基本需求。目录摘要·····························································································-0-1概述··························································································-1-1.1课题简介···········································································-1-1.2仿真技术与软硬件技术的结合················································-1-1.3单片机简介········································································-1-2系统总体方案及硬件设计······························································-3-2.1总体方案············································································-3-2.2按键矩阵············································································-4-2.3数码管显示·········································································-4-2.4蜂鸣器模块·········································································-4-3软件设计····················································································-5-3.1播放音乐部分······································································-5-3.2扫描按键部分······································································-7-3.3数码管显示·······································································-10-4Proteus软件仿真······································································-12-4.1键盘部分设计····································································-12-4.2蜂鸣器部分仿真·································································-12-4.3数码管部分仿真·································································-12-4.4整体仿真设计····································································-12-5课程设计体会············································································-14-5.1设计成果··········································································-14-5.2心得体会··········································································-14-参考文献·····················································································-15-书、专著:············································································-15-电子文献:············································································-15-附录1源程序代码······································································-16-附录2系统原理图······································································-27-附录3音乐简谱·········································································-28-河南理工大学本科课程设计报告-1-1概述1.1课题简介单片微型计算机室大规模集成电路技术发展的产物,属于第四代电子计算机它具有高性能、高速度、体积小、价格低廉、稳定可靠、应用广泛的特点。它的应用必定导致传统的控制技术从根本上发生变革。因此,单片机的开发应用已成为高科技和工程领域的一项重大课题。电子琴是现代电子科技与音乐结合的产物,是一种新型的键盘乐器。它在现代音乐扮演重要的角色,单片机具有强大的控制功能和灵活的编程实现特性,它已经溶入现代人们的生活中,成为不可替代的一部分。本课题的主要内容是用AT89S52单片机为核心控制元件,设计一个电子琴。以单片机作为主控核心,与键盘、扬声器等模块组成核心主控制模块,在主控模块上设有8个按键,2个控制按键和1个复位按键。一首音乐是许多不同的音阶组成的,而每个音阶对应着不同的频率,这样我们就可以利用不同的频率的组合,构成我们想演奏的那首曲目。对于单片机来说产生不同的频率非常方便,我们可以利用单片机的定时/计数器T0或T1来产生这样的方波频率信号,因此,我们只要把一首歌曲的音符对应频率关系编写正确,就可以达到我们想要的曲目。1.2仿真技术与软硬件技术的结合本设计中用到了软件Proteus,该软件是世界上著名的EDA工具(仿真软件),从原理图布图、代码调试到单片机与外围电路协同仿真,一键切换到PCB设计,真正实现了从概念到产品的完整设计。是目前世界上唯一将电路仿真软件、PCB设计软件和虚拟模型仿真软件三合一的设计平台,其处理器模型支持8051、HC11、PIC10/12/16/18/24/30/DsPIC33、AVR、ARM、8086和MSP430等。在编译方面,它也支持IAR、Keil和MPLAB等多种编译,给我们做电路设计提供方便快捷的仿真效果。在编译的过程中用到了KeiluVision3,KeilC51是51系列兼容单片机C语言软件开发系统,与汇编相比,C语言在功能上、结构性、可读性、可维护性上有明显的优势,因而易学易用。Keil提供了包括C编译器、宏汇编、连接器、库管理和一个功能强大的仿真调试器等在内的完整开发方案,通过一个集成开发环境(uVision)将这些部分组合在一起。其方便易用的集成环境、强大的软件仿真调试工具令我们事半功倍。1.3单片机简介AT89S52是一种低功耗、高性能CMOS8位微控制器,具有8K在系统可编河南理工大学本科课程设计报告-2-程Flash存储器。使用Atmel公司高密度非易失性存储器技术制造,与工业80C51产品指令和引脚完全兼容。AT89S52具有以下标准功能:8k字节Flash,256字节RAM,32位I/O口线,看门狗定时器,2个数据指针,三个16位定时器/计数器,一个6向量2级中断结构,全双工串行口,片内晶振及时钟电路。另外,AT89S52可降至0Hz静态逻辑操作,支持2种软件可选择节电模式。空闲模式下,CPU停止工作,允许RAM、定时器/计数器、串口、中断继续工作。掉电保护方式下,RAM内容被保存,振荡器被冻结,单片机一切工作停止,直到下一个中断或硬件复位为止。片上Flash允许程序存储器在系统可编程,亦适于常规编程器。在单芯片上,拥有灵巧的8位CPU和在系统可编程Flash,使得AT89S52在众多嵌入式控制应用系统中得到广泛应用。图1.30图1.31AT89S52引脚图AT89S52实物图河南理工大学本科课程设计报告-3-2系统总体方案及硬件设计2.1总体方案开始播放音乐PLAY?显示1SWITCH?播放完毕?显示0显示3显示2无动作按2次扫描按键RESET显示键值调用音符(高八度)调用音符(中八度)调用音符(低八度)发音结束否是按1次按3次图2.1总体方案流程图本设计在音乐播放与键盘扫描之间切换,蜂鸣器能发出共计22个音符,共分三个八度音阶,数码管可显示0-8,由于数码管限制,此处用8代替高一级音符do。当系统运行时,默认进入键盘扫描,并不发音,数码管显示默认值1,即键盘默认可调用低八度音符。当音乐播放键(PLAY)按下时,音乐自动播放,数码管显示0,此间可按下复位键终止音乐。当播放停止时,跳出程序段,默认回到键盘扫描状态,数码管显示返回值1。每当音阶转换控制键(SWITCH)按下时,数码管显示的数值加1,设置最大显示值是3,循环显示;此处1代表可调用低八河南理工大学本科课程设计报告-4-度音符,2代表可调用中八度音符,3代表
本文标题:基于单片机的电子琴发声控制系统
链接地址:https://www.777doc.com/doc-2536058 .html