CHAPTER-1

INTRODUCTION

1.1

INTRODUCTION

LPG gas is supplied in pressurized steel cylinders. As this gas is heavier than air, when it leaks from a cylinder it flows along floor and tends to settle in low spots such as a basement. This can cause fire or suffocation if not dealt with.Here is a circuit that detects leakage of LPG and alerts the user through visual indication on lcd and sms on cell phone.This circuit can detect leakages in your home, car, service station, storage tank environment. This unit can be easily implemented to industrial level by upgrading its ranges. We have made it for domestic purposes. The output of the sensor goes high as soon as the LPG sensor senses any gas leakage from the cylinder. This is fed as input to the microcontroller and is displayed on LCD. After the delay of few milliseconds, knob of cylinder is also turned off it continues sending message as ‗GAS LEAKAGE‘ to a mobile number which is pre-defined. This project is microcontroller based project. A Gas sensor is used to Detect dangerous gas leaks in the kitchen or near the gas heater. This unit detects 300 to 5000ppm of Natural Gas. Ideal to detect dangerous gas leaks in the kitchen. Sensor can be easily configured as an alarm unit. The sensor can also sense LPG and Coal Gas. Ideal sensor for use to detect the presence of a dangerous LPG leak in your car or in a service station, storage tank environment. This unit can be easily incorporated into an alarm unit, to sound an alarm or give a visual indication of the LPG concentration. The sensor has excellent sensitivity combined with a quick response time.detected is messaged to the authorized person using cellular network called GSM.

[1]

In this project there are mainly two units, GSM modem

and microcontroller

unit.GSM modem can be configured by standard GSM AT command set for sending and receiving SMS and getting modem status. Depending upon the Gas sensor output microcontroller can send message to the authorized person and also depending upon the message received the microcontroller unit will control the devices and acknowledges the device status to the user as SMS.

1.2. SOFTWARE & HARDWARE REQUIREMENTS
a) SOFTWARE REQUIREMENTS
 Keil software programming using assembly language  Flash magic

[2]

b) HARDWARE REQUIREMENTS
 LPG sensor:MQ-6  Microcontroller: Atmega32  LCD display screen  GSM  D.C. Motor

[3]

CHAPTER-2
GAS SENSOR
2.1. GAS SENSOR:
The LPG Gas Sensor, MQ-6, is an ideal sensor to detect the presence of a dangerous Liquefied petroleum gas (LPG) and it has high sensitivity to propane, butane, isobutene, natural gas. The sensor can also be used to detect combustible gases, especially methane. It is an electronic device which detects dangerous gas leaks in the kitchen or near the gas heater. This unit detects 200 to 10000ppm of LPG. Sensor can be easily configured as an alarm unit. The MQ-6 gas sensor is made up of SnO2 which has lower conductivity in clean air. A simple electro-circuit is used here which is used to convert the changing conductivity into corresponding output signal of gas concentration. Sensor‘s conductivity increases with increasing concentration of LPG. The sensor has excellent sensitivity combined with a quick response time.

FEATURES:
    High sensitivity to LPG, iso-butane, propane Small sensitivity to alcohol, smoke. Fast response Stable and long life

[4]

Simple drive circuit

2.2STRUCTURE AND CONFIGURATION:

Sensor composed by micro AL2O3 ceramic tube, Tin Dioxide (SnO2) sensitive Layer , measuring electrode and heater are fixed into a crust made by plastic and stainless steel net. The heater provides necessary work conditions for work of sensitive components. The enveloped MQ-6 has 6 pin,4 of them are used to fetch signals, and other 2 are used for providing heating current.This sensor has a high sensitivity and fast response time. The sensor's output is an analog resistance. The drive circuit is very simple; all you need to do is power the heater coil with 5V, add a load resistance, and connect the output to an ADC.

[5]

[6]

CHAPTER-3
MICROCONTROLLER
3.1 A BRIEF HISTORY OF THE AVR FAMILY
The AVR is a modified Harvard architecture 8-bit RISC single chip microcontroller which was developed by Atmel in 1996. The AVR was one of the first microcontroller families to use on-chip flash memory for program storage, as opposed to one-time programmable ROM, EPROM, or EEPROM used by other microcontrollers at the time. Basic families AVRs are generally classified into six broad groups:

tinyAVR — the ATtiny series
o o o

0.5–8 kB program memory 6–32-pin package Limited peripheral set

megaAVR — the ATmega series
o o o

4–256 kB program memory 28–100-pin package Extended instruction set (Multiply instructions and instructions for handling larger program memories)

o 

Extensive peripheral set

XMEGA — the ATxmega series
o o o

16–384 kB program memory 44–64–100-pin package (A4, A3, A1) Extended performance features, such as DMA, "Event System", and cryptography support.

o

Extensive peripheral set with DACs

[7]

Application-specific AVR
o

MegaAVRs with special features not found on the other members of the AVR family, such as LCD controller, USB controller, advanced PWM, CAN etc.

FPSLIC (AVR with FPGA)
o o o

FPGA 5K to 40K gates SRAM for the AVR program code, unlike all other AVRs AVR core can run at up to 50 MHz

32-bit AVRs

In 2006 Atmel released microcontrollers based on the new, 32-bit, AVR32 architecture. They include SIMD and DSP instructions, along with other audio and video processing features. This 32-bit family of devices is intended to compete with the ARM based processors. The instruction set is similar to other RISC cores, but is not compatible with the original AVR or any of the various ARM cores.

3.2 ATMEGA32

The high-performance, low-power Atmel 8-bit AVR RISC-based microcontroller combines 32KB of programmable flash memory, 2KB SRAM, 1KB EEPROM, an 8-channel 10-bit A/D converter, and a JTAG interface for on-chip debugging. The device supports throughput [8]

of 16 MIPS at 16 MHz and operates between 4.5-5.5 volts.By executing instructions in a single clock cycle, the device achieves throughputs approaching 1 MIPS per MHz, balancing power consumption and processing speed.

Features
              

32K BYTES of In-System Programmable Flash 1K BYTES of In-System Programmable EEPROM 2K Bytes SRAM Analog Comparator Watchdog SPI 2 8-bit Timers plus prescaler 2 16-bit Timers with prescaler, capture etc. 4 PWM channels UART 8 channel 10-bit ADC SPI 2 wire serial interface Real Time Counter with separate oscillator Low power and Idle modes, External and External interrupts, selectable on-chip Oscillator

[9]

PIN DESCRIPTION:
VCC:
It is the supply voltage pin and is connected to +5 volts.

GND:
It is ground and connected to ground.

[10]

PORTA (A0-A7):
Port A is an 8-bit open-drain bi-directional I/O port. When 1 is written to all pins of port A it acts as an output port while if 0 is written to pins it acts as an input port. Port A can also be configured to be used as an analog to digital converter (ADC). The ADC is connected to an 8-channel analog multiplexer which allows 8 single-ended voltage inputs constructed from the pins of Port A.

PORTB (B0-B7):
Port B is also an 8-bit open-drain bi-directional I/O port. When 1 is written to all pins of port B it acts as an output port while if 0 is written to pins it acts as an input port. Port Pin PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0 Alternate Functions SCK (SPI Bus Serial Clock) MISO (SPI Bus Master Input/Slave Output) MOSI (SPI Bus Master Output/Slave Input) SS (SPI Slave Select Input) AIN1 (Analog Comparator Negative Input) OC0 (Timer/Counter0 Output Compare Match Output) AIN0 (Analog Comparator Positive Input) INT2 (External Interrupt 2 Input) T1 (Timer/Counter1 External Counter Input) T0 (Timer/Counter0 External Counter Input) XCK (USART External Clock Input/Output)

• SCK – Port B, Bit 7 SCK: Master Clock output, Slave Clock input pin for SPI. When the SPI is enabled as a Slave,this pin is configured as an input regardless of the setting of DDB7. When the SPI is enabled asa Master, the data direction of this pin is controlled by DDB7. When the pin is forced by the SPIto be an input, the pull-up can still be controlled by the PORTB7 bit.

