کد:
$regfile = "m32def.dat"
$crystal = 12000000
Config Debounce = 25
Config Lcd = 16 * 2
Config Lcdpin = Pin , Db4 = Portb.4 , Db5 = Portb.3 , Db6 = Porta.1 , Db7 = Portb.1 , E = Portb.5 , Rs = Portb.7
Config Timer1 = Timer , Prescale = 256
Config Timer0 = Timer , Prescale = 256
Config Int0 = Low Level
Config Int1 = Low Level
Ddrd.3 = 0 : Portd.3 = 1
Ddrd.2 = 0
Timer1 = 21660
Timer0 = 0
Enable Timer1
Enable Timer0
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Declare Sub Gtc
Declare Sub Getham
'''''lcd'''''''''
Ddrb.0 = 1 : Set Portb.0
''''''''''''kbd'''''''''''''
Ddrd.0 = 1 : Ddrd.1 = 1 : Ddra.6 = 1 : Ddra.7 = 1
Ddrd.4 = 0 : Ddrd.5 = 0 : Ddrd.6 = 0 : Ddrd.7 = 0
Set Portd.0 : Set Portd.1 : Set Porta.6 : Set Porta.7
Portd.7 = 1 : Portd.6 = 1 : Portd.5 = 1 : Portd.4 = 1
'''''''''''''''''''ddr'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Ddra.3 = 1 : Reset Porta.3
Ddrc.0 = 1 : Reset Portc.0
Ddrc.1 = 1 : Reset Portc.1
Ddra.5 = 1 : Reset Porta.5
Ddra.4 = 1 : Reset Porta.4
'Ddrc.5 = 0
Ddra.0 = 0
Ddrd.2 = 0
'''''''''''''''''''Alias'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dis Alias Portb.0
Door Alias Porta.3
Keyled Alias Porta.4
K1led Alias Porta.5
K2led Alias Portc.1
K3led Alias Portc.0
Openkey Alias Pind.2
'''''''''''''''Parameters''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim A As Word , B1 As Byte , B As Byte , C As Byte , D As Byte , O As Byte , T As Byte , X1 As Byte , X2 As Byte , J1 As Byte , J2 As Word
Dim F As Byte , G As Byte , H(4) As Byte , V(4) As Byte , L As Byte , M(3) As Byte , Q As Byte , S4 As Byte , Op As Bit , Timeout As Bit , Qe14 As Word
Dim E(10) As Byte , R(10) As Byte , F1(3) As Byte , N As Byte , J As Byte , N1 As Byte , Xy As Byte , Xy1 As Byte , Tf As Bit , Tf1 As Bit , Tf2 As Bit
Dim Ttl As Bit , Ll1 As Byte , Ll2 As Byte
Dim Ee(10) As Eram Byte , Er(10) As Eram Byte , Ef(3) As Eram Byte , Ej As Eram Byte , Error As Eram Byte , Numb As Eram Byte , Hpo As Byte , Error1 As Eram Byte 'EEPROM parameters defination
Deflcdchar 1 , 4 , 10 , 4 , 32 , 32 , 32 , 32 , 32 ' replace [x] with number (0-7)
Deflcdchar 2 , 32 , 10 , 32 , 32 , 17 , 31 , 14 , 32 ' replace [x] with number (0-7)
'''''''''''''''''''''''''''''''''''''''ir parameters'''''''''''''''''''''''''''''
Dim Aham As Byte , Cham As Byte , Oham(24) As Word , Zham(24) As Word , Zzham(5) As Word , Ooham(5) As Word , Numham As Byte , Bham As Byte , Yham As Byte
F = 0 : G = 1 : B = 1 : J1 = 0 : B1 = 0 : X2 = 0 : Xy = 0 : D = 0 : Tf2 = 0 : Timeout = 0
Reset Door
Enable Interrupts
On Timer1 Yeh
On Int0 Run
On Int1 Ir
Cls
Display Off
Reset Dis
Reset Keyled : Reset K1led : Reset K2led : Reset K3led
'for first use''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'Readeeprom D , 50
'Waitus 10
'If D = 0 Then
' Call First
'End If 'for first timeeeeeeeeeeeeeeeeee
'Ready to turn on the display'''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Hpo = Error
Error1 = Hpo
Hpo = Numb
Error = Hpo
Numb = 0
Gg:
If T = 0 Then
Numb = 1
C = 0
X1 = 1
X2 = 0
Timeout = 0
O = 0
N = 0
N1 = 0
Tf2 = 0
Ttl = 0
Reset Keyled : Reset K1led : Reset K2led : Reset K3led
Cls
Display Off
Reset Dis
Numb = 2
Reset Portd.0 : Reset Portd.1 : Reset Porta.6 : Reset Porta.7
Stop Timer1
Stop Timer0
Ddrd.3 = 0
Config Int0 = Low Level
Config Int1 = Low Level
Enable Int1
Enable Int0
Numb = 3
Powerdown
End If
Numb = 4
Start Timer1
C = 0
X1 = 1
X2 = 0
Timeout = 0
O = 0
N = 0
N1 = 0
Tf2 = 0
Numb = 5
Do
If Ttl = 0 Then
Do
If Pind.2 = 1 Then
T = 0
Goto Gg
End If
Loop Until O = 1
End If
Numb = 6 '
Ttl = 1
T = 0
Wrong:
If N1 = 3 Then
N1 = 0
Waitms 4000
Goto Gg
End If
T = 0
X1 = 1
X2 = 0
Timeout = 0
C = 1
If Dis = 0 Then
Set Dis
Display On
Set Keyled : Reset K1led : Reset K2led : Reset K3led
End If
Cls
Cursor Off
Locate 1 , 5
'Generate hash code------------------
We:
J = Ej
Incr J
Ej = J
J2 = J + 7
J2 = J * J2
L = J2 / 10
L = L * 10
J2 = J2 - L
'''''''''''''''''''''''
If Op = 0 Then
E(1) = Ee(1)
E(2) = Ee(2)
E(3) = Ee(3)
E(4) = Ee(4)
E(5) = Ee(5)
E(6) = Ee(6)
E(7) = Ee(7)
E(8) = Ee(8)
E(9) = Ee(9)
E(10) = Ee(10)
''''''''''
R(1) = Er(1)
R(2) = Er(2)
R(3) = Er(3)
R(4) = Er(4)
R(5) = Er(5)
R(6) = Er(6)
R(7) = Er(7)
R(8) = Er(8)
R(9) = Er(9)
R(10) = Er(10)
''''''''''
F1(1) = Ef(1)
F1(2) = Ef(2)
F1(3) = Ef(3)
End If
E(1) = E(1) + R(1)
E(2) = E(2) + R(2)
E(3) = E(3) + R(3)
E(4) = E(4) + R(4)
E(5) = E(5) + R(5)
E(6) = E(6) + R(6)
E(7) = E(7) + R(7)
E(8) = E(8) + R(8)
E(9) = E(9) + R(9)
E(10) = E(10) + R(10)
'''''''''''''''''''''''
E(1) = E(1) * J2
E(2) = E(2) + J2
E(3) = E(3) + J2
E(4) = E(4) * J2
E(5) = E(5) + J2
E(6) = E(6) + J2
E(7) = E(7) * J2
E(8) = E(8) * J2
E(9) = E(9) + J2
E(10) = E(10) + J2
''''''''''''''''''''''
L = E(1) / 10
L = L * 10
E(1) = E(1) - L
L = E(2) / 10
L = L * 10
E(2) = E(2) - L
L = E(3) / 10
L = L * 10
E(3) = E(3) - L
L = E(4) / 10
L = L * 10
E(4) = E(4) - L
L = E(5) / 10
L = L * 10
E(5) = E(5) - L
L = E(6) / 10
L = L * 10
E(6) = E(6) - L
L = E(7) / 10
L = L * 10
E(7) = E(7) - L
L = E(8) / 10
L = L * 10
E(8) = E(8) - L
L = E(9) / 10
L = L * 10
E(9) = E(9) - L
L = E(10) / 10
L = L * 10
E(10) = E(10) - L
''''''''''''''''''''''''''''
M(1) = R(1)
R(1) = R(3)
R(3) = R(9)
R(9) = R(6)
R(6) = R(2)
R(2) = R(7)
R(7) = R(5)
R(5) = R(8)
R(8) = R(10)
R(10) = R(4)
R(4) = M(1)
M(1) = 0
''''''''''''''''update eeprom'''''''''''''''''''
Ee(1) = E(1)
Ee(2) = E(2)
Ee(3) = E(3)
Ee(4) = E(4)
Ee(5) = E(5)
Ee(6) = E(6)
Ee(7) = E(7)
Ee(8) = E(8)
Ee(9) = E(9)
Ee(10) = E(10)
''''''''''
Er(1) = R(1)
Er(2) = R(2)
Er(3) = R(3)
Er(4) = R(4)
Er(5) = R(5)
Er(6) = R(6)
Er(7) = R(7)
Er(8) = R(8)
Er(9) = R(9)
Er(10) = R(10)
'encrept the code'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
N = F1(1) + 1
M(1) = E(n)
N = F1(2) + 1
M(2) = E(n)
N = F1(3) + 1
M(3) = E(n)
'---------------------
Waitms 300
Cls
Locate 1 , 4
Lcd E(1) ; E(2) ; E(3) ; E(4) ; E(5) ; E(6) ; E(7) ; E(8) ; E(9) ; E(10)
Locate 2 , 5
Lcd "CODE:"
Goto Number
Numb = 7
Loop
'getting number from person'''''''''''''''''''''''''''''''''''''''''''''''''''''
Number:
L = 1
Q = 0
F = 0
Cursor Blink
Do
If L = 4 Then Goto Oo
Call Gtc
If Xy = 1 Or Xy = 2 Or Xy = 3 Or Xy = 4 Or Xy = 5 Or Xy = 6 Or Xy = 7 Or Xy = 8 Or Xy = 9 Then
If M(l) = Xy Then Incr Q
Lcd Xy
Incr L
Shiftcursor Left
Waitms 300
Lcd "*"
Goto Nexx
End If
If Xy = 11 Then
If M(l) = 0 Then Incr Q
Lcd 0
Incr L
Shiftcursor Left
Waitms 300
Lcd "*"
Goto Nexx
End If
If Xy = 10 Then
If L > 1 Then
Decr L
Lcd " "
Shiftcursor Left
Shiftcursor Left
End If
End If
If Xy = 16 Then Goto Ut
If Xy = 13 Then Goto Gg
If Xy = 15 Then
Cls
Hpo = Error1
Lcd Hpo
Shiftcursor Right
Hpo = Error
Lcd Hpo
Wait 3
Goto Gg
End If
Nexx:
'''check'''
Select Case L
Case 1
Reset K1led : Reset K2led : Reset K3led
Case 2
Set K1led : Reset K2led : Reset K3led
Case 3
Set K1led : Set K2led : Reset K3led
Case 4
Set K1led : Set K2led : Set K3led
End Select
Loop
'if codes be correct open the door''''''''''''''''''''''''''''''''''''''''''''''
Oo:
Cursor Noblink
X1 = 1
X2 = 0
Timeout = 0
C = 0
Set Keyled : Set K1led : Set K2led : Set K3led
Waitms 200
Cls
If Q = 3 Then
If Tf2 = 1 Then Goto Hub
X1 = 1
X2 = 0
Timeout = 0
Set Door
Waitms 200
Reset Door
Waitms 200
Locate 1 , 5
Lcd "WELCOME"
Waitms 500
Numb = 8
Goto Gg
Else
X1 = 1
X2 = 0
Timeout = 0
Locate 1 , 2
Lcd "CODE IS WRONG"
Waitms 500
N1 = N1 + 1
Set Keyled : Reset K1led : Reset K2led : Reset K3led
Goto Wrong
End If
Numb = 9
Goto Gg
'timer prescale'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Yeh:
Numb = 11
Timer1 = 21660
If Ttl = 0 Then
If T = 1 Then
Incr O
If O > 1 Then O = 0
End If
End If
If X1 = 1 Then
Incr X2
If X2 > 54 Then
X1 = 0
X2 = 0
Timeout = 1
T = 0
End If
End If
Return
'''''''''''''''''''kbd sub''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Sub Gtc
Numb = 10 'start of sub gtc
Xy1 = 255
Xy = 0
Set Portd.0 : Set Portd.1 : Set Porta.6 : Set Porta.7
Do
If Timeout = 1 Then Goto Gg
For J1 = 1 To 4 Step 1
Select Case J1
Case 1
Reset Portd.0 : Set Portd.1 : Set Porta.6 : Set Porta.7
Case 2
Set Portd.0 : Reset Portd.1 : Set Porta.6 : Set Porta.7
Case 3
Set Portd.0 : Set Portd.1 : Reset Porta.6 : Set Porta.7
Case 4
Set Portd.0 : Set Portd.1 : Set Porta.6 : Reset Porta.7
End Select
Waitus 10
Debounce Pind.4 , 0 , Al1
Debounce Pind.5 , 0 , Al2
Debounce Pind.6 , 0 , Al3
Debounce Pind.7 , 0 , Al4
Yy:
If Xy1 <> 255 Then
J1 = J1 * 4
Xy1 = J1 - Xy1
Select Case Xy1
Case 1 : Xy = 13
Case 2 : Xy = 1
Case 3 : Xy = 2
Case 4 : Xy = 3
Case 5 : Xy = 14
Case 6 : Xy = 4
Case 7 : Xy = 5
Case 8 : Xy = 6
Case 9 : Xy = 15
Case 10 : Xy = 7
Case 11 : Xy = 8
Case 12 : Xy = 9
Case 13 : Xy = 16
Case 14 : Xy = 10
Case 15 : Xy = 11
Case 16 : Xy = 12
End Select
End If
While Pind.4 = 0
Wend
While Pind.5 = 0
Wend
While Pind.6 = 0
Wend
While Pind.7 = 0
Wend
Next J1
Loop Until Xy1 <> 255
X1 = 1
X2 = 0
Timeout = 0
Numb = 12
End Sub ' end of sub gtc
Al1:
Xy1 = 3
Goto Yy
Return
Al2:
Xy1 = 2
Goto Yy
Return
Al3:
Xy1 = 1
Goto Yy
Return
Al4:
Xy1 = 0
Goto Yy
Return
Run:
Numb = 13
Disable Int0
Timer1 = 21660
Start Timer1
Timer1 = 21660
T = 1
Ttl = 0
Ddrd.2 = 0
Numb = 14
Return
Hub:
Numb = 15
Set Keyled : Reset K1led : Reset K2led : Reset K3led
Display On
Set Dis
Cls
X1 = 1
X2 = 0
Timeout = 0
Locate 1 , 5
Lcd "NEW CODE"
Locate 2 , 8
Cursor Blink
F1(1) = Ef(1)
F1(2) = Ef(2)
F1(3) = Ef(3)
G = 1
Numb = 16
Do
Lcd F1(g)
Shiftcursor Left
Call Gtc
If Xy = 12 Then
Lcd F1(g)
Incr G
Goto Nex2
End If
If Xy = 10 Then
If G > 1 Then
Lcd " "
Shiftcursor Left
Shiftcursor Left
Decr G
Goto Nex2
Else
Goto We
End If
End If
If Xy = 1 Or Xy = 2 Or Xy = 3 Or Xy = 4 Or Xy = 5 Or Xy = 6 Or Xy = 7 Or Xy = 8 Or Xy = 9 Then
F1(g) = Xy
Lcd F1(g)
Incr G
Goto Nex2
Else
If Xy = 11 Then
F1(g) = 0
Lcd F1(g)
Incr G
Goto Nex2
End If
End If
If Xy = 13 Then Goto Gg
Nex2:
'''check''''''
Select Case G
Case 1
Reset K1led : Reset K2led : Reset K3led
Case 2
Set K1led : Reset K2led : Reset K3led
Case 3
Set K1led : Set K2led : Reset K3led
Case 4
Set K1led : Set K2led : Set K3led
End Select
Loop Until G = 4
Numb = 16
Waitms 200
Set Keyled : Reset K1led : Reset K2led : Reset K3led
Cls
Locate 1 , 3
Cursor Noblink
Lcd "ARE YOU SURE?"
Locate 2 , 8
Lcd F1(1) ; F1(2) ; F1(3)
Tf1 = 0
Tf2 = 0
Numb = 17
Do
Call Gtc
If Xy = 10 Then Goto Hub
If Xy = 12 Then
Ef(1) = F1(1)
Ef(2) = F1(2)
Ef(3) = F1(3)
Tf1 = 1
End If
Loop Until Tf1 = 1
Cls
Locate 1 , 3
Lcd "CODE CHANGED"
Waitms 400
Numb = 18
Goto We
Return
Ut:
Numb = 19
Cls
Cursor Noblink
Locate 1 , 3
Set Keyled : Reset K1led : Reset K2led : Reset K3led
Lcd " CHANGE CODE"
Waitms 600
X1 = 1
X2 = 0
Timeout = 0
Tf2 = 1
Numb = 20
Goto We
Return
'''''''''''''''''''''''''''''''''''''''''ir sub''''''''''''''''''''''''''''''''
Ir:
Set Keyled
Numb = 21 'start of INT1
Disable Int1
Disable Int0
Timer0 = 0
Start Timer0
Ddrd.3 = 0
Bham = 1
Numb = 22
Bitwait Pind.3 , Reset 'start of function
Timer0 = 0
Do
Do
If Timer0 > 200 Then Goto Ch
Loop Until Pind.3 = 1
Oham(bham) = Timer0
Timer0 = 0
Do
If Timer0 > 200 Then Goto Ch
Loop Until Pind.3 = 0
Zham(bham) = Timer0
Timer0 = 0
Incr Bham
Ch:
Loop Until Bham > 24 Or Timer0 > 200
Numb = 23
Ddrd.3 = 1
Numham = 0
Cham = 20
For Aham = 1 To 20
If Oham(aham) > 120 And Oham(aham) < 160 Then
Cham = Aham - 1
For Bham = 1 To 5
Yham = Cham + Bham
Ooham(bham) = Oham(yham)
Zzham(bham) = Zham(yham)
Next Bham
Bham = 0
If Ooham(2) > 70 And Ooham(2) < 90 Then
Cham = 45
If Zzham(3) =< Cham Then Bham = 1
If Zzham(4) =< Cham Then Bham = Bham + 2
If Zzham(5) =< Cham Then Bham = Bham + 4
End If
If Bham = 5 Then Incr Numham
End If
Next Aham
Numb = 24
For Aham = 1 To 24
Oham(aham) = 0 : Zham(aham) = 0
Next Aham
Aham = 222
If Numham >= 2 Then
Set Dis
Display On
Lcd "WELCOME"
Set Door
Set Keyled
Waitms 200
Reset Door
Waitms 1000
Reset Keyled
Reset Dis
Cls
Display Off
Waitms 2000
Else
T = 0
End If
T = 0
Numb = 25
Reset Keyled
Return
این از کدش... یه ذره اضافات هم داره که نشد که دستش کنم، به بزرگی خودتون ببخشید دیگه