资源描述
单片机电子琴设计题 目:学 院:专 业:班 级:姓 名: 完成日期:摘 要随着社会的发展进步,音乐逐渐成为我们生活中很重要的一部分,有人曾说喜欢音乐的人不会向恶。我们都会抽空欣赏世界名曲,作为对精神的洗礼。本论文设计一个基于单片机的简易电子琴。电子琴是现代电子科技与音乐结合的产物,是一种新型的键盘乐器。它在现代音乐扮演着重要的角色,单片机具有强大的控制功能和灵活的编程实现特性,它已经溶入现代人们的生活中,成为不可替代的一部分。本系统是以51系列单片机AT89C51为主控制器,附有矩阵键盘、LED显示管、扬声器组成。系统完成显示输入信息、播放相应音符等基本功能。本系统运行稳定,其优点是硬件电路简单,软件功能完善,控制系统可靠,性价比较高等,具有一定的实用和参考价值。关键词:AT89C51,矩阵键盘,LED显示管,扬声器。1 引言1.1 目的和意义单片微型计算机是大规模集成电路技术发展的产物,属第四代电子计算机,它具有高性能、高速度、体积小、价格低廉、稳定可靠、应用广泛的特点。它的应用必定导致传统的控制技术从根本上发生变革。因此,单片机的开发应用已成为高科技和工程领域的一项重大课题。 电子琴是现代电子科技与音乐结合的产物,是一种新型的键盘乐器。它在现代音乐扮演着重要的角色,单片机具有强大的控制功能和灵活的编程实现特性,它已经溶入现代人们的生活中,成为不可替代的一部分。本文的主要内容是用AT89S51单片机为核心控制元件,设计一个电子琴。以单片机作为主控核心,与键盘、扬声器等模块组成核心主控制模块,在主控模块上设有16个按键和扬声器。 本文主要对使用单片机设计简易电子琴进行了分析,并介绍了基于单片机电子琴统硬件组成。利用单片机产生不同频率来获得我们要求的音阶,最终可随意弹奏想要表达的音乐。并且本文分别从原理图,主要芯片,各模块原理及各模块的程序的调试来详细阐述。本系统是简易电子琴的设计,按下键盘矩阵中的按键会使数码管显示当前按键,扬声器播放器对应的音符。通过设计本系统可了解单片机的基本功能。对单片机的了解有一个小的飞跃。1.2 本系统主要研究内容本系统设计制作一个可演奏的电子琴。综合应用了两项设计。(1)键盘矩阵识别。即矩阵扫描,显示当前按键。(2)不同频率音符播放。可以通过按键控制16种发音。1.3 主要芯片简介AT89S51是一个低功耗,高性能CMOS 8位单片机,片内含4k Bytes ISP(In-system programmable)的可反复擦写1000次的Flash只读程序存储器,器件采用ATMEL公司的高密度、非易失性存储技术制造,兼容标准MCS-51指令系统及80C51引脚结构,芯片内集成了通用8位中央处理器和ISP Flash存储单元,功能强大的微型计算机的AT89S51可为许多嵌入式控制应用系统提供高性价比的解决方案。 AT89S51具有如下特点:40个引脚(引脚图如图1-2所示),4k Bytes Flash片内程序存储器,128 bytes的随机存取数据存储器(RAM),32个外部双向输入/输出(I/O)口,5个中断优先级2层中断嵌套中断,2个16位可编程定时计数器,2个全双工串行通信口,看门狗(WDT)电路,片内时钟振荡器。 此外,AT89S51设计和配置了振荡频率可为0Hz并可通过软件设置省电模式。空闲模式下,CPU暂停工作,而RAM定时计数器,串行口,外中断系统可继续工作,掉电模式冻结振荡器而保存RAM的数据,停止芯片其它功能直至外中断激活或硬件复位。同时该芯片还具有PDIP、TQFP和PLCC等三种封装形式,以适应不同产品的需求。2 系统分析2.1 系统组成本系统只要以51单片机为主控核心,与矩阵键盘、扬声器、LED显示管模块一起组合而成。具体如下:2.2 系统工作原理本系统扫描键盘矩阵、显示按键、扬声器发出对应音符。4X4行列式键盘识别及显示原理如下:组成键盘的按键有机械式、电容式、导电橡胶式、薄膜式多种,但不管什么形式,其作用都是一个使电路接通与断开的开关。目前微机系统中使用的键盘按其功能不同,通常可分为编码键盘和非编码键盘两种基本类型。 编码键盘:键盘本身带有实现接口主要功能所需的硬件电路。不仅能自动检测被按下的键,并完成去抖动、防串键等功能,而且能提供与被按键功能对应的键码(如ASCII码)送往CPU。所以,编码键盘接口简单、使用方便。但由于硬件电路较复杂,因而价格较贵。 非编码键盘:键盘只简单地提供按键开关的行列矩阵。有关按键的识别、键码的确定与输入、去抖动等功能均由软件完成。目前微机系统中,一般为了降低成本大多数采用非编码键盘。 键盘接口必须具有去抖动、防串键、按键识别和键码产生4个基本功能。 (1)去抖动:每个按键在按下或松开时,都会产生短时间的抖动。抖动的持续时间与键的质量相关,一般为520mm。所谓抖动是指在识别被按键是必须避开抖动状态,只有处在稳定接通或稳定断开状态才能保证识别正确无误。去抖问题可通过软件延时或硬件电路解决。 (2)防串键:防串键是为了解决多个键同时按下或者前一按键没有释放又有新的按键按下时产生的问题。常用的方法有双键锁定和N键轮回两种方法。双键锁定,是当有两个或两个以上的按键按下时,只把最后释放的键当作有效键并产生相应的键码。N键轮回,是当检测到有多个键被按下时,能根据发现它们的顺序依次产生相应键的键码。 (3)被按键识别:如何识别被按键是接口解决的主要问题,一般可通过软硬结合的方法完成。常用的方法有行扫描法和线反转法两种。行扫描法的基本思想是,由程序对键盘逐行扫描,通过检测到的列输出状态来确定闭合键,为此,需要设置入口、输出口一个,该方法在微机系统中被广泛使用。线反转法的基本思想是通过行列颠倒两次扫描来识别闭合键,为此需要提供两个可编程的双向输入/输出端口。 (4)键码产生:为了从键的行列坐标编码得到反映键功能的键码,一般在内存区中建立一个键盘编码表,通过查表获得被按键的键码。用AT89S51的并行口P1接44矩阵键盘,以P1.0P1.3作输入线,以P1.4P1.7作输出线;在数码管上显示每个按键的“0F”序号。总体电路具体原理如下:3 系统硬件设计3.1 系统硬件总体设计本系统由键盘矩阵、LED显示管、扬声器这几个部分组成,LED显示管显示当前按键,扬声器发出对应音符。硬件总体设计图如下:3.2子系统(模块)一LED显示模块如图2-2所示,利用AT89S51单片机的P0端口的P0.0P0.7连接到一个七段数码管的ah的笔段上,数码管的公共端接电源。矩阵扫描显示当前按键模块如下:3.3子系统(模块)二矩阵扫描扬声器发出对应音符模块如下:4 系统软件设计4.1 系统软件总体设计本系统的软件流程图如下:4.2 子系统一七段LED显示器内部由七个条形发光二极管和一个小圆点发光二极管组成,根据各管的极管的接线形式,可分成共阴极型和共阳极型。 LED数码管的ga七个发光二极管因加正电压而发亮,因加零电压而不以发亮,不同亮暗的组合就能形成不同的字形,这种组合称之为字形码。本系统按键显示模块软件流程图如下:4.3子系统二一首音乐是许多不同的音阶组成的,而每个音阶对应着不同的频率,这样我们就可以利用不同的频率的组合,即可构成我们所想要的音乐了,当然对于单片机来产生不同的频率非常方便,我们可以利用单片机的定时/计数器T0来产生这样方波频率信号,因此,我们只要把一首歌曲的音阶对应频率关系正确即可。利用AT89C51的内部定时器使其工作计数器模式(MODE1)下,改变计数值TH0及TL0以产生不同频率的方法产生不同音阶,例如,频率为523Hz,其周期T1/5231912s,因此只要令计数器计时956s/1s956,每计数956次时将I/O反相,就可得到中音DO(523Hz)。 计数脉冲值与频率的关系式(如式2-1所示)是: Nfi2fr 2-1式中,N是计数值;fi是机器频率(晶体振荡器为12MHz时,其频率为1MHz);fr是想要产生的频率。其计数初值T的求法如下: T65536N65536fi2fr 例如:设K65536,fi1MHz,求低音DO(261Hz)、中音DO(523Hz)、高音DO(1046Hz)的计数值。 T65536N65536fi2fr6553610000002fr65536500000/fr 低音DO的T65536500000/26263627 中音DO的T65536500000/52364580 高音DO的T65536500000/104665059本系统按键发出对应音符模块软件流程图如下:5 系统使用说明5.1 系统安装及配置说明5.1.1系统运行环境WINDOWS XP PROTEUS 7.1 SP2 Keil uv3 2.125.1.2系统安装及配置安装Protues 和keil uVsision3。5.2 系统操作说明(1)Keil下编译,产生目标HEX文件,Proteus下Programme Files选择产生的HEX文件,点击运行开始模拟。(2)开启本系统,数码管显示“-”。(3)按任意键盘,数码管显示所按下的键盘数,扬声器发出相应的音符。6 结论通过这次课程设计,我学到了不少课本上没有的知识,也锻炼了自己的动手能力,将以前学过的零散的知识串到一起。经过我长时间的设计及调试,本系统基本能实现按下键盘矩阵中的按键会使数码管显示当前按键,扬声器播放对应的音符。但由于仿真系统原因,本设计音频效果不是很好。不足之处有:1.可弹奏的音符数较少,只能在一定范围内满足用户需要。可通过改进键盘识别模块和发生模块来增加其复杂度2.音量不可调。我的综合设计主要涉及硬件和软件两方面的内容,通过这些我的硬件和软件开发能力都获得了提高。首先硬件方面,基本了解了电子产品的开发流程和所要做的工作。基本掌握了Protel99SE原理图的方法,并设计了一个单片机最小系统。通过开发板的设计和硬件搭建的过程,使我对51系单片机的接口有了更深层次的理解,熟悉了一些单片机常用的外围电路引脚和连接方法,如LED数码管,键盘等。并且我学会了分析问题解决问题的能力,加深了对所学理论知识的理解和运用。我的动手能力得到了很大的提高,创新意识得到了锻炼。参考文献1 彭伟.单片机C语言程序设计实训100例.电子工业出版社.2009年2 吴运昌模拟电子线路基础广州:华南理工大学出版社,2004年3 阎石数字电子技术基础北京:高等教育出版社,1997年4 张晓丽等数据结构与算法北京:机械工业出版社,2002年5 马忠梅等 ARM&Linux嵌入式系统教程北京:北京航空航天大学出版社,2004年6 李建忠单片机原理及应用西安:西安电子科技大学,2002年7 韩志军等.单片机应用系统设计M.机械工业出版社,20048 周润景等. Proteus在MCS-51&ARM7系统中的应用百例M.电子工业出版社,20069 马忠梅等.单片机的C语言应用程序设计M.北京航空航天大学出版社,200610 刘树中,孙书膺,王春平.单片机和液晶显示驱动器串行接口的实现J.微计算机信息,2007附录本系统总体代码如下:#include#define uchar unsigned char#define uint unsigned intuchar code DSY_Table=0xc0,0xf9,0xa4,0xb0,0x99,0x92,0x82,0xf8,0x80,0x90,0x88,0x83,0xc6,0xa1,0x86,0x8e,0xBF;uint code Tone_Delay_Table=64021,64103,64260,64400,64524,64580,64684,64777,64820,64898,64968,65030,65058,65110,65157,65178;sbit BEEP=P30;uchar KeyNo;void DelayMS(uchar x)uchar i;while(x-) for(i=0;i4)0x0F;switch(Tmp)case 1:k+=0;break;case 2:k+=4;break;case 4:k+=8;break;case 8:k+=12;break;default:return;KeyNo=k;void play_Tone() interrupt 1TH0=Tone_Delay_TableKeyNo/256;TL0=Tone_Delay_TableKeyNo%256;BEEP=BEEP;void main()P0=0xBF;TMOD=0x01;IE=0x82;while(1)P1=0xF0;if(P1!=0xF0)Keys_Scan();P0=DSY_TableKeyNo;TR0=1;elseTR0=0;DelayMS(2); 13 目 录摘要11 引言21.1 目的和意义21.2 本系统主要研究内容21.3 主要芯片简介32 系统分析32.1 系统组成32.2 系统工作原理33 系统硬件设计53.1 系统硬件总体设计53.2子系统(模块)一63.3子系统(模块)二64 系统软件设计64.1 系统软件总体设计64.2 子系统一74.3子系统二85 系统使用说明95.1 系统安装及配置说明95.1.1系统运行环境95.1.2系统安装及配置95.2 系统操作说明96 结论10参考文献11附录12g an employment tribunal claiEmployment tribunals sort out disagreements between employers and employees.You may need to make a claim to an employment tribunal if: you dont agree with the disciplinary action your employer has taken against you your employer dismisses you and you think that you have been dismissed unfairly.For more information about dismissal and unfair dismissal, seeDismissal.You can make a claim to an employment tribunal, even if you haventappealedagainst the disciplinary action your employer has taken against you. However, if you win your case, the tribunal may reduce any compensation awarded to you as a result of your failure to appeal.Remember that in most cases you must make an application to an employment tribunal within three months of the date when the event you are complaining about happened. If your application is received after this time limit, the tribunal will not usually accept i.If you are worried about how the time limits apply to you, take advice from one of the organisations listed underFurther help.Employment tribunals are less formal than some other courts, but it is still a legal process and you will need to give evidence under an oath or affirmation.Most people find making a claim to an employment tribunal challenging. If you are thinking about making a claim to an employment tribunal, you should get help straight away from one of the organisations listed underFurther help.If you are being represented by a solicitor at the tribunal, they may ask you to sign an agreement where you pay their fee out of your compensation if you win the case. This is known as adamages-based agreement. In England and Wales, your solicitor cant charge you more than 35% of your compensation if you win the case.If you are thinking about signing up for a damages-based agreement, you should make sure youre clear about the terms of the agreement. It might be best to get advice from an experienced adviser, for example, at a Citizens Advice Bureau. To find your nearest CAB, including those that give advice by e-mail, click onnearest CAB.For more information about making a claim to an employment tribunal, seeEmployment tribunals.The (lack of) air up there Watch mCayman Islands-based Webb, the head of Fifas anti-racism taskforce, is in London for the Football Associations 150th anniversary celebrations and will attend Citys Premier League match at Chelsea on Sunday.I am going to be at the match tomorrow and I have asked to meet Yaya Toure, he told BBC Sport.For me its about how he felt and I would like to speak to him first to find out what his experience was.Uefa hasopened disciplinary proceedings against CSKAfor the racist behaviour of their fans duringCitys 2-1 win.Michel Platini, president of European footballs governing body, has also ordered an immediate investigation into the referees actions.CSKA said they were surprised and disappointed by Toures complaint. In a statement the Russian side added: We found no racist insults from fans of CSKA.Age has reached the end of the beginning of a word. May be guilty in his seems to passing a lot of different life became the appearance of the same day; May be back in the past, to oneself the paranoid weird belief disillusionment, these days, my mind has been very messy, in my mind constantly. Always feel oneself should go to do something, or write something. Twenty years of life trajectory deeply shallow, suddenly feel something, do it.一字开头的年龄已经到了尾声。或许是愧疚于自己似乎把转瞬即逝的很多个不同的日子过成了同一天的样子;或许是追溯过去,对自己那些近乎偏执的怪异信念的醒悟,这些天以来,思绪一直很凌乱,在脑海中不断纠缠。总觉得自己自己似乎应该去做点什么,或者写点什么。二十年的人生轨迹深深浅浅,突然就感觉到有些事情,非做不可了。The end of our life, and can meet many things really do?而穷尽我们的一生,又能遇到多少事情是真正地非做不可?During my childhood, think lucky money and new clothes are necessary for New Year, but as the advance of the age, will be more and more found that those things are optional; Junior high school, thought to have a crush on just means that the real growth, but over the past three years later, his writing of alumni in peace, suddenly found that isnt really grow up, it seems is not so important; Then in high school, think dont want to give vent to out your inner voice can be in the high school children of the feelings in a period, but was eventually infarction when graduation party in the throat, later again stood on the pitch he has sweat profusely, looked at his thrown a basketball hoops, suddenly found himself has already cant remember his appearance.童年时,觉得压岁钱和新衣服是过年必备,但是随着年龄的推进,会越来越发现,那些东西根本就可有可无;初中时,以为要有一场暗恋才意味着真正的成长,但三年过去后,自己心平气和的写同学录的时候,突然就发现是不是真正的成长了,好像并没有那么重要了;然后到了高中,觉得非要吐露出自己的心声才能为高中生涯里的懵懂情愫划上一个句点,但毕业晚会的时候最终还是被梗塞在了咽喉,后来再次站在他曾经挥汗如雨的球场,看着他投过篮球的球框时,突然间发现自己已经想不起他的容颜。Originally, this world, can produce a chemical reaction to an event, in addition to resolutely, have to do, and time.原来,这个世界上,对某个事件能产生化学反应的,除了非做不可的坚决,还有,时间。A persons time, your ideas are always special to clear. Want, want, line is clear, as if nothing could shake his. Also once seemed to be determined to do something, but more often is he backed out at last. Dislike his cowardice, finally found that there are a lot of love, there are a lot of miss, like shadow really have been doomed. Those who do, just green years oneself give oneself an arm injection, or is a self-righteous spiritual.一个人的时候,自己的想法总是特别地清晰。想要的,不想要的,界限明确,好像没有什么可以撼动自己。也曾经好像已经下定了决心去做某件事,但更多的时候是最后又打起了退堂鼓。嫌恶过自己的怯懦,最终却发现有很多缘分,有很多错过,好像冥冥之中真的已经注定。那些曾经所谓的非做不可,只是青葱年华里自己给自己注射的一支强心剂,或者说,是自以为是的精神寄托罢了。At the moment, the sky is dark, the air is fresh factor after just rained. Suddenly thought of blue plaid shirt; Those were broken into various shapes of stationery; From the corner at the beginning of deep friendship; Have declared the end of the encounter that havent start planning. Those years, those days of do, finally, like youth, will end in our life.此刻,天空是阴暗的,空气里有着刚下过雨之后的清新因子。突然想到那件蓝格子衬衫;那些被折成各种各样形状的信纸;那段从街角深巷伊始的友谊;还有那场还没有开始就宣告了终结的邂逅计划那些年那些天的非做不可,终于和青春一样,都将在我们的人生中谢幕。Baumgartner the disappointing news: Mission aborted. r plays an important role in this mission. Starting at the ground, conditions have to be very calm - winds less than 2 mph, with no precipitation or humidity and limited cloud cover. The balloon, with capsule attached, will move through the lower level of the atmosphere (the troposphere) where our day-to-day weather lives. It will climb higher than the tip of Mount Everest (5.5 miles/8.85 kilometers), drifting even higher than the cruising altitude of commercial airliners (5.6 miles/9.17 kilometers) and into the stratosphere. As he crosses the boundary layer (called the tropopause),e can expect a lot of turbulence.The supersonic descent could happen as early as Sunda.The weatheThe balloon will slowly drift to the edge of space at 120,000 feet ( Then, I would assume, he will slowly step out onto something resembling an Olympic diving platform.Below, the Earth becomes the concrete bottom of a swimming pool that he wants to land on, but not too hard. Still, hell be traveling fast, so despite the distance, it will not be like diving into the deep end of a pool. It will be like he is diving into the shallow end. Skydiver preps for the big jumpWhen he jumps, he is expected to reach the speed of sound - 690 mph (1,110 kph) - in less than 40 seconds. Like hitting the top of the water, he will begin to slow as he approaches the more dense air closer to Earth. But this will not be enough to stop him completely.If he goes too fast or spins out of control, he has a stabilization parachute that can be deployed to slow him down. His team hopes its not needed. Instead, he plans to deploy his 270-square-foot (25-square-meter) main chute at an altitude of around 5,000 feet (1,524 meters).In order to deploy this chute successfully, he will have to slow to 172 mph (277 kph). He will have a reserve parachute that will open automatically if he loses consciousness at mach speeds.Even if everything goes as planned, it wont. Baumgartner still will free fall at a speed that would cause you and me to pass out, and no parachute is guaranteed to work higher than 25,000 feet (7,620 meters).cause there1
展开阅读全文