[11]

• MISO – Port B, Bit 6 MISO: Master Data input, Slave Data output pin for SPI. When the SPI is enabled as a Master, this pin is configured as an input regardless of the setting of DDB6. When the SPI is enabled as a Slave, the data direction of this pin is controlled by DDB6. When the pin is forced by the SPI to be an input, the pull-up can still be controlled by the PORTB6 bit. • MOSI – Port B, Bit 5 MOSI: SPI Master Data output, Slave Data input for SPI. When the SPI is enabled as a Slave,this pin is configured as an input regardless of the setting of DDB5. When the SPI is enabled asa Master, the data direction of this pin is controlled by DDB5. When the pin is forced by the SPIto be an input, the pull-up can still be controlled by the PORTB5 bit. •SS – Port B, Bit 4 SS: Slave Select input. When the SPI is enabled as a Slave, this pin is configured as an input regardless of the setting of DDB4. As a Slave, the SPI is activated when this pin is driven low. When the SPI is enabled as a Master, the data direction of this pin is controlled by DDB4. When the pin is forced by the SPI to be an input, the pull-up can still be controlled by the PORTB4 bit. • AIN1/OC0 – Port B, Bit 3 AIN1: Analog Comparator Negative Input. Configure the port pin as input with the internal pull-upswitched off to avoid the digital port function from interfering with the function of the analogcomparator.OC0, Output Compare Match output: The PB3 pin can serve as an external output for theTimer/Counter0 Compare Match. The PB3 pin has to be configured as an output (DDB3 set(one)) to serve this function. The OC0 pin is also the output pin for the PWM mode timerfunction. • AIN0/INT2 – Port B, Bit 2 AIN0: Analog Comparator Positive input. Configure the port pin as input with the internal pull-upswitched off to avoid the digital port function from interfering with the function of the

[12]

AnalogComparator.INT2, External Interrupt Source 2: The PB2 pin can serve as an external interrupt source to theMCU. • T1 – Port B, Bit 1 T1, Timer/Counter1 Counter Source. • T0/XCK – Port B, Bit 0 T0, Timer/Counter0 Counter Source. XCK, USART External Clock. The Data Direction Register (DDB0) controls whether the clock isoutput (DDB0 set) or input (DDB0 cleared). The XCK pin is active only when the USART operatesin Synchronousmode. SPI MSTR INPUT and SPI SLAVE OUTPUT constitute the MISO signal,while MOSI is divided into SPI MSTR OUTPUT and SPI SLAVE INPUT.

PORTC (C0-C7):
Port C is an 8-bit open-drain bi-directional I/O port. When 1 is written to all pins of port C it acts as an output port while if 0 is written to pins it acts as an input port. If the JTAG interface is enabled, the pull-up resistors on pins PC5(TDI), PC3(TMS) and PC2(TCK) will be activated even if a reset occurs. Port C Pins Alternate Functions Port Pin PC7 PC6 PC5 PC4 PC3 PC2 PC1 PC0 Alternate Function TOSC2 (Timer Oscillator Pin 2) TOSC1 (Timer Oscillator Pin 1) TDI (JTAG Test Data In) TDO (JTAG Test Data Out) TMS (JTAG Test Mode Select) TCK (JTAG Test Clock) SDA (Two-wire Serial Bus Data Input/output Line) SCL (Two-wire Serial Bus Clock Line)

[13]

The alternate pin configuration is as follows: • TOSC2 – Port C, Bit 7 TOSC2, Timer Oscillator pin 2: When the AS2 bit in ASSR is set (one) to enable asynchronous clocking of Timer/Counter2, pin PC7 is disconnected from the port, and becomes the inverting output of the Oscillator amplifier. In this mode, a Crystal Oscillator is connected to this pin, and the pin cannot be used as an I/O pin. • TOSC1 – Port C, Bit 6 TOSC1, Timer Oscillator pin 1: When the AS2 bit in ASSR is set (one) to enable asynchronous clocking of Timer/Counter2, pin PC6 is disconnected from the port, and becomes the input of the inverting Oscillator amplifier. In this mode, a Crystal Oscillator is connected to this pin, and the pin cannot be used as an I/O pin.

• TDI – Port C, Bit 5 TDI, JTAG Test Data In: Serial input data to be shifted in to the Instruction Register or Data Register (scan chains). When the JTAG interface is enabled, this pin cannot be used as an I/O pin. • TDO – Port C, Bit 4 TDO, JTAG Test Data Out: Serial output data from Instruction Register or Data Register. When the JTAG interface is enabled, this pin cannot be used as an I/O pin. The TD0 pin is tri-stated unless TAP states that shifts out data are entered. • TMS – Port C, Bit 3 TMS, JTAG Test Mode Select: This pin is used for navigating through the TAP-controller state machine. When the JTAG interface is enabled, this pin cannot be used as an I/O pin. • TCK – Port C, Bit 2

[14]

TCK, JTAG Test Clock: JTAG operation is synchronous to TCK. When the JTAG interface is enabled, this pin cannot be used as an I/O pin. • SDA – Port C, Bit 1 SDA, Two-wire Serial Interface Data: When the TWEN bit in TWCR is set (one) to enable the two-wire Serial Interface, pin PC1 is disconnected from the port and becomes the Serial Data I/O pin for the Two-wire Serial Interface. In this mode, there is a spike filter on the pin to suppress spikes shorter than 50 ns on the input signal, and the pin is driven by an open drain driver with slew-rate limitation. When this pin is used by the two-wire serial interface, The pull-up can still be controlled by the PORTC1 bit. • SCL – Port C, Bit 0 SCL, Two-wire Serial Interface Clock: When the TWEN bit in TWCR is set (one) to enable the two-wire Serial Interface, pin PC0 is disconnected from the port and becomes the Serial clock I/O pin for the two-wire serial interface. In this mode, there is a spike filter on the pin to suppress spikes shorter than 50 ns on the input signal, and the pin is driven by an open drain driver with slew-rate limitation. When this pin is used by the two-wire serial interface, the pull-up can still be controlled by the PORT C0 bit.

PORT D (D0-D7):
Port D is an 8-bit open-drain bi-directional I/O port. When 1 is written to all pins of port C it acts as an output port while if 0 is written to pins it acts as an input port.

Port D Pins Alternate Functions Port Pin PD7 PD6 PD5 PD4 PD3 Alternate Function OC2 (Timer/Counter2 Output Compare Match Output) ICP1 (Timer/Counter1 Input Capture Pin) OC1A (Timer/Counter1 Output Compare A Match Output) OC1B (Timer/Counter1 Output Compare B Match Output) INT1 (External Interrupt 1 Input)

[15]

PD2 PD1 PD0

INT0 (External Interrupt 0 Input) TXD (USART Output Pin) RXD (USART Input Pin)

The alternate pin configuration is as follows:

• OC2 – Port D, Bit 7
OC2, Timer/Counter2 Output Compare Match output: The PD7 pin can serve as an external output for the Timer/Counter2 Output Compare. The pin has to be configured as an output (DDD7 set (one)) to serve this function. The OC2 pin is also the output pin for the PWM mode timer function.

• ICP1 – Port D, Bit 6
ICP1 – Input Capture Pin: The PD6 pin can act as an Input Capture pin for Timer/Counter1.

• OC1A – Port D, Bit 5
OC1A, Output Compare Match A output: The PD5 pin can serve as an external output for the Timer/Counter1 Output Compare A. The pin has to be configured as an output (DDD5 set (one)) to serve this function. The OC1A pin is also the output pin for the PWM mode timer function.

• OC1B – Port D, Bit 4
OC1B, Output Compare Match B output: The PD4 pin can serve as an external output for the Timer/Counter1 Output Compare B. The pin has to be configured as an output (DDD4 set (one)) to serve this function. The OC1B pin is also the output pin for the PWM mode timer function.

