Sie sind auf Seite 1von 35

Burglar Alarm

Final Report

Submitted By:

Brandon Maciel, Linda Thompson, Bradford Savage—Team 1A

ETEE3255 Lab VII

Instructor: Barry Sherlock

Date Due: November 18th, 2010


1
Final Report
Team 1A
Abstract

The purpose of this project was to design, build, and test a burglar system. Using

simulation software and a programming code that was made to control operation of the

system via a microcontroller. A user interface was designed that will enabled the user

to manipulate several functions, such as arming/disarming the system and turning

particular sensors on or off. In order to demonstrate practical user implementation of

the burglar alarm system, the programming code was implemented with a visual

interface, a LCD display unit and a keyboard. The system was tested by triggering

various sensors, mostly magnetic switches, which were connected to the

microprocessor. Successful operation of the project was done by proper programming

code, user interface, and sensor compatibility while undergoing random presentation

testing. The team as a whole cumulatively worked on all paperwork of the project,

testing the system, designing the programming code, and building an interface for

burglar alarm system.


2
Final Report
Team 1A
1. History of the Burglar Alarm

Home safety is a key concern among many homeowners. The burglar alarm system

provides an added sense of security when just locking the doors is not gratifying

enough. This need for household security is a concern that dates back to the 19th

Century. The electric burglar alarm system has been around since the mid 1800s. The

first electric burglar alarm system was invented in Boston, MA, by Edwin Holmes in

1852. It consisted of a tripwire that electrically powered a solenoid which struck a gong

when it was set off. Holmes then turned his system into a business and moved to New

York. When in New York the American Telephone and Telegraph Company (AT&T)

bought the company from Holmes. Once bought, AT&T hooked all the personal burglar

alarms up to the same grids as those aligned with the police and fire department. This

let the police or fire department know when somebody was breaking into a house or if

there was a fire.

In the 1970s the burglar alarm system evolved to have motion detectors installed with

each system that was set up. The following decade brought about the introduction of

infrared sensors, which contributed to the overall efficacy of the alarm system. Now

burglar alarm systems are in the majority of homes across America. With the advent of

more intricate and well-developed technologies, burglar alarms have now become

equipped with a device that allows the owner to arm or disarm the security system from

his or her cellular device or laptop. As time progresses, so too does the vastness of the

range of capabilities of the alarm system. In today’s world, individuals are able to

monitor the safety of their children, homes, and priceless belongings with the use of

video surveillance. The burglar alarm system has now become less expensive and
3
Final Report
Team 1A
more advanced than ever before giving households everywhere the sense of safety and

security they have been yearning to attain for centuries on end.

2. Review of Current Literature

Many burglar alarms on the market today are either overpriced or are not dependable.

While the more expensive alarm systems are dependable with sound engineering, they

are simply too expensive for most people. On the other hand, less expensive alarm

systems are simply not dependable enough. The cost of competitive alarm systems the

team analyzed varied from $99.95 – $619.99. This project has tackled both of these

with the goal of designing a less expensive, fully dependable alarm system.

Advanced Technology Solutions has a tech savvy, high priced alarm system for

$619.99. Their product consists of 2 x 1/3 inch SONY Super HAD CCD Cameras and 1

x 4-Channel Digital Video Recorder (DVR). The wide angle cameras have built in

infrared sensors that serve 2 purposes: video surveillance and motion detecting.

Coupled with the DVR, this system is state of the art with an almost fool-proof

dependability scenario. Although the Advanced Technology Solutions system has one

major flaw; it is priced too high for the average consumer.

Wireless Home has a less expensive solution priced at $99.95. While the price is right

for the average consumer, this system lacks dependability as it contains only 1 infrared

sensor and 2 magnetic window sensors. This obvious lack of security is unacceptable

for most consumers, considering most home have 10 sets of windows and two doors.
4
Final Report
Team 1A
The fact that one has to buy warning signs and decals separately might lead the

consumer to the conclusion that the company has trimmed all costs to provide a “great

deal”. But with minimal experience in commercial sensor pricing, this product is also

drastically overpriced, although touted as a “great deal”.

The purpose of this project is to deliver a reasonably priced, dependable alarm system.

After analyzing the competition, the projects 14 sensor array will provide beefed-up

security than even the more expensive systems. More sensors simply equal more

security. Finding dependable sensors will be a tough task for the project, but once

