Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
ABSTRACT
In India burglary cases are increasing dramatically. Therefore this project is designed to
reduce this crime since this wireless alarm system is low in cost and able to be owned by everyone.
This system could check the condition of transmitters continuously to ensure that the entire system
is able to work without interruption. Furthermore, all zones transmitters can be armed and disarmed
individually. A remote control which require password is built in order to access the system. This
project is analysed and designed before beginning the hardware selection and implementation
stage. System is built after software simulation for the three main parts of the project namely
remote control, transmitter and receiver is done. Then, the hardware is tested and improved to
make it more reliable. The wireless system built at the end of this project has the required features
and met the objectives of this project. Furthermore, it can be applied in a double storey house as
expected since the transmission distance is reasonably long. Finally, the project is completed within
the low cost budget expected.
With the economic development and peoples living standards, it was the home of their
demands higher and higher. Now the people are only hope that has a warm and comfortable home,
in its security, intelligence also set a higher request. How to make use of modern advanced
communications and electronics technology to achieve accurate and reliable home security has
become a home security alarm system at this stage need to be solved.This paper analyzes
deficiencies of the existing home security alarm system, designed a user-friendly, reliable operation
of intelligent wireless home security alarm system. It collects anti-invasion, anti-fire, and other
functions. The front-end of Alarm system using hybrid wireless sensors to achieve a variety of
residential analog signal (the infrared signals issued by the human body, the invasion signals, the
concentration of smoke and so on) forautomatic monitoring. It can overcome the cable-alarm
system wiring difficulties, but also difficult to extend and affect the room artistic. The sensors
output the alarm signal through a wireless way to send the police to host when monitor disaster.
The host accords to dangerous category to send warning messages to mobile phone users and
security-related personnel by Siemens TC35i GSM module. Users can receive warning information
only have a cell phone, and also send text messages to restart the wireless sensors. It can achieve
the non-distance limit truly.The design of wireless home security alarm system is not only high-
quality transmission, anti-jamming ability, easy to expand, and brings at will in the actual
operations; the system integration, the performance perfect, the application leads widely. The
system is cost lower, practical, reliable, flexible and diverse functions, but also widely used in
banks, stores and other important places.
.
TABLE OF CONTENTS
1 INTRODUCTION 1
1.1 Background 1
1.2 Problem Background 2
1.3 Objectives 2
1.4 Scope of the Project 3
1.5 Project Outcome 4
1.6 Thesis Organization 4
1.7 Project Duration 5
2 LITERATURE REVIEW 6
2.1 Chapter Overview 6
2.2 Previous Projects 7
viii
3 METHODOLOGY 24
3.1 Chapter Overview 24
3.2 Design Housing Zone 24
3.2.1 Ground Floor 25
3.2.2 First Floor 26
3.2.3 Roof 27
3.3 Project Flow 27
3.3.1 Understanding 28
3.3.2 Literature Review 28
3.3.3 Hardware and Software 28
ix
3.3.4 Implementation 29
3.3.5 Test and Improve 29
4 PROJECT IMPLEMENTATION 30
4.1 Chapter Overview 30
4.2 Remote Control 30
4.2.1 Hardware Implementation 30
4.2.2 Programming 32
4.2.3 Functions 33
4.2.4 Security 35
4.2.5 Arm and Disarm Zones Individually 36
4.2.6 Problem 38
4.3 Transmitter 39
4.3.1 Hardware Implementation 39
4.3.2 Programming 41
4.3.3 Data Bits of Encoder 42
4.3.4 Status Checking 42
4.3.5 Problem 43
4.3.5.1 Interrupt 43
4.3.5.2 Toggle Switch 44
4.4 Receiver 46
4.4.1 Hardware Implementation 46
4.4.2 Specify Encoder and Decoder 48
4.4.3 Programming 49
4.4.4 Interrupt 50
4.4.5 Arm and Disarm Zones Individually 52
4.4.6 Alarm 52
4.4.7 Status Checking 54
5.2.2 Receiver 60
5.3 Results 62
5.3.1 Outcome of Project 63
5.3.1.1 Alarm Function 63
5.3.1.2 Status Checking Function 67
5.3.2 Project Cost 69
5.4 Limitations 70
REFERENCES 73
APPENDICES A-C 75-95
xi
LIST OF TABLES
LIST OF FIGURES
at Receiver 67
5.24 Transmitter Zone 3 and the Output for Status Checking
at Receiver 68
5.25 Indicates Zone 4 Transmitter not Working 68
xv
LIST OF ABBREVIATIONS
PC - Personal Computer
GSM - Global System for Mobile Communications
SMS - Short Message Service
PIC - Peripheral Interface Controller
IC - Integrated Circuit
LCD - Liquid Crystal Display
HMI - Human Machine Interface
SPST - Single Pole Single Throw
CPU - Central Processing Unit
I/O - Input or Output
EEPROM - Electrically Erasable Programmable Read Only
Memory
ADC - Analogue to Digital Converter
TTL - TransistorTransistor Logic
RAM - Random Access Memory
ROM - Read-Only Memory
ISR ` - Interrupt Subroutine
xvi
LIST OF APPENDICES
INTRODUCTION
1.1 Background
These days when the thefts are all time high, a comprehensive home security system is the need
of the hour to ensure peace of mind of any homeowner. Whenever youre away from your
house, there are good chances that an intruder may enter your house by breaking through the
window or even the main door, and take away all your hard earned money and valuables inside
house.
A robber could injure or even kill the victims. So by installing alarm system in home,
the chances to save the life of the victims may improve. The cost for the alarm system should
be cheap. Therefore residents can buy the system at an affordable price and install it as fast as
possible. In order to have such a system, we should look for wireless home security alarm
system where it could operate without wire for long distance.
2
Today there are a lots of wireless home security alarm system available in the
market. Most of the alarm systems are very expensive and therefore not affordable by
poor or middle class families. Some systems which cost little do not provide reliable
features like status checking. In order to provide the public with a cost effective wireless
security system, it is important to design a low cost system with advanced feature which
ease the residents life and benefits the public and also will decrease the crime rate of
Malaysia.
1.3 Objectives
In this project, the main objective is to design a cost effective wireless alarm
system with 7 zones. Therefore the alarm system could be owned by everyone without
burdening them. Besides that the alarm system also should check the status of the
3
transmitter of the system regularly to ensure that the system could function without any
failure. The failure of the transmitter will be indicated at the receiver through LEDs and
the buzzer beeping sound.
Moreover, the system has a remote control which can arm and disarm the system
and can even switch off any zone of the system individually according to users demand.
The remote control also consists of a 16X2 LCD to display the status of the system and a
4X4 matrix keypad to control the system. Furthermore, the remote control has a default
password which needs to be keyed to operate the system and only the owner has the
password.
In order to realize this type of alarm system by considering time constraint and
budget, there are several scopes that need to be outlined. The project is intended to be
implemented in a double storey house with approximately 22 feet X 70 feet. This house
will be divided into 7 zones which are main door (parking area), living hall, 3 bedrooms,
kitchen and roof.
For this project, only one transmitter is built. This transmitter is flexible such that
it can be used at any zones by just changing its zone configuration. Besides that, the
system is designed to perform status checking of the transmitters only without
considering receiver status. The remote control can be switched off and on each zone
transmitters individually.
4
This project targets to develop an alarm system for a house with 7 different
zones. Besides, the system will continuously check the status of the transmitters and
indicate the failure at the receiver which acts as the central processing unit of the
system. The system can be operated through a password secured remote control. This
remote control can arm and disarm the whole system or each individual zone.
Chapter 2 discusses the theory and the previous works related to this project.
Chapter 3 presents the methods and alternatives that have been used from the beginning
until the end of this project. The next chapter describes how this project is built and how
the components are implemented besides discuss the problem faced in this project.
Chapter 5 discusses the simulation and the results of this project. Furthermore, this
chapter also talks about the limitation in this project. The final chapter presents
summary for this and recommends possible future works.
5
MONTH/TASK JUL AUG SEP OCT NOV DEC JAN FEB MAR APR
Project title selection
Topic understanding
Literature Review
Objective and scope setting
Initial design planning
Hardware Selection
Design implementation
FYP 1 Presentation
Hardware testing and verification
Report Writing
FYP 2 Presentation
Documentation
CHAPTER 2
LITERATURE REVIEW
This chapter discusses projects and paper works related to this project. These
related works have been reviewed carefully in order to improve the quality and
reliability of this project. By analysing the projects did by other researchers, there is a
possibility to know what features are lacking in their projects. They also will
recommend some future works that could be done to improve the same project.
Moreover, there are some useful ideas that can be implemented in this project from other
similar projects.
Therefore, literature review process extended right from the start until the end of
the project. By reviewing the previous works, a proper plan on how this project can be
conducted and the features that have to be added in order to make this project reliable
and marketable are enlightened.
7
Besides that, there are some findings from internet and books which are very
contributive to this project. Throughout the analysis at the beginning of the project, the
special feature in this project is determined and the components used in this project are
decided. In addition, the function and the concept are well understood.
The goal of this project is to design a home security system with 3 detection
zones. Each zone is equipped with a magnetic sensor with connected to the door. When
the door is opened without permission from the owner, the magnetic switches attached
to the doors will trigger the alarm system. The system can only arm and disarm all the
zones together but not individually. Furthermore, the system could not indicate the zone
from where the sensor is triggered
Therefore by acknowledging the problems arise from the project, the design of
this project solved the problems. The alarm system has seven zones so that more areas
can be attached to the sensors. In addition, the design of the system has seven LEDs to
indicate the armed zones and they also inform the owner exactly which zone is alarmed.
Hence, the owner can immediately take action towards that particular zone. This design
has considered adding on a feature that could arm and disarm any zones individually.
Thus, the owner can arm certain zones depending on the need. For example, the house
owner can disarm certain zones in ground floor of the house in the morning to begin his
works while other zones are still secure.
8
2.2.2 Home Security System by Chun-Pai Jimmy Hsieh, Yang Cao [3]
This project built a wired home security system using different type of sensors.
Besides the magnetic switch used at the doors and windows, this project also
implemented temperature sensor, smoke detectors, and motion sensor. Thus, the security
system will sound the siren for two purposes namely when there is intruders or when
there is a smoke or fire. This product equipped with a voice playback chip which will
speak when there is alarm to indicate which sensor contribute to the alarm.
This project is built without considering how the owner of the system could
switch off the system when he enters the armed house from outside. This is because the
main control unit of the system is attached inside the house. This central processing unit
of the system will input all the sensors and keypad while the outputs indicate zones and
voice alarm. Furthermore, a wired system like this project could not provide portability
to operate the system. Thus in wired system, the project designer will probably set a
delay of around 15 seconds in triggering the alarm at the front door in order to provide
some time for the owner to disarm the system. The siren will sound if the owner is
unable to turn off the system within the given time frame and this will be inconvenient.
In designing this alarm system, a wireless system which will be convenient to the
owner is considered. Hence the system is built with a wireless remote control which has
high portability and will ease the owner to bring it along when he is out of the house.
This is because the owner can disarm the system before entering the house and no need
to rush into the house to disarm the system.
9
This smoke detector project is mainly designed for the hearing impaired. Besides
that, this project can be implemented when there is nobody in particular place while the
alarm for the smoke detector is sound. In this paper, the smoke detector will connect to
personal computer (PC) in order to control the GSM (Global System for Mobile
Communications) to send SMS (short message Service) from the detection place and
receive SMS from the victim.
This project is conducted using a laptop which has to be in online status all the
time for the monitoring purpose. Although the laptop can be easily available, it is not
practical to keep the laptop online all the time. This is because it could contribute to the
hang up of the operating system whereby it cannot send signal to the GSM. Thus, it is
recommended to use microcontroller like Peripheral Interface Controller (PIC) instead
of PC as the control unit. By considering this, this project is designed by using a PIC
microcontroller as main device to control the inputs and outputs. Therefore, it is very
convenient from using a laptop which is consumes a lot of power compared with the
PIC.
In this project, all the components using +5 volts (V) direct current. Therefore in
order to supply this voltage to the components, we need a regulator circuit to step down
10
the voltage source like +9V alkaline battery to +5V. Since the regulator Integrated
Circuit (IC) is cheap and easily available, the regulator IC 7805 is used in this project
[7].
There will be noise occurred when regulating the voltage. Therefore capacitors
need to be added to get an accurate +5V. [5]
An encoder is a circuit where the data can be changed from one format to
another format which suits the circuitry it interfaces with. On the other hand, decoder is
a circuit as encoder which change a specifically coded signal received from receiver to a
format suitable with the interfacing circuit.
When the preceding bits are matched with decoders address bits, the decoder will
decodes the 4 data bits. The VT pin also goes high to indicate that the transmission is
valid. The data will be very safe and correctly decoded to parallel in order to match the
interfacing circuitry. Besides this, the address pins at the encoder and decoder can be set
accordingly to communicate smoothly between both ICs. [7]
On the other hand, receiver circuit will receive and process the electromagnetic
waves from the transmitter using the same carrier frequency. In this project, the
transmitter and receiver module used are those which are easily available at market at
low cost. The modules used in this project are using 433 MHz and 315 MHz as their
carrier frequencies. In this case, receiver used to receive the signal sent from transmitter.
The information from the signal is extracted using decoder. [8][9]
13
Furthermore, the antenna is needed to transmit data over a long distance. Hence,
in this project a 10cm long single core wire is used as antenna. This length of antenna
could provide transmission over the specified distance
The main concern for the transmitter and receiver is the working range for the
wireless system. Although the range is provided by the manufacturer, it is a must to test
the range in order to verify how far the system could work. The transmitter and the
receiver are tested by looking at the valid transmission LED light at the receiver and the
transmit enable pin is enabled throughout the test.
14
Effective distance of communication bet the transmitter and the receiver is tested
at different location and the result obtained is shown at table 2.1. The results are the
average values collected from different conditions for three times.
Open Field 65
Apartment Building 28
Single Family Home 33
In this project, LCD is used for display purpose. A 16X2 LCD is chosen as it is
suitable with the number of character needed in this case. 16X2 display means there are
16 column and 2 rows to display alphanumeric. It is a parallel display with LED
backlight. This LCD with 2 controllers has 16 pins whereby two of the pins are used for
backlight connection if compare with normal LCD. Pin description is shown in the table
below. [10]
2.3.5 Keypad
The keypad is a part of Human Machine Interface (HMI) needed to input data
into the system. This project required a 4X4 matrix keypad to configure the alarm
system. It consists of 16 buttons. This keypad can be constructed using 16 Single Pole
Single Throw (SPST) switches. [11]
2.3.6 PIC
So basically some peripherals and features are readily built into the PIC
microcontroller namely Central Processing Unit (CPU), memory, serial port, Input or
Output (I/O), timer and interrupt. [13]
Serial port is use to communicate with other devices like PC. Therefore in this
example PC could read the microcontrollers program or even its model. The PC can
write the program into the microcontroller by interfacing them. Three pins are used by
the microcontroller in transferring the data, namely sending data pin TX, receiving data
pin RX and a reference for the input and output. [15]
Input and output of the microcontroller are significant component to interact with
outside world. By inputting certain signals, the microcontroller can react to the input as
programmed to produce useful outputs. There are 33 I/O pins in this PIC16F877A which
can be used as input or output. This microcontroller can only read digital signals and
therefore it is necessary to convert the analogue signal to digital signal using Analogue
to Digital Converter (ADC). With this feature, the PIC microcontroller is suited for any
type of signals. [15]
2.3.6.4 Timer
oscillator. For instance in order to control a programs output at certain delay of time,
the timer is in charge to inform the CPU on when to give that particular output. [16]
2.3.6.5 Interrupt
In is crucial to have a boot loader circuit and D-sub-9 to interface with PC. By
using this circuit, it is possible to read the PIC and write the program in hex file into the
PIC microcontroller by ourselves without buying expensive programmer.
Only certain pins from the total of 9 pins are used in this project to detect and
burn the programming into to PIC microcontroller. Those are pin 2, 3, and 5. The pins
assignments of the D-sub-9 are as below.
Figure 2.16 below shows how the bootloader circuit is connected to detect PIC
through pin TX and RX. [20]
2.4 Software
This MikroC software is a rich development tool for PIC microcontroller. Its
purpose is to provide the developer or programmer with the easiest ways to develop
applications for embedded systems by providing the same performance or outcomes.
The writing language of this software is C language. There are many libraries in this
23
software that can be used for various applications and to easily interface with the
external hardware like LCD and Keypad. Besides that, it also provides some examples
for reference purpose with its software.
ISIS starts from a design to a real time interactive simulation by associate with
the source code. Moreover, some graph objects and signal generator can be placed on
the schematic to perform frequency and swept variable simulation.
CHAPTER 3
METHODOLOGY
This chapter will discuss the methods and alternatives that have been used from
the beginning until the end of this project. Besides this, the design of the house at which
this system is going to be applied is discussed.
Ground floor was allocated two zones, namely the front part and the back part of
the house as shown in figure 3.1. At the front part of the house two sensors can be used
at window and main door by using one transmitter. This is because in this project, the
scope was narrowed down to only one transmitter per zone. While at back door and
bathroom window can be placed two sensors also.
There are three zones reserved for this floor as shown in figure 3.2. The third
zone will be at the front facing balcony and the fourth will be at the middle of the house.
The fourth zone can be placed motion sensor which could detect any motion when the
house is in armed condition. This is because there might be intruders who came down
from the roof. On the other hand, the fifth zone is located at the room number 4 and
bathroom.
3.2.3 Roof
The roof is divi ded into 2 z ones as in figure 3.3. I nside the ro of motion
sensors can be placed.
There are certain steps follo wed in order to conduct this project as shown below.
Understanding
Literature Review
Implementation
3.3.1 Understanding
The previous works related to this project are studied and analyzed in order to
determine the disadvantages in their researches or projects. Then, the lacking features in
their works are improved and implemented in this project.
In this section, the hardware and the software are determined to conduct this
project according to the features needed. Besides this, the availability of the hardware
and its cost are considered in choosing the components. Cost is important in this project
since this system is targeted on a low cost product. Then, the hardware is studied based
on the theories and its interfacing with other components. The software is used for
simulation and programming purposes. Besides that, software is required to program the
microcontroller.
29
3.3.4 Implementation
In this stage, the ways on how this hardware and software implemented are
discussed. The project is divided into three parts. Each part will deal with the data
transmission to operate the system besides to trigger the alarm and check the status of
transmitter. Therefore, different data bits for each function are considered.
In this final step, the system hardware is tested to improve the system. Besides
that, this system is imagined as a real system to figure out the problems that could face
when implemented in a house.
CHAPTER 4
PROJECT IMPLEMENTATION
This chapter describes how this project is built and how the components are
implemented. Moreover, the problem faced in this project is discussed.
outputs of this remote are LCD and serial encoded data signals which transmitted to
receiver.
The Port B of PIC is connected to keypad while the LCD is connected to Port
Ds pin 4, 5, 6 and 7. Port C is connected to encoder data lines and transmit enable pin.
While the encoder data out pin is connected with transmitter module data pin in
order to transmit the data from PIC to receiver.
32
4.2.2 Programming
Figure 4.3 shows the block diagram for the programming code to handle this
remote control.
33
4.2.3 Functions
There are many options or functions that can be performed through remote
control.
34
The remote control can control the zones that wish to undergo status checking
process. By pressing # button, the user can then choose the zones that would not be
included for status checking. Once configured, button 0 has to be pressed to indicate
that status checking zones are chosen. This option is important because sometimes the
voltage of battery may be low and need to be changed. Therefore that particular zone
can be turned off for status checking process.
35
4.2.4 Security
void password(){
Lcd_Custom_Cmd(Lcd_CLEAR); // Clear display
strConstCpy(text,please_enter);
Lcd_Custom_Out(1,1,text); // print please enter at LCD
Delay_ms(1000);
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,password1);
Lcd_Custom_Out(1,1,text);
Lcd_Custom_Cmd(LCD_BLINK_CURSOR_ON);
void compare_password(){
if ( va1==pass1 && va2==pass2 && va3==pass3 &&
va4==pass4){ Lcd_Custom_Cmd(Lcd_CLEAR);
Lcd_Custom_Cmd(Lcd_CURSOR_OFF);
Lcd_Custom_Out(1, 1, "PASSWORD"); // indicate password is set
Lcd_Custom_Out(2, 5, "ACCEPTED");
Delay_ms(1000);}
else{ Lcd_Custom_Cmd(Lcd_CLEAR);
Lcd_Custom_Cmd(Lcd_CURSOR_OFF);
Lcd_Custom_Out(1, 1, "PASSWORD"); // indicate password is wrong
Lcd_Custom_Out(2, 5, "REJECTED");
Delay_ms(1000);}}
The password will be requested for three times if previous password entered is
wrong. If the password does not match with the default password for three times, the
LCD will display access denied and thus the alarm system cannot be operated.
One of the objectives of this project is to arm and disarm the system zones
individually. Therefore, the system can arm specifically the place which is important and
37
is not used by the residents of the house at certain time. The signals sent from the
transmitter are set accordingly with the receiver program to perform this function.
The code to arm and disarm the other zones is similar but only need to change
the variables and the output data.
38
4.2.6 Problem
When using MikroC software to write the program for the LCD, a problem
occurred due to the strings. Since many strings are used in this program, there is a
warning when compiling the code. It is caused by the RAM usage which exceeds fifty
percent. Thus, it is necessary to determine on how the strings would not increase the
RAM (Random Access Memory) usage.
Example of Usage:
strConstCpy(text,arm_system);
Lcd_Custom_Out(1,1, text);
39
4.3 Transmitter
In this project, no attention is given to the type of the sensors used. A sensor can
generally be considered as a toggle switch. Besides that, there is jumper to assign zone
for the transmitters.
Port C and Port D 3 pins connected with jumper which is grounded. So the zone
can be set using this jumper. While pin RB0 from port B is connected with a toggle
switch which acts as a sensor. Port B also connects with encoder HT12E to transmit data
to receiver.
The data lines connected directly with PICs Port B while the data out pin is
connected with the transmitter module.
41
4.3.2 Programming
Figure 4.5 shows the block diagram for the programming code to handle this
transmitter.
In order to implement status checking and trigger alarm, two different data bits
required to differentiate these two functions. So in this project, the data bits are set as in
the table below.
The difference in this type of data bits is the first bit. The first bit of the status
checking is 1 while the first bit of the alarm triggering data is 0. Therefore when the
data signals are transmitted to receiver, it can be differentiated.
Since the status checking is a continuous process, all zones transmitters need to
be synchronized. Besides that, the receiver can only process one data at one time.
Therefore, the transmitter has to follow a sequence for those seven zones. In this project,
43
the seven transmitters are programmed to send continuous signals according to the time
frame in table 4.4.
For example zone 1 will send data for status checking in 30 minutes after its
transmitter is switched on. After sending the signals, zone 1 transmitter will wait for
another 240 mins before sending the signal again. Similarly, zone 2 will also send
signals in 60 mins then wait for 240 mins before sending the signal again like zone 1.
Similar actions are applied to all zone transmitters.
4.3.5 Problem
4.3.5.1 Interrupt
In this part of the project interrupt in PIC is used. There are two main functions
in transmitters namely trigger alarm and status checking. The signal for status checking
will be sent continuously according to the program. Since the signals for alarm
44
triggering is very important, the priority should be given to this signals. Therefore when
the transmitter is running according to the program in PIC, it should be able to send the
trigger signal once sensor like smoke detector is activated.
Besides that in a real alarm system when the alarm is triggered, the signal is only
sent for a small instant of time like a pulse. When the alarm signal is sent, the buzzer at
the receiver will sound. Then, the program of the receiver has to looking for other
inputs, like instruction by a user to stop the alarm. Therefore, if the status checking
signal from a transmitter is sent continuously, the receiver may not ignore the alarm
triggering signal and unable to take subsequent action.
As a solution for this problem, the interrupt is implemented in the program. Thus,
the program at the transmitter PIC will jump to interrupt subroutine (ISR) when an alarm
is triggered which immediately send signals to the receiver.The interrupt will only detect
the positive edge of the signals of the toggle switch. Although the switch is still on, the
program will only jump to the ISR once.
There is another problem caused by the toggle switch. This is a common problem
that will occur when using mechanical switches. It is call contact bounce. When the
toggle switch is on, the springy metals in the switch will be forced to contact by actuator.
The bounce is caused when the momentum and elasticity of the contact acted together.
Therefore, rapidly pulsed electrical current is resulted instead of a steady transition from
zero to full current. [21]
45
From the above graph it can be interpreted that in order to get a smooth and
steady transition from zero to five volts, a delay of few milliseconds need to be inserted
in the program. Thus when the toggle switch is on, the program will enter the ISR and
wait for 20ms. This is required because the interrupt is configured for positive edge. So
if there is contact bounce, the interrupt function will not execute since it assumes that
the voltage is from 5v to 0v (negative edge).
void interrupt(){
Delay_ms(50); // delay to avoid contact bounce
if(portb.f0==1){
zone_checker();
portb.f4=0;
portb.f3=0;
delay_ms(1000);
portb.f3=1;}
INTCON.f1 = 0;} // clear the int flag
4.4 Receive
46
4.4 Receiver
In the receiver, the components used are PIC16F877A, two decoder HT12E,
receiver module 433MHz and 315 MHz, LEDs and buzzer. The function of the receiver
is to indicate which zones are armed using LEDs. The zone which triggered the alarm
will be indicated by the LED too. The receiver will indicate processed zone for status
checking at another three LEDs. Moreover, status checking LED will shows the faulty
transmitter.
The Port Bs pin RB0 is connected to the VT pin of transmitter while the other
pins in Port B connect with LEDs. The data output from the decoder for remote control
is connected with the Port A of PIC. Port C connected with data lines from the decoder
for transmitter. The pin RD0 of Port D is connected with the buzzer.
Figure 4.9: Decoder HT12D (remote control) and receiver module circuit
In this project, two decoders and two encoders are used. It is required to specify
the encoder that being used so that data is decoded at its decoder only. This can be done
by using encoder HT12E and decoder HT12D. For this purpose, the eight address bits of
the encoder and decoder for remote control is set as 0000 0000. On the other hand, the
address bits for transmitters encoder and decoder is set as 1000 0000.
According to the above flow chart when there is a code entering the data input
pin, the decoder will compare its address bits with the data address bits. If the address
bits are same for three times, then the data is decoded.
4.4.3 Programming
The programming in the receiver part is to output at the LEDs and buzzer
according the inputs from the decoder. Figure 4.11 shows the block diagram for the
programming code to handle this receiver.
4.4.4 Interrupt
case, external interrupt at pin RB0 of PIC is used. The RB0 pin is connected with the
Valid Transmission (VT) pin of decoder for transmitter.
VT pin will go high when the data input at decoder from the receiver module
matched its address bits with the decoder address bits. Therefore if the RB0 pin is
connected with VT pin, the program will jump to ISR when the data is decoded. There
are data bits for status checking and trigger alarm from the transmitter. In lieu of this,
the ISR will check whether the data is for the alarm trigger or status checking.
if(y==2){
portb.f7=1; // zone 1 light will on
y=0;
delay_ms(1500);}}
4.4.6 Alarm
When the alarm is triggered, the LED will indicate which zone transmitter is
triggered and subsequently sound the buzzer. There are two situations where the alarm
will be off. One is when the buzzer is sounded, the alarm can be turned off through
remote control. By pressing D, the buzzer will turn off.
The main program of the receiver will keep checking for alarm off input signal
from the remote control once the alarm is triggered.
53
Besides that, the alarm is set to automatically shut off within 20 minutes. This is
important when the system alarm is triggered and the house owner is not at home. Thus,
the system has to be set off automatically after a certain delay of time.
This chapter includes the simulation of this project using Proteus 7 Professional.
The results of this project are explained. In addition, the limitations in this project are
discussed. The total cost to build this hardware is presented.
5.2 Simulation
The simulation part is done before the hardware is assembled. This is important
because if the simulation is working as expected, then the circuit can be used to build up
the hardware. Furthermore in the simulation, programming code has to be inserted into
the PIC microcontroller. The programming code is ensured correct if the simulation is
functioning properly.
57
For this simulation purpose the remote control and the receiver are used since the
transmitter component is also similar with remote control. The basic circuit of the PIC
microcontroller is similar for all PIC used in this project. Therefore if the LCD has
display, then the circuit is correct and can be implemented in other parts like transmitter
and receiver of this project.
In the remote control, the LCD display can be simulated. Besides that, the data
send to encoder can simulate through LEDs.
Step three: If the password does not match, the display will show password rejected
message. After three trials and failed to key in the correct password, then it will show
access denied message.
If the password is matched, then the display will show password accepted message.
The system is armed and disarmed by pressing A and B respectively and the message
will be displayed accordingly.
The armed zones can be turned off or turned on individually through remote control. It
will show message like zone 1 off and zone 1 on.
The output of the remote control microcontroller will be connected with the
encoder to transmit the signals to receiver. Since encoder has only one data output, it is
quite difficult to interpret the sending data. For simulation purpose, the data sent to
encoder are connected with LEDs. If the LEDs are blinking, it will indicate that the pin
is high.
60
5.2.2 Receiver
In the receiver part, the decoder is assumed as a push button switch which is
connected to PIC through resistor. Therefore according to the program when there is any
input at port A, the output LEDs which indicate zones will be blink.
When push button is pressed, according to the program for receiver, all zones
LEDs will blink to indicate that all zones are armed.
5.3 Results
In this section, the outcome of the project will be discussed by using the
hardware built. Besides that, it will show how the three parts of the system will
communicate in detail. Furthermore, the distance of transmission for this wireless
system is determined. Moreover, the total cost of this project is described in detail.
63
In this part, the hardware of the project is used to describe how the entire system
works. Moreover, it includes the features of this wireless security system. First of all the
system is focused on the remote control. After that, the remote control will used to show
how it could communicate with the receiver and transmitter.
The display on the LCD will be discussed sequentially after the remote control is
switch on. Besides that, the receiver is turned on at the same time in order to show the
effect at receiver when operating using remote control.
In this division, the hardware is used to show how to arm the system and how the
system is triggered.
Step 3: If the password entered matched the default password, then the password
accepted screen will appear.
If the password did not match, then password rejected screen will appear. If the
password mismatched for three times, access denied screen will appear. Therefore, user
has to contact the manufacturer of this alarm system.
Step 4: When the password is accepted, the screen asking for the subsequent action will
appear. The options for these actions are stated in section 4.2.3.
For example when key A which function to arm the system is pressed, the text
armed system is displayed and it will turn on all the LEDs at receiver to indicate all
zones are armed.
If zone 2 is disarmed by pressing 2 button, the LED indicating zone 2 will turn
off at receiver. Therefore if the alarm is triggered at zone 2 while zone 2 is disarmed, the
alarm would not activate.
When the transmitter at zone 1 is triggered by using the toggle switch, only the
zone 1 LED will turn on at receiver in order to indicate that zone 1 alarm is triggered
beside the buzzer sound.
When the alarm is triggered, it will off automatically within 20 minutes or it can
be turned off through remote control D button.
When the transmitter is on, it will start to send the status checking signals
automatically according to the time frame as discussed in section 4.3.4. Therefore when
the transmitter is from zone 2, the status checking LED at receiver will indicate zone 2.
This is because for the first time, the PIC programming at the receiver will check for the
zone where the signal is from.
Figure 5.23: Transmitter zone 2 and the output for status checking at receiver
68
After checking the status of the second zone, the receiver will expect the signal
from zone 3. If the zone 3 signal is received, it will indicate zone 3 at status checking
LEDs as shown below.
Figure 5.24: Transmitter zone 3 and the output for status checking at receiver
Then, receiver will expect to receive signals from zone 4. If the zone 4
transmitter is in fault condition, the signal from zone 5 will reached the receiver. At this
time, the receiver will indicate that zone 4 transmitter is not working through the LED as
shown below. Besides that, the buzzer will beep repeatedly to get the attention of the
user.
The completed hardware of this project is targeted to be within low cost so that it
is marketable to everyone.
The table 5.1 shows the cost consumed for the whole project.
PIC16F877A 25 3 75
LCD 16X2 35 1 35
4X4 keypad 30 1 30
HT12E 4.50 2 9
HT12D 4.50 2 9
TX-433 25 1 25
TX-315 25 1 25
RX-433 35 1 35
RX-315 35 1 35
Crystal 20Mhz 3.50 3 10.50
Other 30 1 30
TOTAL 318.50
70
Since the project cost is within RM500, it can be concluded that the project is
still under low cost category.
5.4 Limitations
There are some limitations in this project. Firstly, only one transmitter is built for
this project due to limited budget. Although this problem is solved through the zone
select at transmitter, the flow of status checking cannot be done efficiently with only one
transmitter.
The communication between the transmitter and the receiver is only one way
communication. Therefore, the system cannot perform bi-directional communication
which allowed the receiver to send signals to transmitter to request the status of the
transmitter.
6.1 Conclusion
In a nutshell, this alarm system is built within low cost. Moreover, the system
can be implemented in a double storey house due to long transmission distance. In
addition, this wireless system zones can be armed or disarmed individually.
This system is highly secure since password is needed to operate the system.
Furthermore, all transmitter status can be checked and the faulty transmitter zone is
indicated at receiver. The triggered zone will be indicated through LED at receiver.
It can be concluded that the system functions as intended and meet the objectives
of this project.
72
The receiver should be put in a box which triggers alarm when it is opened.
- If the intruder tries to cut off the power supply for the receiver, he needs to
open the box. Thus, the siren will sound to indicate that somebody has
entered the house.
73
REFERENCES
2. Zachary Seto, Jackson Yu. Home Security System. Cornell University EE476 Final
Project, May 3,1999.
3. Chun-Pai Jimmy Hsieh, Yang Cao. Home Security System. Cornell University EE476
Final Project, May 5, 2004.
4. Dr. Hussein Abdulkadir , Eng. Nada Al-Khatib ,Eng. Osama AlShamma and Eng.
Mahmood Saleh (2006). A Smoke Detection System Using Wireless Network.
Communications and Electronics Department /Faculty of Engineering, Philadelphia
University Amman, Jordan.
5. Holtek Semiconductor Inc. HT12A/HT12E 212 Series of Encoders. April 11, 2000.
6. Holtek Semiconductor Inc. HT12D/HT12F 212 Series of Decoders. November 18, 2002.
7. Cytron Technologies. RF Transmitter Module Datasheet. June 2008.
8. Cytron Technologies. RF Receiver Module Datasheet. June 2008.
10. http://www.8051projects.net/keypad-interfacing
11. http://www.8051projects.net/keypad-interfacing/introduction.php
12. http://www.hvwtech.com/products_view.asp?ProductID=339
13. Lawrence A. Duarte. The Microcontroller Beginners Handbook. 2nd Edition. United
States of America: Prompt Publication. 3-5; 1998.
14. Steven F. Barrett, Daniel J. Pack .Microcontrollers Fundamentals for Engineers and
Scientists. Morgan & Claypool Publishers, 2006.
15. Microchip. PIC16F87XA datasheet. 2003.
16. Dogan Ibrahim. PIC BASIC Projects: 30 Projects Using PIC BASIC and PIC BASIC
PRO. Newnes, 2006.
17. Dhananjay V. Gadre . Programming and Customizing the AVR Microcontroller
Published by McGraw-Hill Professional, 2000.
18. http://en.wikipedia.org/wiki/MAX232
19. http://www.zytrax.com/tech/layer_1/cables/tech_rs232.htm#pins
20. http://mdubuc.freeshell.org/Colt/
21. http://en.wikipedia.org/wiki/Switch
22. http://www.geocities.com/thetonegod/debounce/debounce.html
APPENDIX A
if(j==2){
;======================= Infinite portc = 0x08;
Loop Subroutine portd.f0=0;
=================== Lcd_Custom_Cmd(Lcd_CLEAR);
void infinite_loop(){ strConstCpy(text,zone_2_on);
while(1) { // keep looping Lcd_Custom_Out(1,1,text);
Lcd_Custom_Cmd(Lcd_CLEAR); j=0;
Delay_ms(700); { if (k==5) //
portc=0; ZONE 4
delay_ms(500); {m++;
portc.f0=1;}} if(m==1){
portc = 0x04;
if (k==3) // portd.f0=1;
ZONE 3 Lcd_Custom_Cmd(Lcd_CLEAR);
{l++; strConstCpy(text,zone_4_off);
if(l==1){ Lcd_Custom_Out(1,1, text);
portc = 0x08; Delay_ms(700);
portd.f0=1; portd.f0=0;
Lcd_Custom_Cmd(Lcd_CLEAR); portc=0;
strConstCpy(text,zone_3_off); delay_ms(500);
Lcd_Custom_Out(1,1, text); portc.f0=1;}
Delay_ms(700);
portd.f0=0; if(m==2){
portc=0; portc = 0x04;
delay_ms(500); portd.f0=1;
portc.f0=1;} Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_4_on);
if(l==2){ Lcd_Custom_Out(1,1, text);
portc = 0x08; m=0;
Delay_ms(700); portd.f0=0; portc=0;
portd.f0=1; delay_ms(500); portc.f0=1;}}
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_3_on); if (k==6) //
Lcd_Custom_Out(1,1, text); ZONE 5
l=0; Delay_ms(700); portd.f0=0; portc=0; {n++;
delay_ms(500); portc.f0=1;}} if(n==1){
portc = 0x0C;
if (k==4){ // portd.f0=0;
ARM WHOLE SYSTEM Lcd_Custom_Cmd(Lcd_CLEAR);
portc = 0x04; strConstCpy(text,zone_5_off);
portd.f0=0; Lcd_Custom_Out(1,1, text);
Lcd_Custom_Cmd(Lcd_CLEAR); Delay_ms(700);
strConstCpy(text,arm_system); portc=0;
Lcd_Custom_Out(1,1, text); delay_ms(500);
i=0,j=0,l=0,m=0,n=0,b=0,v=0; portc.f0=1;}
Delay_ms(700);
portd.f0=0; if(n==2){
portc=0; portc = 0x0C;
delay_ms(500); portd.f0=0;
portc.f0=1;} Lcd_Custom_Cmd(Lcd_CLEAR);
sub();} strConstCpy(text,zone_5_on);
Lcd_Custom_Out(1,1, text);
void sub() n=0;
Delay_ms(700);
portc=0; portc = 0x02;
delay_ms(500); portd.f0=1;
portc.f0=1;}} Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_7_off);
if (k==7) // Lcd_Custom_Out(1,1, text);
ZONE 6 Delay_ms(700);
{b++; portd.f0=0;
if(b==1){ portc=0;
portc = 0x0C; delay_ms(500);
portd.f0=1; portc.f0=1;}
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_6_off); if(v==2){
Lcd_Custom_Out(1,1, text); portc = 0x02;
Delay_ms(700); portd.f0=1;
portd.f0=0; Lcd_Custom_Cmd(Lcd_CLEAR);
portc=0; strConstCpy(text,zone_7_on);
delay_ms(500); Lcd_Custom_Out(1,1, text);
portc.f0=1;} v=0;
Delay_ms(700);
if(b==2){ portd.f0=0;
portc = 0x0C;
portc=0; delay_ms(500); portc.f0=1;}}
portd.f0=1;
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,zone_6_on);
Lcd_Custom_Out(1,1, text); if (k==14) //
b=0; Delay_ms(700); portd.f0=0; portc=0; Configured Status Checking
delay_ms(500); portc.f0=1;}} {portc = 0x0E;
portd.f0=0;
if (k==8) // Lcd_Custom_Cmd(Lcd_CLEAR);
DISARM WHOLE SYSTEM strConstCpy(text,stat);
{portc = 0x02; Lcd_Custom_Out(1,1, text);
portd.f0=0; strConstCpy(text,configured);
Lcd_Custom_Cmd(Lcd_CLEAR); Lcd_Custom_Out(2,1, text);
strConstCpy(text,disarm_system); Delay_ms(700);
Lcd_Custom_Out(1,1, text); portc=0;
i=1,j=1,l=1,m=1,n=1,b=1,v=1; delay_ms(500);
Delay_ms(700); portc.f0=1;}
portd.f0=0;
portc=0; if (k==15){ //
delay_ms(500); Configure status checking
portc.f0=1;} portc = 0x0A;
portd.f0=0;
if (k==9) // Lcd_Custom_Cmd(Lcd_CLEAR);
ZONE 7 strConstCpy(text,configure);
{v++; Lcd_Custom_Out(1,1, text);
if(v==1){ strConstCpy(text,stat);
Lcd_Custom_Out(2,1, text);
Delay_ms(700);
portd.f0=0;
portc=0;
delay_ms(500);
portc.f0=1;}
if (k==16){ // off
alarm
portc = 0x0A;
portd.f0=1;
Lcd_Custom_Cmd(Lcd_CLEAR);
strConstCpy(text,alarm_OFF);
Lcd_Custom_Out(1,1, text);
Delay_ms(700);
portd.f0=0;
portc=0;
delay_ms(500);
portc.f0=1;}}
Compare Password
===================
void compare_password(){
if ( va1==pass1 && va2==pass2 &&
va3==pass3 && va4==pass4){
Lcd_Custom_Cmd(Lcd_CLEAR); // Clear display
Lcd_Custom_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
Lcd_Custom_Out(1, 1, "PASSWORD"); // indicate password is set
Lcd_Custom_Out(2, 5, "ACCEPTED");
Delay_ms(1000);}
else{
Lcd_Custom_Cmd(Lcd_CLEAR); // Clear display
Lcd_Custom_Cmd(Lcd_CURSOR_OFF); // Turn cursor off
Lcd_Custom_Out(1, 1, "PASSWORD"); // indicate password is wrong
Lcd_Custom_Out(2, 5, "REJECTED");
Delay_ms(1000);}}
END OF PROGRAM
====================
while(1){
APPENDIX B status_checking();}}
;=======================
Subroutines
============================
void alarm(); void remote(); void remote1();
void status_checking(); void zone_check();
void status_configure();
;======================= Interrupt
Subroutine ======================
void interrupt(){
Delay_ms(1100);
alarm();
if(x==0){
zone_check();
x++;}
status_checking();
INTCON.f1 = 0;} //clear
the int flag
89 if(porta==0b001101) // alarm off
press, system alarm off
{portd.f0=0;}
PORTA = 0; //
Initialize port A as 0
if(porta==0b001000) // when zone
TRISC = 0x0F; //
Configure port C as input
1 button press,
PORTC = 0; // {y++;
Initialize port C as 0 if(y==1){ // zone 1
TRISD = 0x00; // disarmed
Configure port D as output portb.f7=0;
PORTD = 0; // Initialize delay_ms(1500);}
port D as 0
if(y==2){
while(1) { portb.f7=1; // zone 1
remote(); armed
if(portd.f0==1) y=0;
{kp=0; delay_ms(1500);}}
do{ // alarm
will stop automatically in 15s if(porta==0b000100) // when zone
Delay_ms(1000); // if not 2 button press,
turn off {q++;
kp=kp++; if(q==1){ // zone 2
remote1();} disarmed
while(kp!=15); portb.f6=0;
do delay_ms(1500);}
{portd.f0=0;} // turn off
alarm and keep looping if(q==2){ // zone 2
while(1);}}} armed
portb.f6=1;
Remote Subroutine q=0;
======================== delay_ms(1500);}}
void remote(){ if(n!=2){
if(porta==0b001100) // when zone
if(porta==0x02) // when arm button press,
3 button press,
all light will on {portb=0xFE;
{o++;
y=0,q=0,o=0,e=0,l=0,t=0,u=0;} if(o==1){ // zone 3
disarmed
if(porta==0b000001) // when portb.f5=0;
disarm button, all light will off delay_ms(1500);}
{portb=0b00000000;
portd.f0=0; if(o==2){
y=1,q=1,o=1,e=1,l=1,t=1,u=1;} portb.f5=1; // zone 3
armed
if(porta==0b000101) // configure o=0;
status checking delay_ms(1500);}}
{status_configure();}
if(porta==0b001010) // when zone 4
button press,
{e++;
if(e==1){ // zone 4 if(u==2){ // zone 7
disarmed armed
portb.f4=0; portb.f1=1;
delay_ms(1500);} u=0;
delay_ms(1500);}}}
if(e==2){ // zone 4
armed Remote1 Subroutine
portb.f4=1; =======================
{portb.f4=0;} void remote1(){
e=0; if(porta==0b000001) // when disarm button,
delay_ms(1500);}} all light will off {portb=0b00000000;
portd.f0=0;
if(porta==0b000110) // when zone 5 kp=15;}
button press,
{l++; if(porta==0b001101) // alarm off
if(l==1){ // zone 5 press, system alarm off
disarmed {portd.f0=0;
portb.f3=0; kp=15;}}
delay_ms(1500);}
Status Configure
if(l==2){ // zone 5 =========================
armed void status_configure(){
portb.f3=1; do{
l=0; if(porta==0b001000) // deactivate
delay_ms(1500);}} zone 1
{qq=1;}
if(porta==0b001110) // when zone if(porta==0b000100) // deactivate
6 button press, zone 2
{t++; {oo=1;}
if(t==1){ // zone 6 if(porta==0b001100) // deactivate
disarmed zone 3
portb.f2=0; {ee=1;}
delay_ms(1500);} if(porta==0b001010) // deactivate
zone 4
if(t==2){ // zone 6 {ll=1;}
armed if(porta==0b000110) // deactivate
portb.f2=1; zone 5
t=0; {tt=1;}
delay_ms(1500);}}
if(porta==0b001110) // deactivate
if(porta==0b001001) // when zone 7 zone 6
button press, {uu=1;}
{u++; if(porta==0b001001) // deactivate
if(u==1){ // zone 7 zone 7
disarmed {hh=1;}
portb.f1=0; }while(porta!=0b000111);}
delay_ms(1500);}
Status Checking
=========================
void status_checking(){ k++; else
if(k==1){ // zone 1 status checking {if(portc.f0==1 && portc.f1==1 &&
if(qq==1) portc.f2==0 && portc.f3==0)
{portd=0x40;}
{k=2;} else else{
{if(portc.f0==1 && portc.f1==0 && portd=0x40;
portc.f2==0 && portc.f3==1) while(1){
{portd=0x10;} portd.f0=1; delay_ms(2000); portd.f0=0;
else{ delay_ms(2000);
portd=0x10; }}}}
while(1){
portd.f0=1; delay_ms(2000); portd.f0=0; if(k==5){ // zone 5 status
delay_ms(2000); checking
}}}} if(tt==1)
{k=6;}
if(k==2){ // zone 2 status else
checking {if(portc.f0==1 && portc.f1==1 &&
if(oo==1) portc.f2==0 && portc.f3==1)
{k=3;} {portd=0x50;}
else else{
{if(portc.f0==1 && portc.f1==0 && portd=0x50;
portc.f2==1 && portc.f3==0) while(1){
{portd=0x20;} portd.f0=1; delay_ms(2000); portd.f0=0;
else{ delay_ms(2000);
portd=0x20; }}}}
while(1){
portd.f0=1; delay_ms(2000); portd.f0=0; if(k==6){ // zone 6 status
delay_ms(2000); checking
}}}} if(uu==1)
{k=7;}
if(k==3){ // zone 3 status else
checking {if(portc.f0==1 && portc.f1==1 &&
if(ee==1) portc.f2==1 && portc.f3==0)
{k=4;} {portd=0x60;}
else else{
{if(portc.f0==1 && portc.f1==0 && portd=0x60;
portc.f2==1 && portc.f3==1) while(1){
{portd=0x30;} portd.f0=1;
else{
portd=0x30; delay_ms(2000); portd.f0=0; delay_ms(2000);
while(1){ }}}}
portd.f0=1; delay_ms(2000); portd.f0=0;
delay_ms(2000); if(k==7){ // zone 7 status
}}}} checking
if(hh==1)
if(k==4){ // zone 4 status {k=0;}
checking else
if(ll==1) {if(portc.f0==1 && portc.f1==1 &&
{k=5;} portc.f2==1 && portc.f3==1) {portd=0x70;
k=0;} portd.f0=1;
else{ x=0;
portd=0x70; n=2;}
while(1){ if( portc.f0==0 && portc.f1==0 &&
portd.f0=1; delay_ms(2000); portd.f0=0; portc.f2==1 && portc.f3==0 &&
delay_ms(2000); portb.f6==1)
}}}} {portb=0x40; // zone 2 alarmed
portd.f0=1;
if(k==8) x=0;
{x=0;}} n=2;}
if( portc.f0==0 && portc.f1==0 &&
Zone Check portc.f2==1 && portc.f3==1 &&
========================== portb.f5==1)
void zone_check(){ {portb=0x20; // zone 3 alarmed
if( portc.f0==1 && portc.f1==0 && portd.f0=1;
portc.f2==0 && portc.f3==1) //zone 1 status x=0;
{k=0;} n=2;}
if( portc.f0==1 && portc.f1==0 && if( portc.f0==0 && portc.f1==1 &&
portc.f2==1 && portc.f3==0) //zone 2 status portc.f2==0 && portc.f3==0 &&
{k=1;} portb.f4==1)
if( portc.f0==1 && portc.f1==0 && {portb=0x10; // zone 4 alarmed
portc.f2==1 && portc.f3==1) //zone 3 status portd.f0=1;
{k=2;} x=0;
if( portc.f0==1 && portc.f1==1 && n=2;}
portc.f2==0 && portc.f3==0) //zone 4 status if( portc.f0==0 && portc.f1==1 &&
{k=3;} portc.f2==0 && portc.f3==1 &&
if( portc.f0==1 && portc.f1==1 && portb.f3==1)
portc.f2==0 && portc.f3==1) //zone 5 status {portb=0x08; // zone 5 alarmed
{k=4;} portd.f0=1;
if( portc.f0==1 && portc.f1==1 && x=0;
portc.f2==1 && portc.f3==0) //zone 6 status n=2;}
{k=5;}
if( portc.f0==0 && portc.f1==1 &&
if( portc.f0==1 && portc.f1==1 && portc.f2==1 && portc.f3==0 &&
portc.f2==1 && portc.f3==1) //zone 7 status
{k=6;} portb.f2==1)
{portb=0x04; // zone 6 alarmed
if(portd.f0==1) // when alarm is ring {k=7; portd.f0=1;
x=0;} x=0;
n=2;}
if( portc.f0==0 && portc.f1==1 &&
if(portd.f0==0&& portc.f0==0) {k=7;
portc.f2==1 && portc.f3==1 &&
x=0;}}
portb.f1==1)
{portb=0x02; // zone 7 alarmed
Alarm Subroutine portd.f0=1;
======================== x=0;
void alarm(){ n=2;}
if( portc.f0==0 && portc.f1==0 && if( portc.f0==0)
portc.f2==0 && portc.f3==1 && {x=0;}}
portb.f7==1) END OF PROGRAM
{portb=0x80; // zone 1 alarmed ====================