• INT1 – Port D, Bit 3
INT1, External Interrupt Source 1: The PD3 pin can serve as an external interrupt source.

• INT0 – Port D, Bit 2
[16]

INT0, External Interrupt Source 0: The PD2 pin can serve as an external interrupt source.

•TXD – Port D, Bit 1
TXD, Transmit Data (Data output pin for the USART). When the USART Transmitter is enabled, this pin is configured as an output regardless of the value of DDD1.

RESET:
Reset input. A low on this pin for two machine cycles while the oscillator is running resets the device.

AVCC:
It is the input pin for analog voltage.

XTAL1:
Input to the inverting oscillator amplifier and input to the internal clock operating circuit.

XTAL2:
Output from the inverting oscillator.

AREF:
It is used to give external reference voltage.

Oscillator Characteristics:
XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier which can be configured for use as an on-chip oscillator. Either a quartz crystal or ceramic resonator may be used. To drive the device from an external clock source, XTAL2 and XTAL1should be connected to a crystal oscillator.

[17]

There are no requirements on the duty cycle of the external clock signal, since the input to the internal clocking circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage high and low time specifications must be observed.

FIG 3.2.1 OSCILLATOR CONNECTIONS
Note C1 = 30 pF ± 10 pF for Crystals C2 = 40 pF ± 10 pF for Ceramic Resonators

[18]

CHAPTER-4
LCD INTERFACING

4.1.1 LCD INTERFACING

[19]

Most alphanumeric LCD displays have HD44780 compatible driver chipsets that follow the original Hitachi commands to control the LCD. The most common connectors for alphanumeric LCD‘s are either 14-pin single row or 2X7 pins dual row connectors.

PIN DIAGRAM:

4.1.2 PIN DAIGRAM OF LCD
[20]

PIN DESCRIPTION:
1. GND (Ground) 2. Vcc(Supply Voltage) 3. Vee(Contrast Voltage) 4. R/S (Instruction/Register Select) 5. R/W (Read/Write) 6. E (Clock) 7. D0 (Data0) 8. D1 (Data1) 9. D2 (Data2) 10. D3 (Data3) 11. D4 (Data4) 12. D5 (Data5) 13. D6 (Data6) 14. D7 (Data7)

A typical LCD write operation takes place as shown in the following timing waveform:

FIG 4.1.3 LCD DATA WRITE WAVEFORM
[21]

The interface is either a 4-bit or 8-bit parallel bus that allows fast reading/writing of data to and from the LCD. This waveform will write an ASCII Byte out to the LCD's screen. The ASCII code to be displayed is eight bits long and is sent to the LCD either four or eight bits at a time. If 4-bit mode is used, two nibbles of data (First high four bits and then low

four bits with an E Clock pulse with each nibble) are sent to complete a full eight-bit transfer. The E Clock is used to initiate the data transfer within the LCD.

8-bit mode is best used when speed is required in an application and at least ten I/O pins are available. 4-bit mode requires a minimum of six bits. In 4-bit mode, only the top 4 data bits (DB4-7) are used. The R/S pin is used to select whether data or an instruction is being transferred between the microcontroller and the LCD. If the pin is high, then the byte at the current LCD Cursor Position can be read or written. If the pin is low, either an instruction is being sent to the LCD or the execution status of the last instruction is read back (whether or not it has completed)

TABLE 4.1.4 VARIOUS FUNCTIONS POSSIBLE WITH DIFFERENT MODES

The bit descriptions for the different commands are [22]

"*" - Not Used/Ignored. This bit can be either "1" or "0" Set Cursor Move Direction ID - Increment the Cursor after Each Byte Written to Display if Set S - Shift Display when Byte Written to Display Enable Display/Cursor D - Turn Display On(1)/Off(0) C - Turn Cursor On(1)/Off(0) B - Cursor Blink On(1)/Off(0) Page 3 Move Cursor/Shift Display SC - Display Shift On(1)/Off(0) RL - Direction of Shift Right(1)/Left(0) Set Interface Length DL - Set Data Interface Length 8(1)/4(0) N - Number of Display Lines 1(0)/2(1)

F - Character Font 5x10(1)/5x7(0) Poll the "Busy Flag" BF - This bit is set while the LCD is processing Move Cursor to CGRAM/Display A - Address Read/Write ASCII to the Display D - Data Reading Data back is best used in applications which required data to be moved back and forth on the LCD (such as in applications which scroll data between lines). The "Busy Flag" can be polled to determine when the last instruction that has been sent has completed processing. For most applications, there really is no reason to read from the LCD. The application can write to the LCD and wait the maximum amount of time for each instruction (4.1 milliseconds for clearing the display or moving the cursor/display to the "home position", 160 microseconds for all other commands). Different LCD‘s execute instructions at [23]

differentrates and to avoid problems later on (such as if the LCD is changed to a slower unit), the recommended maximum delays can be used. Before you can send commands or data to the LCD, the LCD must be initialized. For 8-bit mode, this is done as follows          

Wait more than 15 msecs after power is applied. Write 0x030 to LCD and wait 5 msecs for the instruction to complete Write 0x030 to LCD and wait 160 usecs for instruction to complete Write 0x030 AGAIN to LCD and wait 160 usecs or Poll the Busy Flag Set the Operating Characteristics of the LCD Write "Set Interface Length" Write 0x010 to turn off the Display Write 0x001 to Clear the Display Write "Set Cursor Move Direction" Setting Cursor Behavior Bits

Write "Enable Display/Cursor" & enable Display and Optional Cursor

In 4-bit mode, the high nibble is sent before the low nibble and the E pin is toggled each time four bits is sent to the LCD. To initialize in 4-bit mode      

Wait more than 15 msecs after power is applied. Write 0x03 to LCD and wait 5 msecs for the instruction to complete Write 0x03 to LCD and wait 160 usecs for instruction to complete Write 0x03 AGAIN to LCD and wait 160 usecs (or poll the Busy Flag) Set the Operating Characteristics of the LCD Write 0x02 to the LCD to Enable 4-Bit Mode

[24]

CHAPTER-5
SERIAL COMMUNICATION

DB-9(RS-232):
RS-232 is simple, universal, well understood and supported but it has some serious shortcomings as a data interface. The standards to 256kbps or less and line lengths of 15M (50 ft) or less but today we see high speed ports on our home PC running very high speeds and with high quality cable maxim distance has increased greatly. The rule of thumb for the length a data cable depends on speed of the data, quality of the cable. Electronic data communications between elements will generally fall into two broad categories single-ended and differential. RS232 (single-ended) was introduced in 1962, and despite rumors for its early demise, has remained widely used through the industry. Independent channels are established for two-way (full-duplex) communications. The RS232 signals are represented by voltage levels with respect to a system common (power / logic ground). The "idle" state (MARK) has the signal level negative with respect to common, and the "active" state (SPACE) has the signal level positive with respect to common. RS232 has numerous handshaking lines (primarily used with modems), and also specifies a communications protocol. The RS-232 interface presupposes a common ground between the DTE and DCE. This is a reasonable assumption when a short cable connects the DTE to the DCE, but with longer lines and connections between devices that may be on different electrical busses with different grounds, this may not be true. RS232 data is bi-polar.... +3 TO +12 volts indicates an "ON or 0-state (SPACE) condition" while A -3 to -12 volts indicates an "OFF" 1-state (MARK) condition.... Modern computer equipment ignores the negative level and accepts a zero voltage level as the "OFF" state. In fact, the "ON" state may be achieved with lesser positive potential. This means [25]

