Professional Documents
Culture Documents
1/97)
UNIVERSITI TEKNOLOGI MALAYSIA
BORANG PENGESAHAN STATUS TESIS
J UDUL: CAR PARK CONTROL SYSTEM:
INTERFACE RFID TO PIC USING SERIAL PORT
SESI PENGAJIAN: 2006/2007
Saya AHMAD DZAFIR BIN JOHARI
(HURUF BESAR)
mengaku membenarkan tesis (PSM/Sarjana/Doktor Falsafah)* ini disimpan di Perpustakaan
Universiti Teknologi Malaysia dengan syarat-syarat kegunaan seperti berikut:
1. Tesis adalah hakmilik Universiti Teknologi Malaysia.
2. Perpustakaan Universiti Teknologi Malaysia dibenarkan membuat salinan untuk tujuan
pengajian sahaja.
3. Perpustakaan dibenarkan membuat salinan tesis ini sebagai bahan pertukaran antara
institusi pengajian tinggi.
4. **Sila tandakan ( )
(Mengandungi maklumat yang berdarjah keselamatan atau
kepentingan Malaysia seperti yang termaktub di dalam
Disahkan oleh
(TANDATANGAN PENULIS) (TANDATANGAN PENYELIA)
Alamat Tetap:
255, JLN. DAMAI 1,
TMN. DAMAI, EN. MOHD. AFZAN OTHMAN
81400, SENAI, JOHOR. Nama Penyelia
Tarikh: 23 NOVEMBER 2007 Tarikh: 23 NOVEMBER 2007
SULIT
AKTA RAHSIA RASMI 1972)
TERHAD
(Mengandungi maklumat TERHAD yang telah ditentukan
oleh organisasi/badan di mana penyelidikan dijalankan)
TIDAK TERHAD
Theuser
scanshisID
Tagtothe
RFID
Reader.
*REDLED
alwayson.
Computer
receivetheID
Tagnumberand
compareittothe
database.
IftheIDTag
numberissame
asinthe
database,User
IDisvalid.
Then
Computer
transmitting
signal1tothe
PIC.
PICthensend
signaltomotor
torunand
GREENLEDon.
REDLEDoff.
IftheIDTag
numberisnot
sameasinthe
database,User
IDisinvalid.
Then
Computer
transmitting
signal0tothe
PIC
Noaction
willbetaken.
VALI
D
I NVAL
I D
Figure 4.17 : User Confirmation flow
4.4 PIC Circuit
The PIC Circuit is design to connect to the PC serial port via RS232. The
connection from PIC16F84A to PC serial port is through MAX232. The PIC Circuit
has 14 components. Table 4.1 shows the components and the numbers of the item
used to build the PIC Circuit. Figure 4.18 shows the PIC Circuit diagram complete
with the power supply circuit.
59
Table 4.1 : PIC Circuit component.
No. Component Numbers of item
1 PIC16F84A 1
2 MAX232 1
3 Voltage Regulator 7805 1
4 Resistor 10k 1
5 Resistor 100 1
6 Resistor 220 2
7 Capacitor 0.1u 3
8 Capacitor 10u 3
9 Capacitor 22u 2
10 Capacitor 22p 2
11 Crystal 40MHz 1
12 Green LED 1
13 Red LED 1
14 Push Button 1
This PIC Circuit has been tested with several simples program. The testing
process is to see the functionality of the circuit before installing the program for this
project. The simple program is Blink-blink, Running Light and Switch LED.
The entire program runs smoothly. So with that, this PIC Circuit is well function.
60
Figure 4.18 : PIC Circuit diagram.
.
CHAPTER V
RESULTS AND DISCUSSION
5.1 Results
This project called Car Park Control System : Interface RFID to PIC via
Serial Port has three main objective. There are designing the interface using VB6
between the computers to the RFID READER via serial connection, to identify the
correct user ID that had been permited to use the parking space and to attach the
PIC16F84A to the PC using serial connection for sending signal to on either GREEN
LED or RED LED.
In this chapter, all the result will be discus. Wheres the outcome of this
project is compared to the main three objective.
62
5.1.1 Interface VB6 to RFID READER
As shown in Figure 5.1 the ID-TAG number has appeared in the TAG ID
text column wheres match the STAFF NO. text column. The tags that is used in
this project in ISO 15693 that has ten digit format ID-TAG, which it will change only
the last two digit for around 100 user.
That means the connection between VB6 interface and the RFID READER
were establish.
Figure 5.1 : Result of the ID-TAG shown in the TAG ID text column.
63
5.1.2 Identify User
As shown in Figure 5.2, the message box note as Valid User. Please
Proceed. This will appear after the user has tag his ID-TAG to the RFID READER.
The RFID READER will send the ID-TAG number to PC. From the database, it will
compare either the ID-TAG number is match with in the database or not. In this case,
it matches.
Figure 5.2 : Result of the confirmation as a VALID user.
64
Figure 5.3 shown that the unregistered user that tags to the RFID READER
and cannot enter the parking space. The message box noted as Invalid User. Cannot
Enter !!!. This is because the ID-TAG number does not matches with the data in
database.
As result the second objective, to identify the correct user ID that had been
permited to use the parking space is a success.
Figure 5.3 : Result of the confirmation as a INVALID user.
65
5.1.3 Connecting PIC16F84A to PC
PIC16F84A has successfully program. The program runs smoothly by
sending a positive voltage to the input port which is RB0. By sending low input
voltage the GREEN LED will on and by sending high input voltage the RED LED
will on. Normally well the high logic to on the GREEN LED, but in this project we
use low input because the signal the PIC receive from the computer is normal high.
But, unfortunately transmitting signal from PC serial port to the PIC was
failed. This is because the PC serial port is sending an always high input while PIC
read 8-bits inputs. In order to change the first bit, the high voltage must be change
into a low voltage with the same amount (e.g. -11V change to +11V). Using VB6,
after trying with sending an ASCII character from 0-255, the biggest change is
0.16V, so its not enough to change the first bit in order to send signal to the
PIC16F84A.
5.2 Discussions
This system is well built with the database and the identifying run smoothly.
But the database has one insufficient thats make it look undesirable or unofficial.
That is formatting. The database does not have a solid format for the administrator to
insert the user data, it can insert anything. For example in the STAFF IC NO. text
column it suppose can only enter numbers but it also can enter alphabets.
66
So in order to solve this problem, more research need to be done and
comparing to others database system using VB6, most of it using SQL as a link
database source. Furthermore SQL is more advance compared to using Microsoft
Access.
Another insufficient in this project is the failing to make an establish
connection between VB6 and PIC16F84A. Its not the program in the PIC thats
incorrect, it just the serial port has always send a high logic and with VB6, it has
some others coding in order to successfully change the -11V to +11V. Then the PIC
first bit input can change and the LEDs will on and off like it program.
CHAPTER VI
CONCLUSION
6.1 Conclusion
RFID is now becoming the most use identification system in world wide. It is
increasingly used by big companies because of it data structure and reliability to
identify and detected. Although the price is a bit higher compare to the barcode
system, the secure system it has makes it more reliable to use. PICs are popular with
developers due to their low cost, wide availability and large user base. This are the
two main product used in this project.
Overall of this project is a success. The database functioning very well, the
connection from the RFID READER to VB6 also functioning so that the each
different ID-TAG number can be matches with each different user. Lastly the
program in the PIC16F84A is also functioning well, with GREEN LED and RED
LED on after a signal sent to the input pin.
68
REFERENCES
1. Alka R. Harringer, Susan K. Lisack, J ohn K. Gotwals, and Kyle D. Lutes
(2001). Introduction to Computer Programming with Visual Basic 6 : A
Problem Solving Approach. United Kingdom. Que E&T.
2. Barnett, Cox, and OCull. (2002). Embedded C Programming and The
Microchip PIC. United Kingdom. Thomson Delmar.
3. Chan Kok Keong (2006). RFID Convocation Graduates Name Call.
University Technology of Malaysia: Degree Thesis.
4. Bong Khong Lee (2006). RFID Car Security System. University
Technology of Malaysia: Degree Thesis.
5. Chong Shih J un (2005). To Develop RFID System. University Technology
of Malaysia: Degree Thesis.
6. PIC Manual: www.microchip.com
7. Information: en.wikipedia.org
8. PIC Programming: www.electronic-engineering.ch
9. Visual Basic: www.planetsourcecode.com
APPENDIX A
VISUAL BASIC 6 SOURCE CODE
APPENDIX A 70
DATABASE
FORM 1: ADMIN
Private Sub Command1_Click()
If Text1.Text ="123" Then
Timer1.Enabled =False
MsgBox ("Welcome to the FKE CARPARK SYSTEM DATABASE")
Form2.Show
Me.Hide
Else
MsgBox ("SORRY, YOUR PASSWORD IS NOT VALID !")
End If
End Sub
Private Sub exitbtn_Click()
Dim Form1 As New Form1
t =MsgBox("Are you sure to exit?", vbQuestion +vbYesNo)
Me.Hide
If t =vbYes Then
End
Else
Form1.Show
End If
End Sub
Private Sub Timer1_Timer()
MsgBox ("Sorry, your time is up!!!")
End
End Sub
Private Sub Timer2_Timer()
Label1.Caption =Now
End Sub
FORM 2: STAFF REGISTRATION
Private Sub cthbtn_Click()
Form6.Show
Me.Hide
End Sub
Private Sub scanbtn_Click()
Form4.Show
Unload Me
End Sub
Private Sub exitbtn_Click()
APPENDIX A 71
Dim Form2 As New Form2
t =MsgBox("Are you sure to exit?", vbQuestion +vbYesNo)
Me.Hide
If t =vbYes Then
End
Else
Form2.Show
End If
End Sub
Private Sub newbtn_Click()
Form3.Show
Unload Me
End Sub
FORM 3: STAFF IDENTIFICATION
Private Sub backbtn_Click()
Form2.Show
Unload Me
End Sub
Private Sub addbtn_Click()
Text1.SetFocus
t =MsgBox(" New User ID?", vbQuestion +vbYesNo)
Me.Show
If t =vbYes Then
MsgBox (" Please Insert Data ")
Adodc1.Recordset.AddNew
Else
Me.Show
Adodc1.Recordset.Cancel
End If
End Sub
Private Sub searchbtn_Click()
Dim a As String
Dim b As Integer
a =Text1.Text
Let a =UCase(InputBox("Insert Staff No", "INPUT"))
If Len(a) >0 Then
Adodc1.Recordset.MoveFirst
Let b =0
Do While b =0 And Not Adodc1.Recordset.EOF
If UCase(Adodc1.Recordset.Fields("staff_id").Value) =a Then
Let b =1
MsgBox "Record Found !", vbOKOnly +vbQuestion, "No Record"
APPENDIX A 72
Else
Adodc1.Recordset.MoveNext
End If
Loop
If b =0 Then
MsgBox "Record Not Found !", vbOKOnly +vbQuestion, "No Record"
Me.Show
End If
Else
MsgBox "Insert Staff No"
End If
End Sub
Private Sub deletebtn_Click()
t =MsgBox(" Delete User ID? ", vbQuestion +vbYesNo)
Me.Show
If t =vbYes Then
Adodc1.Recordset.Delete
Adodc1.Recordset.MoveFirst
MsgBox (" User ID Deleted ")
Else
Me.Show
Adodc1.Recordset.Cancel
End If
End Sub
Private Sub id_tagbtn_Click()
Form5.Show
Unload Me
End Sub
Private Sub savebtn_Click()
t =MsgBox(" Save User ID?", vbQuestion +vbYesNo)
Me.Show
If t =vbYes Then
Adodc1.Recordset.Save
MsgBox (" User ID Saved ")
Else
Me.Show
Adodc1.Recordset.Cancel
Adodc1.Recordset.MoveFirst
End If
End Sub
Private Sub Timer1_Timer()
Label1.Caption =Now
End Sub
APPENDIX A 73
FORM 4: USER GUIDE
Private Sub backbtn_Click()
Form2.Show
Unload Me
End Sub
FORM 5: RFID ID-TAG
Private Sub backbtn_Click()
Form3.Show
Unload Me
End Sub
Private Sub searchbtn_Click()
Dim a As String
Dim b As Integer
a =Text2.Text
Let a =UCase(InputBox("Insert Staff No", "INPUT"))
If Len(a) >0 Then
Adodc1.Recordset.MoveFirst
Let b =0
Do While b =0 And Not Adodc1.Recordset.EOF
If UCase(Adodc1.Recordset.Fields("staff_id").Value) =a Then
Let b =1
MsgBox "Record Found !", vbOKOnly +vbQuestion, "No Record"
Else
Adodc1.Recordset.MoveNext
End If
Loop
If b =0 Then
MsgBox "Record Not Found !", vbOKOnly +vbQuestion, "No Record"
Form2.Show
Unload Me
End If
Else
MsgBox "Insert Staff No"
End If
End Sub
Private Sub savebtn_Click()
Adodc1.Recordset.Save
Adodc1.Refresh
End Sub
Private Sub CommCtrl_OnComm()
On Error Resume Next
Dim tmpStr As String
APPENDIX A 74
Dim chrRet As String
Dim TagId As String
chrRet =Chr(13)
tmpStr =txtReply
If CommCtrl.CommEvent =comEvReceive Then
While CommCtrl.InBufferCount >0
tmpStr =tmpStr & CommCtrl.Input
If InStr(tmpStr, chrRet) >0 Then
TagId =InRFID125Ctrl1.GetId(tmpStr)
If Len(TagId) >0 Then
txtTagId.Text =TagId
txtReply.Text =""
tmpStr =""
End If
End If
Wend
txtReply.Text =tmpStr
End If
End Sub
Private Sub btnOpen_Click()
If CommCtrl.PortOpen =True Then
CommCtrl.PortOpen =False
End If
If Len(cmbPort) <=0 Then
Exit Sub
End If
Dim strComm As String
strComm ="9600,N,8,1"
Dim Port As Integer
Dim strPort As String
strPort =cmbPort.Text
strPort =Replace(strPort, "COM", "")
Port =CInt(strPort)
CommCtrl.Settings =strComm
CommCtrl.CommPort =Port
CommCtrl.RThreshold =1
CommCtrl.SThreshold =255
CommCtrl.InputLen =0
CommCtrl.OutBufferCount =0
CommCtrl.PortOpen =True
End Sub
Private Sub LoadPort()
cmbPort.Clear
cmbPort.AddItem "COM1"
cmbPort.AddItem "COM2"
End Sub
APPENDIX A 75
Private Sub Form_Load()
txtReply =""
txtCommand =""
LoadPort
End Sub
FORM 6: EXAMPLE
Private Sub backbtn_Click()
Form2.Show
Unload Me
End Sub
APPENDIX A 76
IDENTIFY
FORM 1: ID CONFIRMATION
Private Sub LoadPort()
cmbPort1.Clear
cmbPort2.Clear
cmbPort1.AddItem "COM1"
cmbPort1.AddItem "COM2"
cmbPort2.AddItem "COM1"
cmbPort2.AddItem "COM2"
End Sub
Private Sub btnConnect2_Click()
If CommCtrl.PortOpen =True Then
CommCtrl.PortOpen =False
End If
If Len(cmbPort2) <=0 Then
Exit Sub
End If
Dim strComm As String
strComm ="9600,N,8,1"
Dim Port As Integer
Dim strPort As String
strPort =cmbPort2.Text
strPort =Replace(strPort, "COM", "")
Port =CInt(strPort)
CommCtrl.Settings =strComm
CommCtrl.CommPort =Port
CommCtrl.RThreshold =1
CommCtrl.SThreshold =255
CommCtrl.InputLen =0
CommCtrl.OutBufferCount =0
CommCtrl.PortOpen =True
End Sub
Private Sub btnConnect1_Click()
If CommCtrl.PortOpen =True Then
CommCtrl.PortOpen =False
End If
If Len(cmbPort1) <=0 Then
Exit Sub
End If
Dim strComm As String
strComm ="9600,N,8,1"
Dim Port As Integer
Dim strPort As String
strPort =cmbPort1.Text
strPort =Replace(strPort, "COM", "")
Port =CInt(strPort)
APPENDIX A 77
CommCtrl.Settings =strComm
CommCtrl.CommPort =Port
CommCtrl.RThreshold =1
CommCtrl.SThreshold =255
CommCtrl.InputLen =0
CommCtrl.OutBufferCount =0
CommCtrl.PortOpen =True
End Sub
Private Sub exitbtn_Click()
Dim Form1 As New Form1
t =MsgBox("Are you sure to exit?", vbQuestion +vbYesNo)
Me.Hide
If t =vbYes Then
End
Else
Me.Show
End If
End Sub
Private Sub Form_Load()
txtReply =""
txtCommand =""
LoadPort
End Sub
Private Sub CommCtrl_OnComm()
On Error Resume Next
Dim tmpStr As String
Dim chrRet As String
Dim TagId As String
chrRet =Chr(13)
tmpStr =txtReply
If CommCtrl.CommEvent =comEvReceive Then
While CommCtrl.InBufferCount >0
tmpStr =tmpStr & CommCtrl.Input
If InStr(tmpStr, chrRet) >0 Then
TagId =InRFID125Ctrl1.GetId(tmpStr)
If Len(TagId) >0 Then
masuk.Text =TagId
txtReply.Text =""
tmpStr =""
scanbtn_Click
End If
End If
Wend
txtReply.Text =tmpStr
End If
End Sub
APPENDIX A 78
Private Sub scanbtn_Click()
Dim a As String
Dim ada As Boolean:
a =masuk.Text
ada =False
Adodc1.Recordset.MoveFirst
Do While Not Adodc1.Recordset.EOF
Debug.Print Adodc1.Recordset("id_tag") & "=" & a
If a =Adodc1.Recordset("id_tag") Then
ada =True
Exit Do
Else
ada =False
End If
Adodc1.Recordset.MoveNext
Loop
If ada Then
MsgBox "Valid User. Please Proceed"
Call onled(1)
Else
MsgBox "Invalid User. Cannot Enter !!!"
Call onled(0)
End If
End Sub
Public Function onled(led As Long)
'led
'----------
'1 : green
'0 : red
'----------
If CommCtrl.PortOpen =True Then CommCtrl.PortOpen =False
CommCtrl.CommPort =2
CommCtrl.PortOpen =True
'selecting led
Dim temp As Long
Select Case led
Case 0
temp =4 '0000 0100 : bit2 is on
Case 1
temp =2 '0000 0010 : bit1 is on
End Select
'sending
Dim i As Long
For i =1 To 2000
DoEvents
CommCtrl.Output =Chr(temp)
Next
End Select
End Function
APPENDIX B
PIC16F84A SOURCE CODE
APPENDIX B 80
; FILE: rcv1_1.asm
; AUTH: P.Oh
; DATE: 04/27/02 18:00 1.0 - WORKS
; 04/27/02 18:35 1.1
; DESC: 1.0: PC-to-PIC serial communications.
; REFS: rcv4800.asm
;--------------------------------------------------------------------------
list p=16f84
radix hex
;--------------------------------------------------------------------------
; CPU EQUATES
tmr0 equ 0x01 ; Timer/counter register
status equ 0x03 ; Status word register. See Easy PIC'n p. 145
portA equ 0x05 ; Port A register
portB equ 0x06 ; Port B register
intCon equ 0x0b ; Interrupt control register
rcvReg equ 0x0c ; General purpose register
count equ 0x0d ; General purpose register
temp equ 0x0e ; General purpose register
optReg equ 0x81 ; File register in Bank 1
trisA equ 0x85 ; File register in Bank 1. See Easy PIC'n p. 145
trisB equ 0x86 ; File register in Bank 1. See Easy PIC'n p. 145
;--------------------------------------------------------------------------
; BIT EQUATES
APPENDIX B 81
rp0 equ 5
;--------------------------------------------------------------------------
org 0x000
start bsf status, rp0 ; Switch to Bank 1
movlw b'00001000' ; A3 are input and the rest is output
movwf trisA
movlw b'00000000' ; All port B are output
movwf trisB
bcf status, rp0 ; Switch back to Bank 0
clrf portB
clrf rcvReg
doThis call rcv4800 ; Yes, to serial in subroutine
movf rcvReg, w ; Get byte received
movwf portB ; Display byte on the 8 LEDs
circle goto doThis ; Done
;--------------------------------------------------------------------------
rcv4800 bcf intCon, 5 ; Disable tmr0 interrupts
bcf intCon, 7 ; Disable global interrupts
clrf tmr0 ; Clear timer/counter
clrwdt ; Clear wdt prep prescaler assign
bsf status, rp0 ; to page 1
movlw b'11011000' ; set up timer/counter
movwf optReg
bcf status, rp0 ; Back to page 1
movlw 0x08 ; Init shift counter
APPENDIX B 82
movwf count
sbit btfsc portA, 0 ; Look for start bit
goto sbit ; For Mark
movlw 0x98 ;
movwf tmr0 ; Load and start timer/counter
bcf intCon, 2 ; Clear tmr0 overflow flag
time1 btfss intCon, 2 ; Has the timer (bit 2) overflowed? Skip next line if 1
goto time1 ; No
btfsc portA, 0 ; Start bit still low?
goto sbit ; False start, go back
movlw 0x30 ; real, define N for timer
movwf tmr0 ; start timer/counter - bit time
bcf intCon, 2 ; Clear tmr0 overflow flag
time2 btfss intCon, 2 ; Timer overflow?
goto time2 ; No
movlw 0x30 ; Yes, define N for timer
movwf tmr0 ; Start timer/counter
bcf intCon, 2; ; Clear tmr0 overflow flah
movf portA, w ; Read port A
movwf temp ; Store
rrf temp, f ; Rotate bit 0 into carry flag
rrf rcvReg, f ; Rotate carry into rcvReg bit 7
decfsz count, f ; Shifted 8?
goto time2 ; No
time3 btfss intCon, 2 ; Timer overflow?
APPENDIX B 83
goto time3 ; No
return ; Yes, byte received
;-----------------------------------------------------------------------
end
;-----------------------------------------------------------------------
APPENDIX C
DATA SHEET AND MANUAL