Вы находитесь на странице: 1из 78

PSZ 19:16(Pind.

1/07)
UNIVERSITI TEKNOLOGI MALAYSIA

DECLARATION OF THESIS / UNDERGRADUATE PROJECT REPORT AND COPYRIGHT

Authors full name : MUHAMAD NAIM BIN AHMAD

Date of Birth : 24th JANUARY 1989

Title : DEVELOPMENT OF ALERT SECURITY HOME SYSTEM USING ZIGBEE


TECHNOLOGY

Academic Session : 2012/2013

I declare that this thesis classified as:

CONFIDENTIAL (Contains confidential information under the Official Secret Act


1972)*

RESTRICTED (Contains restricted information as specified by the


organization where research was done)*

OPEN ACCESS I agree that my thesis to be published as online open access



(full text)

I acknowledged that UniversitiTeknologi Malaysia reserves the right as follows:

1. The thesis the property of UniversitiTeknologi Malaysia


2. The Library of UniversitiTeknologi Malaysia has the right to make copies for the purpose
of research only.
3. The Library has the right to make copies of the thesis for academic exchange.

Certified by

SIGNATURE SIGNATURE OF SUPERVISOR

890124-02-5523
DR NORLAILI BT MAT SAFRI
(NEW IC NO/PASSPORT) NAME OF SUPERVISOR

Date: 24thJUNE 2013 Date: 24thJUNE 2013

NOTES: * If the thesis is CONFIDENTAL or RESTRICTED, please attach with the letter from
the organization with period and reasons for confidentiality or restriction.
I hereby declare that I have read this thesis and in my opinion this project
report is
sufficient in terms of scope and quality for the award of the degree of
Bachelor of Engineering (Electrical Electronics)

Signature :
Name : DR. NORLAILI BINTI MAT SAFRI
Date : JUNE 2013
DEVELOPMENT OF ALERT SECURITY HOME SYSTEM USING ZIGBEE
TECHNOLOGY

MUHAMAD NAIM BIN AHMAD

A thesis submitted in fulfillment of the


requirements for the award of the degree of
Bachelor of Engineering (Electrical-Electronic Engineering)

Faculty of Electrical Engineering


UniversitiTeknologi Malaysia

JUNE 2013
ii

I declare that this thesis entitled Development of Alert Security Home System Using
Zigbee Technology is the result of my own research except as cited in the
references. The thesis has not been accepted for any degree and is not concurrently
submitted in candidature of any other degree.

Signature : .
Name : MUHAMAD NAIM BIN AHMAD
Date : JUNE 2013
iii

Specially dedicated to my beloved parents, siblings, lecturers and friends who had
encouraged, guided and inspired me throughout my four years of study in University
Technology of Malaysia
iv

ACKNOWLEDGEMENT

In the name of Allah, the Most Gracious and the Most Merciful

Alhamdulillah, Praise to Allah s.w.t for his blessing and guidance have helped me
carry out my thesis completely. I would like to express my deepest gratitude to my
supervisor Dr. Norlaili Bt Mat Safri for her support and guidance to help me
completion of my research project. Her kindness for accepting me as her student
final years project will be always remembered.

My sincere appreciation also to my family especially my lovely parents


Ahmad Bin Khamis and Che Badariyah Bt Ahmad who always behind me and
supported me either morally or financially. Thanks so much to them for the faith that
put in me.

Lastly, I would like to express gratitude to my friend Siti Aishah Bt Zulkifli


and all fourth SEL members who help me so much to ensure my project completed
on time. I hope our friendship will stand forever.
v

ABSRACT

Burglary cases are in increasing trend in Malaysia as can be seen lately in the
number of such cases reported in local newspapers. In severe cases, death of the
victim is reported. In response to such criminal act, this project was developed to
help community being alert if burglary is being attempted in the neighborhood. This
project presents the development of an alert security home system based on Zigbee
technology. The objective of the project was to provide an emergency sign to
surrounding neighbors. Besides that this project also developed alert security with
low cost to ensure ordinary people can each own this alert security system. The study
included the design circuit that can receive and transmit signals to other circuits that
are placed at other houses in the neighborhood, including the security guard house if
the neighborhood has any. Each circuit can receive and transmit signals by using
application of wireless Zigbee technology and microcontroller as the main control of
circuits. The code programming was developed using MPLAB software and was
burned in PIC 18F4550. The system works when a user pressed button on SK40C
board, then the signals are sent to the other circuits. Once receive, the other circuits
produced buzzer emergency sound and show users house numbers on the LCD
display. This will surely, alert the neighbors and the security guard, and improve the
alertness of people near the crime scene. All hardware and software designed and
used in the project were tested and the integrated security system worked
successfully during the field test. In conclusion, the alert security home system was
developed so that the on-the-spot alertness of community surrounding the burglary
scene in Malaysia can be improved.
vi

ABSTRAK

Kes pecah rumah telah meningkat dan sering menghiasi akhbar sejak hari ini.
Beberapa kespecah rumah turut menyebabkan kematian mangsa.Oleh itu projek ini
telah dibangunkan untuk membantu masyarakat dalam mengurangkan masalah kes
pecah rumah. Projek ini membentangkan pembangunan sistem penggera keselamatan
rumah berdasarkan ZigBee teknologi. Objektif projek ini adalah untuk memberi satu
tanda kecemasan kepada jiran-jiran sekitar. Selain itu projek ini juga membangunkan
sistem penggera keselamatan rumah dengan kos rendah bagi memastikan orang
ramai boleh memiliki alat penggera keselamatan ini setiap satu. Kajian ini termasuk
mereka bentuk litar yang boleh menerima dan menghantar isyarat kepada litar lain.
Setiap litar boleh menerima dan menghantar isyarat dengan menggunakan aplikasi
teknologi ZigBee tanpa wayer dan mikropengawal sebagai kawalan utama litar.
Pengaturcaraan kod adalah menggunakan perisian MPLAB dan menyimpan dalam
PIC 18F4550. Hasil kajian yang menunjukkan apabila menekan butang pada litar
SK40C, maka isyarat akan dihantar kepada litar lain. Kemudian litar yang lain akan
menghasilkan bunyi buzzer kecemasan dan nombor rumah mangsa dengan
menunjukkan nombor rumah mangsa pada paparan LCD. Semua litar telah diuji dan
keputusan menunjukkan litar telah berfungsi dengan jayanya. Kesimpulannya, sistem
penggera keselamatan rumah berdasarkan kecemasan secara langsung dapat
ditingkatkan dalam masyarakat di kawasan perumahan di Malaysia.
vii

TABLE OF CONTENTS

TITLE PAGE

DECLARATION ii
DEDICATION iii
ACKNOWLEDGEMENT iv
ABSTRACT v
ABSTRAK vi
TABLE OF CONTENTS vii
LIST OF TABLES x
LIST OF FIGURES xi
LIST OF APPENDICES xiii
LIST OF ABBREVIATIONS xiv

INTRODUCTION
1.1 Chapter Overview 1
1.2 Background of Study 1
1.3 Problem Statement 2
1.4 Objectives 3
1.5 Scope 4
1.6 Project methodology 4
1.7 Outline of report 6
viii