circuits powered by 5 VDC are capable of driving RS232 circuits directly, however, the overall range that the RS232 signal may be transmitted/received may be dramatically reduced. The output signal level usually swings between +12V and -12V. The "dead area" between +3v and -3v is designed to absorb line noise. In the various RS-232-like definitions this dead area may vary. For instance, the definition for V.10 has a dead area from +0.3v to 0.3v. Many receivers designed for RS-232 are sensitive to differentials of 1v or less. This can cause problems when using pin powered widgets - line drivers, converters, modems etc. These types of units need enough voltage & current to power them self's up. Typical URART (the RS-232 I/O chip) allows up to 50ma per output pin - so if the device needs 70ma to run we would need to use at least 2 pins for power. Some devices are very efficient and only require one pin (some times the Transmit or DTR pin) to be high - in the "SPACE" state while idle. An RS-232 port can supply only limited power to another device. The number of output lines, the type of interface driver IC, and the state of the output lines are important considerations. Data is transmitted and received on pins 2 and 3 respectively. Data Set Ready (DSR) is an indication from the Data Set (i.e., the modem or DSU/CSU) that it is on. Similarly, DTR indicates to the Data Set that the DTE is on. Data Carrier Detect (DCD) indicates that a good carrier is being received from the remote modem. Pins 4 RTS (Request To Send - from the transmitting computer) and 5 CTS (Clear To Send - from the Data set) are used to control. In most Asynchronous situations, RTS and CTS are constantly on throughout the communication session. However where the DTE is connected to a multipoint line, RTS is used to turn carrier on the modem on and off. On a multipoint line, it's imperative that only one station is transmitting at a time (because they share the return phone pair). When a station wants to transmit, it raises RTS. The modem turns on carrier, typically waits a few milliseconds for carrier to stabilize, and then raises CTS. The DTE transmits when it sees

[26]

CTS up. When the station has finished its transmission, it drops RTS and the modem drops CTS and carrier together. Clock signals (pins 15, 17, & 24) are only used for synchronous communications. The modem or DSU extracts the clock from the data stream and provides a steady clock signal to the DTE. Note that the transmit and receive clock signals do not have to be the same, or even at the same baud rate. Note Transmit and receive leads (2 or 3) can be reversed depending on the use of the equipment DCE Data Communications Equipment or a.

Sub-D15 Male

Sub-D15 Female

This is a standard 9 to 25 pin cable layout for async data on a PC AT serial cable Description Carrier Detect Receive Data Transmit Data Data Terminal Ready Signal Ground Data Set Ready Request to Send Clear to Send Ring Indicator Signal CD RD TD DTR SG DSR RTS CTS RI 9-pin DTE 1 2 3 4 5 6 7 8 9 25-pin DCE 8 3 2 20 7 6 4 5 22 Source DTE or DCE from Modem from Modem from Terminal/Computer from Terminal/Computer from Modem from Modem from Terminal/Computer from Modem from Modem

TABLE 5.1.1 STANDARD 9 TO 25 PIN LAYOUT

[27]

FIG 5.1.2 EXTERNAL APPEARANCE OF PIN RS232

FIG 5.1.3 INTERNAL DESCRIPTION OF PIN RS232

[28]

RS-232 WAVEFORM:

FIG 5.1.4 TTL/CMOS SERIAL LOGIC WAVEFORM
The diagram above shows the expected waveform from the UART when using the common 8N1 format. 8N1 signifies 8 Data bits, No Parity and 1 Stop Bit. The RS-232 line, when idle is in the Mark State (Logic 1). A transmission starts with a start bit which is (Logic 0). Then each bit is sent down the line, one at a time. The LSB (Least Significant Bit) is sent first. A Stop Bit (Logic 1) is then appended to the signal to make up the transmission. The data sent using this method, is said to be framed. That is the data is framed between a Start and Stop Bit.

RS-232 Voltage levels    +3 to +25 volts to signify a "Space" (Logic 0) -3 to -25 volts for a "Mark" (logic 1). Any voltage in between these regions (i.e. between +3 and -3 Volts) is undefined. The data byte is always transmitted least-significant-bit first. The bits are transmitted at specific time intervals determined by the baud rate of the serial signal. This is the signal present on the RS-232 Port of your computer, shown below.

FIG 5.1.5 RS-232 LOGIC WAVEFORM
[29]

RS-232 LEVEL CONVERTER
Standard serial interfacing of microcontroller (TTL) with PC or any RS232C Standard device , requires TTL to RS232 Level converter . A MAX232 is used for this purpose. It provides 2-channel RS232C port and requires external 10uF capacitors.The driver requires a single supply of +5V.

FIG 5.1.6 MAX-232 INCLUDES A CHARGE PUMP, WHICH GENERATES +10V AND -10V FROM A SINGLE 5V SUPPLY.

5.2 MAX 232:
     Two Drivers and Two Receivers -V Input Levels Low Supply Current . . . 8 mA Typical [30] Operates With Single 5-V Power Supply

  

Meets or Exceeds TIA/EIA-232-F and ITU Recommendation V.28 Designed to be Interchangeable With

APPLICATIONS:
         TIA/EIA-232-F Battery-Powered Systems Modems Computers ESD Protection Exceeds 2000 V Per MIL-STD-883, Method 3015 Package Options Include Plastic Small-Outline (D, DW) Packages and Standard Plastic (N) DIPs

Absolute maximum ratings
   Input supply voltage range, VCC – 0.3 V to 6 V Positive output supply voltage rangeVS+ VCC – 0.3 V to 15 V Negative output supply voltage range VS––0.3 V to –15 V [31]

         

Input voltage range, VI Driver–0.3 V to VCC + 0.3 V Receiver 30 V Output voltage range, VO T1OUT, T2OUT VS –0.3 V to VS+ + 0.3 V R1OUT, R2OUT –0.3 V to VCC + 0.3 V Short-circuit duration T1OUT, T2OUT Unlimited Package thermal impedance, D package 113C/W DW package 105C/W N package 78C/W Storage temperature range, Tstg –65C to 150C

Stresses beyond those listed under ―absolute maximum ratings‖ may cause permanent damage to the device. These are stress ratings only, and functional operation of the device at these or any other conditions beyond those indicated under ―recommended operating conditions‖ is not implied. Exposure to absolute-maximum-rated conditions for extended periods may affect device reliability. NOTE 1: All voltage values are with respect to network ground terminal.2. The package thermal impedance is calculated in accordance with JESD 51, except for through-hole packages, which use a trace length of zero description.

[32]

FIG 5.2.1 MAX 232 INTERFACING RS232 AND ATMEG32 MICROCONTROLLER The MAX232 device is a dual driver/receiver that includes a capacitive voltage generator to supply EIA-232 voltage levels from a single 5-V supply. Each receiver converts EIA-232 inputs to 5-V TTL/CMOS levels. These receivers have a typical threshold of 1.3 V and a -V inputs. Each driver converts TTL/CMOS input levels into EIA-232 levels. The driver, receiver, and voltage-generator functions are available as cells in the Texas

[33]

CHAPTER-6 GLOBAL SYSTEM FOR MOBILE COMMUNICATIONS
5.1 INTRODUCTION:
The Global System for Mobile Communications (GSM: originally from Groupe Special Mobile) is the most popular standard for mobile phones in the world. GSM service is used by over 2 billion people across more than 212 countries and territories. The ubiquity of the GSM standard makes international roaming very common between mobile phone operators, enabling subscribers to use their phones in many parts of the world. GSM differs significantly from its predecessors in that both signaling and speech channels are Digital call quality, which means that it is considered a second generation (2G) mobile phone system. This fact has also meant that data communication was built into the system from the 3rd GenerationPartnership Project (3GPP). From the point of view of the consumers, the key advantage of GSM systems has been higher digital voice quality and low cost alternatives to making calls such as text messaging. The advantage for network operators has been the ability to deploy equipment from different vendors because the open standard allows easy inter-operability. Like other cellular standards GSM allows network operators to offer roaming services which mean subscribers can use their phones all over the world. As the GSM standard continued to develop, it retained backward compatibility with the original GSM phones; for example, packet data capabilities were added in the Release '97 version of the standard, by means of GPRS. Higher speed data transmission has also been introduced with EDGE in the Release '99 version of the standard.