reasonably priced sensors have been found, accomplishing the low-cost goal will be

within reach.

3. Experimental Method

A program was written that simulated a basic house burglary alarm system. This alarm

system was able to detect when there was an intrusion through any door, window, or

garage door. Also there was an LCD screen which displayed the alarm status along

with a 16-bit hexadecimal keypad that helped navigate through the LCD screen.

The house consisted of sensors on all windows and doors. There had to be at least six

window sensors, two garage door sensors, and two regular door sensors. In addition to

the sensors it was required that there be four either infrared motion detectors. The
5
Final Report
Team 1A
motion detectors detected motion throughout the house. The program that was written

was a link to all switches and infrared detectors to the AVR ATMEGA 128.

After the sensors and infrared detectors were set up, a user interface was created to

display on the LCD screen. The 16-bit hexadecimal keypad was used to navigate

through the LCD screen. The user interface had four different modes the user could

choose from. There were the Setup, Arm, Disarm, and Status modes to select from.

The screens looked similar to the figure below.

S Y S T E M S T A T U S
1 0 / 2 0 / 0 9 1 0 : 3 0 A M
A L A R M M O D E : A R M E D
S T A T U S : S E C U R E

Fig. 1 Display Screen

The Setup mode was used initially to set up the time, date and a five-digit disarm code.

After the setup was complete the alarm system started monitoring the sensors and

infrared detectors. The system then went into status mode. The status mode gave the

current situation at each sensor and infrared detector. To arm the alarm system the

user selected alarm mode and this mode set the system in arm mode. All sensors and

detectors were secure before the system was armed. Once the system was armed

there was a 45-second wait period to allow the family to leave the house without tripping

the alarm. If the alarm had been tripped after the initial 45-seconds then an alarm

would go off to signify that an intruder was in the building. The alarm system would

then go into the disarm mode. In disarm mode it allowed the individual 45 seconds to
6
Final Report
Team 1A
disarm the alarm with the five digit disarm code after it has been tripped. When the

alarm system was not armed there was the main screen where the user could select

between all four modes by push button. The push buttons had to be hardware

debounced in order for them to work properly. This was done by using capacitors and

resistors between the switch and AVR connection. All equipment required is shown on

Table 1 shown below.

Requirements Usage

AVR ATMEGA 128 Microcontroller used

4x20 LCD Screen User interface screen

16 Button Hexadecimal Keypad Type to LCD screen

6 Sensors 2 door, 6 window, 2 garage door

4 Infrared motion/beam detectors Detect motion or intrusion

RS 232 Serial Communication Terminal Communicate with AVR ATMEGA 128

4 user interface modes Setup, Arm, Disarm, Status

Table I: Equipment Requirements


7
Final Report
Team 1A
4. Program Code

The program code was written piece by piece. The first important piece of the

code was to initialize the ports being used. Port A was initialized to be the

sensors for the windows and doors. Port D was initialized to communicate with

the Keypad. Port E was initialized to communicate with the LCD screen. Finally

Port F was used to initialize the motion sensors.

// Port A initialization
PORTA=0x00;//port for window and door sensors
DDRA=0xFF;//0-3 for windows and 4-7 for door sensors

// Port D initialization
PORTD=0x0F; //Port for the keypad
DDRD=0xF0; //Upper 4-bits are output and lower 4-bits are
inputs
// Port E initialization

PORTE=0x00; //Port for the LCD


DDRE=0xFC; //Pins 2-7 are outputs for LCD
// Port E initialization

PORTF=0x00; //Port for the motion sensors


DDRF=0xFF; //Pins 0-1 for door sensors and 2-5 for motion
sensors

Fig 2. Code initializing Ports

The second piece of code that was a major portion was telling the LCD screen

what to display. The LCD screen is how the user communicates with the burglar

alarm system. So what is shown on the display screen is important so the user

can navigate through the screens without any problems. An example of this

code is displayed below in figure three.


8
Final Report
Team 1A

//Text used for Set-up Screen


unsigned char setup_screen0[21] = (" SYSTEM SETUP ");//press A
for setup
unsigned char setup_screen1[21] = (" ARM ");//press B
for Arm--45 seconds to leave and ALL sensors armed
unsigned char setup_screen2[21] = (" DISARM ");//press C
for disarm--45 seconds to enter correct 5 DIGIT code
unsigned char setup_screen3[21] = (" STATUS ");//press D
for Sensor Status Screen