LITERATURE REVIEW
2.1 Chapter overview 7
2.2 Previous Projects 8
2.2.1 Wireless Home Security and Automation System
based Multi-hop Communication 8
2.2.1.1 Home security system 8
2.2.1.2 Home automation system 8
2.2.2 Home Security Using Zigbee Technology 9
2.2.3 The Smart Home Security System Based On Wireless
Sensor 10

METHODOLOGY
3.1 Chapter Overview 11
3.2 Block Diagram of the Project 11
3.3 Flow Chart of the Project 12
3.4 Hardware Development 15
3.4.1 Interface PIC18F4550 with 15
LCD (2 X 16 characters)
3.4.2 Interface PIC 18F4550 with Xbee 17
3.4.3 SK40C board- Enhanced 40 Pins PIC
Start-up Kit 21
3.4.4 Buzzer as the output of projects 23
3.4.5 PIC 18F4550 Microcontroller 24
3.4.6 Power Supply for the Circuit 25
3.4.7 Donut board as base of circuit 26
3.5 Software Development 27
3.5.1 Software Component 27
3.5.1.1 USB to UART Converter (UC00B) 27
3.5.1.2 USB ICSP PIC Programmer
V2010 (UIC00B) 29
3.5.2 Software Simulation 31
3.5.2.1 MPLAB Software 31
3.5.2.2 XCTU Software 33
ix

PROJECT RESULT
4.1 Chapter Overview 35
4.2 Initialized input and output system 35
4.3 Complete circuits 36
4.4 Complete circuits with the power supply 37
4.5 Cases for Push Button 38
4.5.1 When a user press switch button on circuit A 39
4.5.2 When a user press switch button on circuit B 40
4.5.3 When a user press switch button on circuit C 41

CONCLUSION & RECOMMENDATION


5.1 Chapter Overview 42
5.2 Conclusion 42
5.3 Recommendation 43

REFERENCES 44

APPENDICES
APPENDIX A 45
APPENDIX B 51
APPENDIX C 57
x

LIST OF TABLE

Table No Title Page

1.1 Gantt chart FYP 1 5


1.2 Gantt chart FYP 2 6
3.1 LCD Pin Function 17
3.2 Function of Pin Diagram Xbee S2 19
3.3 Specification of SK40C board 22
3.4 Function of UC00B Pin 28
3.5 Function of Each UIC00B Part 30
xi

LIST OF FIGURE

Figure No Title Page

1.1 Project Flow 5


2.1 Flow Chart Process Home Security Using Zigbee Technology 9
2.2 Flow Chart Process Smart Home Security System 10
3.1 Block Diagram of the Project 12
3.2 Flow Chart of the Transmitter program 13
3.3 Flow Chart of the Receiver program 14
3.4 LCD (2 X 16 characters) 15
3.5 LCD Connection Pins 16
3.6 16 Pin Headers 16
3.7 Xbee S2 18
3.8 Xbee S2 Pin Diagram 18
3.9 System Data Flow in a UART Interfaced Environment 18
3.10 Connection Xbee with SK40C Board 20
3.11 Resistors of 1k and 2.2k 20
3.12 Voltage Regulator 3.3v (LM1117) 21
3.13 Schematic Voltage Regulator 3.3v (Lm1117) 21
3.14 SK40C (Top View) 22
3.15 SK40C (Side View) 23
3.16 SK40C (Bottom View) 23
3.17 Buzzer 6-12V c/w Wire 24
3.18 PIC 18F4550 microcontroller 24
3.19 PIC18F4550 Pin Diagram 25
3.20 9V Battery 25
xii

3.21 AC to DC Adaptor 26
3.22 Connection 9v Battery to SK40C Board 26
3.23 Donut Board 26
3.24 UC00B Module 28
3.25 Connection Pin XBEE Breakout Board to UC00B 28
3.26 3.3V Is Selected 29
3.27 Connection USB of UC00B into USB Port Of Computer 29
3.28 UIC00B Module 30
3.29 Connection UIC00B with SK40C Board 30
3.30 MPLAB Interface 32
3.31 PIC Kit2 Show Programming Successful 32
3.32 Zigbee Coordinator 33
3.33 Zigbee Router 34
4.1 Initialize of Input and Output Project 36
4.2 The Three Complete Circuits 36
4.3 Circuits Connected To Power Supply 37
4.4 User Press Button Circuit A 39
4.5 Circuit B and C Show Victims House Numbers and
Produces Buzzer Sound 39
4.6 User Press Button Circuit B 40
4.7 Circuit C and A Show Victims House Numbers and
Produces Buzzer Sound 40
4.8 User Press Button Circuit C 41
4.9 Circuit C and A Show Victims House Numbers and
Produces Buzzer Sound 41
xiii

LIST OF APPENDICES

APPENDIX TITLE PAGE

APPENDIX A Programming code for circuit A 45


APPENDIX B Programming code for circuit B 51
APPENDIX C Programming code for circuit C 57
xiv

LIST OF ABBREVIATION

AC Alternating Current
ACZD Access Control Zigbee Devices
BTBEE Bluetooth Bee
DC Direct current
DTR Data Terminal Ready
GSM Global System for Mobile Communication
ICSP In Circuit Serial Programming
ID Identification
I/O Input/Output
LCD Liquid Crystal Display
LED Light Emitter Diode
PDRM Royal Malaysian Police
PIC Peripheral Interface Connection
PCB Printed Circuit Board
RTS Request To Send
RX Received Data
SMS short message service
SW Switch
TTL Transistor-Transistor Logic
TX Transmitted Data
UART Universal Asynchronous Receiver Transmitter
UC00B USB to UART Converter
UIC00B USB ICSP PIC Programmer V2010
USB Universal Serial Bus
WSN Wireless sensor network
CHAPTER 1

INTRODUCTION

1.1 Chapter Overview

This chapter will be discussing about project background, problem statement,


objective of the project, the scope of the project and the thesis outline.

1.2 Background of Study

Burglary cases become growing every year. There are many cases of burglary
in Malaysia show burglars could hurt or kill the victims. According to statistics from
the Royal Malaysian Police (PDRM), burglary cases increased even though the
police increase patrols during the 24-hour control. Most burglary cases happened at
night rather than during the day. The increasing of burglary cases does not mean the
failure of the police but due to the density of the Malaysian population is growing
every year. An increasing number of people can cause a lot of social problems in the
2

community. Besides the presence of many foreign employees in Malaysia is also a


factor increase of burglary cases.

There are several ways to reduce burglary cases such as by an installing alert
security home system. Numerous products of an alert security home system based on
wireless technology in the markets nowadays. The reasons why wireless technologies
become popular because easy to use, saves cost of wiring and low cost of
maintenance. There are many types of wireless technology such as Zigbee, infrared,
Bluetooth and radio frequency. Zigbee technology is chosen to develop an alert
security home system based on wireless technology because it is more reliable, high
efficiency and connectivity range can cover long distances.

Zigbee is created by Zigbee Alliance. The Zigbee Alliance is a company that


maintain and publish the Zigbee standard. Zigbee works at the frequencies which is
2.4002.484 GHz (Universal), 902-928 MHz (North America) and 868.0868.6
MHz (Europe). There are three types of communication are applied in Zigbee
wireless technology which is star topology, tree topology and mesh topology. The
Zigbee wireless device operates with low power consumption which makes it the
smartest wireless device to use in Wireless Sensor Network (WSN).