5.2 HISTORICAL BACKGROUND OF GSM:
The growth of cellular telephone systems took off in the early 1980s, particularly in Europe. The lack of a technological standardization prompted the European Conference of Postal and Telecommunications Administrations (CEPT) to create the Groupe Special

[34]

Mobile (GSM) in 1982 with the objective of developing a standard for a mobile telephone system that could be used across Europe. The first GSM network was launched in 1991 by Radiolinja in Finland. In 1989, GSM responsibility was transferred to the European Telecommunications Standards Institute (ETSI), and phase I of the GSM specifications were published in 1990. By the end of 1993, over a million subscribers were using GSM phone networks being operated by 70 carriers across 48 countries.

5.3 ARCHITECTURE:

3.3.1 General Architecture of a GSM network 5.4 NETWORK STRUCTURE
The network behind the GSM system seen by the customer is large and complicated in order to provide all of the services which are required. It is divided into a number of sections and these are each covered in separate articles. [35]

   

The Base Station Subsystem (the base stations and their controllers). The Network and Switching Subsystem (the part of the network most similar to a fixed network). This is sometimes also just called the core network. The GPRS Core Network (the optional part which allows packet based Internet connections). All of the elements in the system combine to produce many GSM services such as voice calls and SMS.

5.4.1 The Structure of a GSM network

SUBSCRIBER IDENTITY MODULE:
One of the key features of GSM is the Subscriber Identity Module (SIM), commonly known as a SIM card. The SIM is a detachable smart card containing the user's subscription information and phonebook. This allows the user to retain his or her information after switching handsets. Alternatively, the user can also change operators while retaining the handset simply by changing the SIM. Some operators will block this by allowing the phone

[36]

to use only a single SIM, or only a SIM issued by them; this practice is known as SIM locking, and is illegal in some countries. In the United States, Canada, Europe and Australia, many operators lock the mobiles they sell. This is done because the price of the mobile phone is typically subsidized with revenue from subscriptions and operators want to try to avoid subsidizing competitor's mobiles. A subscriber can usually contact the provider to remove the lock for a fee, utilize private services to remove the lock, or make use of ample software and websites available on the Internet to unlock the handset themselves. While most web sites offer the unlocking for a fee, some do it for free. The locking applies to the handset, identified by its International Mobile Equipment Identity (IMEI) number, not to the account (which is identified by the SIM card). It is always possible to switch to another (non-locked) handset if such other handset is available. Some providers will unlock the phone for free if the customer has held an account for a certain period. Third party unlocking services exist that are often quicker and lower cost than that of the operator. In most countries removing the lock is legal. Cingular and T-Mobile provide free unlock services to their customers after 3 months of subscription. In countries like India, Pakistan, Indonesia, Belgium, etc., all phones are sold unlocked. However, in Belgium, it is unlawful for operators there to offer any form of subsidy on the phone's price. This was also the case in Finland until April 1, 2006, when selling subsidized combinations of handsets and accounts became legal though operators have to unlock phone free of charge after a certain period (at most 24 months).

GSM SECURITY
GSM was designed with a moderate level of security. The system was designed to authenticate the subscriber using shared-secretcryptography. Communications between the subscriber and the base station can be encrypted. The development of UMTS introduces an optional USIM, that uses a longer authentication key to give greater security, as well as mutually authenticating the network and the user - whereas GSM only authenticated the user

[37]

to the network (and not vice versa). The security model therefore offers confidentiality and authentication, but limited authorization capabilities, and no non-repudiation. GSM uses several cryptographic algorithms for security. The A5/1 and A5/2stream ciphers are used for ensuring over-the-air voice privacy. A5/1 was developed first and is a stronger algorithm used within Europe and the United States; A5/2 is weaker and used in other countries. A large security advantage of GSM over earlier systems is that the Key, the crypto variable stored on the SIM card that is the key to any GSM ciphering algorithm, is never sent over the air interface. Serious weaknesses have been found in both algorithms, and it is possible to break A5/2 in real-time in a cipher text-only attack. The system supports multiple algorithms so operators may replace that cipher with a stronger one.

GSM SERVICES
GSM services are a standard collection of applications and features available to mobile phone subscribers all over the world. The GSM standards are defined by the 3GPP collaboration and implemented in hardware and software by equipment manufacturers and mobile phone operators. The common standard makes it possible to use the same phones with different companies' services, or even roam into different countries. GSM is the world's most dominant mobile phone standard. The design of the service is moderately complex because it must be able to locate a moving phone anywhere in the world, and accommodate the relatively short battery life, limited input/output capabilities, and weak radio transmitters on mobile devices.

ACCESSING A GSM NETWORK:
In order to gain access to GSM services, a user needs three things:  A subscription with a mobile phone operator. This is usually either a Pay As YouGo arrangement, where all GSM services are paid for in advance, or a Pay Monthly option where a bill is issued each month for line rental, normally paid for a month in advance, and for services used in the previous month.

[38]

 

A mobile phone which is GSM compliant and operates at the same frequency as the operator. Most phone companies sell phones from third-party manufacturers. A SIM card which is issued by the operator once the subscription is granted. The card comes pre-programmed with the subscriber's phone "identity" and will be used to store personal information (like contact numbers of friends and family).

After subscribers sign up, information about their phone's identity and what services they are allowed to access are stored in a "SIM record" in the Home Location Register (HLR). The Home Location Register is a database maintained by the "home" phone company for all of its subscribers. It is used to answer queries like, "Where on the mobile phone network is the device associated with this phone number?" and "What services is this subscriber paying for?" Once the SIM card is loaded into the phone and it is powered on, it will search for the nearest mobile phone mast, also called a Base Transceiver Station or BTS. If a mast can be successfully contacted, then there is said to be coverage in the area. Stationary phones are always connected to the same part of the phone network, but mobile phones can "visit" any part of the network, whether across town or in another country via a foreign provider. Each geographic area has a database called the Visitors Location Register (VLR) which contains details of all the local mobiles. Whenever a phone attaches, or visits, a new area, the Visitors Location Register must contact the Home Location Register. The Visitors LR will tell the Home LR where the phone is connected to the network (which VLR), and will ask it for a copy of the SIM record (which includes, for example, what services the phone is allowed to access). The current cellular location of the phone (i.e. which BTS it is at) is entered into the VLR record and will be used during a process called paging when the GSM network wishes to locate the mobile phone. Every SIM card contains a secret key, called the Ki, which it uses to prove its identity to the phone network (to prevent theft of services), upon first contact. The network does this by consulting the Authentication Center of the "home" phone company, which also has a copy [39]

of the secret key. (Though the authentication is accomplished without transmitting the key directly.) Every phone contains a unique identifier (different from the phone number, which is associated at the HLR with the removable SIM card), called the International Mobile Equipment Identity (IMEI). When a phone contacts the network, its IMEI is supposed to be checked against the global Equipment Identity Register to locate stolen phones and facilitate monitoring.

5.5 AT COMMANDS:
1. +CMGD - Delete SMS Message
Exec Command: +CMGD=<index> Execution command deletes message from preferred message storage <mem1> (<mem1> is the selected message storage from the +CPMS command) location <index>. If deleting fails, final result code +CMS

[40]

ERROR: <cms_err> is returned. An example of an error report is: +CMS ERROR: <cms_err> Where <cms_err> can be one of the numbers below:     1 unassigned number 8 operator barred 10 call barred 21 SM transfer rejected

2. +CMGF - SMS Message Format
Set Command: +CMGF= [<mode>] Set command tells the phone, which input and output format of messages to use. <Mode> indicates the format of messages used with send, list, read and write commands and unsolicited result codes resulting from received messages. Mode can be either PDU mode (entire TP data units used) or text mode (headers and body of the messages given as separate parameters). Only PDU mode is supported at this time. Valid values for <mode> are:    0 PDU mode (default) Read Command: +CMGF? Read command returns the current <mode> set. Response is in the form:

+CMGF: <mode> Test Command: +CMGF=? Test command returns the list of supported <mode>s. Response is in the form: +CMGF: (list of supported <mode>s)