Fig 3. LCD Screen Display

The last portion of the code was setting up the sensors to communicate when a door or

window was being opened/close. This part of the code tells the ATmega 128 to

communicate with the sensors see if the doors or windows are opened or closed. If

they are closed then the system does not do anything, but if the sensors detect a open

door or window it will then notify the ATmega 128 that there has been a breech in the

house.

//-------------updates alarm triggers on sensor status screen via an


array
void UpdateSensorStatus ()
{

if(PINA.7==1)sensor_screen3[10]='-';else sensor_screen3[10]='A';
if(PINA.6==1)sensor_screen3[9]='-';else sensor_screen3[9]='A';
if(PINA.5==1)sensor_screen3[8]='-';else sensor_screen3[8]='A';
if(PINA.4==1)sensor_screen3[7]='-';else
sensor_screen3[7]='A';
if(PINA.3==1)sensor_screen3[5]='-';else
sensor_screen3[5]='A';
if(PINA.2==1)sensor_screen3[4]='-';else
sensor_screen3[4]='A';
if(PINA.1==1)sensor_screen3[3]='-';else
sensor_screen3[3]='A';
if(PINA.0==1)sensor_screen3[2]='-';else
sensor_screen3[2]='A';
if(PINF.7==1)sensor_screen3[18]='-';else
sensor_screen3[18]='A';
if(PINF.6==1)sensor_screen3[17]='-';else
sensor_screen3[17]='A';
if(PINF.5==1)sensor_screen3[16]='-';else
sensor_screen3[16]='A';
if(PINF.4==1)sensor_screen3[15]='-';else
sensor_screen3[15]='A';
if(PINF.3==1)sensor_screen3[12]='-';else
sensor_screen3[12]='A';
9
Final Report
Team 1A
if(PINF.2==1)sensor_screen3[11]='-';else
sensor_screen3[11]='A';
Fig 4. Setting Up Sensors

The rest of the code set up the time and date, and also linked the major parts of

the code together.

The switches on the ATmega128 were simulations of the sensor for the burglar

alarm system. When the sensor was set to high then the door/window was

closed. When it was set to low the door/window was opened.

5. Experimental Results

While writing the program, there were several issues that had to be dealt with

before we got the code working. The first problem was trying to find which port to

use for the LCD screen. The LCD screen has its own slot on the ATmega 123

but it does not show what port it was. After a great deal of research it was found

that port E was needed to work the LCD screen.

Once the right port was initialized for the LCD screen there was also trouble

trying to get the screen display what was desired for it to display. The screen

would just show blocks across the entire screen. It took a lot of trial and error to

finally get the LCD displaying what it needed to display.


10
Final Report
Team 1A
Setting up the Date and Time in the system setup also took a lot longer than

planned in the original work breakdown structure. Through research on the

internet about different commands in the C programming language finally gave a

solution on how to fix the problems encountered with setting up the time and date

for the burglar alarm system.

Overall the parts completed from the objectives performed to expectations.

There was a problem getting infrared motion detectors so there was no way to

check the code written to see if it worked. Also switches were used in the place

of the sensors for the doors and windows. If the switch read high then the

door/window was closed, and if the switch read low then the door/window was

open.

6. Conclusion

The objective of this project was to create a model burglar alarm system that

would detect motion and the opening of all doors and windows when the system

is armed. The system should have a LCD screen that allowed you to setup, arm,

disarm, and check the status of the alarm system. A keypad was also needed to

navigate through the LCD screen. There had to be a total of six window sensors,

four door sensors (two regular doors and two garage doors), and four motion

detectors.
11
Final Report
Team 1A
The greatest challenge faced in this project was writing and debugging the code

to get it to operate correctly. There were several problems in the code that had

to be fixed before it would work correctly. A few of the main problems corrected

were assigning the right port to the LCD screen (Port E), getting the LCD screen

to display correctly, and getting the time and date to set up correctly.

Overall the parts of the objectives that were completed worked correctly as the

objectives specified. Although infrared motion detectors could not be obtained,

code was still written to include them.

7. References

“Atomic Mall product Info- Wireless Home -Business Security Burglar Alarm System.”

Web.< http://www.atomicmall.com/view.php?id=540587>

“Dino Direct- Advanced Technology Solutions 4 Channel DVR & 2 Color Cameras

Security System.” Web.< http://www.dinodirect.com/cameras-security-system-4channel-

dvr-sky-8204st-cam-817l/AFFID-183.html>
12
Final Report
Team 1A
“Amtel Products- AVR ATMEGA 128.” Web. <

http://www.atmel.com/dyn/products/product_card.asp?part_id=2018>

http://www.ehow.com/facts_5038281_history-burglar-alarm.html

http://www.guide4home.com/care-alarm/house.htm

http://www.top5inrealestate.com/items/view/null/8973/
13
Final Report
Team 1A
8. Appendix

Appendix 1. Project Guidelines


14
Final Report
Team 1A
15
Final Report
Team 1A
16
Final Report
Team 1A

Appendix 2. Complete Code


****************************************
This program was produced by the
CodeWizardAVR V2.04.1 Evaluation
Automatic Program Generator
© Copyright 1998-2009 Pavel Haiduc, HP InfoTech s.r.l.
http://www.hpinfotech.com
Project : Brandon, Linda, and Bradford
Version : 1
Date : 11/16/2010
Author : Freeware, for evaluation and non-commercial use only
Company :
Comments:
17
Final Report
Team 1A
Chip type : ATmega128L
Program type : Application
AVR Core Clock frequency: 16.000000 MHz
Memory model : Small
External RAM size : 0
Data Stack size : 1024
*****************************************************/
#include <mega128.h>
#include <delay.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define FIRST_ADC_INPUT 0
#define LAST_ADC_INPUT 0
unsigned char adc_data[LAST_ADC_INPUT-FIRST_ADC_INPUT+1];
#define ADC_VREF_TYPE 0xE0
#define LCD_PORT PORTE //LCD connected to Port E
#define LCD_RS 0x04 //LCD Register Select 0=Instruction input,
1=Data input
#define LCD_EN 0x08 //LCD Enable bit
#define TRUE 0
#define FALSE 1

#define door1 PORTA.0


#define door2 PORTA.1
#define door3 PORTA.2
#define door4 PORTA.3
#define window_1 PORTA.4
#define window_2 PORTA.5
#define window_3 PORTA.6
#define window_4 PORTA.7

#define window_5 PORTF.0


#define window_6 PORTF.1

#define sensor_1 PORTF.2


#define sensor_2 PORTF.3
#define sensor_3 PORTF.4
#define sensor_4 PORTF.5

//Declared variables
void intsetup ();
void InputData1 ();
char button (char keycode);
void SensorScreen ();
void MainMenu();
void MainMenu2();
void zone_set_up();
unsigned long GetCurrentDate();
unsigned long GetCurrentTime();
void clock ();
18
Final Report
Team 1A

// Timer 0 overflow interrupt service routine


interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
// Reinitialize Timer 0 value
TCNT0=0x06;
clock ();
}
// ADC interrupt service routine
// with auto input scanning
interrupt [ADC_INT] void adc_isr(void)
{
static unsigned char input_index=0;
// Read the 8 most significant bits
// of the AD conversion result
adc_data[input_index]=ADCH;
// Select next ADC input
if (++input_index > (LAST_ADC_INPUT-FIRST_ADC_INPUT))
input_index=0;
ADMUX=(FIRST_ADC_INPUT | (ADC_VREF_TYPE & 0xff))+input_index;
// Delay needed for the stabilization of the ADC input voltage
delay_us(10);
// Start the AD conversion
ADCSRA|=0x40;
}
unsigned char lcd_x; //X position of the LCD screen
unsigned char lcd_y; //Y position of the LCD screen
static unsigned char base_y[4] = {0x80, 0xC0, 0x94, 0xD4}; //Array for the y
positions on the LCD
unsigned char a;
unsigned long current_time;