1.3 Problem Statement

Home wireless alert security systems were developed to reduce burglary


cases and becoming popular in Malaysia today. In order to design alert security home
system, the cost of alert security must be affordable so that ordinary people can own
it. It is important to ensure that alert security system in high quality shape although
the price is not expensive as well as in markets.
3

Other than that, the application of the hardwired alert security system is not
efficient nowadays. Hardwired alert security system also gives lots of troubleshoot
and disorganized. So here necessities of design alert security home system with new
approach. Wireless technology is one solution to replace the application of
hardwired because wireless technology offer greater productivity and quality.

Besides that, alert security systems that exist currently only involve
communication between the victims and security guard or the specific organization
who design that alert security. Actually one should know what happened to their
neighbors when neighbors in the trouble situation. So the project of alert security that
can give awareness to surrounding neighbors should be developed by wisely.

1.4 Objectives

The main objective of this project is to design and develop alert security
home using Zigbee wireless technology that can provide emergency signs to
surrounding neighbors. People who live as one community needs to know what
happened to their neighbors if they got trouble cases.

Another objective of this project is to design alert security home system by


using a microcontroller as the main control panel of the wireless alert security
system. Microcontroller as the brain of the project can control more than one of
output or input. In the presence microcontroller so that buzzer and LCD display as
output components can function simultaneously.
4

Besides that, another objective is to develop an alert security system with low
cost. Alert security that has been a designed should not give financial burden to
society.

1.5 Scope

The scope of this project is divided into two parts which are hardware and
software. In the hardware part of design alert security home project needs
PIC18F4550 microcontroller, Xbee S2, SK40C board, buzzer, LCD display, battery
9V, resistors 1k and 2.2k, capacitor 10F, voltage regulator 3.3V (LM1117) and
donut board.

In software part are programming the PIC microcontroller using the MPLAB
software. To configure Xbee needs XCTU software. UIC00B component is well-
matched with PIC kit 2, thus PIC kit 2 programming software should be installed.

1.6 Project Methodology

Project methodology shows the flow of projects that have been developed as
Figure 1.1. The Gantt chart for FYP 1 and FYP 2 also was included in this chapter.
Table 1.1 represents Gantt chart FYP 1 and Table 1.2 for Gantt chart FYP 2.
5

Understanding the problem


1

Literature review
2

Xbee configuration
3

Hardware development
4

PIC microcontroller programming


5

Combine hardware and programming parts


6

Testing project
7

Figure 1.1: Project Flow

Table 1.1: Gantt chart FYP 1


6

Table 1.2: Gantt chart FYP 2

1.7 Outline of Report

This project consists five chapters. In the first chapter, discuss about the
background of the study, problem statement, objective, scope and project
methodology of this project. While Chapter 2 will discuss more on theory and
literature reviews that have been done. In Chapter 3, the discussion will about
methodology parts, hardware and software implementation of this project. Chapter 4
discusses about the result of the project. Lastly chapter 5 are about conclusion and
some suggestions for future works.
CHAPTER 2

LITERATURE REVIEW

2.1 Chapter Overview

A literature review was carried out throughout the whole project to increase
knowledge to complete this project. The main sources for gain knowledge about this
project are from books, journals and some articles from the internet. So this chapter
discussed the previous projects and theses related to this project. By doing analysis to
the previous projects or researchers, there are important to know how the system
works. Therefore it can be applied to the project that will be developed.
8

2.2 Previous Projects

2.2.1 Wireless Home Security and Automation System Utilizing ZigBeebased


Multi-hop Communication by Rozeha A. Rashid, MohdAdib B. Sarijari,
MohdRozainiAbd Rahim, NurHijaMahalin

These projects explained about smart home divided into two features there are home
security system and home automation system.

2.2.1.1 Home security system

The triggered sensor node (intruder sensor) will send an alert signal to the
main microcontroller through the application of Xbee using multi-hop
communication. The main microcontroller that receives the alert signal will send the
signal to the user by using SMS via the GSM Modem.

2.2.1.2 Home automation system

User controls their house by sending the command through SMS to the main
microcontroller at home. The main microcontroller at home that received the
command will send the command to the destination node via application of Xbee
using multi-hop communication. The destination node then will work out the task as
commanded by the user.
9

2.2.2 Home Security Using Zigbee Technology by R.Saravanan&A.Vijayaraj

These journals explain about home security using Zigbee technology written
by R.Saravanan&A.Vijayaraj from Saveetha engineering college, Chennai, India.
When the sensor detects intruders, the sensor sent a signal to the microcontroller.
Then microcontroller produced the alarm sound. Zigbee was connected to the
microcontroller using RS232 cable. Zigbee will send signals to the other Zigbee that
located in security room. So the security guard noticed this emergency sign happened
at the victims house. Figure 2.1 shows the flow chart the system works.

Figure 2.1: Flow Chart Process Home Security Using Zigbee Technology
10

2.2.3 The smart home security system based on wireless sensor network by Yu
Hu and Tao Zhou

The Pyro electric infrared sensor identified the human body when someone
approaches the door of the smart home. Then the Pyro electric infrared sensor is
made the access control Zigbee devices (ACZD) sent a signal to catch peoples
identification. If the person brings an ID tag (Zigbee device), the tag will send an
encrypted signal to ACZD, then ACZD choose whether to open the digital door. The
ACZD will inform the householders the visitors is coming through internet if there
are no people stay in the house. The main controller will send a command to capture
a guests image and send through householder remote PC. After a householder
endorses the visitors identity, then he can open through remote controlling the
access system without making the visitor wait outdoor the house. Figure 2.2 shows
the flow chart works.

Figure 2.2: Flow Chart Process Smart Home Security System


CHAPTER 3

METHODOLOGY

3.1 Chapter Overview

This chapter describes about the method that have been used to develop an
alert security home system using Zigbee technology. This chapter also included
block diagram, flow chart, hardware and software development of the project.

3.2 Block Diagram of the Project

Figure 3.1 shows a block diagram of the project that was developed. Block
diagram shows the situation of two houses there are the victims house and the
neighbors house. These situations show when the victim pressed the switch button,
then the main microcontroller will give command to UART for transmits signal
through Xbee component. The others Xbee located at a neighbors house will be
receiving the signal. Then the signal will be sent to the main microcontroller through
UART connection.
12

Finally the main microcontroller gave a command to the buzzer for produce
emergency sound and LCD display for show victims house number.

Figure 3.1: Block Diagram of the Project

3.3 Flow Chart of the Project

Figure 3.2 shows a flow chart of the transmitter program. In other words this
flow chart is about a situation when victim pressed switch button. After a user
pressed the switch button, then the main microcontroller produced LED blinking as
the indicator that are the connection happened between UART connections. Finally
Xbee sent the signal to others house that installed the Zigbee devices too. After
pressing the reset button, Xbee will stop the communication between them.
13

Figure 3.2: Flow Chart of the Transmitter Program


14

Figure 3.3 shows a flow chart of the receiver diagram. If Zigbee devices
detected the signal then it will send to the main microcontroller through UART
connection. Then the main microcontroller will produce led blinking, buzzer
emergency sound and display victims house number through the LCD display. After
user pressed reset button then all output components will disable function.