[41]

3. +CMGR - Read SMS Message
Exec Command: +CMGR=<index> Execution command returns the SMS message with location value <index> from message storage <mem1> (<mem1> is the selected message storage from the +CPMS command). If status of the message is ‘received unread‘, status in the storage changes to ‘received read‘. If reading fails, final result code +CMS ERROR: <cms_err> is returned. Response is in the following format for PDU mode: +CMGR: <stat>, [<alpha>], <length><CR><LF><pdu> where: <alpha>: string type alphanumeric representation of TP-destination address or TP-originating address corresponding to the entry found in the phonebook (optional field); <length>: in PDU mode, this is the length of the actual TP data unit in octets (i.e. the RP layer SMSC address octets are not counted in the length) <pdu>: GSM 04.11 SC address followed by GSM 03.40 TPDU in hexadecimal format.

4. +CMGS - Send SMS Message
Exec Command: +CMGS=<length><CR><pdu><ctrl-Z/ESC> (PDU mode) Execution command sends message from a DTE to the network (SMS-SUBMIT). In PDU mode, <length> is the length of the actual TP data unit in octets; <pdu> is the GSM 04.11 SC address followed by GSM 03.40 TPDU in hexadecimal format. PDU entry must be terminated by <ctrl-Z>. Sending can be cancelled by the <ESC> character. Response is in the following format for PDU mode: +CMGS: <mr> Where <mr> is the message reference value of the message. [42]

If sending fails, final result code +CMS ERROR: <cms_err> is returned.

TO SEND A MESSAGE IN TEXT MODE:
To send an SMS message in text mode use the AT+CMGS command. The format of this command is:AT+CMGS=‖<destination number>‖ [, <type of destination] <CR> The GSM engine will then respond with a > prompt, next enter the message to send followed by Control-Z. The Engine will then respond with a reference number or and error.

Example:
At+cmgs="+61418400200" >test^Z +CMGS: 188 OK

Note:
The Conexant engine does not correctly support the <type of destination> field, the <destination number> field must be an international ISDN number as in the example above and the <type of destination> file must be left blank.

TO RECEIVE MESSAGES IN TEXT MODE:
The most straightforward way to read incoming SMS messages is to use the AT+CMGL command. This command will list any received SMS messages.

Example:
[43]

AT+CMGL +CMGL: 1,"REC UNREAD","+61418400200","02/08/23, 11:35:05-40" test +CMGL: 2,"REC UNREAD","+61418400200","02/08/23, 11:39:52-40" test OK In this case there are 2 messages displayed.

[44]

CHAPTER-5
SERIAL COMMUNICATION

DB-9(RS-232):
RS-232 is simple, universal, well understood and supported but it has some serious shortcomings as a data interface. The standards to 256kbps or less and line lengths of 15M (50 ft) or less but today we see high speed ports on our home PC running very high speeds and with high quality cable maxim distance has increased greatly. The rule of thumb for the length a data cable depends on speed of the data, quality of the cable.

[45]

Electronic data communications between elements will generally fall into two broad categories single-ended and differential. RS232 (single-ended) was introduced in 1962, and despite rumors for its early demise, has remained widely used through the industry. Independent channels are established for two-way (full-duplex) communications. The RS232 signals are represented by voltage levels with respect to a system common (power / logic ground). The "idle" state (MARK) has the signal level negative with respect to common, and the "active" state (SPACE) has the signal level positive with respect to common. RS232 has numerous handshaking lines (primarily used with modems), and also specifies a communications protocol. The RS-232 interface presupposes a common ground between the DTE and DCE. This is a reasonable assumption when a short cable connects the DTE to the DCE, but with longer lines and connections between devices that may be on different electrical busses with different grounds, this may not be true. RS232 data is bi-polar.... +3 TO +12 volts indicates an "ON or 0-state (SPACE) condition" while A -3 to -12 volts indicates an "OFF" 1-state (MARK) condition.... Modern computer equipment ignores the negative level and accepts a zero voltage level as the "OFF" state. In fact, the "ON" state may be achieved with lesser positive potential. This means circuits powered by 5 VDC are capable of driving RS232 circuits directly, however, the overall range that the RS232 signal may be transmitted/received may be dramatically reduced. The output signal level usually swings between +12V and -12V. The "dead area" between +3v and -3v is designed to absorb line noise. In the various RS-232-like definitions this dead area may vary. For instance, the definition for V.10 has a dead area from +0.3v to 0.3v. Many receivers designed for RS-232 are sensitive to differentials of 1v or less. This can cause problems when using pin powered widgets - line drivers, converters, modems etc. These types of units need enough voltage & current to power them self's up. Typical URART (the RS-232 I/O chip) allows up to 50ma per output pin - so if the device needs 70ma to run we would need to use at least 2 pins for power. Some devices are very [46]

efficient and only require one pin (some times the Transmit or DTR pin) to be high - in the "SPACE" state while idle. An RS-232 port can supply only limited power to another device. The number of output lines, the type of interface driver IC, and the state of the output lines are important considerations. Data is transmitted and received on pins 2 and 3 respectively. Data Set Ready (DSR) is an indication from the Data Set (i.e., the modem or DSU/CSU) that it is on. Similarly, DTR indicates to the Data Set that the DTE is on. Data Carrier Detect (DCD) indicates that a good carrier is being received from the remote modem. Pins 4 RTS (Request To Send - from the transmitting computer) and 5 CTS (Clear To Send - from the Data set) are used to control. In most Asynchronous situations, RTS and CTS are constantly on throughout the communication session. However where the DTE is connected to a multipoint line, RTS is used to turn carrier on the modem on and off. On a multipoint line, it's imperative that only one station is transmitting at a time (because they share the return phone pair). When a station wants to transmit, it raises RTS. The modem turns on carrier, typically waits a few milliseconds for carrier to stabilize, and then raises CTS. The DTE transmits when it sees CTS up. When the station has finished its transmission, it drops RTS and the modem drops CTS and carrier together. Clock signals (pins 15, 17, & 24) are only used for synchronous communications. The modem or DSU extracts the clock from the data stream and provides a steady clock signal to the DTE. Note that the transmit and receive clock signals do not have to be the same, or even at the same baud rate. Note Transmit and receive leads (2 or 3) can be reversed depending on the use of the equipment DCE Data Communications Equipment or a.

Sub-D15 Male

Sub-D15 Female

This is a standard 9 to 25 pin cable layout for async data on a PC AT serial cable [47]

Description Carrier Detect Receive Data Transmit Data Data Terminal Ready Signal Ground Data Set Ready Request to Send Clear to Send Ring Indicator

Signal CD RD TD DTR SG DSR RTS CTS RI

9-pin DTE 1 2 3 4 5 6 7 8 9

25-pin DCE 8 3 2 20 7 6 4 5 22

Source DTE or DCE from Modem from Modem from Terminal/Computer from Terminal/Computer from Modem from Modem from Terminal/Computer from Modem from Modem

TABLE 5.1.1 STANDARD 9 TO 25 PIN LAYOUT

FIG 5.1.2 EXTERNAL APPEARANCE OF PIN RS232

[48]

FIG 5.1.3 INTERNAL DESCRIPTION OF PIN RS232

RS-232 WAVEFORM:

FIG 5.1.4 TTL/CMOS SERIAL LOGIC WAVEFORM
The diagram above shows the expected waveform from the UART when using the common 8N1 format. 8N1 signifies 8 Data bits, No Parity and 1 Stop Bit. The RS-232 line, when idle is in the Mark State (Logic 1). A transmission starts with a start bit which is (Logic 0). Then each bit is sent down the line, one at a time. The LSB (Least Significant Bit) is sent first. A Stop Bit (Logic 1) is then appended to the signal to make up the transmission. [49]

The data sent using this method, is said to be framed. That is the data is framed between a Start and Stop Bit.