void LCD_reset () //Reset the LCD


{
LCD_PORT = LCD_EN; //Enable the LCD
LCD_PORT = 0x30|LCD_EN; //Routine used for reseting the LCD
LCD_PORT = 0x30;
delay_ms (1);
LCD_PORT = LCD_EN; //Routine repeated
LCD_PORT = 0x30|LCD_EN;
LCD_PORT = 0x30;
delay_ms (1);
LCD_PORT = LCD_EN; //Routine repeated
LCD_PORT = 0x30|LCD_EN;
LCD_PORT = 0x30;
delay_ms (1);
LCD_PORT = LCD_EN; //Sets the Bus width of 4-bit mode
LCD_PORT = 0x20|LCD_EN;
LCD_PORT = 0x20;
delay_ms (1);
}
19
Final Report
Team 1A
void lcd_cmd (unsigned char cmd) //Sending command to the LCD
{
//send high bits
LCD_PORT = LCD_EN; // makes EN high
LCD_PORT = (cmd & 0xF0) |LCD_EN; // Put on commands ports
makes EN low
LCD_PORT = (cmd & 0xF0); //Port retains the command
//send low bits
LCD_PORT = LCD_EN; // makes EN high
LCD_PORT = ((cmd << 4) & 0xF0) |LCD_EN; //Shifts to upper 4 bits
LCD_PORT = ((cmd << 4) & 0xF0); // Put on commands ports
makes EN low
delay_ms (5); //Delay to give LCD time to
process the command

}
void LCD_init() //Initializes the LCD
{
LCD_reset();
lcd_cmd (0x28); //4-bit, 2 line, 5x7 dots
lcd_cmd (0x0C); //Display on Cursor off
lcd_cmd (0x06); //Entry Mode
lcd_cmd (0x01); //Clears the Screen
lcd_cmd (0x80); // Set Cursor at line 1
}
//Set the LCD display position x=0...39, y=0...3
void lcd_gotoxy (unsigned char x, unsigned char y)
{
lcd_cmd (base_y [y] + x);
lcd_x = x;
lcd_y = y;
}
/*void lcd_senddata (unsigned char data) //Write one character to LCD
{
//send high bits
LCD_PORT = LCD_EN|LCD_RS; // Allow data to be
sent to LCD
LCD_PORT = ((data & 0xF0) |LCD_EN|LCD_RS); //Write the data to
the LCD
LCD_PORT = ((data & 0xF0) |LCD_RS); // Put on commands
ports makes EN low
//send low bits
LCD_PORT = LCD_EN|LCD_RS; // makes EN high
LCD_PORT = (((data << 4 ) & 0xF0) |LCD_EN|LCD_RS);
LCD_PORT = (((data << 4) & 0xF0) |LCD_RS); //Puts data on the LCD
delay_ms (5); //Give LCD time to
process
}
*/
void lcd_displaystring (unsigned char *var) //Display a string on the
LCD
{
unsigned char current_char;
while (*var != 0)
{
current_char = *var++;
20
Final Report
Team 1A
//send high bits
LCD_PORT = LCD_EN|LCD_RS; // makes EN high and RS
high to write to LCD
LCD_PORT = ((current_char & 0xF0) |LCD_EN|LCD_RS);
LCD_PORT = ((current_char & 0xF0) |LCD_RS); // Put on commands
ports makes EN low
//send low bits
LCD_PORT = LCD_EN|LCD_RS; // makes EN high
LCD_PORT = (((current_char << 4 ) & 0xF0) |LCD_EN|LCD_RS);
LCD_PORT = (((current_char << 4) & 0xF0) |LCD_RS); //Puts string
on the LCD
delay_ms (5); //Give LCD time to process
}
}