Figure 3.3: Flow Chart of the Receiver Program


15

3.4 Hardware Development

The project was ongoing with developing the hardware parts. Before that,
chosen the suitable components very important to make sure the project can work
fine. Every connection between the components needs to refer to the data sheet.

3.4.1 Interface PIC18F4550 with LCD (2 X 16 characters)

LCD used in this project is JHD162A (2 X 16 characters). Figure 3.4 shows


the LCD (2 X 16 characters) and Figure 3.5 shows an LCD connection pin to SK40C
board. The LCD was connected by soldering the 16 pin header pin to the LCD
components. Figure 3.6 shows the image of 16 pin header. Table 3.1analyses the
function of each pin of LCD display.

Figure 3.4: LCD (2 X 16 characters)


16

Figure 3.5: LCD Connection Pins

Figure 3.6: 16 Pin Headers


17

Table 3.1: LCD pin function

Connection
Pin Name Pin Function
1 VSS GROUND GND
2 VCC Positive supply for LCD 5V
3 VEE Brightness adjust Connected to a preset to adjust brightness
4 RS Select register RC0
5 R/W Select read/write GND
6 E Start data read/write RC1
7 DB0 Data bus pin RD0
8 DB1 Data bus pin RD1
9 DB2 Data bus pin RD2
10 DB3 Data bus pin RD3
11 DB4 Data bus pin RD4
12 DB5 Data bus pin RD5
13 DB6 Data bus pin RD6
14 DB7 Data bus pin RD7
15 LED+ Data bus pin VCC
16 LED- Data bus pin GND

3.4.2 Interface PIC 18F4550 with Xbee

Nowadays Zigbee is currently being built into millions of home automation &
smart energy devices. The model of Zigbee that be used is XBee Module 2mW PCB
Antenna - Series 2 (Zigbee Mesh). Series 2 modules allow creating complex mesh
networks. These modules allow a very reliable and simple communication between
microcontrollers or computers or other systems. Figure 3.7 shows the image of Xbee
that have been used. Xbee have 20 pin diagram and each of the pins have the
different function. Figure 3.8 shows the pin diagram of Xbee S2 and Table 3.2 shows
the function of each pin of Xbee S2. While Figure 3.9 shows the ways of the UART
interface works between Xbee components and microcontroller.
18

Figure 3.7: Xbee S2

Figure 3.8: Xbee S2 pin diagram

Figure 3.9: System Data Flow in a UART Interfaced Environment


19

Table 3.2: Function OfPin Diagram Xbee S2

Once the configuration of UART was done, Xbee is now set for the
embedded wireless development. Figure 3.10 shows connection Xbee with SK40C
Board. The connection between Xbee and SK40C Board only involve four
connections, there are TX, RX, ground and VCC. TX and RX pins should be cross
connected between them.

TX Xbee should be connected to the RX pin of SK40C Board and RX pin of


Xbee should be connected to TX on the pin SK40C Board. A voltage divider circuit
was developed between the connection of RX (Xbee) and TX (SK40C Board).
Figure 3.11shows the resistors of 1k and 2.2k that are used to develop voltage
divider circuit. This connection important to ensure TX (Xbee) will be work
20

appropriated. The range voltage for TX (Xbee) is around 3.3V-3.5V. An equation 3.1
shows the calculation of voltage divider circuit that has been developed.

Make sure placed the voltage regulator 3.3V (LM1117) at the connection
between VCC (Xbee) and VCC (SK40C board). It is because Xbee only can be
operated on 3.3V. Figure 3.12 shows the image and Figure 3.13shows a schematic
diagram of the voltage regulator 3.3v (LM1117).Vin and Vout of voltage regulator
need to connect in parallel with 10F to store electrical charge. Finally ground
(Xbee) connects to ground (SK40C board).

Figure 3.10: Connection Xbee with SK40C Board

Figure 3.11: Resistors of 1k and 2.2k


21

(3.1)

(5) = 3.44V

Figure 3.12: Voltage Regulator 3.3v (Lm1117)

Figure 3.13: Schematic Voltage Regulator 3.3v (Lm1117)

3.4.3 SK40C board- Enhanced 40 Pins PIC Start-Up Kit

SK40C is one of the simple boards built in 40 pins PIC microcontroller start-
up kit. SK40C Board delivers additional structures like 2 x Programmable switch, 2 x
22

LED indicator, LCD display, UART communication and USB on board. Besides
that, SK40C Board easy to use because it has small shape dimension, solid and
powerful. This part to show the circuit of SK40C in Figure 3.14 which is a top view
of SK40C board and also Table 3.3 for specification of SK40C board.

Figure 3.14: SK40C (Top View)

Table 3.3: Specification of SK40C board

Label Function
A Connector For Uic00b Programmer
B Jp10 For PIC kit
C UART Connector
D Led Connector
E 40pin Ic Socket For Pic MCU
F Programmable Push Button
G Reset Button
H LCD Contrast
I Jp9 For USB
J Jp8 For LCD Backlight
K Turn Pin For Crystal
L LCD Display
M Header Pin And Turn Pin
N Dc Power Adopter Circuit
O USB Connector
P Power Indicator Led
Q Toggle Switch For Power Supply
23

Figure 3.15 and Figure 3.16shows the side view and the bottom view.

Figure 3.15: SK40C (Side View)

Figure 3.16: SK40C (Bottom View)

3.4.4 Buzzer as the output of projects

A buzzer can be connected to any I/O pin as output. Figure 3.17shows an


image for the buzzer that be used in this project. The buzzer was defined as output at
RB2 pin of pic 18F4550 microcontroller. The buzzer will produce alarm sound after
microcontroller received alert signal from UART connection of Xbee.
24

Figure 3.17: Buzzer 6-12V c/w Wire

3.4.5 PIC 18F4550 Microcontroller

Peripheral Interface Connection (PIC) microcontroller is the main processing


unit for design alert security home system. The type of PIC microcontroller that be
used is the PIC 18F4550. This PIC was developed in 40 pins which can be
programmed by using the appropriate type of software and a special device to
transfer the program into the microchip. PIC18F4550 also introduces design
enhancements that make design in high-performance and power sensitive
applications. Figure 3.18 shows the image of PIC18F4550 microcontroller and
Figure 3.19 show the image pin diagram of microcontroller PIC18F4550.

Figure 3.18: PIC 18F4550 microcontroller


25

Figure 3.19: PIC18F4550 Pin Diagram

3.4.6 Power Supply for the Circuit

User can choose either AC to DC adaptor or 9V battery to power up the


SK40C board. Figure 3.20 and Figure 3.21 show image of 9V battery and AC to DC
adaptor. In Figure 3.22is the image of model connection 9v battery to SK40C board.

Figure 3.20: 9V Battery


26

Figure 3.21: AC to DC Adaptor

Figure 3.22: Connection 9v Battery to SK40C Board

3.4.7 Donut board as base of circuit

Donut board will be used as a base for each circuit that be designed. All
components must be soldered on the donut board to make those components more
solid. Figure 3.23 shows the image of donut board.

Figure 3.23: Donut Board


27

3.5 Software Development

After finishing run for hardware part, then need to continue for developing software
part. Software development divided into two structures which is software component
and software simulation.