RS-232 Voltage levels    +3 to +25 volts to signify a "Space" (Logic 0) -3 to -25 volts for a "Mark" (logic 1). Any voltage in between these regions (i.e. between +3 and -3 Volts) is undefined. The data byte is always transmitted least-significant-bit first. The bits are transmitted at specific time intervals determined by the baud rate of the serial signal. This is the signal present on the RS-232 Port of your computer, shown below.

FIG 5.1.5 RS-232 LOGIC WAVEFORM

RS-232 LEVEL CONVERTER
Standard serial interfacing of microcontroller (TTL) with PC or any RS232C Standard device , requires TTL to RS232 Level converter . A MAX232 is used for this purpose. It provides 2-channel RS232C port and requires external 10uF capacitors.The driver requires a single supply of +5V.

[50]

FIG 5.1.6 MAX-232 INCLUDES A CHARGE PUMP, WHICH GENERATES +10V AND -10V FROM A SINGLE 5V SUPPLY.

5.2 MAX 232:
        Two Drivers and Two Receivers -V Input Levels Low Supply Current . . . 8 mA Typical Meets or Exceeds TIA/EIA-232-F and ITU Recommendation V.28 Designed to be Interchangeable With Operates With Single 5-V Power Supply

APPLICATIONS:
   TIA/EIA-232-F Battery-Powered Systems Modems [51]

     

Computers ESD Protection Exceeds 2000 V Per MIL-STD-883, Method 3015 Package Options Include Plastic Small-Outline (D, DW) Packages and Standard Plastic (N) DIPs

Absolute maximum ratings
           Input supply voltage range, VCC – 0.3 V to 6 V Positive output supply voltage rangeVS+ VCC – 0.3 V to 15 V Negative output supply voltage range VS––0.3 V to –15 V Input voltage range, VI Driver–0.3 V to VCC + 0.3 V Receiver 30 V Output voltage range, VO T1OUT, T2OUT VS –0.3 V to VS+ + 0.3 V R1OUT, R2OUT –0.3 V to VCC + 0.3 V Short-circuit duration T1OUT, T2OUT Unlimited Package thermal impedance, D package 113C/W DW package 105C/W N package 78C/W [52]

 

Storage temperature range, Tstg –65C to 150C

Stresses beyond those listed under ―absolute maximum ratings‖ may cause permanent damage to the device. These are stress ratings only, and functional operation of the device at these or any other conditions beyond those indicated under ―recommended operating conditions‖ is not implied. Exposure to absolute-maximum-rated conditions for extended periods may affect device reliability. NOTE 1: All voltage values are with respect to network ground terminal.2. The package thermal impedance is calculated in accordance with JESD 51, except for through-hole packages, which use a trace length of zero description.

FIG 5.2.1 MAX 232 INTERFACING RS232 AND ATMEG32 MICROCONTROLLER

[53]

The MAX232 device is a dual driver/receiver that includes a capacitive voltage generator to supply EIA-232 voltage levels from a single 5-V supply. Each receiver converts EIA-232 inputs to 5-V TTL/CMOS levels. These receivers have a typical threshold of 1.3 V -V inputs. Each driver converts TTL/CMOS input levels into EIA-232 levels. The driver, receiver, and voltage-generator functions are available as cells in the Texas.

[54]

5.

[55]

CHAPTER-5

SMOKE OR FIRE OR GAS DETECTION THROUGH GSM NETWORK

5.1 BLOCK DIAGRAM:

[56]

5.2 CIRCUIT DIAGRAM:

[57]

5.3 FLOWCHART:
[58]

[59]

CHAPTER 6

[60]

SOFTWARE DEVELOPMENT
6.1 INTRODUCTION:
In this chapter the software used and the language in which the program code is defined is mentioned and the program code dumping tools are explained. The chapter also documents the development of the program for the application. This program has been termed as ―Source code‖. Before we look at the source code we define the two header files that we have used in the code.

6.2 TOOLS USED:

FIGURE 6.2 KEIL SOFTWARE- INTERNAL STAGES

[61]

Keil development tools for the 8051 Microcontroller Architecture support every level of software developer from the professional applications

6.3 C51 COMPILER & A51 MACRO ASSEMBLER:
Source files are created by the µVision IDE and are passed to the C51 Compiler or A51 Macro Assembler. The compiler and assembler process source files and create replaceable object files. The Keil C51 Compiler is a full ANSI implementation of the C programming language that supports all standard features of the C language. In addition, numerous features for direct support of the 8051 architecture have been added.

µVISION
What's New in µVision3? µVision3 adds many new features to the Editor like Text Templates, Quick Function Navigation, and Syntax Coloring with brace high lighting Configuration Wizard for dialog based startup and debugger setup. µVision3 is fully compatible to µVision2 and can be used in parallel with µVision2.

WHAT IS µVISION3? µVision3 is an IDE (Integrated Development Environment) that helps you write, compile, and debug embedded programs. It encapsulates the following components:
    

A project manager. A make facility. Tool configuration. Editor. A powerful debugger. To help you get started, several example programs (located in the \C51\Examples, \C251\Examples, \C166\Examples, and \ARM\...\Examples) are provided.

  

HELLO is a simple program that prints the string "Hello World" using the Serial Interface. MEASURE is a data acquisition system for analog and digital systems. TRAFFIC is a traffic light controller with the RTX Tiny operating system. [62]

 

SIEVE is the SIEVE Benchmark. DHRY is the Dhrystone Benchmark.

WHETS is the Single-Precision Whetstone Benchmark. Additional example programs not listed here are provided for each device architecture.

BUILDING AN APPLICATION IN µVISION
To build (compile, assemble, and link) an application in µVision2, you must: 1. Select Project -(forexample,166\EXAMPLES\HELLO\HELLO.UV2). 2. Select Project - Rebuild all target files or Build target. µVision2 compiles, assembles, and links the files in your project.

CREATING YOUR OWN APPLICATION IN µVISION2 To create a new project in µVision2, you must: 1. Select Project - New Project. 2. Select a directory and enter the name of the project file. 3. Select Project - Select Device and select an 8051, 251, or C16x/ST10 device from the Device Database™. 4. Create source files to add to the project. 5. Select Project - Targets, Groups, Files. Add/Files, select Source Group1, and add the source files to the project. 6. Select Project - Options and set the tool options. Note when you select the target device from the Device Database™ all special options are set automatically. You typically only need to configure the memory map of your target hardware. Default memory model settings are optimal for most applications. 7. Select Project - Rebuild all target files or Build target.

[63]

DEBUGGING AN APPLICATION IN µVISION2 To debug an application created using µVision2, you must: 1. Select Debug - Start/Stop Debug Session. 2. Use the Step toolbar buttons to single-step through your program. You may enter G, main in the Output Window to execute to the main C function. 3. Open the Serial Window using the Serial #1 button on the toolbar. Debug your program using standard options like Step, Go, Break, and so on.

6.4STARTING µVISION2 AND CREATING A PROJECT
µVision2 is a standard Windows application and started by clicking on the program icon. To create a new project file select from the µVision2 menu Project – New Project…. This opens a standard Windows dialog that asks you for the new project file name.

We suggest that you use a separate folder for each project. You can simply use the icon Create New Folder in this dialog to get a new empty folder. Then select this folder and enter the file name for the new project, i.e. Project1.

µVision2 creates a new project file with the name PROJECT1.UV2 which contains a default target and file group name. You can see these names in the Project Window – Files. Now use from the menu Project – Select Device for Target and select a CPU for your project. The Select Device dialog box shows the µVision2 device database. Just select the microcontroller you use. We are using for our examples the Philips 80C51RD+ CPU. This selection sets necessary tool options for the 80C51RD+ device and simplifies in this way the tool Configuration [64]

