该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
P3 = &B11011111
If P3.0 = 0 Then Goto Key8
If P3.1 = 0 Then Goto Key9
If P3.2 = 0 Then Goto Keya
If P3.3 = 0 Then Goto Keyb
P3 = &B11101111
If P3.0 = 0 Then Goto Keyc
If P3.1 = 0 Then Goto Keyd
If P3.2 = 0 Then Goto Keye
If P3.3 = 0 Then Goto Keyf
Goto Again
' =============================
Key0:
P2 = &HC0
Goto Again
Key1:
P2 = &HF9
Goto Again
Key2:
P2 = &HA4
Goto Again
Key3:
P2 = &HB0
Goto Again
Key4:
P2 = &H99
Goto Again
Key5:
P2 = &H92
Goto Again
Key6:
P2 = &H82
Goto Again
Key7:
P2 = &HF8
Goto Again
Key8:
P2 = &H80
Goto Again
Key9:
P2 = &H90
Goto Again
Keya:
P2 = &H88
Goto Again
Keyb:
P2 = &H83
Goto Again
Keyc:
P2 = &HC6
Goto Again
Keyd:
P2 = &HA1
Goto Again
Keye:
P2 = &H86
Goto Again
Keyf:
P2 = &H8E
Goto Again
End
'例程二:'世上只有妈妈好.BAS
'实现方案:〖使用Beta-EISP下载型可编程多功能实验板〗
'【功能】:让51系列单片机演奏音乐《世上只有妈妈好》,器件为P1.1接口的蜂鸣器。
Dim Tone As Byte , Tempo As Byte
Dim Nhi As Byte , Nlow As Byte
Dim N As Byte
Config Timer0 = Timer , Gate = Internal , Mode = 1
On Timer0 Timer0sub
Enable Interrupts
Enable Timer0
Priority Set Timer0
Start Timer0
Repeat:
Restore Music
Again:
Read Tone
If Tone = 99 Then
Goto Repeat
Elseif Tone = 44 Then
Bitwait P1.1 , Set
Stop Timer0
Stop
Else
Read Tempo
For N = 1 To Tempo
Waitms 125
Next
Bitwait P1.1 , Set
Stop Timer0
Waitms 25
Start Timer0
Goto Again
End If
End
Rem The Interrupt Handler For The Timer0 Interrupt
Timer0sub:
Nhi = Tone * 2
Nlow = Nhi + 1
Th0 = Lookup(nhi , Table)
Tl0 = Lookup(nlow , Table)
If Tone = 0 Then
P1.1 = 1
Else
P1.1 = P1.1 Xor 1
End If
Return
Table:
Data &HF1 , &H17
Data &HF1 , &H17
Data &HF2 , &HB7
Data &HF4 , &H2A
Data &HF4 , &HD7
Data &HF6 , &H09
Data &HF7 , &H1F
Data &HF8 , &H18
Data &HF8 , &H8C
Data &HF9 , &H5C
Data &HFA , &H15
Data &HFA , &H67
Data &HFB , &H04
Data &HFB , &H90
Data &HFC , &H0C
Data &HFC , &H42
Data &HFC , &HAC
Data &HFD , &H09
Data &HFD , &H36
Data &HFD , &H82
Data &HFD , &HC8
Data &HFE , &H06
Music:
Data 13 , 6 , 12 , 2 , 10 , 4 , 12 , 4 , 15 , 4 , 13 , 2 , 12 , 2 , 13 , 6 , 0 , 2
Data 10 , 4 , 12 , 2 , 13 , 2 , 12 , 4 , 10 , 2 , 9 , 2 , 8 , 2 , 6 , 2 , 12 , 2 , 10 , 2 , 9 , 6 , 0 , 2
Data 9 , 4 , 9 , 2 , 10 , 2 , 12 , 4 , 12 , 2 , 13 , 2 , 10 , 6 , 9 , 2 , 8 , 6 , 0 , 2
Data 12 , 6 , 10 , 2 , 9 , 2 , 8 , 2 , 6 , 2 , 8 , 2 , 5 , 6 , 0 , 2
Data 99
'例程三:LCD&左移多汉字LED.BAS