3.5.1 Software Component

A software component that be used are USB to UART Converter (UC00B)


and USB ICSP PIC Programmer V2010 (UIC00B). All software components will be
explained more detail in the section below.

3.5.1.1 USB to UART Converter (UC00B)

UC00B is a USB to UART converter that provided a simple interface to most of


microcontroller UART pins. It offers the replacement to the old-style technique of
serial communication. However, since computer serial port used RS232 protocol and
microcontroller used TTL (Transistor-transistor Logic) UART, a level shifter is
needed between these standards. Lately, serial port of computer has been phased out
and being replaced by USB. UC00B offers the simplest interface for microcontroller
to communicate with the computer. UC00B is a USB to UART converter offers low
cost, no external source and easy to use. UC00B also have a 6 pin interface there are
TXD, RXD, Ground, DTR, RTS and VCC (5V or 3.3V). Figure 3.24 shows the
image of UC00B components and Table 3.4 shows the function that was labeled at
image of UC00B components.
28

Figure 3.24: UC00B module

Table 3.4: Function of UC00B Pin

LABEL FUNCTION
A USB A Type (male)
B Voltage selector (3.3V or 5V)
C 6 ways header pin for interface to microcontroller

Connect pin from XBEE Breakout board to UC00B by using female to


female jumper wires. There are only four pins used are VCC, ground, TX and RX
pin. TX pin of BTBEE should be connected to Rx pin of UC00B and RX pin of
BTBEE should be connected to TX pin of UC00B.Figure 3.25 shows the connection
pin Xbee Breakout Board UC00B. Make sure 3.3V is select on UC00B as Figure
3.26. Finally connect USB of UC00B into USB port of computer/laptop as Figure
3.27. Wait a minute for driver devices detect the COM port.

Figure 3.25: Connection Pin XBEE Breakout Board to UC00B


29

Figure 3.26: 3.3V Is Selected

Figure 3.27: Connection USB of UC00B into USB Port Of Computer

3.5.1.2 USB ICSP PIC Programmer V2010 (UIC00B)

UIC00B provide low cost yet reliable, productive and easy to use. It is
designed to program popular Flash PIC MCU which includes most of the PIC family.
It can be programmed in 8bit, 16bit and 32bit PIC MCU. So UIC00B allow user to
quickly program and debug the source code while the target PIC is on the
development board. UIC00B is designed to be plug and play with USB connection as
nowadays USB port is available and widely used on laptops. UIC00B receive power
directly from the USB connection, so no need external power supply. UIC00B offers
reliable, high speed programming and free windows interface software. Figure 3.28
shows the image of UIC00B and table 3.5 is the function of each part in UIC00B.
30

Figure 3.28: UIC00B Module

Table 3.5: Function of Each UIC00B Part

No Function
1 UIC00B main board
2 Mini USB cable
3 Rainbow cable (programming cable)

Connect one side of programming cable to box header of UIC00B and the
other side to box header on a development board (SK40C board) to be programmed.
Since UIC00B is compatible with PIC kit 2, thus PIC kit 2 programming software
should be installed. Figure 3.29 shows the connection UIC00B with SK40C board to
burn programming code in PIC 18F4550.

Figure 3.29: Connection UIC00B with SK40C Board


31

3.5.2 Software Simulation

The software is used for simulation and programming purposes. Besides that,
the software is compulsory to program the microcontroller. The software is very
important so that the system can be operated. Below is the software that has been
used in to design alert security home:

1. For PIC microcontroller the MPLAB is used to run programs c code.


2. UIC00B programmer needs PIC kit2 software to run programming code.
3. Lastly for Xbee components need XCTU software to configure Xbee.

3.5.2.1 MPLAB Software

MPLAB is a windows program platform that makes writing and developing a


program easier. MPLAB software is available from www.microchip.com. MPLAB
version 8.46 has been installed in laptop to run programming code. After download
MPLAB, install using all of the default settings. Figure 3.30 shows the MPLAB
software interface. By writing the complete programming code for the system will
not make the hardware work until it is finally transmitted to the microcontroller
parts. USB ICSP PIC Programmer V2010 (UIC00B) will be used to burn
programming code into PIC microcontroller. The original source code file format is
in *. asm* format for MPLAB. After the program had successfully been compiled,
an *. hex* file will appear for both software as in Figure 3.31.
32

Figure 3.30: MPLAB Interface

Figure 3.31: PIC Kit2 Show Programming Successful


33

3.5.2.2 X-CTU Software

Digi organization was created X-CTU software and it works on all versions
of windows. The X-CTU program has 4 core responsibilities which are to browse
current configurations, send raw text commands or data to the Xbee, and perform a
range test with another Xbee or to setup how your local PC should communicate
with the Xbee Module. The Xbee components also offer a quick and easy solution
for wireless needs and it even uses a standardized protocol to make sure your
information reaches its destination. Figure 3.32 shows the methods to configure Xbee
as Zigbee coordinators. Roughly fixed function set as ZIGBEE COORDINATOR
AT. Then press read pin and XCTU will show serial number high and serial
number low at addressing part. Both serial numbers were saved because it will be a
copy of the serial numbers of others Xbee components to set as the router nodes (end
nodes).

Figure 3.32: Zigbee Coordinator


34

Figure 3.33 shows the method to configure Xbee as Zigbee routers. Fixed
function set as ZIGBEE ROUTER AT. Copy the both serial numbers and put on
the serial number high and serial number low at addressing part as normal. Then
press write pin and it will be set up as Zigbee routers. After doing setup Xbee as
coordinator and the others as router nodes, so it will be automatically operated based
on multi hop communication.

Figure 3.33: Zigbee Router


CHAPTER 4

PROJECT RESULT

4.1 Chapter Overview


This chapter will show the full complete circuit and how the input and output system
work.

4.2 Initialized input and output system

Figure 4.1 shows the function that be initialized in MPLAB software. The
initialize parts are essential to ensure the input or output will be workable when
program code burned in PIC microcontroller.
36

Figure 4.1: Initialize Input and Output of the Project

4.3 Complete circuits

These are the complete circuit was developed in this project. Figure 4.2
shows three complete circuits have been designed and are labeled with A, B and C.
Each circuit has a SK40C board, Xbee, PIC18F4550 microcontroller, LCD display
and buzzer as the main components

Figure 4.2: Three Complete Circuits


37

4.4 Complete circuits with the power supply

Figure 4.3is the circuits when connected with power supply. Battery 9V as power
supply was connected to the DC power adapter circuit. When toggle switch was on,
led beside toggle switch will be lighting up with green color. The led green color will
always light up to notify the board already has a power supply. At the same time,
LED 1 will be lit up with red color after connecting to the power supply. LED 1 was
set in programming code to be lit up when circuit already connected to the power
supply. LED 2 will be lit up when microcontroller notify transmit and receive signal
occur between Xbee components. LED 2 also produces a red color when its
lightning up.

Figure 4.3: Circuits Connected To Power Supply


38

4.5 Cases for Push Button

