کد:
'$sim
$regfile = "m8def.dat"
$crystal = 4000000
Config Portb = Output
Config Portc = Input
Config Kbd = Portd , Debounce = 100 , Delay = 5
'===============================================================================
Dim A As Byte , B As Byte , C As Dword , D As Byte , R As Byte , Z As Byte , Q As Byte , F As Byte , _
G As Dword , E As Byte , K As Dword , X As Byte , L As Dword,
Readeeprom K , 1
C = 0
G = 0
X = 0
E = 0
Main:
Reset Portb.7
Set Portb.6
A = Getkbd()
If Pinc.0 = 1 Then Goto Firest
If A = 16 Then Goto Main
Ese:
D = Getkbd()
If D <> 16 Then Goto Ese
B = Lookup(a , Keydata)
Select Case B
'===============================================================================
Case 0 To 9:
Incr X
C = C * 10
C = C + B
Sound Portb.3 , 100 , 25
Goto Main
'===============================================================================
Case 23:
Readeeprom K , 1
L = K
If C = L Then Goto Ok
If X < 6 Then Goto Wrong
If C <> L Then Goto Wrong
Goto Main
'===============================================================================
End Select
End
'===============================================================================
Ok:
Sound Portb.3 , 100 , 20
Sound Portb.3 , 100 , 40
Sound Portb.3 , 100 , 60
Sound Portb.3 , 100 , 85
Sound Portb.3 , 100 , 100
Sound Portb.3 , 100 , 125
Sound Portb.3 , 100 , 150
Sound Portb.3 , 100 , 180
Sound Portb.3 , 100 , 200
Set Portb.4
Waitms 500
Reset Portb.4
C = 0
G = 0
X = 0
E = 0
L = 0
K = 0
Goto Main
'===============================================================================
Wrong:
Sound Portb.3 , 200 , 20
Sound Portb.3 , 200 , 40
Sound Portb.3 , 200 , 20
Sound Portb.3 , 200 , 40
Sound Portb.3 , 200 , 20
C = 0
G = 0
X = 0
E = 0
L = 0
K = 0
Goto Main
'=======================================================
Firest:
Reset Portb.6
Set Portb.7
Z = Getkbd()
If Z = 16 Then Goto Firest
Check:
R = Getkbd()
If R <> 16 Then Goto Check
F = Lookup(z , Keydata)
Select Case F
'===============================================================================
Case 0 To 9:
Incr E
G = G * 10
G = G + F
Sound Portb.3 , 100 , 30
If E > 6 Then
Sound Portb.3 , 200 , 20
Sound Portb.3 , 200 , 40
Sound Portb.3 , 200 , 20
Sound Portb.3 , 200 , 40
Sound Portb.3 , 200 , 20
E = 0
G = 0
End If
Goto Firest
Goto Firest
Case 23:
If E < 6 Then
Sound Portb.3 , 200 , 20
Sound Portb.3 , 200 , 40
Sound Portb.3 , 200 , 20
Sound Portb.3 , 200 , 40
Sound Portb.3 , 200 , 20
E = 0
G = 0
Goto Firest
If E > 6 Then
Sound Portb.3 , 200 , 20
Sound Portb.3 , 200 , 40
Sound Portb.3 , 200 , 20
Sound Portb.3 , 200 , 40
Sound Portb.3 , 200 , 20
E = 0
G = 0
Goto Firest
If E = 6 Then
K = G
Sound Portb.3 , 100 , 20
Sound Portb.3 , 100 , 40
Sound Portb.3 , 100 , 60
Writeeeprom K , 1
Readeeprom K , 1
Reset Portb.7
Goto Main
End If
End If
End If
End Select
'========================================================================
'===============================================================================
Keydata:
Data , 7 , 8 , 9 , 20 , 4 , 5 , 6 , 21 , 1 , 2 , 3 , 22 , 23 , 0 , 24 , 25