//Text used for System Status Screen


unsigned char system_screen0 [21] = (" SYSTEM STATUS "); // system
status screen
unsigned char system_screen1 [21] = (" "); // time
date display---00:00 00/00/00
unsigned char system_screen2 [21] = (" ALARM MODE: "); // armed or
disarmed
unsigned char system_screen3 [21] = (" STATUS: "); //secure or
insecure

armed or disarmed

//Text used for the Sensor Status Screen


21
Final Report
Team 1A
unsigned char sensor_screen0 [21] = (" SENSOR STATUS "); // sensor
status screen
unsigned char sensor_screen1 [21] = (" DOOR WINDOW MOTION ");//type or
location of sensor
unsigned char sensor_screen2 [21] = (" 1234 123456 1234 ");//sensor #'s
unsigned char sensor_screen3 [21] = (" ");//A= tripped, N=
nominal

//Text used for Set-up Screen


unsigned char setup_screen0[21] = (" SYSTEM SETUP ");//press A for
setup
unsigned char setup_screen1[21] = (" ARM ");//press B for
Arm--45 seconds to leave and ALL sensors armed
unsigned char setup_screen2[21] = (" DISARM ");//press C for
disarm--45 seconds to enter correct 5 DIGIT code
unsigned char setup_screen3[21] = (" STATUS ");//press D for
Sensor Status Screen

////Text used for Initial Set-up Screen