Each of SK40C board has three buttons. There are two push buttons and a
reset button already included on SK40C board. Then pushbutton 1 was defined as
sw1 at RB0 and button 2 as sw2 at RB1. Sw1 will push to send emergency
signal to surrounding houses which also attach alert security home that be designed.
Sw2 always disabled. The other house also can receive emergency alert security
from the victims house because of the Xbee components which attach to the
microcontroller. Xbee components have a connection with microcontroller part in
this project design. Every signal that receive or transmit will be analyzed by main
microcontroller. Xbee transmit signal based on multi hop communication will
communicate with other Xbee. The other Xbee that receives the signal will prepare
main microcontroller to produce buzzer sound and display the victims house
numbers. Then neighbor or victim needs to press reset button to stop the
communication between Xbee components. So LCD display will look likes as
normal and the buzzer will stop ringing.
39

4.5.1 When a User Pressed Switch Button on Circuit A

The figure 4.4 shows when a switch button at circuit A was pressed by the
user. So Xbee on the circuit A will send a signal to other circuits. Circuit B and C
that received the signal will make the main microcontroller will produce buzzer
sound and display victims house numbers as figure 4.5. The LCD display will show
House A Security Alert on screen.

Figure 4.4: User Press Button Circuit A

Figure 4.5: Circuit B and C Show Victims House Numbers and Produces Buzzer
Sound
40

4.5.2 When a User Press Switch Button on Circuit B

The figure 4.6 show when a switch button at circuit B was pressed by a user.
Then Xbee at circuit B sent a signal to circuit A and C. Circuit A and C that received
the signal will make the main microcontroller produced a buzzer sound and display
victims house numbers as figure 4.8. The LCD display showed House B Security
Alert on screen.

Figure 4.6: User Press Button Circuit B

Figure 4.7: Circuit C and A Show Victims House Numbers and Produces Buzzer
Sound
41

4.5.3 When a User Press Switch Button on Circuit C

The figure 4.8 show when a user pressed a switch button on circuit C. Then
Xbee at circuit C sent a signal to circuit A and B. Circuit A and B that received the
signal will make the main microcontroller produced a buzzer sound and display
victims house numbers as figure 4.9. The LCD display showed House C Security
Alert on screen.

Figure 4.8: User Press Button Circuit C

Figure 4.9: Circuit A and B Show Victims House Numbers and Produces Buzzer
Sound
CHAPTER 5

CONCLUSION & RECOMMENDATION

5.1 Chapter Overview

This chapter will state the conclusion and recommendation for the whole
project. A few of recommendation need to enhance this project become better.

5.2 Conclusion

Finally, an alert security home system based on wireless Zigbee technology


has been successfully developed. The objective of the project also have been
achieved such as application of wireless Zigbee technology can send emergency
signal to the surrounding neighbors house based on multi hop communication.
Besides that, this project also designs alert security home with low cost and reliable
to use. The wireless established in Zigbee technology also offer high stability and
cover for long distance up to 300m, so that it's very suitable residential areas in
Malaysia.
43

5.3 Recommendation

However, the system still needs extra improvement in future to achieve more
effective system so that it can contribute to the user. In order to attain this
recommendation, few sensors need to be developed such as intruder sensor. Intruder
sensor can be located at the doors or steel windows to ensure the burglars will be
detected when they tried to come into a house.

Besides that, this system or circuit can be designed in small shape, portable
which is convenient for the user to bring the device everywhere and it will be easy to
take quick action during an emergency case.
44

REFERENCES

1. Patrick Kinney, (2003), ZigBee Technology: Wireless Control that Simply


Works, Kinney Consulting LLC.

2. Zachary Seto, Jackson Yu (May 3, 1999.), Home Security System. Cornell


University EE476 Final Project.

3. Li CaiNina Dai (2009), The Home Security System Based on ZigBee


Technology, College of Physic and Electronic Engineer Chongqing Three
Gorges University Wanzhou, Chongqing

4. Yu Hu and Tao Zhou (2011), The Smart Home Security System Based On
Wireless sensor Network, measuring and controlling technology institute,
Taiyuan university of technology, Taiyuan 030024, China.

5. Chan Hwoh Chueng(2009). "Wireless Home Security System". UTM, BEng.


Thesis.

6. http://www.cytron.com.my

7. Norfatin AkmaBintiElias (2010), DevelopmentOf Wireless Sensor Node For


Intruders Detection, System.UniversitiTeknologi Malaysia: BEng. Thesis.

8. Logeswaran A/L Arumugam(2008), Wireless Home Security System,


Universiti Teknologi Malaysia: BEng. Thesis.

9. Mohd Arif B MdKurdi (2008), Wireless Security Alarm System Using


MicrocontrollerUniversiti Teknologi Malaysia: BEng. Thesis.
45

APPENDIX A

Programming code for circuit A

//===========================================================
//===========================================================
#include <p18f4550. h>
#include "x lcd. h"
#include "delays. h"
#include "usart. h"
//===========================================================
// Define Pins
//===========================================================
#define led1 LATBbits.LATB6
#define led2 LATBbits.LATB7
#define buzz LATBbits.LATB2
#define sw1 PORTBbits.RB0
#define sw2 PORTBbits.RB1
//===========================================================
// Function Prototypes
//===========================================================
void Delay_1msX (unsigned int miliseconds);
void Delay_100msX (unsigned int msec);
void delay(unsigned long time);
unsigned char uart_rec(void) //receive uart value
{
unsigned char rec_data;
while(PIR1bits.RCIF==0); //wait for data
rec_data=RCREG;
return rec_data; //return the data received
}
void uart_send(unsigned char data)
{
while(TXSTAbits.TRMT==0); //only send the new data after
TXREG=data; //the previous data finish sent
44

}
void uart_str(const rom char *s)
{
while(*s)uart_send(*s++);
}
//======================================================
// Global Variables
//======================================================
unsigned int i, t;
unsigned char data_tx, data_rx;
//======================================================
// Main Program
//======================================================
void main ()
{
//set I/O input output
TRISB = 0b00000011; //Configure PORTB I/O direction
TRISC = 0b11000000; //Configure PORTC I/O direction
TRISD = 0b00000000; //Configure PORTD I/O direction
PORTB = 0;
PORTC = 0;
PORTD = 0;
buzz=1;
//-------------------------------------------------------------------------
// Configure External LCD
//-------------------------------------------------------------------------
OpenXLCD( EIGHT_BIT & LINES_5X7 );
ClearXLCD(); //Clear display
led1=1; //Turn on led1
//-------------------------------------------------------------------------
// Configure UART
//-------------------------------------------------------------------------
OpenUSART (USART_TX_INT_OFF & //Transmit interrupt off
USART_RX_INT_OFF & //Receive interrupt off
USART_ASYNCH_MODE & //Asynchronous mode - UART
USART_EIGHT_BIT & //8-bit transmit/receive
45

USART_CONT_RX & //Continuous reception


USART_BRGH_HIGH, //High baudrate
129); //9600 baudrate at 20MHz frequency
led2=0; //Turn on led2
while(1)
{
//-------------------------------------------------------------------------
// UART Transmit
//-------------------------------------------------------------------------
SetCurXLCD(0); //Set cursor to line 1, position 0
putrsXLCD("Neigh. Security"); //Display LCD
SetCurXLCD(20); //Set cursor to line 2, position 0
putrsXLCD("System");
led1=1;
delay(10000);
led1=0;
delay(10000);
led1=1;
data_rx=getcUSART(); //Assign received data to variable
data_tx='A';
if(sw1==0){
led2=1;
// while(1){
while(BusyUSART()); //Check if Usart is busy or not
putcUSART(data_tx); //Echo the data in Hyperterminal
// }
while(1);
}
else if(data_rx=='B'){
led2=1;
ClearXLCD(); //Clear LCD
SetCurXLCD(0); //Set cursor to line 1, position 0
putrsXLCD("House B"); //Display LCD
SetCurXLCD(20); //Set cursor to line 2, position 0
46

putrsXLCD("Security Alert");
while(BusyUSART()); //Check if Usart is busy or not
putcUSART(data_rx); //Echo the data in Hyperterminal
// while(1){
led1=0;
buzz=0;
while(BusyUSART()); //Check if Usart is busy or not
putcUSART(data_rx); //Echo the data in Hyperterminal
// }
while(1);
}
else if(data_rx=='C'){
led2=1;
ClearXLCD();
SetCurXLCD(0); //Set cursor to line 1, position 0
putrsXLCD("House C"); //Display LCD
SetCurXLCD(20); //Set cursor to line 2, position 0
putrsXLCD("Security Alert");
buzz=0;
while(BusyUSART()); //Check if Usart is busy or not
putcUSART(data_rx); //Echo the data in Hyperterminal
// while(1){
led1=0;
buzz=0;
while(BusyUSART()); //Check if Usart is busy or not
putcUSART(data_rx); //Echo the data in Hyperterminal
// }
while(1);
}
Delay_100msX(5); //Delay for 2 seconds
ClearXLCD(); //Clear LCD
}
}//End of main
47

