'(
找简谱换算的,不懂音乐,五音不全,不知道跑调没有。
蜂鸣器也可以,但音质太差。
修改计算Duration , Pulses的系数,可以改变音调。
PB0接SPEAKER。
说明一下数据格式:
1234567基本脉冲数据
Data 956% , 864% , 758% , 716% , 638% , 568% , 506%
Data数据结构
Data 100% , 11 , 1
每1行data为1个音,第1个数是节拍;第2个数是音调,对应1234567,以1为例,顶着点为21,踩着点为1,上下都没点是11;第3个数是停顿长短,0为不停顿。
Data -1% , 0 , 0 为结束标记
含2首歌数据,Restore相应标签即可
')
$regfile = "m16def.dat"
$crystal = 7372800
Ddrb = &HFF
Dim Duration As Integer
Dim Pulses As Integer
Dim Pause As Byte
Dim Mybyte As Byte
Dim Myinteger As Integer
Dim Myword As Word
Dim Mysingle As Single
Dim K As Byte
Dim Tone(1 To 7) As Integer
Restore Tone
For Mybyte = 1 To 7
Read Tone(mybyte)
Next
Do
Restore Myheart
Do
Read Duration
Read Mybyte
Read Pause
If Duration = -1 Then
Exit Do
End If
Pulses = Mybyte
If Pulses > 20 Then
Pulses = Pulses - 20
Pulses = Tone(pulses)
Pulses = Pulses / 2
Pulses = Pulses - 8
Else
If Pulses > 10 Then
Pulses = Pulses - 10
Pulses = Tone(pulses)
Else
Pulses = Tone(pulses)
Pulses = Pulses * 2
End If
End If
Mysingle = Duration * 6
Duration = Fix(mysingle)
Mysingle = Pulses * .6
Pulses = Fix(mysingle)
Pause = Pause * 10
Sound Portb.0 , Duration , Pulses
Waitms Pause
Loop
Wait 1
Loop
End
Tone:
Data 956% , 864% , 758% , 716% , 638% , 568% , 506%
Music:
Data 75% , 5 , 1
Data 25% , 5 , 1
Data 100% , 11 , 1
Data 100% , 5 , 1
Data 100% , 13 , 1
Data 100% , 11 , 1
Data 150% , 15 , 0
Data 50% , 16 , 1
Data 100% , 15 , 1
Data 75% , 15 , 1
Data 25% , 15 , 1
Data 150% , 21 , 1
Data 150% , 21 , 1
Data 75% , 16 , 1
Data 25% , 15 , 1
Data 50% , 14 , 0
Data 40% , 16 , 1
Data 200% , 15 , 1
Data 75% , 15 , 1
Data 25% , 15 , 1
Data 100% , 16 , 1
Data 100% , 16 , 1
Data 100% , 12 , 1
Data 75% , 12 , 1
Data 25% , 12 , 1
Data 150% , 15 , 0
Data 50% , 14 , 1
Data 100% , 13 , 1
Data 75% , 5 , 1
Data 25% , 5 , 1
Data 100% , 15 , 1
Data 50% , 15 , 0
Data 50% , 16 , 1
Data 50% , 15 , 1
Data 50% , 14 , 1
Data 50% , 13 , 0
Data 50% , 12 , 1
Data 200% , 11 , 1
Data 75% , 15 , 1
Data 25% , 15 , 1
Data 100% , 21 , 1
Data 100% , 21 , 1
Data 100% , 16 , 1
Data 75% , 16 , 1
Data 25% , 15 , 1
Data 150% , 14 , 0
Data 50% , 15 , 1
Data 100% , 16 , 1
Data 75% , 12 , 1
Data 25% , 12 , 1
Data 100% , 15 , 1
Data 50% , 15 , 0
Data 50% , 16 , 1
Data 50% , 15 , 1
Data 50% , 14 , 1
Data 50% , 13 , 0
Data 50% , 12 , 1
Data 300% , 11 , 1
Data 75% , 12 , 1
Data 25% , 12 , 1
Data 100% , 15 , 1
Data 50% , 15 , 0
Data 50% , 16 , 1
Data 50% , 17 , 1
Data 50% , 15 , 1
Data 50% , 16 , 0
Data 50% , 17 , 1
Data 300% , 21 , 1
Data -1% , 0 , 0
Myheart:
Data 150% , 6 , 1
Data 50% , 13 , 1
Data 50% , 12 , 1
Data 50% , 13 , 1
Data 50% , 11 , 1
Data 50% , 7 , 1
Data 300% , 6 , 3
Data 50% , 13 , 1
Data 100% , 16 , 1
Data 50% , 15 , 1
Data 50% , 13 , 1
Data 50% , 12 , 1
Data 50% , 11 , 1
Data 50% , 12 , 1
Data 300% , 13 , 1
Data 50% , 13 , 1
Data 50% , 15 , 1
Data 150% , 16 , 1
Data 50% , 17 , 1
Data 50% , 16 , 1
Data 50% , 15 , 1
Data 50% , 13 , 1
Data 50% , 12 , 1
Data 50% , 11 , 1
Data 100% , 11 , 0
Data 50% , 12 , 0
Data 200% , 13 , 1
Data 150% , 12 , 1
Data 50% , 13 , 1
Data 50% , 7 , 0
Data 50% , 6 , 1
Data 50% , 5 , 1
Data 300% , 6 , 3
Data 50% , 13 , 1
Data 150% , 15 , 1
Data 50% , 13 , 1
Data 150% , 13 , 3
Data 50% , 13 , 1
Data 150% , 21 , 1
Data 50% , 16 , 1
Data 100% , 16 , 1
Data 50% , 16 , 1
Data 50% , 21 , 1
Data 100% , 16 , 1
Data 100% , 15 , 1
Data 100% , 11 , 1
Data 50% , 12 , 0
Data 25% , 11 , 0
Data 25% , 12 , 1
Data 300% , 13 , 4
Data 50% , 13 , 1
Data 150% , 21 , 1
Data 50% , 16 , 1
Data 150% , 16 , 1
Data 50% , 16 , 1
Data 150% , 21 , 1
Data 50% , 22 , 1
Data 250% , 23 , 1
Data 50% , 23 , 1
Data 50% , 22 , 1
Data 150% , 17 , 1
Data 50% , 15 , 1
Data 300% , 16 , 4
Data 150% , 6 , 1
Data 50% , 13 , 1
Data 50% , 12 , 1
Data 50% , 13 , 1
Data 50% , 11 , 1
Data 50% , 7 , 1
Data 300% , 6 , 4
Data 50% , 13 , 1
Data 100% , 16 , 1
Data 50% , 15 , 1
Data 50% , 13 , 1
Data 50% , 12 , 1
Data 50% , 11 , 1
Data 50% , 12 , 1
Data 300% , 13 , 1
Data 50% , 13 , 1
Data 50% , 15 , 1
Data 150% , 16 , 1
Data 50% , 17 , 1
Data 50% , 16 , 1
Data 50% , 15 , 1
Data 50% , 13 , 1
Data 50% , 12 , 1
Data 50% , 11 , 1
Data 100% , 11 , 0
Data 50% , 12 , 0
Data 300% , 13 , 4
Data 150% , 12 , 1
Data 50% , 13 , 1
Data 50% , 17 , 0
Data 50% , 16 , 0
Data 100% , 15 , 1
Data 300% , 16 , 1
Data -1% , 0 , 0