机械基础设计

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

音乐盒实验报告专业:生产过程自动化班级:08机电(2)班姓名:何远龙指导老师:陈玉琼2010-10-08一、实验材料1、仪器设备,软件工具软件用途keil软件源程序的编译Proteus软件实现电路的仿真Progisp软件将程序下载到学习板上进行实验硬件用途万用表检测硬件电路学习板实现源程序的调试,并通过实验现象来修改程序2、元器件清单元件名称参数数量IC插座DIP401单片机89C511晶体振荡器12MHZ1瓷片电容22PF2按键4IC插座DIP81三极管2N50881电阻1K4电解电容47uF1电阻5108蜂鸣器无源式1小喇叭1放大器LM3861二、实验过程描述1、设计功能描述(1)通过改变单片机输出脉冲高低电平的保持时间和频率,可以得到音阶和调节不同的音调,运用定时中断来控制节拍,从而来演奏乐曲。(2)用数码管显示当前播放的歌曲序号。(3)通过功能键控制上,下曲目的选择以及乐曲的暂停和播放。2、原理图设计思路由P1.0口控制一个LM386功率放大器,经功率放大器控制发声器件小喇叭。当P1.0口输出低电平时,三极管导通,小喇叭通电;当P1.0口输出高电平时,三极管截止,小喇叭断电。通过连续不断周期性地改变P1.0口的高、低电平,就会产生一定频率的矩形波,小喇叭就能产生一定频率的声音,再配合延时程序控制高、低电平的持续时间,就能改变音调。由P3.2、P3.3、P3.4、P3.5分别作为开始键/停止键,暂停键、下一曲键、上一曲键。图中还将共阳级数码管相应的段选控制端用P0口控制,将数码管的公共端,也称“位选端”由P2口控制。原理图如下:3、程序设计思路,并画出流程图程序思路:初始化设置,开延时与外部中断,按下P3.2键先唱第一首,然后循环播放。若有按下P3.3键则执行暂停作用,再按一次则继续播放;若有按下P3.3,P3.4键则分别执行下一曲、上一曲功能。播放歌曲是多少数码管则显示相应的数字。流程图如下:主流程调用del20子程序First子程序判断P3.2键是否释放选曲地址清0显示码送P0口,显示位送P2口表1首地址送DPTR调用music0子程序调用next子程序RETNext子程序选曲地址加1显示码送P0口,显示位送P2口表2首地址送DPTR是=1?调用music0子程序选曲地址加1RET调用first子程序是=2?表3首地址送DPTR显示码送P0口,显示位送P2口调用music0子程序选曲地址加1是=3?是=1?是=0?表1首地址送DPTR显示码送P0口,显示位送P2口显示码送P0口,显示位送P2口调用music0子程序RETLast子程序选曲地址加1是=2?表3首地址送DPTR调用music0子程序表2首地址送DPTR显示码送P0口,显示位送P2口调用music0子程序Music0子程序中断计数单元清0查表取常数是结束符00H?恢复初始条件A清零延时1秒后,再循环是休止符FFH?P3.2键按下?P3.4键按下?P3.5键按下?音阶常数送R6R0=0?取节拍常数送R7启动T0定时器P1.0取反,按R6常数延时节拍时间到否停止T0计数,中断计数20H单元清0,DPTR加1RET调用del20子程序延时100ms调用del20子程序跳转到STARTP3.4键释放?P3.5键释放?调用next子程序调用last子程序调用del20子程序P3.2键释放?4、写出源程序与必要的注释shuzhiequ3fh;选曲目的地址songequp1.0;扬声器播放P1.0playequp3.2;播放停止键P3.2addoneequp3.4;曲目加一键P3.4suboneequp3.5;曲目减一键P3.5dulequp0;数码管段选P0口welequp2;数码管位选P2口org0000hljmpstartorg000bh;定时器0溢出中断入口地址ajmpcont;指向定时器中断程序org0013h;外部中断一入口地址ajmppause;指向外部中断程序org0100hstart:movsp,#50hmovth0,#0dbh;定时器赋初值movtl0,#0ffhmovtmod,#01hmovie,#86h;开中断movtcon,#00hDel20子程序循环次数05送R4空操作RETR4-1=0?R3-1=0?中断响应调用del20子程序P3.3键释放?R0值取反中断返回movr0,#00hmovshuzhi,#00hmain:jnbplay,first;判断P3.2键是否按下sjmpmainfirst:acalldel20jnbplay,first;判断P3.2键是否释放movshuzhi,#00hmovdul,#0f9h;显示数值1movwel,#7fh;显示位送P2口movdptr,#dat1;表1首地址送DPTRacallmusic0acallnextretnext:incshuzhi;shuzhi+1mova,shuzhicjnea,#01,loop3;A是否=1,不等就跳转到LOOP3movdptr,#dat2;表2首地址送DPTRmovdul,#0a4h;显示数值2movwel,#7fhacallmusic0incaloop3:cjnea,#02,loop4;A是否=2,不等就跳转到LOOP4movdptr,#dat3;表3首地址送DPTRmovdul,#0b0h;显示数值3movwel,#7fhacallmusic0incaloop4:cjnea,#03,next;A是否=3,不等就跳转到nextacallfirstretlast:decshuzhi;shuzhi-1mova,shuzhicjnea,#02,last1movdptr,#dat3movdul,#0b0hmovwel,#7fhacallmusic0last1:cjnea,#01,last2movdptr,#dat2movdul,#0a4hmovwel,#7fhacallmusic0last2:cjnea,#00,lastmovdptr,#dat1movdul,#0f9hmovwel,#7fhacallmusic0retmusic0:mov20h,#00h;中断计数单元清0music1:clramovca,@a+dptr;查表取音阶常数jzend0;是结束符?cjnea,#0ffh,music5;是休止符?ljmpmusic3;产生100ms停顿music5:nopkey:jnbplay,k0;判断P3.2键是否按下jnbaddone,k1;判断P3.4键是否按下jnbsubone,k2;判断P3.5键是否按下movr6,a;音阶常数送R6incdptr;DPTR+1mova,#0movca,@a+dptr;取常数送R7movr7,asetbtr0;启动定时器T0music2:nopcjner0,#0,$cplsong;输出电平取反mova,r6movr3,a;音阶常数送R3lcalldel20mova,r7;节拍常数送Acjnea,20h,music2;节拍时间到否mov20h,#00h;为取下一音阶作准备incdptrljmpmusic1music3:nop;休止100msclrtr0;关闭定时器movr2,#14h;R2=20music4:nopmovr3,#250;R3=250lcalldel20djnzr2,music4incdptr;为取下一音阶作准备ljmpmusic1end0:movr2,#200;歌曲结束后,延时1s后继续music6:movr3,#250lcalldel20djnzr2,music6k1:acalldel20;调用延时子程序jnbaddone,k1;判断P3.4键是否释放acallnextk2:acalldel20jnbsubone,k2;判断P3.5键是否释放acalllastk0:acalldel20jnbplay,k0ljmpstartretdel20:movr4,#05hdel4:nopdjnzr4,del4djnzr3,del20retcont:inc20h;计数单元+1movth0,#0dbh;重新10ms定时初值movtl0,#0ffhreti;跳出中断pause:acalldel20jnbp3.3,pause;判断P3.3键是否有释放mova,r0;把R0的值给Acpla;A值取反movr0,aretidat1:db3bh,20h,3bh,20h,30h,20h,33h,20h,3bh,80h,0ffhdb3bh,20h,3bh,20h,26h,20h,2bh,20h,26h,80h,0ffhdb26h,20h,26h,20h,20h,20h,26h,20h,2bh,20h,2bh,20h,30h,20h,33h,10h,33h,10hdb3bh,60h,40h,20h,4ch,80h,0ffhdb3bh,20h,3bh,20h,30h,20h,33h,20h,3bh,80h,0ffhdb3bh,20h,3bh,20h,26h,20h,2bh,20h,26h,80h,0ffhdb26h,20h,26h,20h,20h,20h,26h,20h,2bh,20h,2bh,20h,2bh,20h,30h,20hdb33h,20h,3bh,20h,3bh,20h,40h,2bh,3bh,80h,0ffhdb19h,20h,1ch,40h,26h,20h,19h,20h,1ch,40h,26h,20h,0ffhdb20h,20h,1ch,20h,1ch,20h,20h,20h,26h,80h,0ffhdb19h,20h,1ch,40h,26h,20h,19h,20h,1ch,40h,26h,20h,0ffhdb20h,20h,1ch,20h,1ch,20h,20h,20h,26h,80h,0ffhdb2bh,20h,2bh,40h,3bh,20h,2bh,20h,2bh,40h,2bh,20h,0ffhdb26h,20h,2bh,20h,2bh,20h,30h,20h,2bh,80h,0ffhdb2bh,20h,2bh,40h,3bh,20h,30h,20h,30h,40h,2bh,20h,0ffhdb33h,20h,3bh,20h,3bh,20h,40h,20h,3bh,80h,0ffh,0ffhdat2:db18h,30h,1ch,10h,20h,40h,1ch,10hdb18h,10h,20h,10h,1ch,10h,18h,40hdb1ch,20h,20h,20h,1ch,20h,18h,20hdb20h,80h,0ffh,20h,30h,1ch,10h,18hdb20h,15h,20h,1ch,20h,20h,20h,26hdb40h,20h,20h,2bh,20h,26h,20h,20hdb20h,30h,80h,0ffh,20h,20h,1ch,10hdb18h,10h,20h,20h,26h,20h,2bh,20hdb30h,20h,2bh,40h,20h,20h,1ch,10hdb18h,10h,20h,20h,26h,20h,2bh,20hdb30h,20h,2bh,40h,20h,30h,1ch,10hdb18h,20h,15h,20h,1ch,20h,20h,20hdb26h,40h,20h,20h,2bh,20h,26h,20hdb20h,20h,30h,80h,20h,30h,1ch,10hdb20h,10h,1ch,10h,20h,20h,26h,20hdb2bh,20h,30h,20h,2bh,40h,20h,15hdb1fh,05h,20h,10h,1ch,10h,20h,20hdb26h,20h,2bh,20h,30h,20h,2bh,40hdb20h,30h,1ch,10h,18h,20h,15h,20hdb1ch,20h,20h,20h,26h,40h,20h,20hdb2bh,20h,26h,20h,20h,20h,30h,30hdb20h,30h,1ch,10h,18h,4

1 / 14
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功