//========================================================
// Subroutines
//========================================================

/*******************************************************************
* Function Name: Delay_1msX *
* Return Value: void *
* Parameters: miliseconds: amount of delay *
* Description: This routine generates various delays *
* needed by xlcd functions. *
* For delay of 1ms (18F4550 running at 48MHz) *
* Cycles = (TimeDelay * Fosc) / 4 *
* Cycles = (1ms * 48MHz) / 4 *
* Cycles = 12,000 *
* Since call of function also takes some *
* instruction cycles, the exact value to get *
* 1ms delay is less than 12,000. *
*******************************************************************/
void delay(unsigned long time){
while(time--);
}
void Delay_1msX (unsigned int miliseconds)
{
t=0;
while(t<miliseconds)
{
Delay1KTCYx(11);
Delay10TCYx(96);
Nop();
Nop();
Nop();
Nop();
Nop();
48

t++;
}
}//End of Delay_1msX

/*******************************************************************
* Function Name: Delay_100msX *
* Return Value: void *
* Parameters: miliseconds: amount of delay *
* Description: This routine generates various delays *
* needed by xlcd functions. *
* For delay of 100ms *
* (18F4550 running at 48MHz) *
* Cycles = (TimeDelay * Fosc) / 4 *
* Cycles = (100ms * 48MHz) / 4 *
* Cycles = 1,200,000 *
* Since call of function also takes some *
* instruction cycles, the exact value to get *
* 1ms delay is less than 1,200,000. *
*******************************************************************/
void Delay_100msX (unsigned int msec)
{
t=0;
while(t<msec)
{
Delay10KTCYx(119);
Delay1KTCYx(9);
Delay10TCYx(96);
t++;
}
}//End of Delay_100msX
49

APPENDIX B

Programming code for circuit B

//======================================================
//======================================================
#include <p18f4550.h>
#include "xlcd.h"
#include "delays.h"
#include "usart.h"
//===========================================================
// Define Pins
//===========================================================
#define led1 LATBbits.LATB6
#define led2 LATBbits.LATB7
#define buzz LATBbits.LATB2
#define sw1 PORTBbits.RB0
#define sw2 PORTBbits.RB1
//===========================================================
// Function Prototypes
//===========================================================
void Delay_1msX (unsigned int miliseconds);
void Delay_100msX (unsigned int msec);
void delay(unsigned long time);
unsigned char uart_rec(void) //receive uart value
{
unsigned char rec_data;
while(PIR1bits.RCIF==0); //wait for data
rec_data=RCREG;
return rec_data; //return the data received
}
void uart_send(unsigned char data)
{
50

while(TXSTAbits.TRMT==0); //only send the new data after


TXREG=data; //the previous data finish sent
}
void uart_str(const rom char *s)
{
while(*s)uart_send(*s++);
}
//===========================================================
// Global Variables
//===========================================================
unsigned int i, t;
unsigned char data_tx, data_rx;
//===========================================================
// Main Program
//===========================================================
void main ()
{
//set I/O input output
TRISB = 0b00000011; //Configure PORTB I/O direction
TRISC = 0b11000000; //Configure PORTC I/O direction
TRISD = 0b00000000; //Configure PORTD I/O direction
PORTB = 0;
PORTC = 0;
PORTD = 0;
buzz=1;
//-------------------------------------------------------------------------
// Configure External LCD
//-------------------------------------------------------------------------
OpenXLCD( EIGHT_BIT & LINES_5X7 );
ClearXLCD(); //Clear display
led1=1; //Turn on led1
//-------------------------------------------------------------------------
// Configure UART
//-------------------------------------------------------------------------
51

OpenUSART (USART_TX_INT_OFF & //Transmit interrupt off


USART_RX_INT_OFF & //Receive interrupt off
USART_ASYNCH_MODE & //Asynchronous mode - UART
USART_EIGHT_BIT & //8-bit transmit/receive
USART_CONT_RX & //Continuous reception
USART_BRGH_HIGH, //High baudrate
129); //9600 baudrate at 20MHz frequency
led2=0; //Turn on led2
while(1)
{
//-------------------------------------------------------------------------
// UART Transmit
//-------------------------------------------------------------------------
SetCurXLCD(0); //Set cursor to line 1, position 0
putrsXLCD("Neigh. Security"); //Display LCD
SetCurXLCD(20); //Set cursor to line 2, position 0
putrsXLCD("System");
led1=1;
delay(10000);
led1=0;
delay(10000);
led1=1;
data_rx=getcUSART(); //Assign received data to variable
data_tx='B';
if(sw1==0){
led2=1;
// while(1){
while(BusyUSART()); //Check if Usart is busy or not
putcUSART(data_tx); //Echo the data in Hyperterminal
// }
while(1);
}
else if(data_rx=='A'){
led2=1;
52

ClearXLCD(); //Clear LCD


SetCurXLCD(0); //Set cursor to line 1, position 0
putrsXLCD("House A"); //Display LCD
SetCurXLCD(20); //Set cursor to line 2, position 0
putrsXLCD("Security Alert");
// while(1){
led1=0;
buzz=0;
// }
while(1);
}
else if(data_rx=='C'){
led2=1;
ClearXLCD();
SetCurXLCD(0); //Set cursor to line 1, position 0
putrsXLCD("House C"); //Display LCD
SetCurXLCD(20); //Set cursor to line 2, position 0
putrsXLCD("Security Alert");
buzz=0;
// while(1){
led1=0;
buzz=0;
// }
while(1);
}
Delay_100msX(5); //Delay for 2 seconds
ClearXLCD(); //Clear LCD
}
}//End of main
53