unsigned char isetup_screen0[21] = (" ENTER TIME ");//press A for
setup
unsigned char isetup_screen1[21] = (" 00:00 ");//press B for
Arm--45 seconds to leave and ALL sensors armed
unsigned char isetup_screen2[21] = (" Enter DATE ");//press C for
disarm--45 seconds to enter correct 5 DIGIT code
unsigned char isetup_screen3[21] = (" 00/00/00 ");//press D for
Sensor Status Screen

unsigned char code1[21] = (" ENTER CODE ");


unsigned char arm_disarm1[21] = ("ARM = 1 DISARM = 2 ");

unsigned char c = 0;
unsigned char temperature_data;
int clock_hours;
int time_counter;
22
Final Report
Team 1A
int clock_seconds;
int clock_minutes;
int date_DD;
int date_MM;
int date_YY;

unsigned char ZZ = 0;
int arm;
int code_a;
int code_b;
int code_c;
int code_d;
int code_e;
int decide;
int status;

void main(void)
{
// Port A initialization
PORTA=0x00;//port for window and door sensors
DDRA=0xFF;//0-3 for windows and 4-7 for door sensors

// Port D initialization
PORTD=0x0F; //Port for the keypad
DDRD=0xF0; //Upper 4-bits are output and lower 4-bits are inputs
// Port E initialization

PORTE=0x00; //Port for the LCD


DDRE=0xFC; //Pins 2-7 are outputs for LCD
// Port E initialization
23
Final Report
Team 1A
PORTF=0x00; //Port for the motion sensors
DDRF=0xFF; //Pins 0-1 for door sensors and 2-5 for motion sensors

// Timer/Counter 0 initialization
// Clock source: System Clock
// Clock value: 250.000 kHz
// Mode: Normal top=FFh
// OC0 output: Disconnected

ASSR=0x00;
TCCR0=0x04;
TCNT0=0x06;
OCR0=0x00;
// ADC initialization
// ADC Clock frequency: 1000.000 kHz
// ADC Voltage Reference: Int., cap. on AREF
// Only the 8 most significant bits of
// the AD conversion result are used

ADMUX=FIRST_ADC_INPUT | (ADC_VREF_TYPE & 0xff);


ADCSRA=0xCC;
delay_ms(1000);
LCD_init(); //Initialize LCD
MainMenu();
// Timer(s)/Counter(s) Interrupt(s) initialization
TIMSK=0x01;
ETIMSK=0x00;
// Global enable interrupts
#asm("sei")
intsetup();//-------------calls up int set up initially
24
Final Report
Team 1A

while (1)
{
keyData1 = PIND & 0x0F;
if ((keyData1 != 0xF) & ZZ==0)
{
delay_ms (5);
keyData2 = PIND & 0x0F;
if (keyData1 == keyData2)
{
key_select = button(keyData2); //Takes data from keypad
and put in a variable
ZZ=1;
}
}

if((keyData1 == 0xF) & ZZ==1)


{ZZ=0;}
current_time = GetCurrentTime();
system_screen1[2]=(clock_hours/10)+0x30;
system_screen1[3]=clock_hours%10+0x30;
system_screen1[4]=':';
system_screen1[5]=clock_minutes/10+0x30;
system_screen1[6]=clock_minutes%10+0x30;
system_screen1[7]='_';
current_date = GetCurrentDate();
system_screen1[8]=(date_MM/10)+0x30;
system_screen1[9]=date_MM%10+0x30;
system_screen1[10]=(date_DD/10)+0x30;
system_screen1[11]=date_DD%10+0x30;
system_screen1[12]=(date_YY/10)+0x30;
system_screen1[13]=date_YY%10+0x30;

}//was a semicolon here??


}
25
Final Report
Team 1A

void SatusMenu()//-----------tells what status menu displays


{
lcd_cmd (0x01);
lcd_gotoxy(0,0);
lcd_displaystring (setup_screen0);
lcd_gotoxy (0,1);
lcd_displaystring (setup_screen1);
lcd_gotoxy (0,2);
lcd_displaystring (setup_screen2);
lcd_gotoxy (0,3);
lcd_displaystring (setup_screen3);
}
void SensorMenu()//defines sensor menu
{
lcd_cmd (0x01);
lcd_gotoxy(0,0);
lcd_displaystring (system_screen0);
lcd_gotoxy (0,1);
lcd_displaystring (system_screen1);
lcd_gotoxy (0,2);
lcd_displaystring (system_screen2);
lcd_gotoxy (0,3);
lcd_displaystring (system_screen3);
}

