sajadgreat
21-03-2013, 21:34
سلام دوستان من قصد داشتم یه قفل دیجیتال واسه در درست کنم ولی به مشکل برخوردم میخواستم برنامه ایی بنویسم که تا 6 رقم رمز بگیره و وقتی اولین بار اجرا میشه آماده دریافت رمز باشه و با زدن کلید مربع به منزله تایید رمز رمز رو در حافظه پاک نشدنی بریزه و سپس آماده دریافترمز ست شده باشه و با زدن رمز و زدن مبع در رو باز کنه من این برنامه رو نوشتتم نمیدونم مشکلش چیه که کار نمیکنه لطفا راهنماییم کنید
'$sim
$regfile = "m8def.dat"
$crystal = 4000000
Config Portb = Output
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 Long , _
G As Dword , E As Byte , K As Dword , N As Byte , X As Byte , P As Word , _
L As Byte
Readeeprom Q , 2
Readeeprom K , 1
C = 0
E = 0
X = 0
N = 0
Main:
If Q <> 2 Then Goto Firest
A = Getkbd()
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:
Readeeprom K , 1
Incr X
C = C * 10
C = C + B
Sound Portb.3 , 100 , 25
If X > 6 Then Goto Wrong
Goto Main
'================================================= ==============================
Case 23:
If C = K Then Goto Ok
If X < 6 Then Goto Wrong
If C <> K 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
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
X = 0
Waitms 20
Goto Main
'================================================= ======
Firest:
Set Portb.3
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
If E > 6 Then Goto Wrong
K = G
Writeeeprom K , 1
Waitms 20
Readeeprom K , 1
Goto Main
Case 23:
If E < 6 Then
Goto Wrong
If E > 6 Then
Goto Wrong
Q = 2
Writeeeprom Q , 2
Waitms 20
Readeeprom Q , 2
Goto Main
End If
End If
End Select
End
Goto Main
'================================================= ==============================
Keydata:
Data , 7 , 8 , 9 , 20 , 4 , 5 , 6 , 21 , 1 , 2 , 3 , 22 , 23 , 0 , 24 , 25
'$sim
$regfile = "m8def.dat"
$crystal = 4000000
Config Portb = Output
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 Long , _
G As Dword , E As Byte , K As Dword , N As Byte , X As Byte , P As Word , _
L As Byte
Readeeprom Q , 2
Readeeprom K , 1
C = 0
E = 0
X = 0
N = 0
Main:
If Q <> 2 Then Goto Firest
A = Getkbd()
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:
Readeeprom K , 1
Incr X
C = C * 10
C = C + B
Sound Portb.3 , 100 , 25
If X > 6 Then Goto Wrong
Goto Main
'================================================= ==============================
Case 23:
If C = K Then Goto Ok
If X < 6 Then Goto Wrong
If C <> K 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
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
X = 0
Waitms 20
Goto Main
'================================================= ======
Firest:
Set Portb.3
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
If E > 6 Then Goto Wrong
K = G
Writeeeprom K , 1
Waitms 20
Readeeprom K , 1
Goto Main
Case 23:
If E < 6 Then
Goto Wrong
If E > 6 Then
Goto Wrong
Q = 2
Writeeeprom Q , 2
Waitms 20
Readeeprom Q , 2
Goto Main
End If
End If
End Select
End
Goto Main
'================================================= ==============================
Keydata:
Data , 7 , 8 , 9 , 20 , 4 , 5 , 6 , 21 , 1 , 2 , 3 , 22 , 23 , 0 , 24 , 25