Building Projects and Creating a HEX Files Typical, the tool settings under Options – Target are all you need to start a new application. You may translate all source files and line the application with a click on the Build Target toolbar icon. When you build an application with syntax errors, µVision2 will display errors and warning messages in the Output Window – Build page. A double click on a message line opens the source file on the correct location in a µVision2 editor window. Once you have successfully generated your application you can start debugging. After you have tested your application, it is required to create an Intel HEX file to download the software into an EPROM programmer or simulator. µVision2 creates HEX files with each build process when Create HEX files under Options for Target – Output is enabled. You may start your PROM programming utility after the make process when you specify the program under the option Run User Program #1.

CPU Simulation µVision2 simulates up to 16 Mbytes of memory from which areas can be mapped for read, write, or code execution access. The µVision2 simulator traps and reports illegal memory accesses. In addition to memory mapping, the simulator also provides support for the integrated peripherals of the various 8051 derivatives. The on-chip peripherals of the CPU you have selected are configured from the Device.

Database selection You have made when you create your project target. Refer to page 58 for more information about selecting a device. You may select and display the on-chip peripheral components using the Debug menu. You can also change the aspects of each peripheral using the controls in the dialog boxes.

Start Debugging You start the debug mode of µVision2 with the Debug – Start/Stop Debug Session command. Depending on the Options for Target – Debug Configuration, µVision2 will load [65]

the application program and run the startup code µVision2 saves the editor screen layout and restores the screen layout of the last debug session. If the program execution stops, µVision2 opens an editor window with the source text or shows CPU instructions in the disassembly window. The next executable statement is marked with a yellow arrow. During debugging, most editor features are still available. For example, you can use the find command or correct program errors. Program source text of your application is shown in the same windows. The µVision2 debug mode differs from the edit mode in the following aspects:  The ―Debug Menu and Debug Commands‖ described below are available. The additional debug windows are discussed in the following.  The project structure or tool parameters cannot be modified. All build Commands are disabled.

Disassembly Window The Disassembly window shows your target program as mixed source and assembly program or just assembly code. A trace history of previously executed instructions may be displayed with Debug – View Trace Records. To enable the trace history, set Debug – Enable/Disable Trace Recording. If you select the Disassembly Window as the active window all program step commands work on CPU instruction level rather than program source lines. You can select a text line and set or modify code breakpoints using toolbar buttons or the context menu commands. You may use the dialog Debug – Inline Assembly… to modify the CPU instructions. That allows you to correct mistakes or to make temporary changes to the target program you are debugging.

6.5 SOURCE CODE 1. Click on the Keil Vision Icon on Desktop 2.The following fig will appear

[66]

1. 2.

Click on the Project menu from the title bar Then Click on New Project

3.

Save the Project by typing suitable project name with no extension in u r own folder sited in either C:\ or D:\

[67]

4. 5. 6.

Then Click on Save button above. Select the component for u r project. i.e. Atmel…… Click on the + Symbol beside of Atmel

7.

Select AT89C51 as shown below

[68]

8. 9.

Then Click on ―OK‖ The Following fig will appear

10. 11.

Then Click either YES or NO………mostly ―NO‖ Now your project is ready to USE Now double click on the Target1, you would get another option ―Source group 1‖ as shown in next page. [69]

12.

13.

Click on the file option from menu bar and select ―new‖

14.

The next screen will be as shown in next page, and just maximize it by double clicking on its blue boarder.

[70]

15. 16.

Now start writing program in either in ―C‖ or ―ASM‖ For a program written in Assembly, then save it with extension ―. asm‖ and for ―C‖ based program save it with extension ― .C‖

17.

Now right click on Source group 1 and click on ―Add files to Group Source‖ [71]

18.

Now you will get another window, on which by default ―C‖ files will appear.

19. 20.

Now select as per your file extension given while saving the file Click only one time on option ―ADD‖

[72]

21.

Now Press function key F7 to compile. Any error will appear if so happen.

22. 23.

If the file contains no error, then press Control+F5 simultaneously. The new window is as follows

24.

Then Click ―OK‖ [73]

25.

Now Click on the Peripherals from menu bar, and check your required port as shown in fig below

26.

Drag the port a side and click in the program file.

27. 28.

Now keep Pressing function key ―F11‖ slowly and observe. You are running your program successfully

[74]

6.6 FLASH MAGIC:
FEATURES: Straightforward and intuitive user interface Five simple steps to erasing and programming a device and setting any options desired Programs Intel Hex Files Automatic verifying after programming Fills unused flash to increase firmware security Ability to automatically program checksums. Using the supplied checksum calculation routine your firmware can easily verify the integrity of a Flash block, ensuring no unauthorized or corrupted code can ever be executed Program security bits Check which Flash blocks are blank or in use with the ability to easily erase all blocks in use Read the device signature Read any section of Flash and save as an Intel Hex File Reprogram the Boot Vector and Status Byte with the help of confirmation features that prevent accidentally programming incorrect values Displays the contents of Flash in ASCII and Hexadecimal formats Single-click access to the manual, Flash Magic home page and NXP Microcontrollers home page Ability to use high-speed serial communications on devices that support it. Flash Magic calculates the highest baud rate that both the device and your PC can use and switches to that baud rate transparently Command Line interface allowing Flash Magic to be used in IDEs and Batch Files Manual in PDF format [75]

supports half-duplex communications Verify Hex Files previously programmed Save and open settings Able to reset Rx2 and 66x devices (revision G or higher) Able to control the DTR and RTS RS232 signals when connected to RST and /PSEN to place the device into Boot ROM and Execute modes automatically. An example circuit diagram is included in the Manual. This is essential for ISP with target hardware that is hard to access. This enables us to send commands to place the device in Boot ROM mode, with support for command line interfaces. The installation includes an example project for the Keil and Raisonance 8051 compilers that show how to build support for this feature into applications. Able to play any Wave file when finished programming. built in automated version checker - helps ensure you always have the latest version. Powerful, flexible Just In Time Code feature. Write your own JIT Modules to generate last minute code for programming. Uses include: o Serial number generation o Copy protection and copy authorization o Storing program date and time - manufacture date o Storing program operator and location o Lookup table generation o Language tables or language selection o Centralized record keeping  Obtaining latest firmware from the Corporate Web site or project intranet

[76]

REQUIREMENTS: Flash Magic works on any versions of Windows, except Windows 95. 10Mb of disk space is required. As mentioned earlier, we are automating two different routines in our project and hence we used the method of polling to continuously monitor those tasks and act accordingly

[77]

APPLICATIONS
 They are used in gas leakage detecting equipments in family and industry.  They are suitable for detecting of LPG, natural gas , town gas.  Avoid the noise of alcohol and cooking fumes and cigarette smoke.

ADVANTAGES
 GSM providers are almost available almost in every countries  We can control the home appliances by sending an sms to programmed home automation kit with coded instructions by the auntheticated programmer imultaneously we will get a feedback and the status of the device. Since we have an option of roaming service provided by gsm service providers hence we can get sms at any place on the earth.  We can switch on/off the devices by sending a sms from any place in the world.  It is cheaper when compared to other type of automation system.  It is more effective when compared to other type of automation system.  It is easy to change to the systems action according to change in situation.

[78]

CONCLUSION
This project is microcontroller based project. A Gas sensor is used to Detect dangerous gas leaks in the kitchen or near the gas heater. Ideal to detect dangerous gas leaks in the kitchen. Sensor can be easily configured as an alarm unit. The sensor can also sense LPG and Coal Gas as well as Ideal sensor for use to detect the presence of a dangerous LPG leak in your car or in a service station, storage tank environment. This unit can be easily incorporated into an alarm unit, to sound an alarm or give a visual indication of the LPG concentration. The sensor has excellent sensitivity combined with a quick response time.When GAS leakage is detected and is messaged to the authorized person using cellular network called GSM. . .

[79]

BIBILOGRAPHY

BOOKS:
1) 8051 Microcontroller and Embedded Systems -MAZIDI AND MAZIDI.

INTERNET:
1) www.beyondlogic.org/serial/serial.html. 2) www.intersil.com. 3) www.atmel.com. 4) www.national.com/pf/LM/LM35.html 5) www.powerbacks.net/textures10.html?

[80]