void intsetup()//----------tells what setup screen says


{
lcd_cmd (0x01);
lcd_gotoxy(0,0);
lcd_displaystring (setup_screen0);
lcd_gotoxy (0,1);
lcd_displaystring (setup_screen1);
lcd_gotoxy (0,1);
lcd_displaystring (setup_screen2);
lcd_gotoxy (0,2);
lcd_displaystring (setup_screen3);

InputData1();//------------inputs date and time


clock_hours = key_select*10;
InputData1();
26
Final Report
Team 1A
clock_hours += key_select;
InputData1();
clock_minutes = key_select*10;
InputData1();
clock_minutes += key_select;

InputData1();
date_MM = key_select*10;
InputData1();
date_MM += key_select;
InputData1();
date_DD = key_select*10;
InputData1();
date_DD += key_select;
InputData1();
date_YY = key_select*10;
InputData1();
date_YY += key_select;
lcd_gotoxy (0,1);
lcd_displaystring (enter_code);

digit_code();

void digit_code()//5 digit code===1,2,3,4,5


{

InputData1();
code_a = key_select;
if (code_a == 1);
{
continue;
27
Final Report
Team 1A
}
InputData1();
code_b = key_select;
if (code_b == 2);
{
continue;
}
InputData1();
code_c = key_select;
if (code_c == 3);
{
continue;
}
InputData1();
code_d = key_select;
if (code_d == 4);
{
continue;
}
InputData1();
code_e = key_select;
if (code_e == 5);
{
continue;
}

lcd_gotoxy (0,2);

lcd_displaystring (arm_disarm);//---------decide if arm or disarm


InputData1();
decide = key_select;
if (decide == 1);
{
status = 1;
UpdateSensorStatus();//armed and secure
return;
}
else if (decide == 2);
{
status = 2;
UpdateSensorStatus();//disarmed and secure
return;
}

}
28
Final Report
Team 1A

void SensorScreen ()//----------tells what sensor screen to say


{
lcd_cmd (0x01);
lcd_gotoxy (0,0);
lcd_displaystring (sensor_screen0);
lcd_gotoxy (0,1);
lcd_displaystring (sensor_screen1);
lcd_gotoxy (0,2);
lcd_displaystring (sensor_screen2);
lcd_gotoxy (0,3);
lcd_displaystring (sensor_screen3);
}

unsigned long GetCurrentTime()


{
current_time = 60*(unsigned long)clock_hours + (unsigned
long)clock_minutes;
return current_time;
}

unsigned GetCurrentDate()
{
current_date = (unsigned)date_MM + (unsigned)date_DD +
(unsigned)date_YY;
29
Final Report
Team 1A
return current_date;
}

//---------------clock counter function

void clock (){


// internal counter increments each time the overflow interrupt occurs (every
1 msec)
if (time_counter < 999){ // Has it counted up to 1000 msec or 1 second
(adjusted down to 999 to account for instruction cycle overhead)...
time_counter++; // No?...keep counting
} else {
time_counter = 0; // Yes?...reset counter and...
if(++clock_seconds == 60){ // increment the seconds counter and
check to see if we are ready to ...
clock_seconds = 0; // rollover the seconds counter from
60 to to zero and...
if(++clock_minutes == 60){ // increment the minutes counter and
then check to see if we are ready to ...
clock_minutes = 0; // rollover the minutes from 60 to
zero and...
if(++clock_hours == 24){// increment the hours counter and
check to see if we are ready to ...
clock_hours = 0; // rollover the hours from 24 to 00
}
}
}
}
}
30
Final Report
Team 1A

//-------------updates alarm triggers on sensor status screen via an array