//===========================================================
// Subroutines
//===========================================================
/*******************************************************************
* Function Name: Delay_1msX *
* Return Value: void *
* Parameters: miliseconds: amount of delay *
* Description: This routine generates various delays *
* needed by xlcd functions. *
* For delay of 1ms (18F4550 running at 48MHz) *
* Cycles = (TimeDelay * Fosc) / 4 *
* Cycles = (1ms * 48MHz) / 4 *
* Cycles = 12,000 *
* Since call of function also takes some *
* instruction cycles, the exact value to get *
* 1ms delay is less than 12,000. *
*******************************************************************/
void delay(unsigned long time){
while(time--);
}
void Delay_1msX (unsigned int miliseconds)
{
t=0;
while(t<miliseconds)
{
Delay1KTCYx(11);
Delay10TCYx(96);
Nop();
Nop();
Nop();
Nop();
Nop();
t++;
}
54

}//End of Delay_1msX
/*******************************************************************
*
* Function Name: Delay_100msX *
* Return Value: void *
* Parameters: miliseconds: amount of delay *
* Description: This routine generates various delays *
* needed by xlcd functions. *
* For delay of 100ms *
* (18F4550 running at 48MHz) *
* Cycles = (TimeDelay * Fosc) / 4 *
* Cycles = (100ms * 48MHz) / 4 *
* Cycles = 1,200,000 *
* Since call of function also takes some *
* instruction cycles, the exact value to get *
* 1ms delay is less than 1,200,000. *
*******************************************************************/
void Delay_100msX (unsigned int msec)
{
t=0;
while(t<msec)
{
Delay10KTCYx(119);
Delay1KTCYx(9);
Delay10TCYx(96);
t++;
}
}//End of Delay_100msX
55

APPENDIX C

Programming code for circuit C

//======================================================
//======================================================
#include <p18f4550.h>
#include "xlcd.h"
#include "delays.h"
#include "usart.h"
//===========================================================
//Define Pins
//===========================================================
#define led1 LATBbits.LATB6
#define led2 LATBbits.LATB7
#define buzz LATBbits.LATB2
#define sw1 PORTBbits.RB0
#define sw2 PORTBbits.RB1

//===========================================================
//Function Prototypes
//===========================================================
void Delay_1msX (unsigned int miliseconds);
void Delay_100msX (unsigned int msec);
void delay(unsigned long time);
unsigned char uart_rec(void) //receive uart value
{
unsigned char rec_data;
while(PIR1bits.RCIF==0); //wait for data
rec_data=RCREG;
return rec_data; //return the data received
}
void uart_send(unsigned char data)
{
56

while(TXSTAbits.TRMT==0); //only send the new data after


TXREG=data; //the previous data finish sent
}
void uart_str(const rom char *s)
{
while(*s)uart_send(*s++);
}
//===========================================================
//Global Variables
//===========================================================
unsigned int i, t;
unsigned char data_tx, data_rx;
//===========================================================
//Main Program
//===========================================================
void main ()
{
//set I/O input output
TRISB = 0b00000011; //Configure PORTB I/O direction
TRISC = 0b11000000; //Configure PORTC I/O direction
TRISD = 0b00000000; //Configure PORTD I/O direction
PORTB = 0;
PORTC = 0;
PORTD = 0;
buzz=1;
//-------------------------------------------------------------------------
// Configure External LCD
//-------------------------------------------------------------------------
OpenXLCD( EIGHT_BIT & LINES_5X7 );
ClearXLCD(); //Clear display
led1=1; //Turn on led1
57

//-------------------------------------------------------------------------
// Configure UART
//-------------------------------------------------------------------------
OpenUSART (USART_TX_INT_OFF & //Transmit interrupt
offUSART_RX_INT_OFF & //Receive interrupt
offUSART_ASYNCH_MODE & //Asynchronous mode - UART
USART_EIGHT_BIT & //8-bit transmit/receive
USART_CONT_RX & //Continuous reception
USART_BRGH_HIGH, //High baudrate
129); //9600 baudrate at 20MHz frequency
led2=0; //Turn on led2
while(1)
{
//-------------------------------------------------------------------------
// UART Transmit
//-------------------------------------------------------------------------
SetCurXLCD(0); //Set cursor to line 1, position 0
putrsXLCD("Neigh. Security"); //Display LCD
SetCurXLCD(20); //Set cursor to line 2, position 0
putrsXLCD("System");
led1=1;
delay(10000);
led1=0;
delay(10000);
led1=1;
data_rx=getcUSART(); //Assign received data to variable
data_tx='C';
if(sw1==0){
led2=1;
// while(1){
while(BusyUSART()); //Check if Usart is busy or not
putcUSART(data_tx); //Echo the data in Hyperterminal
// }
58

while(1);
}
else if(data_rx=='A'){
led2=1;
ClearXLCD(); //Clear LCD
SetCurXLCD(0); //Set cursor to line 1, position 0
putrsXLCD("House A"); //Display LCD
SetCurXLCD(20); //Set cursor to line 2, position 0
putrsXLCD("Security Alert");
//while(1){
led1=0;
buzz=0;
// }
while(1);
}
else if(data_rx=='B'){
led2=1;
ClearXLCD();
SetCurXLCD(0); //Set cursor to line 1, position 0
putrsXLCD("House B"); //Display LCD
SetCurXLCD(20); //Set cursor to line 2, position 0
putrsXLCD("Security Alert");
buzz=0;
//while(1){
led1=0;
buzz=0;
// }
while(1);
}
Delay_100msX(5); //Delay for 2 seconds
ClearXLCD(); //Clear LCD
}
}//End of main
59

//===========================================================
//Subroutines
//===========================================================
/*******************************************************************
* Function Name: Delay_1msX *
* Return Value: void *
* Parameters: miliseconds: amount of delay *
* Description: This routine generates various delays *
* needed by xlcd functions. *
* For delay of 1ms (18F4550 running at 48MHz) *
* Cycles = (TimeDelay * Fosc) / 4 *
* Cycles = (1ms * 48MHz) / 4 *
* Cycles = 12,000 *
* Since call of function also takes some *
* instruction cycles, the exact value to get *
* 1ms delay is less than 12,000. *
*************************************************************/
void delay(unsigned long time){
while(time--);
}
void Delay_1msX (unsigned int miliseconds)
{
t=0;
while(t<miliseconds)
{
Delay1KTCYx(11);
Delay10TCYx(96);
Nop();
Nop();
Nop();
Nop();
Nop();
t++;
60

}}//End of Delay_1msX
/*******************************************************************
* Function Name: Delay_100msX *
* Return Value: void *
*Parameters: miliseconds: amount of delay *
* Description:This routine generates various delays *
* needed by xlcd functions. *
*For delay of 100ms(18F4550 running at 48MHz) *
* Cycles = (TimeDelay * Fosc) / 4 *
*Cycles = (100ms * 48MHz) / 4 *
* Cycles = 1,200,000 *
*Since call of function also takes some *
*instruction cycles, the exact value to get *
*1ms delay is less than 1,200,000. *
*************************************************************/
void Delay_100msX (unsigned int msec)
{
t=0;
while(t<msec)
{
Delay10KTCYx(119);
Delay1KTCYx(9);
Delay10TCYx(96);
t++;
}
}//End of Delay_100msX

Вам также может понравиться