MAGE16单片机应用音乐演奏.ppt

上传人:仙人指路1688 文档编号:2210398 上传时间:2023-01-31 格式:PPT 页数:14 大小:556.02KB
返回 下载 相关 举报
MAGE16单片机应用音乐演奏.ppt_第1页
第1页 / 共14页
MAGE16单片机应用音乐演奏.ppt_第2页
第2页 / 共14页
MAGE16单片机应用音乐演奏.ppt_第3页
第3页 / 共14页
MAGE16单片机应用音乐演奏.ppt_第4页
第4页 / 共14页
MAGE16单片机应用音乐演奏.ppt_第5页
第5页 / 共14页
点击查看更多>>
资源描述

《MAGE16单片机应用音乐演奏.ppt》由会员分享,可在线阅读,更多相关《MAGE16单片机应用音乐演奏.ppt(14页珍藏版)》请在三一办公上搜索。

1、MAGE16单片机应用,音乐演奏,声音插件:声音输入接PORTD.7或PORTB.3口。经晶体管电路放大后,用蜂鸣器发声。,例五、音阶演奏Config pind.7=OutputSound Portd.7,500,2000 Sound Portd.7,561,1783 Sound Portd.7,630,1588Sound Portd.7,667,1500Sound Portd.7,750,1333Sound Portd.7,842,1188Sound Portd.7,945,1058Sound Portd.7,1000,1000End,按钮与发光二极管插件电路,1/定义D.7为输出,接声音插

2、件的放大器输入。2/后数是分频数(除数),决定音的高低。数值越大,音高的频率越低。3/前、后两个数值的乘积决定音的时值(发声时间长短)。4/本例的8个音为1 2 3 4 5 6 7 i 时值相同。注意相同时值,不同音高时前数的差异。,结论:1、相同时值,前后两数的乘积相等。前数控制时值,但时值还与后数有关。2、后数半音之间(3-4、7-i之间)为1.0595 倍,其余全音之间为1.1225倍(二个1.0595倍)。3、8度音(例1-i)之间正好为2倍关系。(12个1.0595相乘等于2),例六、音阶与乐曲Config pind.7=OutputDim S As Byte,F As Byte,D

3、im A As Word,B As Word,C As Word Restore MusicDoRead S Read FIf S=0 Then Exit DoA=8000/FB=A*SC=F*5Sound Portd.7,B,CWaitms 10LoopEnd,Music:Data 8,214,8,190,8,170,8,160,8,143,8,127,8,113,8,107Data 8,107,8,113,8,127,8,143,8,160,8,170,8,190,8,214Data 16,252,8,189,8,168,12,150,4,142,8,150,8,189Data 12,16

4、8,4,168,8,189,8,224,32,189Data 16,252,8,189,8,168,12,150,4,142,8,126,8,189Data 12,142,4,150,8,126,4,168,4,150,32,168,0,0注:时值(S)1=1/8拍 2=1/4拍 4=1/2拍 8=1拍 16=2拍 32=4拍,参考分频数(F):,例七、音乐选曲程序:Config Pina.7=InputConfig Pind.7=OutputPorta.7=1 接上拉电阻Dim S As Byte,F As Byte,P As Byte,E As ByteDim B As Word,C As

5、 Word,A As WordWait 2E=Pina And&B10000000If E=128 Then Restore Music2If E=0 Then Restore Music1,DoRead S:Read FIf S=0 Then Exit DoA=8000/FB=A*SC=F*5Sound Portd.7,B,CWaitms 10LoopEndMusic1:Data 16,252,8,189-0,0Music2:Data 16,254,12,214-0,0,四个按钮选曲程序段DoWaitms 20E=Pinc And&B11110000Loop Until E 240If E=112 Then Portc=&B00001000If E=176 Then Portc=&B00000100If E=208 Then Portc=&B00000010If E=224 Then Portc=&B00000001Waitms 500Portc=&B00000000If E=112 Then Restore Music1If E=176 Then Restore Music2If E=208 Then Restore Music3If E=224 Then Restore Music4,参考分频数(F):,

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号