void UpdateSensorStatus ()
{

if(PINA.7==1)sensor_screen3[10]='-';else sensor_screen3[10]='A';
if(PINA.6==1)sensor_screen3[9]='-';else sensor_screen3[9]='A';
if(PINA.5==1)sensor_screen3[8]='-';else sensor_screen3[8]='A';
if(PINA.4==1)sensor_screen3[7]='-';else sensor_screen3[7]='A';
if(PINA.3==1)sensor_screen3[5]='-';else sensor_screen3[5]='A';
if(PINA.2==1)sensor_screen3[4]='-';else sensor_screen3[4]='A';
if(PINA.1==1)sensor_screen3[3]='-';else
sensor_screen3[3]='A';
if(PINA.0==1)sensor_screen3[2]='-';else
sensor_screen3[2]='A';
if(PINF.7==1)sensor_screen3[18]='-';else sensor_screen3[18]='A';
if(PINF.6==1)sensor_screen3[17]='-';else sensor_screen3[17]='A';
if(PINF.5==1)sensor_screen3[16]='-';else sensor_screen3[16]='A';
if(PINF.4==1)sensor_screen3[15]='-';else
sensor_screen3[15]='A';
if(PINF.3==1)sensor_screen3[12]='-';else
sensor_screen3[12]='A';
if(PINF.2==1)sensor_screen3[11]='-';else
sensor_screen3[11]='A';

if(status = 1)//-------------carried over from correct code entry


{

system_screen2[13] ='A';
system_screen2[14] ='R';
system_screen2[15] ='M';
system_screen2[16] ='E';
system_screen2[17] ='D';

system_screen3[10]='S';
system_screen3[11]='E';
system_screen3[12]='C';
31
Final Report
Team 1A
system_screen3[13]='U';
system_screen3[14]='R';
system_screen3[15]='E';
return;
}

else(status = 2)//--------------carried over from correct code entry


{

system_screen2[13] ='D';
system_screen2[14] ='I';
system_screen2[15] ='S';
system_screen2[16] ='A';
system_screen2[17] ='R';
system_screen2[18] ='M';
system_screen2[19] ='E';
system_screen2[20] ='D';

system_screen3[10]='I';
system_screen3[11]='N';
system_screen3[12]='S';
system_screen3[13]='E';
system_screen3[14]='C';
system_screen3[15]='U';
system_screen3[16]='R';
system_screen3[17]='E';

return;
}

}
32
Final Report
Team 1A

void InputData1()//-----------------allows data to be input via


keypad(decoder)
{
key_select = 'ZZ';
while (key_select == 'ZZ')
{
keyData1 = PIND & 0x0F;
if ((keyData1 != 0xF) & ZZ==0)
{
delay_ms (5);
keyData2 = PIND & 0x0F;
if (keyData1 == keyData2)
{
key_select = button(keyData2); //Takes data from keypad
and put in a variable
ZZ=1;
}
}
if((keyData1 == 0xF) & ZZ==1)
{ZZ=0;}
}
}
33
Final Report
Team 1A

char button(char keycode)//-----------------------assigns screen options


from the status screeen
{
char keypressed;
DDRD = 0x0F;
PORTD = 0xF0;
switch(keycode)
{
case 0xE:
PORTD = 0xFE; delay_ms(5);
keycode = (PIND & 0xF0);
switch(keycode)
{
case 0xE0: keypressed =1;
break;
case 0xD0: keypressed =2;
break;
case 0xB0: keypressed =3;
break;
case 0x70: keypressed ='A';
intsetup();//----------------------------------
break;
}
break;
case 0xD:
PORTD = 0xFD; delay_ms(5);
keycode = (PIND & 0xF0);
switch(keycode)
{
case 0xE0: keypressed =4;
break;
case 0xD0: keypressed =5;
break;
case 0xB0: keypressed =6;
break;
case 0x70: keypressed ='B';
//change_zone();//------------------------------
break;
}
break;
case 0xB:
PORTD = 0xFB; delay_ms(5);
keycode = (PIND & 0xF0);
switch(keycode)
{
case 0xE0: keypressed =7;
break;
case 0xD0: keypressed =8;
break;
34
Final Report
Team 1A
case 0xB0: keypressed =9;
break;
case 0x70: keypressed ='C';
break;//---------------------------------
}
break;
case 0x7:
PORTD = 0xF7; delay_ms(5);
keycode = (PIND & 0xF0);
switch(keycode)
{
case 0xE0: keypressed ='*';
MainMenu2 ();
break;
case 0xD0: keypressed =0;
break;
case 0xB0: keypressed ='#';
break;
case 0x70: keypressed ='D';
SensorScreen ();//------------------------------
break;
}
break;
}
DDRD = 0xF0; //rows are outputs, cols are inputs
PORTD = 0x0F; //pullup resistor for inputs, set outputs to low
return (keypressed);
}

Das könnte Ihnen auch gefallen