1 / 14

MAGE16 单片机应用

MAGE16 单片机应用. 音乐演奏. 声音插件: 声音输入接 PORTD.7 或 PORTB.3 口。 经晶体管电路放大后,用蜂鸣器发声。. 例五、 音阶演奏 Config pind.7 = Output Sound Portd.7 ,500 , 2000 Sound Portd.7 ,561 , 1783 Sound Portd.7 ,630 , 1588 Sound Portd.7 ,667 , 1500 Sound Portd.7 ,750 , 1333 Sound Portd.7 ,842 , 1188

nelson
Download Presentation

MAGE16 单片机应用

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. 声音插件: 声音输入接PORTD.7或PORTB.3口。 经晶体管电路放大后,用蜂鸣器发声。

  3. 例五、 音阶演奏 Config pind.7 = Output Sound Portd.7 ,500 , 2000 Sound Portd.7 ,561 , 1783 Sound Portd.7 ,630 , 1588 Sound Portd.7 ,667 , 1500 Sound Portd.7 ,750 , 1333 Sound Portd.7 ,842 , 1188 Sound Portd.7 ,945 , 1058 Sound Portd.7 ,1000 , 1000 End

  4. 按钮与发光二极管插件电路

  5. 1/定义D.7为输出,接声音插件的放大器输入。 2/后数是分频数(除数),决定音的高低。 数值越大,音高的频率越低。 3/前、后两个数值的乘积决定音的时值 (发声时间长短)。 4/本例的8个音为1 2 3 4 5 6 7 i 时值相同。 注意相同时值,不同音高时前数的差异。

  6. 结论: 1、相同时值,前后两数的乘积相等。 前数控制时值,但时值还与后数有关。 2、后数半音之间(3-4、7- i之间)为1.0595 倍, 其余全音之间为1.1225倍(二个1.0595倍)。 3、8度音(例1- i)之间正好为2倍关系。 (12个1. 0595相乘等于2)

  7. 例六、 音阶与乐曲 Config pind.7 = Output Dim S As Byte , F As Byte, Dim A As Word , B As Word , C As Word Restore Music Do Read S Read F If S = 0 Then Exit Do A = 8000 / F B = A * S C = F * 5 Sound Portd.7 , B , C Waitms 10 Loop End

  8. Music: Data 8 , 214 , 8 , 190 ,8 , 170 , 8 , 160 , 8 , 143 , 8 , 127 , 8 , 113 , 8 , 107 Data 8 , 107, 8 , 113 , 8 , 127 , 8 , 143 , 8 , 160 , 8 , 170 , 8 , 190 , 8 , 214 Data 16 , 252 , 8 , 189 , 8 , 168 , 12 , 150 , 4 , 142 , 8 , 150 , 8 , 189 Data 12 , 168 , 4 , 168 , 8 , 189 , 8 , 224 , 32 , 189 Data 16 , 252 , 8 , 189 , 8 , 168 , 12 , 150 , 4 , 142 , 8 , 126 , 8 , 189 Data 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拍

  9. 参考分频数(F):

  10. 例七、 音乐选曲程序: Config Pina.7 = Input Config Pind.7 = Output Porta.7 = 1接上拉电阻 Dim S As Byte , F As Byte , P As Byte , E As Byte Dim B As Word , C As Word , A As Word Wait 2 E = Pina And &B10000000 If E = 128 Then Restore Music2 If E = 0 Then Restore Music1

  11. Do Read S : Read F If S = 0 Then Exit Do A = 8000 / F B = A * S C = F * 5 Sound Portd.7 , B , C Waitms 10 Loop End Music1: Data 16 , 252 , 8 , 189 --------0,0 Music2: Data 16 , 254 , 12 , 214 --------0,0

  12. 四个按钮选曲程序段 Do Waitms 20 E = Pinc And &B11110000 Loop Until E < 240 If E = 112 Then Portc = &B00001000 If E = 176 Then Portc = &B00000100 If E = 208 Then Portc = &B00000010 If E = 224 Then Portc = &B00000001 Waitms 500 Portc = &B00000000 If E = 112 Then Restore Music1 If E = 176 Then Restore Music2 If E = 208 Then Restore Music3 If E = 224 Then Restore Music4

  13. 参考分频数(F):

More Related