GSM Based Home Security System
GSM Based Home Security System
GSM Based Home Security System
CHAPTER 1 INTRODUCTION
1. INTRODUCTION
The project is aimed at developing the security of Home against Intruders , Gas Leak and Fire . In any of the above three cases any one met while you are out of your home than the device sends SMS to the emergency no provided to it.The report consists of a background into the area of 8051 microcontroller and mobile communication. In this project we interfaced 8051 microcontroller with Motorolas C168 GSM mobile phone to decode the received message and do the required action. The microcontroller pulls the SMS received by phone, decode it, recognizes theMobile no. and then switches on the relays attached to its port to control the appliances. After successful operation, controller sends back the acknowledgement to the users mobile through SMS.
Page 1
Page 2
Page 3
2.3.Pindescription
Page 4
Page 5
Page 6
Page 7
Port 0 This is a dual-purpose port occupying pins 32 to 39 of the device. The port is an opendrain bidirectional I/O port with Schmitt trigger inputs. Pins that have 1s written to them float and can be used as high-impedance inputs. The port may be used with external memory to provide a multiplexed address and data bus. In this application internal pull-ups are used when emitting 1s. The port also outputs the code bytes during EPROM programming. External pull-ups are necessary during program verification. Port 1 This is a dedicated I/O port occupying pins 1 to 8 of the device. The pins are connected via internal pull-ups and Schmitt trigger input. Pins that have 1s written to them are pulled high by the internal pull-ups and can be used as inputs; as inputs, pins that are externally pulled low will source current via the internal pull-ups. The port also receives the low-order address byte during program memory verification. Pins P1.0 and P1.1 could also function as external inputs for the third timer/counter i.e.: (P1.0) T2 Timer/counter 2 external count input/clockout (P1.1) T2EX Timer/counter 2 reload/capture/direction control Port 2 This is a dual-purpose port occupying pins 21 to 28 of the device. The specification is similar to that of port 1. The port may be used to provide the high-order byte of the address bus for external program memory or external data memory that uses 16-bit addresses. When accessing external data memory that uses 8-bit addresses, the port emits the contents of the P2 register. Some port 2 pins receive the high-order address bits during EPROM programming and verification. Port 3 This is a dual-purpose port occupying pins 10 to 17 of the device. The specification is similar to that of port 1. These pins, in addition to the I/O role, serve the special features of the 80C51 family; the alternate functions are summarized below: P3.0 P3.1 P3.2 RxD serial data input port TxD serial data output port INT0 external interrupt 0
Page 8
INT1 external interrupt 1 T0 timer/counter 0 external input T1 timer/counter 1 external input WR external data memory writes strobe RD external data memory read strobe.
Page 9
TMOD - Timer/Counter mode control register (address 89H) bit allocation Not bit addressable; Reset value: 00000000B; Reset source(s): any source
TMOD - Timer/Counter mode control register (address 89H) M1/M0 operating mode
Page 10
TCON - Timer/Counter control register (address 88H) bit allocation Bit addressable
Page 11
Mode 0
Putting either Timer into Mode 0 makes it look like an 8048 Timer, which is an 8-bit Counter with a fixed divide-by-32 prescaler. Figure 7 shows Mode 0 operation.
Page 12
In this mode, the Timer register is configured as a 13-bit register. As the count rolls over from all 1s to all 0s, it sets the Timer interrupt flag TFn. The count input is enabled to the Timer when TRn = 1 and either GATE = 0 or INTn = 1. (Setting GATE = 1 allows the Timer to be controlled by external input INTn, to facilitate pulse width measurements). TRn is a control bit in the Special Function Register TCON (Figure 6). The GATE bit is in the TMOD register. The 13-bit register consists of all 8 bits of THn and the lower 5 bits of TLn. The upper 3 bits of TLn are indeterminate and should be ignored. Setting the run flag (TRn) does not clear the registers. Mode 0 operation is the same for Timer 0 and Timer 1 (see Figure 7). There are two different GATE bits, one for Timer 1 (TMOD.7) and one for Timer 0 (TMOD.3).
Mode 1
Page 13
Mode 1 is the same as Mode 0, except that all 16 bits of the timer register (THn and TLn) are used.
Mode 2
Mode 2 configures the Timer register as an 8-bit Counter (TLn) with automatic reload, as shown in Figure 9. Overflow from TLn not only sets TFn, but also reloads TLn with the contents of THn, which must be preset by software. The reload leaves THn unchanged. Mode 2 operation is the same for Timer 0 and Timer 1.
Page 14
Mode 3
When timer 1 is in Mode 3 it is stopped (holds its count). The effect is the same as setting TR1 = 0. Timer 0 in Mode 3 establishes TL0 and TH0 as two separate 8-bit counters. The logic for Mode 3 and Timer 0 is shown in Figure 10. TL0 uses the Timer 0 control bits: T0C/T, T0GATE, TR0, INT0, and TF0. TH0 is locked into a timer function (counting machine cycles) and takes over the use of TR1 and TF1 from Timer 1. Thus, TH0 now controls the Timer 1 interrupt. Mode 3 is provided for applications that require an extra 8-bit timer. With Timer 0 in Mode 3, the P89V51RD2 can look like it has an additional Timer. Note: When Timer 0 is in Mode 3, Timer 1 can be turned on and off by switching it into and out of its own Mode 3. It can still be used by the serial port as a baud rate generator, or in any application not requiring an interrupt.
Page 15
Timer 2
Timer 2 is a 16-bit Timer/Counter which can operate as either an event timer or an event counter, as selected by C/T2 in the special function register T2CON. Timer 2 has four operating modes: Capture, Auto-reload (up or down counting), Clock-out, and Baud Rate Generator which are selected according to Table 17 using T2CON (Table 18 and Table 19) and T2MOD (Table 20 and Table 21). Timer 2 operating mode
Page 16
Page 17
Fig: 3.5.1 Timer 2 in capture mode This bit can be used to generate an interrupt (by enabling the Timer 2 interrupt bit in the IEN0 register). If EXEN2 = 1, Timer 2 operates as described above, but with the added feature that a 1- to -0 transition at external input T2EX causes the current value in the Timer 2 registers, TL2 and TH2, to be captured into registers RCAP2L and RCAP2H, respectively. In addition, the transition at T2EX causes bit EXF2 in T2CON to be set, and EXF2 like TF2 can generate an interrupt (which vectors to the same location as Timer 2 overflow interrupt). The Timer 2
Page 18
interrupt service routine can interrogate TF2 and EXF2 to determine which event caused the interrupt. There is no reload value for TL2 and TH2 in this mode. Even when a capture event occurs from T2EX, the counter keeps on counting T2 pin transitions or fosc/6 pulses. Since once loaded contents of RCAP2L and RCAP2H registers are not protected, once Timer2 interrupt is signalled it has to be serviced before new capture event on T2EX pin occurs. Otherwise, the next falling edge on T2EX pin will initiate reload of the current value from TL2 and TH2 to RCAP2L and RCAP2H and consequently corrupt their content related to previously reported interrupt.
Fig: 3.6.1 Timer 2 in auto-reload mode(DCEN=0) In this mode, there are two options selected by bit EXEN2 in T2CON register. If EXEN2 = 0, then Timer 2 counts up to 0FFFFH and sets the TF2 (Overflow Flag) bit upon overflow. This causes the Timer 2 registers to be reloaded with the 16-bit value in RCAP2L and RCAP2H. The values in RCAP2L and RCAP2H are preset by software means.
Page 19
Auto reload frequency when Timer 2 is counting up can be determined from this formula:
Where Supply Frequency is either fosc (C/T2 = 0) or frequency of signal on T2 pin (C/T2 = 1). If EXEN2 = 1, a 16-bit reload can be triggered either by an overflow or by a 1-to-0 transition at input T2EX. This transition also sets the EXF2 bit. The Timer 2 interrupt, if enabled, can be generated when either TF2 or EXF2 is 1. Microcontrollers hardware will need three consecutive machine cycles in order to recognize falling edge on T2EX and set EXF2 = 1: in the first machine cycle pin T2EX has to be sampled as 1; in the second machine cycle it has to be sampled as 0, and in the third machine cycle EXF2 will be set to 1. In Figure 13, DCEN = 1 and Timer 2 is enabled to count up or down. This mode allows pin T2EX to control the direction of count. When a logic 1 is applied at pin T2EX Timer 2 will count up. Timer 2 will overflow at 0FFFFH and set the TF2 flag, which can then generate an interrupt, if the interrupt is enabled. This timer overflow also causes the 16-bit value in RCAP2L and RCAP2H to be reloaded into the timer registers TL2 and TH2.
Page 20
When a logic 0 is applied at pin T2EX this causes Timer 2 to count down. The timer will underflow when TL2 and TH2 become equal to the value stored in RCAP2L and RCAP2H. Timer 2 underflow sets the TF2 flag and causes 0FFFFH to be reloaded into the timer registers TL2 and TH2. The external flag EXF2 toggles when Timer 2 underflows or overflows. This EXF2 bit can be used as a 17th bit of resolution if needed.
Fig: 3.7.1 Timer 2 in Baud Rate Generator Mode The baud rate generation mode is like the auto-reload mode, when a rollover in TH2 causes the Timer 2 registers to be reloaded with the 16-bit value in registers RCAP2H and RCAP2L, which are preset by software. The baud rates in modes 1 and 3 are determined by Timer 2s overflow rate given below:
Page 21
Modes 1 and 3 Baud Rates = Timer 2 Overflow Rate/16 The timer can be configured for either timer or counter operation. In many applications, it is configured for timer' operation (C/T2 = 0). Timer operation is different for Timer 2 when it is being used as a baud rate generator. Usually, as a timer it would increment every machine cycle (i.e., 16 the oscillator frequency). As a baud rate generator, it increments at the oscillator frequency. Thus the baud rate formula is as follows: Modes 1 and 3 Baud Rates =
Where: (RCAP2H, RCAP2L) = The content of RCAP2H and RCAP2L taken as a 16-bit unsigned integer. The Timer 2 as a baud rate generator mode is valid only if RCLK and/or TCLK = 1 in T2CON register. Note that a rollover in TH2 does not set TF2, and will not generate an interrupt. Thus, the Timer 2 interrupt does not have to be disabled when Timer 2 is in the baud rate generator mode. Also if the EXEN2 (T2 external enable flag) is set, a 1-to-0 transition in T2EX (Timer/counter 2 trigger input) will set EXF2 (T2 external flag) but will not cause a reload from (RCAP2H, RCAP2L) to (TH2,TL2). Therefore when Timer 2 is in use as a baud rate generator, T2EX can be used as an additional external interrupt, if needed. When Timer 2 is in the baud rate generator mode, one should not try to read or write TH2 and TL2. Under these conditions, a read or write of TH2 or TL2 may not be accurate. The RCAP2 registers may be read, but should not be written to, because a write might overlap a reload and cause write and/or reload errors. The timer should be turned off (clear TR2) before accessing the Timer 2 or RCAP2 registers. Table 22 shows commonly used baud rates and how they can be obtained from Timer 2.
Page 22
Timer 2 is in baud rate generating mode. If Timer 2 is being clocked through pin T2(P1.0) the baud rate is: Baud rate = Timer 2 overflow rate / 16 If Timer 2 is being clocked internally, the baud rate is: Baud rate = fosc / (16 (65536 - (RCAP2H, RCAP2L))) Where fosc = oscillator frequency To obtain the reload value for RCAP2H and RCAP2L, the above equation can be rewritten as: RCAP2H, RCAP2L = 65536 - fosc / (16 baud rate) Table 22: Timer 2 generated commonly used baud rates
Page 23
2 1000u F /25V
Fig: 3.10.1 Pins of LM7805 The LM7805 monolithic 3-terminal positive voltage regulators employ internal current-limiting, thermal shutdown and safe-area compensation, making them essentially indestructible. If adequate heat sinking is provided, they can deliver over 1.0A output current. They are intended as fixed voltage regulators in a wide range of applications including local (on-card) regulation for elimination of noise and distribution problems associated with single-point regulation. In addition to us these devices can be used with external components to obtain adjustable output voltages and currents. Considerable effort was expended to make the entire series of regulators easy to use and minimize the number of external components. It is not necessary to bypass the output, although this does improve transient response. Input bypassing is needed only if the regulator is located far from the filter capacitor of the power supply.
Page 24
3.11. RS-232
Information being transferred between data processing equipment and peripherals is in the form of digital data which is transmitted in either a serial or parallel mode. Parallel communications are used mainly for connections between test instruments or computers and printers, while serial is often used between computers and other peripherals.Serial transmission involves the sending of data one bit at a time, over a single communications line. In contrast, parallel communications require at least as many lines as there are bits in a word being transmitted (for an 8-bit word, a minimum of 8 lines are needed).Serial transmission is beneficial for long distance communications, whereas parallel is designed for short distances or when very high transmission rates are required.
3.12.Standards
One of the advantages of a serial system is that it lends itself to transmission over telephone lines. The serial digital data can be converted by modem, placed onto a standard voicegrade telephone line, and converted back to serial digital data at the receiving end of the line by another modem. Officially, RS-232 is defined as the Interface between data terminal Equipment and data communications equipment using serial binary data exchange. This definition defines data terminal equipment (DTE) as the computer, while data communications equipment (DCE) is the modem. A modem cable has pin-to-pin connections, and is designed to connect a DTE device to a DCE device.
ST.ANNS COLLEGE OF ENGINEERING AND TECHNOLOGY Page 25
3.13. Interfaces
In addition to communications between computer equipment over telephone lines, RS232 is now widely used for direct connections between data acquisition devices and computer systems. As in the definition of RS-232, the computer is data transmission equipment (DTE). However, many interface products are not data communications equipment (DCE). Null modem cables are designed for this situation; rather than having the pin- to-pin connections of modem cables, null modem cables have different internal wiring to allow DTE devices to communicate with one another.
3.15. UART
The UART operates in all standard modes. Enhancements over the standard 80C51 UART include Framing Error detection, and automatic address recognition. Mode 0 Serial data enters and exits through RxD and TxD outputs the shift clock. Only 8 bits are transmitted or received, LSB first. The baud rate is fixed at 16 of the CPU clock frequency. UART configured to operate in this mode outputs serial clock on TxD line no matter whether it sends or receives data on RxD line.
Page 26
Mode 1 10 bits are transmitted (through TxD) or received (through RxD): a start bit (logical 0), 8 data bits (LSB first), and a stop bit (logical 1). When data is received, the stop bit is stored in RB8 in Special Function Register SCON. The baud rate is variable and is determined by the Timer 12 overflow rate. More about UART mode 1 Reception is initiated by a detected 1-to-0 transition at RxD. For this purpose RxD is sampled at a rate of 16 times whatever baud rate has been established. When a transition is detected, the divide-by-16 counter is immediately reset to align its rollovers with the boundaries of the incoming bit times. The 16 states of the counter divide each bit time into 16ths. At the 7th, 8th, and 9th counter states of each bit time, the bit detector samples the value of RxD. The value accepted is the value that was seen in at least 2 of the 3 samples. This is done for noise rejection. If the value accepted during the first bit time is not 0, the receive circuits are reset and the unit goes back to looking for another 1-to-0 transition. This is to provide rejection of false start bits. If the start bit proves valid, it is shifted into the input shift register, and reception of the rest of the frame will proceed. The signal to load SBUF and RB8, and to set RI, will be generated if, and only if, the following conditions are met at the time the final shift pulse is generated: (a) RI = 0, and (b) Either SM2 = 0, or the received stop bit = 1. If either of these two conditions is not met, the received frame is irretrievably lost. If both conditions are met, the stop bit goes into RB8, the 8 data bits go into SBUF, and RI is activated. Mode 2 11 bits are transmitted (through TxD) or received (through RxD): start bit (logical 0), 8 data bits (LSB first), a programmable 9th data bit, and a stop bit (logical 1). When data is transmitted, the 9th data bit (TB8 in SCON) can be assigned Or (e.g. the parity bit (P, in the PSW) could be moved into TB8). When data is received, the 9th data bit goes into RB8 in
Page 27
Special Function Register SCON, while the stop bit is ignored. The baud rate is programmable to either 116 or 132 of the CPU clock frequency, as determined by the SMOD1 bit in PCON. Mode 3 11 bits are transmitted (through TxD) or received (through RxD): a start bit (logical 0), 8 data bits (LSB first), a programmable 9th data bit, and a stop bit (logical 1). In fact, Mode 3 is the same as Mode 2 in all respects except baud rate. The baud rate in Mode 3 is variable and is determined by the Timer 1/2 overflow rate. More about UART modes 2 and 3 Reception is performed in the same manner as in mode 1. The signal to load SBUF and RB8, and to set RI, will be generated if, and only if, the following conditions are met at the time the final shift pulse is generated: (a) RI = 0, and (b) Either SM2 = 0, or the received 9th data bit = 1. If either of these conditions is not met, the received frame is irretrievably lost, and RI is not set. If both conditions are met, the received 9th data bit goes into RB8, and the first 8 data bits go into SBUF. Table 23: SCON - Serial port control register (address 98H) bit allocation
Page 28
Table 24: SCON - Serial port control register (address 98H) bit description
Page 29
Table 25: SCON - Serial port control register (address 98H) SM0/SM1 mode definition
Page 30
The slaves that werent being addressed leave their SM2 bits set and go on about their business, ignoring the subsequent data bytes. SM2 has no effect in Mode 0, and in Mode 1 can be used to check the validity of the stop bit, although this is better done with the Framing Error flag. When UART receives data in mode 1 and SM2 = 1, the receive interrupt will not be activated unless a valid stop bit is received.
Page 31
Fig: 3.18.1 Schemes used by UART The following examples will help to show the versatility of this scheme. Table 26: Slaves 0 and 1 scheme examples
In the above example SADDR is the same and the SADEN data is used to differentiate between the two slaves. Slave 0 requires a 0 in bit 0 and it ignores bit 1. Slave 1 requires a 0 in bit 1 and bit 0 is ignored. A unique address for Slave 0 would be 1100 0010 since slave 1 requires a 0 in bit 1. A unique address for slave 1 would be 1100 0001 since a 1 in bit 0 will exclude slave 0. Both
Page 32
slaves can be selected at the same time by an address which has bit 0 = 0 (for slave 0) and bit 1 = 0 (for slave 1). Thus, both could be addressed with 1100 0000. In a more complex system the following could be used to select slaves 1 and 2 while excluding slave 0
Page 33
Fig: 3. 19.1 Block diagram of Watchdog timer Table 33: WDTC - Watchdog control register (address COH) bit allocation
Table 34: WDTC - Watchdog control register (address COH) bit description
Page 34
3.21. Reset
A system reset initializes the MCU and begins program execution at program Memory location 0000H. The reset input for the device is the RST pin. In order to reset the device, a logic level high must be applied to the RST pin for at least two machine cycles (24 clocks), after the oscillator becomes stable. ALE, PSEN are weakly pulled high during reset. During reset, ALE and PSEN output a high level in order to perform a proper reset. This level must not be affected by external element. A system reset
Page 35
will not affect the 1 kbyte of on-chip RAM while the device is running, however, the contents of the on-chip RAM during power up are indeterminate.
Page 36
indeterminate location, which may cause corruption in the code of the flash. The power-on detection is designed to work as power-up initially, before the voltage reaches the brown-out detection level. The POF flag in the PCON register is set to indicate an initial power-up condition. The POF flag will remain active until cleared by software. Please refer to the PCON register definition for detail information. Following reset, the P89V51RD2 will either enter the SoftICE mode (if previously enabled via ISP command) or attempt to autobaud to the ISP boot loader. If this autobaud is not successful within about 400 ms, the device will begin execution of the user code.
reset will reset the program counter to address 0000H. All SFR registers will be set to their reset values, except FCF[1] (SWR), WDTC[2] (WDTS), and RAM data will not be altered.
Page 38
interrupt or a hardware reset. The start of the interrupt clears the PD bit and exits Power-down mode. Holding the external interrupt pin low restarts the oscillator, the signal must hold low at least 1024 clock cycles before bringing back high to complete the exit.
L C D
D E V I C E S D E V I C E S 8 0 5 1 D E V I C E S G S M M O D E M C E L L P H O N E
4.2.Definition
Global system for mobile communication (GSM) is a globally accepted standard for digital cellular communication. GSM is the name of a standardization group established in 1982 to create a common European mobile telephone standard that would formulate specifications for a pan-European mobile cellular radio system operating at 900 MHz. It is estimated that many countries outside of Europe will join the GSM partnership.
Page 39
4.3.Overview
This tutorial provides an introduction to basic GSM concepts, specifications,networks, and services. A short history of network evolution is provided in order set the context for understanding GSM.
4.5. FEATURES 1
Dual band EGSM/GPRS module (EGSM 900/1800 MHz, EGSM 950/1900 MHz) designed for M2M and automotive applications. Compliant with ETSI GSM Phase 2+ standard. Class 4 (2W @ 900MHz). Class 1 (1W @ 1800MHz) Less than 3.5mA current is required during the idle mode. Remote control by AT commands (according to GSM 07.07 and GSM 07.05). Can be used with normal SIM card with GPRS facility activated by the service provider.
Page 40
Standard RS-232 interface using 9 pin D connector provided with the device for communication. Modem can be linked to a PC or a micro-controller based embedded system for sending SMS . Data circuit asynchronous, transparent and non-transparent upto 14400 bits/s and baud rate of 30 to 115,200 bits/s. GPRS class 2. Coding schemes: CS1 to CS4. Point to Point(MT/MO) and Cell Broadcast. Latch type SIM holder (3V/5V SIM interface).
4.6.TECHNICAL SPECIFICATIONS
FEATURES Working Frequency Noise Transmission Power Receiving Sensitivity Working Temperature Storage Temperature Transmitting Current Receiving Current VALUES 900/1800 MHz. <-79dBm. 33dBm +/- 2dBm. -102dBm. -20C to 55C. -30C to 85C. <=2A (peak). <=80mA(peak).
Page 41
5 .3V to 12V DC, 2A peak. 123.5mm X 68.75mm X 23.6mm. RS-232, 9 pin D connector. 300 to 115,200 bits/s.
Page 42
send_char(0x0A); send_char(0x0D);
Page 43
send_string("AT+CNMI=2,2,2,0,0"); // for send_char(0x0A); send_char(0x0D); for(i=0;i<6;i++) temp=RX_CHAR(); // just for discarding ok // catrige return // catrige return
send_char(0x0A); send_char(0x0D);
send_string("AT+CMGF=1");//for making the GSM modem to work in text mode. send_char(0x0A); send_char(0x0D); for(i=0;i<6;i++) temp=RX_CHAR(); P1=0x00; while(1) { status=0; for (i=0;i<68;i++) // just for discarding ok // catrige return // catrige return
{ a[i]=RX_CHAR(); if(a[i]=='>') { k=i; // the SMS message from the mobile should be ended with '>'
Page 44
} } k=k-1; if(a[k]=='1') { device1=1; } else if(a[k]=='2') { device1=0; } else if(a[k]=='3') { device2=1; } else if(a[k]=='4') { device2=0; } // DEVICE 2 Off WHEN MESSAGE UNREAD.. // DEVICE 2 ON WHEN MESSAGE UNREAD // DEVICE 1 off WHEN MESSAGE READ //DEVICE 1 ON WHEN MESSAGE READ
Page 45
else if(a[k]=='5') { device3=1; } else if(a[k]=='6') { device3=0; } else if(a[k]=='7') { device4=1; } else if(a[k]=='8') { device4=0; }
temp=SBUF; // jus for clearing the read buffer temp=SBUF; temp=SBUF; temp=SBUF; } }
Page 46
Page 47
Keil Software is used provide you with software development tools for 8051 based microcontrollers. With the Keil tools, you can generate embedded applications for virtually every 8051 derivative. The supported microcontrollers are listed in the -viSION
LANGUAGE
- EMBEDDED_C
CONTROLLER - P89V51RD2
Page 48
Talktime is generally higher in GSM phones due to the pulse nature of transmission. The much bigger number of subscribers globally creates a better network effect foGSM .
Page 49
GSM has a fixed maximum cell site range of 35 km, which is imposed by technical limitations.
Page 50
CHAPTER 10 CONCLUSION
GSM technology capable solution has provide home security and is cost-effective as compared to the previously existing systems. Hence we can conclude that the required goals and objectives of HACS have been achieved. The basic level of home appliance control and remote monitoring has been implemented. The system is extensible and more levels can be further developed using automatic motion/glass breaking detectors so the solution can be integrated with these and other detection systems. In case of remote monitoring other appliances can also be monitored such that if the level of tem-perature rises above certain level then it should generate SMS or sensors can also be applied that can detect gas, smoke or fire in case of emergency the system will automatically generate SMS.
Page 51
BIBLIOGRAPHY
1. U s e r M a n u a l P89V51RD2
Page 52