Tuesday, April 19, 2011

Program BascomAVR For SmartCard ACS120S

Nih Program Basom Yg bwat Smart Card Baca data DLLL Program pling Kren Dah

$regfile = "m8535.dat"
$crystal = 8000000
$baud = 9600
Open "comd.3:9600,8,n,1" For Output As #1

Declare Sub Keypad()

Declare Function Select_card() As Byte
Declare Function Login_card(byval Sector As Byte) As Byte
Declare Function Read_data() As String
Declare Function Read_block(byval Blok As Byte) As String

Dim Tag As Byte
Dim R As Byte
Dim Nama As Byte
Dim Buffstr As String * 20
Dim Hrf As String * 20
Dim Fde As String * 10

Dim S As Byte
Dim Key As Byte
Dim Key_i As Byte
Dim Key_str As String * 1
Dim Pwd As String * 10
Dim Pgr As String * 4
Dim A As String * 10
Dim _data As String * 10

Rem ------------ lcd ------------------
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7 = Portc.7 , E = Portc.2 , Rs = Portc.0
Config Lcd = 16 * 2

Rem - - - - - - - - - - - - -keypad - - - - - - - - - - -
Config Kbd = Portb , Debounce = 200

Awal:
Cls
Locate 1 , 3
Lcd "Selamat datang"
Lowerline
Lcd "Tekan *"
Wait 3

Pwd = ""
For S = 1 To 1
Call Keypad()
Next S
If Pwd = "*" Then

Goto Main
Else
Goto Awal
End If

Main:
set
Cls
Lcd "Dekatkan kartu"
Wait 3

set
Tag = 0
Tag = Select_card()
Cls
Lcd "SELECT KARTU"
Wait 1
Tag = 0
Tag = Login_card(2)
If Tag = 0 Then
R = 0
Do
R = R + 1
Cls
Lcd "KARTU KOSONG"
Waitms 800
Cls
Waitms 500
Loop Until R = 3
Waitms 300
Goto Awal
End If

Cls
Lcd "LOGIN BERHASIL"
Wait 1
Buffstr = Read_block(8)
Cls
Lcd "Selamat Datang"
Lowerline
Lcd Buffstr
Hrf = Buffstr
Wait 3

Fde = ""
For R = 1 To 4
Buffstr = Read_block(9)
Fde = Buffstr
Cls
Lcd "pas1" ; Fde
Next R

Wait 2

Cls
Lcd "Enter Password"
Lowerline
Lcd "Pass>> "

Pwd = ""
For S = 1 To 4
Call Keypad()
Lcd "*"
Next S
Do
If Pwd = Fde Then
Cls
Lcd "berhasil"
Wait 6
Goto Awal
Else
Wait 1
Goto Awal
End If
Loop

Function Select_card() As Byte
Dim Sbuf2 As String * 1
Dim Strbuf As String * 20

Printbin 2 ; 1 ; 1 ; 115 ; 115 ; 3
Sbuf2 = ""
Strbuf = ""
Cls
Lcd "No connect to"
Lowerline
Lcd "Smart Card"
Strbuf = Read_data()

Sbuf2 = Mid(strbuf , 2 , 1)

If Sbuf2 = Chr(1) Then
Select_card = 0
Exit Function
End If
Select_card = 1
End Function
Function Login_card(byval Sector As Byte)as Byte

Dim Sbuf4 As String * 25
Dim Sbuf3 As Byte
Dim Sbuf9 As String * 20
Dim Bcc2 As Byte

Sbuf4 = ""
Sbuf3 = ""
Bcc2 = 155 Xor Sector

Printbin &H02 ; &H01 ; &H04 ; &H6C ; Sector ; &HFF ; &H0D ; Bcc2 ; &H03
'Printbin 2 ; 1 ; 4 ; 108 ; Sector ; 255 ; 13 ; Bcc2 ; 3
Do
Sbuf3 = Inkey()
If Sbuf3 > 0 Then
Sbuf4 = Sbuf4 + Chr(sbuf3)
If Sbuf3 = 3 Then Exit Do
End If
Loop

Sbuf9 = Mid(sbuf4 , 3 , 1)
If Sbuf9 = "L" Then
Login_card = 1
Exit Function
End If
Login_card = 0
End Function

Function Read_block(byval Blok As Byte) As String
Dim Sbuf5 As String * 25
Dim Sbuf6 As String * 20
Dim Sbuf7 As Byte
Dim Bcc As Byte

Sbuf6 = ""
Sbuf5 = ""
Bcc = 113 Xor Blok
Printbin 2 ; 1 ; 2 ; 114 ; Blok ; Bcc ; 3

Do
Sbuf7 = Inkey()
If Sbuf7 > 0 Then
Sbuf5 = Sbuf5 + Chr(sbuf7)
If Sbuf7 = 3 Then Exit Do
End If

Loop
Sbuf6 = Mid(sbuf5 , 3 , 4)
Read_block = Sbuf6

End Function

Function Read_data() As String
Dim Sout As String * 25
Dim Sbuf1 As String * 1

Sout = ""
Do
Sbuf1 = Waitkey()
Sout = Sout + Sbuf1
If Sbuf1 = Chr(3) Then Exit Do
Loop
Read_data = Sout
End Function

Sub Keypad()

Key_i = 16
Do
Key = Key_i
Waitms 100
Key_i = Getkbd()

Loop Until Key_i <> 16 And Key <> 16

Key_str = Lookupstr(key , Keydata_str)
Pwd = Pwd + Key_str

End Sub

Keydata_str:
Data "1" , "4" , "7" , "*" , "2" , "5" , "8" , "0" , "3" , "6" , "9" , "#" , "A" , "B" , "C" , "D"

No comments:

Post a Comment

Terima kasih atas komentar yang anda sampaikan , sehingga dapat menambah wawasan saya sebagai penulis dan membuat blog ini semakin berguna banyak orang