Sei sulla pagina 1di 108

ABSTRACT

In spite of the improvement of communication link and despite all progress in advanced communication technologies, there are still very few functioning commercial wireless monitoring systems, which are most off-line, and there are still a number of issues to deal with.

Therefore, there is a strong need for investigating the possibility of design and implementation of an interactive real-time wireless communication system. In our project, a generic real-time wireless communication system was designed and developed for short and long term remote patient-monitoring applying wireless protocol. The primary function of this system is to monitor the temperature and Heart Beat of the Patient and the Data collected by the sensors are sent to the Microcontroller. The Microcontroller transmits the data over the air. Here we are using the GSM modem in order to transmit the information. From the transmitter the recordings are sent as an SMS to the care taker or the expert which have been given as the recipient. Not only we send the information through GSM module as SMS we also display the readings in the PC where we can record them and also keep a track on his/her previous history. And when the conditions go abnormal then we sense those values and then alarm the people around by sending as urgency SMS.

INDEX INTRODUCTION.............................................................5 BLOCK DIAGRAM AND SCHEMATIC......................6


2.1 Block Diagram Description..........................................................................7 2.1.1 HEART BEAT SENSOR..............................................................................8 2.1.2 TEMPERATURE SENSOR..........................................................................9 Schematic Description..........................................................................................11

SENSORS.........................................................................11
3.1 Temperature sensor (LM35):......................................................................11 3.1.1 Features:.......................................................................................................12 3.1.2 Applications:................................................................................................13 3.2 Heart beat Sensor (LM358):.......................................................................14 3.2.1 Features:.......................................................................................................15 3.2.2 Applications:................................................................................................15 3.3 Conclusion..................................................................................................16

MICROCONTROLLER PIC16F877A.........................17
4.1 Introduction.................................................................................................17 Microcontroller Core Features..........................................................................17 4.3 Peripheral Features.....................................................................................19 4.4 Architecture.................................................................................................20 4.5 Pin Description...........................................................................................20 4.5.1 OSC1/CLKI:................................................................................................20 4.5.2 OSC2/CLKO:...............................................................................................21 4.5.3 MCLR/VPP:.................................................................................................21 4.6 Input and Output Pins.................................................................................21 4.6.1 PORTA and TRISA Register:....................................................................21 4.6.2 PORTb and TRISB Register:......................................................................22 4.6.3 PORTC and TRISC Register:......................................................................23 4.6.4 PORTD and TRISD Register:.....................................................................24 4.6.5 PORTE and TRISE Register:......................................................................24 4.7 Memory Organization.................................................................................24 4.7.1 Program Memory Organization:..................................................................25 4.7.2 Data Memory Organization: ......................................................................25 4.7.3 Data EEPROM and Flash Program Memory:.............................................26 4.8 Timers:........................................................................................................26 4.8.1 Timer0 Module: ..........................................................................................26 4.8.2 Timer0 Interrupt:..........................................................................................27 4.8.3 Timer1 Module:...........................................................................................27

4.8.4 Timer2 Module:...........................................................................................28 4.9 In-Circuit Debugger....................................................................................28 4.10 Analog to digital converter Module.........................................................29 4.11 Synchronous and Asynchronous Communications..................................29 4.12 Serial Communication..............................................................................30 4.12.1 Bi-directional Communications:................................................................31 4.12.2 Communicating by bits:.............................................................................31 4.12.3 The Parity Bit: ...........................................................................................31 4.12.4 Cable Lengths:...........................................................................................32 4.13 Conclusion................................................................................................32

5. GLOBAL SYSTEM FOR MOBILE COMMUNICATION......................................................33


5.1 Introduction.................................................................................................33 5.2 GSM Architecture.......................................................................................34 5.3 The Switching System ...............................................................................35 5.3.1 Authentication Center (AUC):.....................................................................35 5.3.2 Equipment Identity Register (EIR):............................................................36 5.3.3 The Base Station System (BSS): ................................................................36 5.3.4 The Operation and Support System: ...........................................................36 5.3.5. Additional Functional Elements: ...............................................................37 5.4 GSM Cellular Network...............................................................................37 5.5 GSM Network Classification......................................................................38 5.6 GSM transmitter.........................................................................................39 5.7 GSM security..............................................................................................40 5.8 GSM Modems and Modules.......................................................................41 A GSM modem is a wireless modem that works with a GSM wireless network. A wireless modem behaves like a dial-up modem. The main difference between them is that a dial-up modem sends and receives data through a fixed telephone line while a wireless modem sends and receives data through radio waves. A GSM modem can be an external device or a PC Card / PCMCIA Card. Typically, an external GSM modem is connected to a computer through a serial cable or a USB cable. A GSM modem in the form of a PC Card / PCMCIA Card is designed for use with a laptop computer. It should be inserted into one of the PC Card / PCMCIA Card slots of a laptop computer. Like a GSM mobile phone, a GSM modem requires a SIM card from a wireless carrier......................................................................................41 5.9 Sim300 GSM Module (GSM / GPRS: SIM300)........................................41 5.9.1 Detailed Modem Description:.....................................................................41 5.10 Conclusion................................................................................................42

6. POWER SUPPLY UNIT............................................42


6.1 Introduction.................................................................................................43 6.2 Step down Transformer.............................................................................43 6.3 Rectifier Unit.............................................................................................44 6.3.1 Half-wave rectifier: ..................................................................................44 3

6.3.2 Full-wave rectifier:.......................................................................................44 6.3.3 Bridge rectifier: ..........................................................................................45 6.4 Input filter..................................................................................................46 6.4.1 Low pass filter: ...........................................................................................47 6.4.2 High pass filter:............................................................................................48 6.5 Regulator Unit............................................................................................49 6.6 Fixed Regulators.........................................................................................50 6.6.1 7805 Voltage Regulator...............................................................................50 The 7805 provides circuit designers with an easy way to regulate DC voltages to 5v. Encapsulated in a single chip/package (IC), the 7805 is a positive voltage DC regulator that has only 3 terminals. They are: Input voltage, Ground, Output Voltage...................................................................................51 6.6.2 7812 12V Integrated Circuit3-Terminal Positive Voltage Regulator........51 6.9 Output filter................................................................................................51 6.10 Conclusion................................................................................................53

7. SOFTWARE USED....................................................53
7.1 Introduction.................................................................................................53 7.2 MPLAB Integration....................................................................................54 7.3 Introduction to Embedded C....................................................................54 7.3.1 Embedded C Compiler.................................................................................55 7.5 Embedded Development Environment......................................................56 7.6 Embedded system Tools.............................................................................56 7.6.1 Assembler:..............................................................................................56 7.7 Phases of compiler......................................................................................56 7.8 Fabrication details.......................................................................................57 7.9 Design of embedded system.......................................................................58 7.10 User interfaces..........................................................................................58 7.11 Platform....................................................................................................59 7.12 Tools.........................................................................................................59 7.13 Debugging.................................................................................................60 7.14 Start up......................................................................................................61 7.15 Coding.......................................................................................................62 7.16 Flow Chart .......................................................97

8. CONCLUSION AND FUTURE SCOPE ...............103 8.Bibliography...............................................................104

INTRODUCTION
As the goal of this project, we see a device that can detect ailments in a patient and inform them to the concerned medical personnel, without the intervention of even the patient himself. This process is done with the help of GSM technology. The GSM technology is used for reading and sending SMS to the concerned person. . 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.

BLOCK DIAGRAM AND SCHEMATIC


Heart Beat Sensor

TEMP SENSOR

OP-AMP

MICROCONTROLLER

GSM

LED

L D R

Figure 1 Block Diagram

2.1 Block Diagram Description


In this block diagram, there is a micro controller, a heart beat sensor circuitry, a GSM MODEM and a Temperature sensor.

The heart beat circuitry sense the heart beat with the help of an LED and an LDR.A continuous light from the LED should fall on the LDR and the finger of the patient is to be placed in between the LED and LDR. The slight variation in the skin due to the heart beat is read by the LDR. The LDR output is fed to an operational amplifier to the digital level (0 and 5) which is fed to the microcontroller. Temperature of the patients body. This is done by using a temperature sensor IC which incorporates a temperature sensor, an Analog-to-digital converter and a serial converter. The GSM Modem is used for sending and receiving messages from the patient to a doctor and vice versa. Whenever the heart beat rate or the B.P. exceeds the threshold value. The micro controller will automatically send the signals to the GSM Modem. Through the GSM Modem, the message will gives to the concerned person or a doctor. For the circuitry operation, it requires the +5V DC power supply.

2.1.1 HEART BEAT SENSOR

This block is used to sense the heart beat with the help of an LED and an LDR.A continuous light from the LED should fall on the LDR and the finger of the patient is to be placed in between the LED and LDR. The slight variation in the skin due to the heart beat is read by the LDR. The LDR output is fed to an operational amplifier to the digital level (0 and 5) which is fed to the microcontroller. 2.1.2 TEMPERATURE SENSOR This sensor is used to read the temperature of the patients body. This is done by using a temperature sensor IC which incorporates a temperature sensor, an Analog-to-digital converter and a serial converter. 2.1.3 MICROCONTROLLER A microcontroller reads the pulses from the heart beat sensor and it also reads the temperature. These two parameters transmitted to a distant location using GSM.

2.2 Schematic Diagram

Figure 2 Schematic

10

Schematic Description

Figure 2 represents the circuit diagram of the Patient monitoring system. The hardware present in the circuit comprises of: Microcontroller PIC16F877A Temperature sensor: LM35 Heart beat sensor: LM358 with LED and LDR

GSM modem Power Supply

SENSORS
A sensor is a transducer which converts physical quantities to electrical quantities.

3.1 Temperature sensor (LM35):


The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in Kelvin, as the user is not required to subtract a large constant voltage from its output to obtain convenient Centigrade scaling. The LM35 does not require any external calibration or trimming to provide typical accuracies of 14C at room temperature and 34C over a full 55 to +150C temperature range.

11

Low cost is assured by miming and calibration at the wafer level. The LM35s low output impedance, linear output, and precise inherent calibration make interfacing to readout or control circuitry especially easy. It can be used with single power supplies, or with plus and minus supplies. As it draws only 60 A from its supply, it has very low self-heating, less than 0.1C in still air. The LM35 is rated to operate over a 55 to +150C temperature range, while the LM35C is rated for a 40 to 110C range (10 with improved accuracy). The LM35 series is available packaged in hermetic TO-46 transistor packages, while the LM35C, LM35CA, and LM35D are also available in the plastic TO-92 transistor package. The LM35D is also available in an 8-lead surface mount small outline package and a plastic TO-220 package. Figure 3.3 shows the pin diagram and figure 3.4 shows the temperature sensor used in the project 3.1.1 Features: Calibrated directly in Celsius (Centigrade) Linear + 10.0 mV/C scale factor 0.5C accuracy guarantee able (at +25C) Rated for full 55 to +150C range Suitable for remote applications Low cost due to wafer-level trimming Operates from 4 to 30 volts Less than 60 A current drain Low self-heating, 0.08C in still air Nonlinearity only 14C typical n Low impedance output, 0.1 W for 1 mA load

12

Figure 3.4: LM35 Temperature Sensor

3.1.2 Applications: The LM35 can be applied easily in the same way as other integratedcircuit temperature sensors. It can be glued or cemented to a surface and its temperature will be within about 0.01C of the surface temperature. This presumes that the ambient air temperature is almost the same as the surface temperature; if the air temperature were much higher or lower than the surface temperature, the actual temperature of the LM35 die would be at an intermediate temperature between the surface temperature and the air temperature. This is especially true for the TO-92 plastic package, where the copper leads are the principal thermal path to carry heat into the device, so its temperature might be closer to the air temperature than to the surface temperature. To minimize this problem, be sure that the wiring to the LM35, as it leaves the device, is held at the same temperature as the surface of interest. The easiest way to do this is to cover up these wires with a bead of epoxy which will insure that the leads and wires are all at the same temperature as the surface, and that the LM35 dies temperature will not be affected by the air temperature. The TO-46 metal package can also be soldered to a metal surface or pipe without damage. Of course, in that case the V terminal of the circuit will be grounded to that metal.

13

Alternatively, the LM35 can be mounted inside a sealed-end metal tube, and can then be dipped into a bath or screwed into a threaded hole in a tank. As with any IC, the LM35 and accompanying wiring and circuits must be kept insulated and dry, to avoid leakage and corrosion. This is especially true if the circuit may operate at cold temperatures where condensation can occur. Printedcircuit coatings and varnishes such as Hum seal and epoxy paints or dips are often used to insure that moisture cannot corrode the LM35 or its connections. These devices are sometimes soldered to a small light-weight heat fin, to decrease the thermal time constant and speed up the response in slowly-moving air. On the other hand, a small thermal mass may be added to the sensor, to give the steadiest reading despite small deviations in the air temperature.

3.2 Heart beat Sensor (LM358):


Heart beat is sensed by using a high intensity type LED and LDR. The finger is placed between the LED and LDR. As Sensor a photo diode or a photo transistor can be used. The skin may be illuminated with visible (red) using transmitted or reflected light for detection. The very small changes in reflectivity or in transmittance caused by the varying blood content of human tissue are almost invisible. Various noise sources may produce disturbance signals with amplitudes equal or even higher than the amplitude of the pulse signal. The new signal processing approach presented here combines analog and digital signal processing in a way that both parts can be kept simple but in combination are very effective in suppressing disturbance signals. The setup described here uses a red LED for transmitted light illumination and a LDR as detector. With only slight changes in the preamplifier circuit the same hardware and software could be used with other illumination and detection concepts. The detectors photo current (AC Part) is converted to voltage and amplified by an operational amplifier (LM358). Output is given to another non-inverting input of the same 14

LM358; here the second amplification is done. The value is preset in the inverting input, the amplified value is compared with preset value if any abnormal condition occurs it will generate an interrupt to the controller PIC18F77A..

3.2.1 Features: Heat beat indication by LED Instant output digital signal for directly connecting to microcontroller Compact Size Operating Voltage +5V DC regulated Operating Current 100 mA Output Data Level 5V TTL level Heart Beat detection Indicated by LED and Output High Pulse Light source 660nm Super Red LED

3.2.2 Applications: Digital Heart Rate monitor Patient Monitoring System Bio-Feedback control of robotics and applications

Figure3.5 describes the internal circuit of heart beat sensor and figure 3.6 shows the LM358 sensor of heart beat sensor and figure 3.7 shows the simulation graph of heart beat of the person.

15

Figure 3.5: Internal circuit of Heart beat Sensor

Figure 3.6: LM358 Heartbeat Sensor

3.3 Conclusion
The temperature and heartbeat sensors are discussed. Using sensors the Analog outputs are obtained which are in electrical form.

16

MICROCONTROLLER PIC16F877A
4.1 Introduction
The PIC is a microcontroller which consists of an inbuilt ADC, USART which are mainly used in this project. ADC is used for the conversion of Analog Output of sensors to digital and USART for serial asynchronous communication.

Microcontroller Core Features


High-performance RISC CPU. Only 35 single word instructions to learn. All single cycle instructions except for program branches which are two cycle. Operating speed: DC - 20 MHz clock input DC - 200 ns instruction cycle. Up to 8K x 14 words of FLASH Program Memory, Up to 368 x 8 bytes of Data Memory (RAM) Up to 256 x 8 bytes of EEPROM data memory. Pin out compatible to the PIC16C73B/74B/76/77 Interrupt capability (up to 14 sources) Eight level deep hardware stack Direct, indirect and relative addressing modes. Power-on Reset (POR). Power-up Timer (PWRT) and Oscillator Start-up Timer (OST). Watchdog Timer (WDT) with its own on-chip RC oscillator for reliable operation. Programmable code-protection. Power saving SLEEP mode. Selectable oscillator options. Low-power, high-speed CMOS FLASH/EEPROM technology. Fully static design.

17

Wide operating voltage range: 2.0V to 5.5V.

Figure 4.1: Pin Diagram of micricontroller PIC16F877A

18

4.3 Peripheral Features


Timer0: 8-bit timer/counter with 8-bit prescaler Timer1: 16-bit timer/counter with prescaler, can be incremented during sleep via external crystal/clock Timer2: 8-bit timer/counter with 8-bit period register, prescaler and postscaler Two Capture, Compare, PWM modules - Capture is 16-bit, max. Resolution is 12.5 ns - Compare is 16-bit, max. Resolution is 200 ns - PWM max. Resolution is 10-bit 10-bit multi-channel Analog-to-Digital converter Synchronous Serial Port (SSP) with SPI (Master Mode) and I2C (Master/Slave) Universal Synchronous Asynchronous Receiver Transmitter (USART/SCI) with 9-bit address detection Parallel Slave Port (PSP) 8-bits wide, with external RD, WR and CS controls (40/44-pin only) Brown-out detection circuitry for Brown-out Reset (BOR)

19

4.4 Architecture

Figure 4.2: Internal Architecture of microcontroller PIC16F877A

4.5 Pin Description


4.5.1 OSC1/CLKI: Oscillator crystal or external clock input (or) Oscillator crystal input or external clock source input. ST buffer when configured in RC mode otherwise CMOS. External clock source input. Always associated with pin function OSC1 (see OSC1/CLKI, OSC2/CLKO pins).

20

4.5.2 OSC2/CLKO: Oscillator crystal or clock output Oscillator. Connects to the crystal or resonator in Crystal Oscillator mode. In RC mode, OSC2 pin outputs CLKO, which has 1/4 the frequency of OSC1 and denotes the instruction cycle rate. 4.5.3 MCLR/VPP: Master Clear (input) (or) programming voltage (output). Master Clear (Reset) input. This pin is an active low Reset to the device. Programming voltage input. RA0/AN0. RA1/AN1. RA2/AN2/VREF-/CVREF. VREFCVREF. RA3/AN3/VREF+. VREF+. RA4/T0CKI/C1OUT. T0CKI. C1OUT. RA5/AN4/SS/C2OUT/SS/C2OUT.

4.6 Input and Output Pins


Some pins for these I/O ports are multiplexed with an alternate function for the peripheral features on the device. In general, when a peripheral is enabled, that pin may not be used as a general purpose I/O pin. 4.6.1 PORTA and TRISA Register: PORTA is a 6-bit wide, bidirectional port. The corresponding data direction register is TRISA. Setting a TRISA bit (= 1) will make the corresponding PORTA pin an input (i.e., put the corresponding output driver in

21

a High Impedance mode). Clearing a TRISA bit (= 0) will make the corresponding PORTA pin an output (i.e., put the contents of the output latch on the selected pin). Reading the PORTA register reads the status of the pins, whereas writing to it will write to the port latch. All write operations are readmodify-write operations. Therefore, a write to a port implies that the port pins are read; the value is modified and then written to the port data latch. Pin RA4 is multiplexed with the Timer0 module clock input to become the RA4/T0CKI pin. The RA4/T0CKI pin is a Schmitt Trigger input and an open-drain output. All other PORTA pins have TTL input levels and full CMOS output drivers. Other PORTA pins are multiplexed with analog inputs and the analog VREF input for both the A/D converters and the comparators. The operation of each pin is selected by clearing/setting the appropriate control bits in the ADCON1 and/or CMCON registers. The TRISA register controls the direction of the port pins even when they are being used as analog inputs. The user must ensure the bits in the TRISA register are maintained set when using them as analog inputs. Note: On a Power-on Reset, these pins are configured as analog inputs and read as 0. The comparators are in the off (digital). 4.6.2 PORTb and TRISB Register: PORTB is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISB. Setting a TRISB bit (= 1) will make the corresponding PORTB pin an input (i.e., put the corresponding output driver in a High-Impedance mode). Clearing a TRISB bit (= 0) will make the corresponding PORTB pin an output (i.e., put the contents of the output latch on the selected pin). Three pins of PORTB are multiplexed with the In-Circuit Debugger and Low-Voltage Programming function: RB3/PGM, RB6/PGC and RB7/PGD. Four of the PORTB pins, RB7:RB4, have an interruption- change feature. Only pins configured as inputs can cause this interrupt to occur (i.e., any 22

RB7:RB4 pin configured as an output is excluded from the interruption- change comparison). The input pins (of RB7:RB4) are compared with the old value latched on the last read of PORTB. The mismatch outputs of RB7:RB4 are ORed together to generate the RB port change interrupt with flag bit RBIF (INTCON<0>). This interrupt can wake the device from Sleep. The user, in the Interrupt Service Routine, can clear the interrupt in the following manner: a) Any read or write of PORTB. This will end the mismatch condition. b) Clear flag bit RBIF. A mismatch condition will continue to set flag bit RBIF. Reading PORTB will end the mismatch condition and allow flag bit RBIF to be cleared. The interrupt-on-change feature is recommended for wake-up on key depression operation and operations where PORTB is only used for the interrupt-on-change feature. Polling of PORTB is not recommended while using the interrupt-onchange feature. This interrupt-on-mismatch feature, together with software configurable pull-ups on these four pins, allow easy interface to a keypad and make it possible for wake-up on key depression. 4.6.3 PORTC and TRISC Register: PORTC is an 8-bit wide, bidirectional port. The corresponding data direction register is TRISC. Setting a TRISC bit (= 1) will make the corresponding PORTC pin an input (i.e., put the corresponding output driver in a High- Impedance mode). Clearing a TRISC bit (= 0) will make the corresponding PORTC pin an output (i.e., put the contents of the output latch on the selected pin). PORTC is multiplexed with several peripheral functions (Table 4-5). PORTC pins have Schmitt Trigger input buffers. When the I2C module is enabled, the PORTC<4:3> pins can be configured with normal I2C levels, or with SMBus levels, by using the CKE bit (SSPSTAT<6>). When enabling peripheral functions, care should be taken in defining TRIS bits for 23

each PORTC pin. Some peripherals override the TRIS bit to make a pin an output, while other peripherals override the TRIS bit to make a pin an input. Since the TRIS bit override is in effect while the peripheral is enabled, readmodify write instructions (BSF, BCF, XORWF) with TRISC as the destination, should be avoided. The user should refer to the corresponding peripheral section for the correct TRIS bit settings. 4.6.4 PORTD and TRISD Register: PORTD is an 8-bit port with Schmitt Trigger input buffers. Each pin is individually configurable as an input or output. PORTD can be configured as an 8-bit wide microprocessor port (Parallel Slave Port) by setting control bit, PSP MODE (TRISE<4>). In this mode, the input buffers are TTL.

4.6.5 PORTE and TRISE Register: PORTE has three pins (RE0/RD/AN5, RE1/WR/AN6 and RE2/CS/AN7) which are individually configurable as inputs or outputs. These pins have Schmitt Trigger input buffers. The PORTE pins become the I/O control inputs for the microprocessor port when bit PSPMODE (TRISE<4>) is set. In this mode, the user must make certain that the TRISE<2:0> bits are set and that the pins are configured as digital inputs. Also, ensure that ADCON1 is configured for digital I/O. In this mode, the input buffers are TTL. Register 4-1 shows the TRISE register which also controls the Parallel Slave Port operation. PORTE pins are multiplexed with analog inputs. When selected for analog input, these pins will read as 0s. TRISE controls. The direction of the RE pins, even when they are being used as analog inputs. The user must make sure to keep the pins configured as inputs when using them as analog inputs.

4.7 Memory Organization

24

There are three memory blocks in each of the PIC16F87XA devices. The program memory and data memory have separate buses so that concurrent access can occur and is detailed in this section. The EEPROM data memory and flah program memory is also detailed. 4.7.1 Program Memory Organization: The PIC16F87XA devices have a 13-bit program counter capable of addressing an 8K word x 14 bit program memory space. The PIC16F876A/877A devices have 8K words x 14 bits of Flash program memory, while PIC16F873A/874A devices have 4K words x 14 bits. Accessing a location above the physically implemented address will cause a wraparound. The Reset vector is at 0000h and the interrupt vector is at 0004h. The data memory is partitioned into multiple banks which contain the General Purpose Registers and the Special Function Registers. Bits RP1 (Status<6>) and RP0 (Status<5>) are the bank select bits. Each bank extends up to 7Fh (128 bytes). The lower locations of each bank are reserved for the Special Function Registers. Above the Special Function Registers are General Purpose Registers, implemented as static RAM. All implemented banks contain Special Function Registers. Some frequently used Special Function Registers from one bank may be mirrored in another bank for code reduction and quicker access.
4.7.2 Data Memory Organization:

The data memory is partitioned into multiple banks which contain the General Purpose Registers and the Special Function Registers. Bits RP1 (Status<6>) and RP0 (Status<5>) are the bank select bits. Each bank extends up to 7Fh (128 bytes). The lower locations of each bank are reserved for the Special Function Registers. Above the Special Function Registers are General Purpose Registers, implemented as static RAM. All implemented banks contain Special Function Registers. Some frequently used Special Function Registers from one bank may be mirrored in another bank for code reduction and quicker access.

25

4.7.3 Data EEPROM and Flash Program Memory: The data EEPROM and Flash program memory is readable and writable during normal operation (over the full VDD range). This memory is not directly mapped in the register file space. Instead, it is indirectly addressed through the Special Function Registers. There are six SFRs used to read and write this memory. EECON1 EECON2 EEDATA EEDATH EEADR EEADRH

4.8 Timers:
4.8.1 Timer0 Module: The Timer0 module timer/counter has the following features: 8-bit timer/counter Readable and writable 8-bit software programmable prescaler Internal or external clock select Interrupt on overflow from FFh to 00h Edge select for external clock Timer mode is selected by clearing bit T0CS (OPTION_REG<5>). In Timer mode, the Timer0 module will increment every instruction cycle (without prescaler). If the TMR0 register is written, the increment is inhibited for the following two instruction cycles. The user can work around this by writing an adjusted value to the TMR0 register.

26

4.8.2 Timer0 Interrupt: The TMR0 interrupt is generated when the TMR0 register overflows from FFh to 00h. This overflow sets bit TMR0IF (INTCON<2>). The interrupt can be masked by clearing bit TMR0IE (INTCON<5>). Bit TMR0IF must be cleared in software by the Timer0 module Interrupt Service Routine before reenabling this interrupt. The TMR0 interrupt cannot awaken the processor from Sleep since the timer is shut-off during Sleep. 4.8.3 Timer1 Module: The Timer1 module is a 16-bit timer/counter consisting of two 8-bit registers (TMR1H and TMR1L) which are readable and writable. The TMR1 register pair (TMR1H:TMR1L) increments from 0000h to FFFFh and rolls over to 0000h. The TMR1 interrupt, if enabled, is generated on overflow which is latched in interrupt flag bit, TMR1IF (PIR1<0>). This interrupt can be enabled/disabled by setting or clearing TMR1 interrupt enable bit, TMR1IE (PIE1<0>). Timer1 can operate in one of two modes: As a Timer As a Counter The operating mode is determined by the clock select bit, TMR1CS (T1CON<1>).In Timer mode, Timer1 increments every instruction cycle. In Counter mode, it increments on every rising edge of the external clock input. Timer1 can be enabled/disabled by setting/clearing control bit, TMR1ON (T1CON<0>).Timer1 also has an internal Reset input. This Reset can be generated by either of the two CCP modules. Shows the Timer1 Control register. When the Timer1 oscillator is enabled (T1OSCEN is set), the RC1/T1OSI/CCP2 and RC0/T1OSO/T1CKI pins become inputs. That is, the TRISC<1:0> value is ignored and these pins read as 0.

27

4.8.4 Timer2 Module: Timer2 is an 8-bit timer with a prescaler and a postscaler. It can be used as the PWM time base for the PWM mode of the CCP module(s). The TMR2 register is readable and writable and is cleared on any device Reset. The input clock (FOSC/4) has a prescale option of 1:1, 1:4 or 1:16, selected by control bits T2CKPS1:T2CKPS0 (T2CON<1:0>). The Timer2 module has an 8-bit period register, PR2. Timer2 increments from 00h until it match PR2 and then resets to 00h on the next increment cycle. PR2 is a readable and writable register. The PR2 register is initialized to FFh upon Reset. The match output of TMR2 goes through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate a TMR2 interrupt (latched in flag bit, TMR2IF (PIR1<1>)). Timer2 can be shut-off by clearing control bit, TMR2ON (T2CON<2>), to minimize power consumption.

4.9 In-Circuit Debugger


PIC16F87XA devices have a Watchdog Timer which can be shut-off only through configuration bits. It runs off its own RC oscillator for added reliability. There are two timers that offer necessary delays on power-up. One is the Oscillator Start-up Timer (OST), intended to keep the chip in Reset until the crystal oscillator is stable. The other is the Power-up Timer (PWRT), which provides a fixed delay of 72 ms (nominal) on power-up only. It is designed to keep the part In Reset while the power supply stabilizes. With these two timers onchip, most applications need no external Reset circuitry. Sleep mode is designed to offer a very low current power-down mode. The user can wake-up from Sleep through external Reset, Watchdog Timer wake-up or through an interrupt. Several oscillator options are also made available to allow the part to fit the application. The RC oscillator option saves system cost while the LP crystal option saves power. A set of configuration bits is used to select various options.

28

4.10 Analog to digital converter Module


The Analog-to-Digital (A/D) Converter module has five inputs for the 28-pin devices and eight for the 40/44-pin devices. The conversion of an analog input signal results in a corresponding 10-bit digital number. The A/D module has high and low-voltage reference input that is software selectable to some combination of VDD, VSS, RA2 or RA3. The A/D converter has a unique feature of being able to operate while the device is in Sleep mode. To operate in Sleep, the A/D clock must be derived from the A/Ds internal RC oscillator. The A/D module has four registers. These registers are: A/D Result High Register (ADRESH) A/D Result Low Register (ADRESL) A/D Control Register 0 (ADCON0) A/D Control Register 1 (ADCON1) The ADCON0 register, shown in Register 11-1, controls the operation of the A/D module. The ADCON1 register, shown in Register 11-2, configures the functions of the port pins. The port pins can be configured as analog inputs (RA3 can also be the voltage reference) or as digital I/O.

4.11 Synchronous and Asynchronous Communications


There are two basic types of serial communications, synchronous and asynchronous. With synchronous communications, the two devices initially synchronize themselves to each other, and then continually send characters to stay in sync. Even when the data is not really being sent, a constant flow of bits allows each device to know where the other is at any given time. That is, each character that is sent is either actual data or an idle character. Synchronous

29

communications allows faster data transfer rates than asynchronous methods, because additional bits to mark the beginning and end of each data byte are not required. The serial ports on IBM style PCs are asynchronous devices and therefore only support asynchronous serial communications. Asynchronous means no synchronization, and thus does not require sending and receiving idle characters. However, the beginning and end of each byte of data must be identified by start and stop bits. The start bit indicates when the data byte is about to begin and the stop bit signals when it ends. The requirement to send these additional two bits causes asynchronous communication to be slightly slower than synchronous however it has the advantage that the processor does not have to deal with the additional idle characters.

4.12 Serial Communication


A serial port sends and receives data one bit at a time over one wire. While it takes eight times as long as to transfer each byte of data this way, only a few wires are required. In fact, two-way (full duplex) communications is possible with only three separate wires- one to send, one to receive, and a common signal ground wire. Bi-directional communications Communicating by wires The Parity Bit Cable lengths MAX-232C DCE And DTE devices Synchronous and Asynchronous Communications

30

4.12.1 Bi-directional Communications: The serial port on your PC is a full-duplex device meaning that it can send and receive data at the same time. In order to be able to do this, it uses separate lines for transmitting and receiving data. Some types of serial devices support only one-way communications and therefore use only two-wires in the cable the transmit line and the signal ground.

4.12.2 Communicating by bits: Once the start bit has been sent, the transmitter sends the actual data bits. There may either be 5,6,7, or 8 data bits, depending on the number you have selected. Both receiver and the transmitter must agree on the number of data bits, as well as the baud rate. Almost all devices transmit data using either 7 or 8 data bits. Notice that when only 7 data bits are employed, you cannot send ASCII values greater than 127. Likewise, using 5 bits limits the highest possible value to 31. After the data has been transmitted, a stop bit is sent. A stop bit has a value of 1- or a mark state- and it can be detected correctly even if the previous data bit also had a value of This is accomplished by the stop bits duration. 4.12.3 The Parity Bit: Besides the synchronization provided by the use of start and stop bits, an additional bit called a parity bit may optionally be transmitted along with the data. A parity bit affords a small amount of error checking, to help detect data corruption that might occur during transmission.

31

4.12.4 Cable Lengths: The MAX-232 standard imposes a cable length limit of 50 feet. You can usually ignore this standard, since a cable can be as long as 10000 feet at baud rates up to 19200 if you use a high quality, well shielded cable. The external environment has a large effect on lengths for unshielded cables

4.13 Conclusion
PIC microcontroller with its advanced features like reduced instruction set, inbuilt Watchdog Timer, Automatic sleep mode, inbuilt ADC and USART provides various number of applications.

32

5. GLOBAL SYSTEM FOR MOBILE COMMUNICATION


5.1 Introduction
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. Cellular is one of the fastest growing and most demanding telecommunications applications. Throughout the evolution of cellular telecommunications, various systems have been developed without the benefit of standardized specifications. This presented many problems directly related to compatibility, especially with the development of digital radio technology. The GSM standard is intended to address these problems. From 1982 to 1985 discussions were held to decide between building an analog or digital system. After multiple field tests, a digital system was adopted for GSM. The next task was to decide between a narrow or broadband solution. In May 1987, the narrowband time division multiple access (TDMA) solution was chosen. GSM provides recommendations, not requirements. The GSM specifications define the functions and interface requirements in detail but do not address the hardware. The reason for this is to limit the designers as little as possible but still to make it possible for the operators to buy equipment from different suppliers. The GSM network is divided into three major systems: the switching system (SS), the base station system (BSS), and the operation and support system (OSS).

33

5.2 GSM Architecture

Figure 5.1: GSM Architecture

34

5.3 The Switching System


The switching system (SS) is responsible for performing call processing and subscriber-related functions. The switching system includes the following functional units. Home Location Register (HLR) The HLR is a database used for storage and management of subscriptions. The HLR is considered the most important database, as it stores permanent data about subscribers, including a subscriber's service profile, location information, and activity status. When an individual buys a subscription from one of the PCS operators, he or she is registered in the HLR of that operator. Mobile Services Switching Center (MSC) The MSC performs the telephony switching functions of the system. It controls calls to and from other telephone and data systems. It also performs such functions as toll ticketing, network interfacing, common channel signaling, and others. Visitor Location Register (VLR) The VLR is a database that contains temporary information about subscribers that is needed by the MSC in order to service visiting subscribers. The VLR is always integrated with the MSC. When a mobile station roams into a new MSC area, the VLR connected to that MSC will request data about the mobile station from the HLR. Later, if the mobile station makes a call, the VLR will have the information needed for call setup without having to interrogate the HLR each time.

5.3.1 Authentication Center (AUC): A unit called the AUC provides authentication and encryption parameters that verify the user's identity and ensure the confidentiality of each call. The AUC protects network operators from different types of fraud found in today's cellular world.

35

5.3.2 Equipment Identity Register (EIR): The EIR is a database that contains information about the identity of mobile equipment that prevents calls from stolen, unauthorized, or defective mobile stations. The AUC and EIR are implemented as stand-alone nodes or as a combined AUC/EIR node. 5.3.3 The Base Station System (BSS): All radio-related functions are performed in the BSS, which consists of base station controllers (BSCs) and the base transceiver stations (BTSs). 5.3.3.1 BSC The BSC provides all the control functions and physical links between the MSC and BTS. It is a high-capacity switch that provides functions such as handover, cell configuration data, and control of radio frequency (RF) power levels in base transceiver stations. A number of BSCs are served by an MSC. 5.3.3.2 BTS The BTS handles the radio interface to the mobile station. The BTS is the radio equipment (transceivers and antennas) needed to service each cell in the network. A group of BTSs are controlled by a BSC. 5.3.4 The Operation and Support System: The operations and maintenance center (OMC) is connected to all equipment in the switching system and to the BSC. The implementation of OMC is called the operation and support system (OSS). The OSS is the functional entity from which the network operator monitors and controls the system. The purpose of OSS is to offer the customer cost-effective support for centralized, regional, and local operational and maintenance activities that are required for a GSM network. An important function of OSS is to provide a network overview and support the maintenance activities of different operation and maintenance organizations.

36

5.3.5. Additional Functional Elements: 5.3.5.1 Message Center (MXE) The MXE is a node that provides integrated voice, fax, and data messaging. Specifically, the MXE handles short message service, cell broadcast, voice mail, fax mail, e-mail, and notification. 5.3.5.2 Mobile Service Node (MSN) The MSN is the node that handles the mobile intelligent network (IN) services . 5.3.5.3 Gateway Mobile Services Switching Center (GMSC) A gateway is a node used to interconnect two networks. The gateway is often implemented in an MSC. The MSC is then referred to as the GMSC. 5.3.5.4 Gsm Interworking Unit (GIWU) The GIWU consists of both hardware and software that provides an interface to various networks for data communications. Through the GIWU, users can alternate between speech and data during the same call. The GIWU hardware equipment is physically located at the MSC/VLR

5.4 GSM Cellular Network


GSM is a cellular network, which means that mobile phones connect to it by searching for cells in the immediate vicinity. GSM networks operate in four different frequency ranges. Most GSM networks operate in the 900 MHz or 1800 MHz bands. Some countries in the Americas (including Canada and the United States) use the 850 MHz and 1900 MHz bands because the 900 and 1800 MHz frequency bands were already allocated. The rarer 400 and 450 MHz frequency bands are assigned in some countries where these frequencies were previously used for first-generation systems. GSM-900 uses 890915 MHz to send information from the mobile station to the base station (uplink) and 935960 MHz for the other direction 37

(downlink), providing 124 RF channels (channel numbers 1 to 124) spaced at 200 kHz. Duplex spacing of 45 MHz is used. In some countries the GSM-900 band has been extended to cover a larger frequency range. This 'extended GSM', E-GSM, uses 880915 MHz (uplink) and 925960 MHz (downlink), adding 50 channels (channel numbers 975 to 1023 and 0) to the original GSM-900 band. Time division multiplexing is used to allow eight full-rate or sixteen half-rate speech channels per radio frequency channel. There are eight radio timeslots (giving eight burst periods) grouped into what is called a TDMA frame. Half rate channels use alternate frames in the same timeslot. The channel data rate for all 8 channels is 270.833 kbit/s, and the frame duration is 4.615 ms. GSM has used a variety of voice codecs to squeeze 3.1 kHz audio into between 5.6 and 13 kbit/s. Originally, two codecs, named after the types of data channel they were allocated, were used, called Half Rate (5.6 kbit/s) and Full Rate (13 kbit/s). These used a system based upon linear predictive coding (LPC). In addition to being efficient with bitrates, these codecs also made it easier to identify more important parts of the audio, allowing the air interface layer to prioritize and better protect these parts of the signal

5.5 GSM Network Classification


There are five different cell sizes in a GSM networkmacro, micro, Pico, femto and umbrella cells. The coverage area of each cell varies according to the implementation environment. Macro cells can be regarded as cells where the base station antenna is installed on a mast or a building above average roof top level. Micro cells are cells whose antenna height is under average roof top level; they are typically used in urban areas. Pico cells are small cells whose coverage diameter is a few dozen meters; they are mainly used indoors. Femto cells are cells designed for use in residential or small business environments and connect to the 38

service providers network via a broadband internet connection. Umbrella cells are used to cover shadowed regions of smaller cells and fill in gaps in coverage between those cells. Cell horizontal radius varies depending on antenna height, antenna gain and propagation conditions from a couple of hundred meters to several tens of kilometers. The longest distance the GSM specification supports in practical use is 35 kilometers (22 mi). There are also several implementations of the concept of an extended cell, where the cell radius could be double or even more, depending on the antenna system, the type of terrain and the timing advance. Indoor coverage is also supported by GSM and may be achieved by using an indoor pico cell base station, or an indoor repeater with distributed indoor antennas fed through power splitters, to deliver the radio signals from an antenna outdoors to the separate indoor distributed antenna system. These are typically deployed when a lot of call capacity is needed indoors, for example in shopping centers or airports. However, this is not a prerequisite, since indoor coverage is also provided by in-building penetration of the radio signals from nearby cells. The modulation used in GSM is Gaussian minimum-shift keying (GMSK), a kind of continuous-phase frequency shift keying. In GMSK, the signal to be modulated onto the carrier is first smoothed with a Gaussian lowpass filter prior to being fed to a frequency modulator, which greatly reduces the interference to neighboring

5.6 GSM transmitter

39

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 phone book. 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 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.

5.7 GSM security


GSM was designed with a moderate level of security. The system was designed to authenticate the subscriber using a pre-shared key and challengeresponse. 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 authenticates the user 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/2 stream 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. Serious weaknesses have been found in both algorithms: it is possible to break A5/2 in real-time with a cipher text-only attack, and in February 2008, Pico Computing, Inc revealed its ability and plans to commercialize FPGAs that allow A5/1 to be broken with a rainbow table attack [1]. The system supports multiple algorithms so operators may replace that cipher with a stronger one.

40

5.8 GSM Modems and Modules


A GSM modem is a wireless modem that works with a GSM wireless network. A wireless modem behaves like a dial-up modem. The main difference between them is that a dial-up modem sends and receives data through a fixed telephone line while a wireless modem sends and receives data through radio waves. A GSM modem can be an external device or a PC Card / PCMCIA Card. Typically, an external GSM modem is connected to a computer through a serial cable or a USB cable. A GSM modem in the form of a PC Card / PCMCIA Card is designed for use with a laptop computer. It should be inserted into one of the PC Card / PCMCIA Card slots of a laptop computer. Like a GSM mobile phone, a GSM modem requires a SIM card from a wireless carrier.

5.9 Sim300 GSM Module (GSM / GPRS: SIM300)


5.9.1 Detailed Modem Description: The Sim300 is a Tri-Brand GSM GPRS solution in a compact plug-in module. Featuring an industry-standard interface, the sim300 delivers GSM GPRS 900 1800 1900MHz performance for voice, SMS, Data, and Fax in a small form factor and with low power consumption. The leading features of Sim300 make it ideal for virtually unlimited application, such as WLL applications (Fixed Cellular Terminal), M2M application, handheld devices and much more. 1) Sim300 is a Tri-band GSM GPRS module with a size of 40x33x2. 85mm 2) Customized MMI and keypad LCD support 3) An embedded Powerful TCP IP protocol stack 4) Based upon mature and field-proven platform, backed up by our support service, from definition to design and production.

41

5.10 Conclusion
GSM is a cellular network, which means that mobile phones connect to it by searching for cells in the immediate vicinity. Architecture, Switching system and classification are discussed.

6. POWER SUPPLY UNIT

42

6.1 Introduction
Figure 8.1 shows the circuit diagram of power supply unit a step down transformer.

Figure 8.1: circuit diagram of power supply unit Power supply unit consists of following units: i) Step down transformer ii) Rectifier unit iii) Input filter iv).Regulator unit v) Output filter

6.2 Step down Transformer


The Step down Transformer is used to step down the main supply voltage from 230V AC to lower value. This 230 AC voltage cannot be used directly, thus it is stepped down. The Transformer consists of primary and secondary coils. To reduce or step down the voltage, the transformer is designed to contain less number of turns in its secondary core. The output from the secondary coil is also AC waveform. Thus 43

the conversion from AC to DC is essential. This conversion is achieved by using the Rectifier Circuit/Unit. Step down transformers can step down incoming voltage, which enables you to have the correct voltage input for your electrical needs. For example, if our equipment has been specified for input voltage of 12 volts, and the main power supply is 230 volts, we will need a step down transformer, which decreases the incoming electrical voltage to be compatible with your 12 volt equipment.

6.3 Rectifier Unit


The Rectifier circuit is used to convert the AC voltage into its corresponding DC voltage. The most important and simple device used in Rectifier circuit is the diode. The simple function of the diode is to conduct when forward biased and not to conduct in reverse bias. Now we are using three types of rectifiers. They are 1. 2. 3. Half-wave rectifier Full-wave rectifier Bridge rectifier

6.3.1 Half-wave rectifier: In half wave rectification, either the positive or negative half of the AC wave is passed, while the other half is blocked. Because only one half of the input waveform reaches the output, it is very inefficient if used for power transfer. Half-wave rectification can be achieved with a single diode in a one phase supply, or with three diodes in a threephase supply. 6.3.2 Full-wave rectifier: A full-wave rectifier converts the whole of the input waveform to one of constant polarity (positive or negative) at its output. Full-wave rectification converts both polarities of the input waveform to DC (direct current), and is more efficient. However, in a circuit with a non-center tapped transformer, four diodes are

44

required instead of the one needed for half-wave rectification. A full-wave rectifier uses a diode bridge, made of four diodes, like this:

Figure 8.2: Full wave Rectifier

6.3.3 Bridge rectifier: A bridge rectifier makes use of four diodes in a bridge arrangement to achieve full-wave rectification. This is a widely used configuration, both with individual diodes wired as shown and with single component bridges where the diode bridge is wired internally.

45

Figure 8.3 Bridge Rectifier A diode bridge or bridge rectifier is an arrangement of four diodes in a bridge configuration that provides the same polarity of output voltage for either polarity of input voltage. When used in its most common application, for conversion of alternating current (AC) input into direct current (DC) output, it is known as a bridge rectifier. A bridge rectifier provides full-wave rectification from a two-wire AC input, resulting in lower cost and weight as compared to a center-tapped transformer design. The Forward Bias is achieved by connecting the diodes positive with positive of the battery and negative with batterys negative. The efficient circuit used is the Full wave Bridge rectifier circuit. The output voltage of the rectifier is in rippled form, the ripples from the obtained DC voltage are removed using other circuits available. The circuit used for removing the ripples is called Filter circuit.

6.4 Input filter

46

Capacitors are used as filter. The ripples from the DC voltage are removed and pure DC voltage is obtained. And also these capacitors are used to reduce the harmonics of the input voltage. The primary action performed by capacitor is charging and discharging. It charges in positive half cycle of the AC voltage and it will discharge in negative half cycle. So it allows only AC voltage and does not allow the DC voltage. This filter is fixed before the regulator. Thus the output is free from ripples. There are two types of filters. They are 1. 2. Low pass filter High pass filter

6.4.1 Low pass filter: One simple electrical circuit that will serve as a low-pass filter consists of a resistor in series with a load, and a capacitor in parallel with the load. The capacitor exhibits reactance, and blocks low-frequency signals, causing them to go through the load instead. At higher frequencies the reactance drops, and the capacitor effectively functions as a short circuit. The combination of resistance and capacitance gives you the time constant of the filter = RC (represented by the Greek letter tau). The break frequency, also called the turnover frequency or cutoff frequency (in hertz), is determined by the time constant: or equivalently (in radians per second): One way to understand this circuit is to focus on the time the capacitor takes to charge. It takes time to charge or discharge the capacitor through that resistor: At low frequencies, there is plenty of time for the capacitor to charge up to

practically the same voltage as the input voltage.

47

At high frequencies, the capacitor only has time to charge up a small amount

before the input switches direction. The output goes up and down only a small fraction of the amount the input goes up and down. At double the frequency, there's only time for it to charge up half the amount Another way to understand this circuit is with the idea of reactance at a particular

frequency: Since DC cannot flow through the capacitor, DC input must "flow out" the path

marked Vout (analogous to removing the capacitor). Since AC flows very well through the capacitor almost as well as it flows

through solid wire AC input "flows out" through the capacitor, effectively short circuiting to ground (analogous to replacing the capacitor with just a wire). It should be noted that the capacitor is not an "on/off" object (like the block or

pass fluidic explanation above). The capacitor will variably act between these two extremes. It is the Bode plot and frequency response that show this variability. 6.4.2 High pass filter: A simple 'RC' high-pass filter we should find that passes 'high' frequencies fairly well, but attenuates 'low' frequencies. Hence it is useful as a filter to block any unwanted low frequency components of a complex signal whilst passing higher frequencies. Circuits like this are used quite a lot in electronics as a 'D.C. Block' - i.e. to pass a.c. signals but prevent any D.C. voltages from getting through. The basic quantities which describe this circuit are similar to those used for the Low Pass Filter. In effect, this circuit is just a simple low-pass filter with the components swapped over. As with the low-pass filter, the circuit's behavior we can be understood as arising due to the time taken to change the capacitor's charge when we alter the applied input voltage. It always takes a finite (i.e. non-zero) time to change the amount of charge stored by the capacitor. Hence it takes time to change 48

the potential difference across the capacitor. As a result, any sudden change in the input voltage produces a similar sudden change on the other side of the capacitor. This produces a voltage across the resistor and causes a current to flow thorough it, charging the capacitor until all the voltage falls across it instead of the resistor.

6.5 Regulator Unit

Figure 8.4: 7805 Regulator Regulator regulates the output voltage to be always constant. The output voltage is maintained irrespective of the fluctuations in the input AC voltage. As and then the AC voltage changes, the DC voltage also changes. Thus to avoid this Regulators are used. Also when the internal resistance of the power supply is greater than 30 ohms, the output gets affected. Thus this can be successfully reduced here. The regulators are mainly classified for low voltage and for high voltage. Further they can also be classified as: i) Positive regulator 1---> input pin

49

2---> ground pin 3---> output pin It regulates the positive voltage. ii) Negative regulator 1---> ground pin 2---> input pin 3---> output pin It regulates the negative voltage.

6.6 Fixed Regulators

Figure 8.5: An assortment of 78xx series ICs "Fixed" three-terminal linear regulators are commonly available to generate fixed voltages of plus 3 V, and plus or minus 5 V, 9 V, 12 V, or 15 V when the load is less than about 7 amperes. 6.6.1 7805 Voltage Regulator

50

The 7805 provides circuit designers with an easy way to regulate DC voltages to 5v. Encapsulated in a single chip/package (IC), the 7805 is a positive voltage DC regulator that has only 3 terminals. They are: Input voltage, Ground, Output Voltage. 6.6.1.1 General Features:

Output Current up to 1A Output Voltages of 5, 6, 8, 9, 10, 12, 15, 18, 24V Thermal Overload Protection Short Circuit Protection Output Transistor Safe Operating Area Protection

6.6.2 7812 12V Integrated Circuit3-Terminal Positive Voltage Regulator

The 7812 fixed voltage regulator is a monolithic integrated circuit in a TO220 type package designed for use in a wide variety of applications including local, onboard regulation. This regulator employs internal current limiting, thermal shutdown, and safe area compensation.

With adequate heat-sinking it can deliver output currents in excess of 1.0 ampere. Although designed primarily as a fixed voltage regulator, this device can be used with external components to obtain adjustable voltages and currents.

6.9 Output filter


The Filter circuit is often fixed after the Regulator circuit. Capacitor is most often used as filter. The principle of the capacitor is to charge and discharge. It charges during the positive half cycle of the AC voltage and discharges during the

51

negative half cycle. So it allows only AC voltage and does not allow the DC voltage. This filter is fixed after the Regulator circuit to filter any of the possibly found ripples in the output received finally. Here we used 0.1F capacitor. The output at this stage is 5V and is given to the Microcontroller. The output voltage overshoots when the load is removed or a short clears. When the load is removing from a switching mode power supply with a LC low-pass output filter, the only thing the control loop can do is stop the switching action so no more energy is taken from the source. The energy that is stored in the output filter inductor is dumped into the output capacitor causing a voltage overshoot. The magnitude of the overshoot is the vector sum of two orthogonal voltages, the output voltage before the load is removed and the current through the inductor times the characteristic impedance of the output filter, Zo = (L/C)^1/2. This can be derived from conservation of energy considerations. The initial energy, Ei, is: Ei = 1/2*(L*Ii^2 + C*Vi^2) The final energy, Ef, is: Ef = 1/2*(L*If^2 = C*Vf^2) The two energies are equal when the load is removed, since the load is no longer taking energy from the system. Equating the two energies, substituting zero current for the final inductor current, then the solution for the final voltage Vf is: Vf = (Vi^2 + (Ii*Zo)^2)^1/2 This is the orthogonal vector sum of the output voltage and the load current times the characteristic impedance and is illustrated in Figure 1.

52

Figure 8.6: Overshoot Voltage as Vector Sum The problem becomes worse if the current in the inductor is established by a short circuit on the output and the short circuit clears. In this case, the initial voltage is zero (short circuit) and the overshoot is I*Zo, where I can be very large, resulting in a ruinous overshoot.

6.10 Conclusion
`

By using the step down transformer and the voltage regulators the

required power is supplied to the PIC microcontroller, and the GSM modem

7. SOFTWARE USED
SOFTWARE REQUIREMENTS

7.1 Introduction
The software tools used for the coding in the experiment are: MPLAB Protel

53

Propic HI-Tech PIC C Compiler

7.2 MPLAB Integration


MPLAB Integrated Development Environment (IDE) is a free, integrated toolset for the development of embedded applications employing Microchip's PIC micro and dsPIC microcontrollers. MPLAB IDE runs as a 32-bit application on MS Windows, is easy to use and includes a host of free software components for fast application development and super-charged debugging. MPLAB IDE also serves as a single, unified graphical user interface for additional Microchip and third party software and hardware development tools. Moving between tools is a snap, and upgrading from the free simulator to MPLAB ICD 2 or the MPLAB ICE emulator is done in a flash because MPLAB IDE has the same user interface for all tools. Choose MPLAB C18, the highly optimized compiler for the PIC18 series microcontrollers, or try the newest Microchip's language tools compiler, MPLAB C30, targeted at the high performance PIC24 and dsPIC digital signal controllers. Or, use one of the many products from third party language tools vendors. They integrate into MPLAB IDE to function transparently from the MPLAB project manager, editor and compiler.

7.3 Introduction to Embedded C


HI-TECH Software makes industrial-strength software development tools and C compilers that help software developers write compact, efficient embedded processor code. For over two decades HI-TECH Software has delivered the industry's most reliable embedded software development tools and compilers for writing

54

efficient and compact code to run on the most popular embedded processors. Used by tens of thousands of customers including General Motors, Whirlpool, Qualcomm, John Deere and many others, HI-TECH's reliable development tools and C compilers, combined with world-class support have helped serious embedded software programmers to create hundreds of breakthrough new solutions. HI-TECH PICC is a high-performance C compiler for the Microchip PIC micro 10/12/14/16/17 series of microcontrollers. HI-TECH PICC is an industrial-strength ANSI C compiler - not a subset implementation like some other PIC compilers. The PICC compiler implements full ISO/ANSI C, with the exception of recursion. All data types are supported including 24 and 32 bit IEEE standard floating point. HI-TECH PICC makes full use of specific PIC features and using an intelligent optimizer, can generate high-quality code easily rivaling hand-written assembler. Automatic handling of page and bank selection frees the programmer from the trivial details of assembler code. 7.3.1 Embedded C Compiler ANSI C - full featured and portable Reliable - mature, field-proven technology Multiple C optimization levels An optimizing assembler Full linker, with overlaying of local variables to minimize RAM usage Comprehensive C library with all source code provided Includes support for 24-bit and 32-bit IEEE floating point and 32-bit long data types Mixed C and assembler programming Unlimited number of source files

55

Listings showing generated assembler Compatible - integrates into the MPLAB IDE, MPLAB ICD and most 3rdparty development tools

Runs on multiple platforms: Windows, Linux, UNIX, Mac OS X, Solaris

7.5 Embedded Development Environment


This environment allows you to manage all of your PIC projects. You can compile, assemble and link your embedded application with a single step. Optionally, the compiler may be run directly from the command line, allowing you to compile, assemble and link using one command. This enables the compiler to be integrated into third party development environments, such as Microchip's MPLAB IDE.

7.6 Embedded system Tools


7.6.1 Assembler: An assembler is a computer program for translating assembly language essentially, a mnemonic representation of machine language into object code. A cross assembler (see cross compiler) produces code for one type of processor, but runs on another. The computational step where an assembler is run is known as assembly time. Translating assembly instruction mnemonics into opcodes, assemblers provide the ability to use symbolic names for memory locations and macro facilities for performing textual substitution typically used to encode common short sequences of instructions to run inline instead of in a subroutine. Assemblers are far simpler to write than compilers for high-level languages.

7.7 Phases of compiler


The compiler has a number of phases plus symbol table manager and an error handler. 56

Input

Source

Program Lexical Analyzer Syntax Analyzer Symbol Table Manager Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator Out Target Program Error Handler

7.8 Fabrication details


The fabrication of one demonstration unit is carried out in the following sequence. Finalizing the total circuit diagram, listing out the components and sources of procurement.

57

Procuring the components, testing the components and screening the components. Making layout, repairing the interconnection diagram as per the circuit diagram. Assembling the components as per the component layout and circuit diagram and soldering components. Integrating the total unit, inter wiring the unit and final testing the unit.

7.9 Design of embedded system


Like every other system development design cycle embedded system too have a design cycle. The flow of the system will be like as given below. For any design cycle these will be the implementation steps. From the initial state of the project to the final fabrication the design considerations will be taken like the software consideration and the hardware components, sensor, input and output. The electronics usually uses either a microprocessor or a microcontroller. Some large or old systems use general-purpose mainframe computers or minicomputers.

7.10 User interfaces


User interfaces for embedded systems vary widely, and thus deserve some special comment. User interface is the ultimate aim for an embedded module as to the user to check the output with complete convenience. One standard interface, widely used in embedded systems, uses two buttons (the absolute minimum) to control a menu system (just to be clear, one button should be "next menu entry" the other button should be "select this menu entry"). Another basic trick is to minimize and simplify the type of output. Designs sometimes use a status light for each interface plug, or failure condition, to tell what failed. A cheap variation is to have two light bars with a printed matrix of errors that they select- the user can glue on the labels for the language that he speaks. For example, most small computer printers use lights labeled

58

with stick-on labels that can be printed in any language. In some markets, these are delivered with several sets of labels, so customers can pick the most comfortable language. In many organizations, one person approves the user interface. Often this is a customer, the major distributor or someone directly responsible for selling the system.

7.11 Platform
There are many different CPU architectures used in embedded designs such as ARM, MIPS, Coldfire/68k, PowerPC, X86, PIC, 8051, Atmel AVR, H8, SH, V850, FR-V, M32R etc. This in contrast to the desktop computer market, which as of this writing (2003) is limited to just a few competing architectures, mainly the Intel/AMD x86, and the Apple/Motorola/IBM PowerPC, used in the Apple Macintosh. With the growing acceptance of Java in this field, there is a tendency to even further eliminate the dependency on specific CPU/hardware (and OS) requirements. Standard PC/104 is a typical base for small, low-volume embedded and ruggedized system design. These often use DOS, Linux or an embedded realtime operating system such as QNX or Inferno. A common configuration for very-high-volume embedded systems is the system on a chip, an application-specific integrated circuit, for which the CPU was purchased as intellectual property to add to the IC's design. A related common scheme is to use a field-programmable gate array, and program it with all the logic, including the CPU. Most modern FPGAs are designed for this purpose.

7.12 Tools
Like typical computer programmers, embedded system designers use compilers, assemblers, and debuggers to develop embedded system software. However, they also use a few tools that are unfamiliar to most programmers. 59

Software tools can come from several sources: Software companies that specialize in the embedded market. Ported from the GNU software development tools. Sometimes, development tools for a personal computer can be used if the embedded processor is a close relative to a common PC processor. Embedded system designers also use a few software tools rarely used by typical computer programmers. One common tool is an "in-circuit emulator" (ICE) or, in more modern designs, an embedded debugger. This debugging tool is the fundamental trick used to develop embedded code. It replaces or plugs into the microprocessor, and provides facilities to quickly load and debug experimental code in the system. A small pod usually provides the special electronics to plug into the system. Often a personal computer with special software attaches to the pod to provide the debugging interface. Another common tool is a utility program (often home-grown) to add a checksum or CRC to a program, so it can check its program data before executing it. An embedded programmer that develops software for digital signal processing often has a math workbench such as MathCad or Mathematical to simulate the mathematics. Less common are utility programs to turn data files into code, so one can include any kind of data in a program. A few projects use Synchronous programming languages for extra reliability or digital signal processing.

7.13 Debugging
Debugging is usually performed with an in-circuit emulator, or some type of debugger that can interrupt the microcontroller's internal microcode. The microcode interrupt lets the debugger operate in hardware in which only the 60

CPU works. The CPU-based debugger can be used to test and debug the electronics of the computer from the viewpoint of the CPU. This feature was pioneered on the PDP-11. As the complexity of embedded systems grows, higher level tools and operating systems are migrating into machinery where it makes sense. For example, cell phones, personal digital assistants and other consumer computers often need significant software that is purchased or provided by a person other than the manufacturer of the electronics. In these systems, an open programming environment such as Linux, OSGi or Embedded Java is required so that the third-party software provider can sell to a large market.

7.14 Start up
All embedded systems have start-up code. Usually it disables interrupts, sets up the electronics, tests the computer (RAM, CPU and software), and then starts the application code. Many embedded systems recover from short-term power failures by restarting (without recent self-tests). Restart times under a tenth of a second are common. Many designers have found a few LEDs useful to indicate errors (they help troubleshooting). A common scheme is to have the electronics turn on all of the LED(s) at reset (thereby proving that power is applied and the LEDs themselves work), whereupon the software changes the LED pattern as the Power-On Self Test executes. After that, the software may blink the LED(s) or set up light patterns during normal operation to indicate program execution progress or errors. This serves to reassure most technicians/engineers and some users. An interesting exception is that on electric power meters and other items on the street, blinking lights are known to attract attention and vandalism.

61

7.15 Coding Project code:


#define MX_PIC //Defines for microcontroller #define P16F877A #define MX_UART_TX 6 #define MX_UART_RX 7 //Functions #define MX_CLK_SPEED 20000000 #ifdef _BOOSTC #include <system.h> #endif #ifdef HI_TECH_C #include <pic.h> #endif //Configuration data #ifdef _BOOSTC //Macro function declarations /Variable declarations char COUNT1; char TEMP; char COUNT; char BP; char BP_COUNT; char _LOOP1; //Defines: /**** Macro Substitutions **** 4 = Which ADC Channel

62

40 = Acquisition time 3 = Conversion Speed 0 = VRef+ Option 500 = VRef Voltage x 0.01V ******************************/ //ADC0: //Macro function declarations void ADC0_SampleADC(); char ADC0_ReadAsByte(); short ADC0_ReadAsInt(); float ADC0_ReadAsVoltage(); void ADC0_ReadAsString(char* RETVAL, char RETVAL_SIZE); //Defines: /**** Macro Substitutions **** portc = RTS Port trisc = RTS Data Direction portc = CTS Port trisc = CTS Data Direction 0 = RTS Pin 4 = CTS Pin 1 = UART Selection 0 = Flow Control 0 = Debug Enable 0 = Echo Enable 4 = UART TXSTA Value 129 = UART SPBRG Value RS232_1508062 = Unique ID Unused = Bitbanged Receive Port Register Unused = Bitbanged Receive Data Direction Register Unused = Bitbanged Receive Pin Unused = Bitbanged Transmit Pin 63 (0-SW / 1-UART1 / 2-UART2) (0-Off / 1-On) (0-Off / 1-On) (0-Off / 1-On)

120 = Bitbanged BAUD Rate Delay 0 = Timout 0 = Data Size BitBanged components) 0 = Parity Enable 0 = Legacy Return MSB err flags) Unused = Bitbanged Transmit Port Register Unused = Bitbanged Transmit Data Direction Register ******************************/ #define RS232 RTS_PORT #define RS232 RTS_TRIS #define RS232 CTS_PORT #define RS232 CTS_TRIS #define RS232 RTS_PIN #define RS232 CTS_PIN #define RS232 UART #define RS232 TOUT #define RS232 DATASIZE #define RS232 PARITY #define RS232 LEGACY_RV #if (0 == 1) #define RS232 HARDWARE #endif #if (0 == 1) #define RS232 DEBUG #endif #if (0 == 1) #define RS232 ECHO #endif 64 portc trisc portc trisc 0 4 1 0 0 0 0 (0-No Parity / 1-Odd Parity / 2-Even Parity) (0-Legacy mode return 255 / 1-New mode return Selection (0-Legacy / 1-MS Timeout) (0-8 bits / 1-9 bits / 2-7 bits & Only available on

#if (RS232 UART == 0) #define RS232 SW_BAUD #else #define RS232 TXSTA_VAL #define RS232 SPBRG_VAL #define RS232 SW_BAUD #endif #define RS232 STATUS_LOOP #define RS232 STATUS_TIMEOUT 1 #define RS232 STATUS_RXBYTE 2 //RS2320: //Macro function declarations void RS2320_SendRS232Char(short nChar); void RS2320_SendRS232String(char* String, char MSZ_String); short RS2320_ReceiveRS232Char(short nTimeout); void RS2320_ReceiveRS232String(char* RETVAL, char RETVAL_SIZE, char nTimeout, char NumBytes); void RS2320_RS232_Delay(char mode); //ADC0: //Macro implementations void ADC0_SampleADC() { #define MX_ADC_CHANNEL #define MX_ADC_SAMP_TIME #define MX_ADC_CONV_SP #define MX_ADC_VREF_OPT //set up ADC conversion char old_tris, cnt; //find appropriate bit #if (MX_ADC_CHANNEL == 0) #define MX_ADC_TRIS_MSK 0x01 #define MX_ADC_TRIS_REG trisa 65 40 3 0 4 0 4 129 0 120

#if (MX_ADC_VREF_OPT == 0) adcon1 = 0x0E; #else adcon1 = 0x05; #endif #endif #if (MX_ADC_CHANNEL == 1) #define MX_ADC_TRIS_MSK 0x02 #define MX_ADC_TRIS_REG trisa #if (MX_ADC_VREF_OPT == 0) adcon1 = 0x04; #else adcon1 = 0x05; #endif #endif #if (MX_ADC_CHANNEL == 2) #define MX_ADC_TRIS_MSK 0x04 #define MX_ADC_TRIS_REG trisa #if (MX_ADC_VREF_OPT == 0) adcon1 = 0x02; #else adcon1 = 0x03; #endif #endif #if (MX_ADC_CHANNEL == 3) #define MX_ADC_TRIS_MSK 0x08 #define MX_ADC_TRIS_REG trisa #if (MX_ADC_VREF_OPT == 0) adcon1 = 0x04; #endif 66

#if (MX_ADC_CHANNEL == 4) #define MX_ADC_TRIS_MSK 0x20 #define MX_ADC_TRIS_REG trisa #if (MX_ADC_VREF_OPT == 0) adcon1 = 0x02; #else adcon1 = 0x03; #endif #endif #if (MX_ADC_CHANNEL == 5) #define MX_ADC_TRIS_MSK 0x01 #define MX_ADC_TRIS_REG trise #if (MX_ADC_VREF_OPT == 0) adcon1 = 0x09; #else adcon1 = 0x01; #endif #endif #if (MX_ADC_CHANNEL == 6) #define MX_ADC_TRIS_MSK 0x02 #define MX_ADC_TRIS_REG trise #if (MX_ADC_VREF_OPT == 0) adcon1 = 0x00; #else adcon1 = 0x01; #endif #endif #if (MX_ADC_CHANNEL == 7) #define MX_ADC_TRIS_MSK 0x04 #define MX_ADC_TRIS_REG trise 67

#if (MX_ADC_VREF_OPT == 0) adcon1 = 0x00; #else adcon1 = 0x01; #endif #endif //assign conversion speed #if (MX_ADC_CONV_SP > 3) st_bit(adcon1, ADCS2); #endif //store old tris value, and set the i/o pin as an input old_tris = MX_ADC_TRIS_REG; MX_ADC_TRIS_REG MX_ADC_TRIS_MSK; //turn ADC on adcon0 = (0x01 | (MX_ADC_CONV_SP << 6)) | (MX_ADC_CHANNEL << 3); //wait the acquisition time cnt = 0; while (cnt < MX_ADC_SAMP_TIME) cnt++; //begin conversion and wait until it has finished adcon0 = adcon0 | 0x04; while (adcon0 & 0x04); //restore old tris value, and reset adc registers 68 = MX_ADC_TRIS_REG |

MX_ADC_TRIS_REG = old_tris; adcon1 = 0x07; adcon0 = 0x00; #undef MX_ADC_CHANNEL #undef MX_ADC_TRIS_REG #undef MX_ADC_TRIS_MSK #undef MX_ADC_SAMP_TIME #undef MX_ADC_CONV_SP #undef MX_ADC_VREF_OPT } char ADC0_ReadAsByte() { ADC0_SampleADC(); return adresh; } //RS2320: //Macro implementations void RS2320_SendRS232Char(short nChar) { #if (RS232 UART == 0) char dMask; char idx; char count = 8; #ifdef RS232 HARDWARE //wait until CTS is low while CTS_PIN) ) != 0); #endif #if(RS232 DATASIZE == 1) count = 9; 69 (( RS232 CTS_PORT & (1 << RS232

#endif #if(RS232 DATASIZE == 2) count = 7; #endif clear_bit( RS232 TX_PORT, RS232 SW_TX); Send Start bit RS2320_RS232_Delay(0); for (idx = 0; idx < count; idx++) { dMask = nChar & 0x01; // Mask off data bit if (dMask) set_bit( RS232 TX_PORT, RS232 SW_TX); else clear_bit( RS232 TX_PORT, RS232 SW_TX); RS2320_RS232_Delay(0); nChar = nChar >> 1; // Move to next data bit } set_bit( RS232 TX_PORT, RS232 SW_TX); Send Stop bit RS2320_RS232_Delay(0); #endif } void RS2320_SendRS232String(char* String, char MSZ_String) { char idx; for(idx = 0; idx < MSZ_String; idx++) { #ifdef _BOOSTC 70 // //

if (String[idx] == 0) break; else RS2320_SendRS232Char(String[idx]); #endif #ifdef HI_TECH_ if (*String == 0) break; else RS2320_SendRS232Char(*String); String++; #endif } } short RS2320_ReceiveRS232Char(short nTimeout) { char delay1 = 0; char delay2 = 0; char regcheck = 0; char dummy = 0; short retVal = 512; char bWaitForever = 0; char rxStatus = RS232 STATUS_LOOP; char idx; char count = 8; #if ( RS232 LEGACY_RV == 0) retVal = 255; #endif #ifdef RS232 HARDWARE //ready to accept data clear_bit( RS232 RTS_PORT, RS232 RTS_PIN); 71

#endif if (nTimeout == 255) bWaitForever = 1; while (rxStatus == RS232 STATUS_LOOP) { if (bWaitForever == 0) { //don't wait forever, so do timeout thing... if (nTimeout == 0) { rxStatus = RS232 STATUS_TIMEOUT; } else { if ( RS232 TOUT) { delay_us(10); delay1 = delay1 + 1; if(delay1 == 100) { nTimeout = nTimeout - 1; delay1 = 0; } } else { //decrement timeout delay1 = delay1 - 1; if (delay1 == 0) { 72

nTimeout = nTimeout - 1; } } } } #if ( RS232 UART == 0) regcheck = test_bit(RS232 RX_PORT, RS232 SW_RX); //Test for start bit if (regcheck == 0) rxStatus = RS232 STATUS_RXBYTE; #endif } if (rxStatus == RS232 STATUS_RXBYTE) { #if ( RS232 UART > 0) #if ( RS232 UART == 1) regcheck = ts_bit(rcsta, FERR); #endif #if ( RS232 UART == 2) regcheck = ts_bit(rcsta2, FERR); #endif if (regcheck != 0) { #if ( RS232 UART == 1) dummy = rcreg; the rcreg to clear FERR #endif #if ( RS232 UART == 2) 73 //need to read

dummy = rcreg2; the rcreg to clear FERR #endif #ifdef RS232 DEBUG

//need to read

RS2320_SendRS232Char('<'); RS2320_SendRS232Char('F'); RS2320_SendRS232Char('E'); RS2320_SendRS232Char('R'); RS2320_SendRS232Char('R'); RS2320_SendRS232Char('>'); #endif #if ( RS232 LEGACY_RV == 1) retVal = 0x400; //Framing Error Flag #endif } else { #if ( RS232 UART == 1) regcheck = ts_bit(rcsta, OERR); #endif #if ( RS232 UART == 2) regcheck = ts_bit(rcsta2, OERR); #endif if (regcheck != 0) { 74

//need to read the rcreg to clear error #if ( RS232 UART == 1) cr_bit(rcsta, CREN); st_bit(rcsta, CREN); #endif #if ( RS232 UART == 2) cr_bit(rcsta2, CREN); st_bit(rcsta2, CREN); #endif #ifdef RS232 DEBUG RS2320_SendRS232Char('<'); RS2320_SendRS232Char('O'); RS2320_SendRS232Char('E'); RS2320_SendRS232Char('R'); RS2320_SendRS232Char('R'); RS2320_SendRS232Char('>'); #endif #if ( RS232 LEGACY_RV == 1) retVal = 0x800; //Overrun Error Flag #endif } else { #if ( RS232 UART == 1) 75

retVal = rcreg; #if( RS232 DATASIZE == 1)

//no error, so rx byte is valid if(ts_bit(rcsta, RX9D)); retVal = retVal | 0x100; #endif #endif #if ( RS232 UART == 2)

retVal = rcreg2;

//no error, so rx byte is valid if(ts_bit(rcsta2, RX9D)); retVal = retVal | 0x100; #endif #endif #ifdef RS232 ECHO S2320_SendRS232Char(retVal); #endif } }

#if( RS232 DATASIZE == 1)

#else #if( RS232 DATASIZE == 1) count = 9; #endif RS2320_RS232_Delay(1); for (idx = 0; idx < count; idx++) { retVal = retVal >> 1; if(count == 9) { 76

if (test_bit( RS232 RX_PORT, RS232 SW_RX)) retVal = retVal | 0x100; } else { if (test_bit( RS232 RX_PORT, RS232 SW_RX)) retVal = retVal | 0x80; } RS2320_RS232_Delay(1); } #ifdef RS232 ECHO RS2320_SendRS232Char(retVal); #endif #endif } #ifdef RS232 HARDWARE //not ready to accept data set_bit( RS232 RTS_PORT, RS232 RTS_PIN); #endif return (retVal); } void RS2320_ReceiveRS232String(char* RETVAL, char RETVAL_SIZE, char nTimeout, char NumBytes) { char idx; short in; 77

#if ( RS232 LEGACY_RV == 0 ) #define RS232_TO #else #define RS232_TO #endif if (NumBytes > RETVAL_SIZE) NumBytes = RETVAL_SIZE; for (idx = 0; idx < NumBytes; idx++) { in = RS2320_ReceiveRS232Char(nTimeout); if(in < RS232_TO) RETVAL[idx] = in & 0xFF; else break; } if (idx < RETVAL_SIZE) RETVAL[idx] = 0; #undef RS232_TO } void RS2320_RS232_Delay(char mode) { unsigned int iterations; unsigned int delay = RS232 SW_BAUD; if (mode) delay = delay + 1; 78 256 255

for (iterations = 0; iterations < delay; iterations++); } //Macro implementations void main() { //Initialisation adcon1 = 0x07; #if (RS232 UART == 0) set_bit(RS232 RX_TRIS, RS232 SW_RX); // Receive pin is a input clear_bit(RS232 TX_TRIS, RS232 SW_TX); // Transmit pin is a output set_bit(RS232 TX_PORT, RS232 SW_TX);// Transmit pin is default high #endif #if (RS232 UART == 1) txsta = RS232 TXSTA_VAL; // 8-bit, async, low speed, off spbrg = RS232 SPBRG_VAL; // set the baud rate rcsta = 0; if(RS232 DATASIZE == 1) { st_bit(txsta, TX9); // 9-bit TX st_bit(rcsta, RX9); } st_bit(rcsta, SPEN); turn on serial interface #endif #if (RS232 UART == 2) txsta2 = RS232 TXSTA_VAL; // 8-bit, async, low speed, off 79 // // 9-bit RX // 8-bit, disabled

spbrg2 = RS232 SPBRG_VAL;// set the baud rate rcsta2 = 0; if(RS232 DATASIZE == 1) { st_bit(txsta2, TX9); st_bit(rcsta2, RX9); } st_bit(rcsta2, SPEN); #endif #ifdef RS232 HARDWARE set_bit( RS232 CTS_TRIS, RS232 CTS_PIN); clear_bit( RS232 RTS_TRIS, RS232 RTS_PIN); set_bit( RS232 RTS_PORT, RS232 RTS_PIN); #endif //Interrupt initialisation code option_reg = 0xC0; //Delay //Delay: 760 ms delay_ms(255); delay_ms(255); delay_ms(250); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("AT") RS2320_SendRS232String("AT",2); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x0d) RS2320_SendRS232Char(0x0d); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("ATE0") RS2320_SendRS232String("ATE0",4); 80 //CTS is an input //RTS is an output // turn on serial interface // 9-bit TX // 9-bit RX // 8-bit, disabled

//not ready to accept data

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x0d) RS2320_SendRS232Char(0x0d); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("AT&W") RS2320_SendRS232String("AT&W",4); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x0d) RS2320_SendRS232Char(0x0d); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("AT+CMGF=1") RS2320_SendRS232String("AT+CMGF=1",9);

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x0d) RS2320_SendRS232Char(0x0d); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("AT+CNMI=1,2,0,0,0") RS2320_SendRS232String("AT+CNMI=1,2,0,0,0",17); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x0d) RS2320_SendRS232Char(0x0d); //Delay //Delay: 20 ms delay_ms(20); //Loop //Loop: While 1 81

while (1) { //Call Component Macro //Call Component Macro: temp=ADC(0)::ReadAsByte TEMP = ADC0_ReadAsByte(); //Input //Input: E0 -> bp trise = trise | 0x01; BP = ((porte & 0x01) == 0x01); //Decision //Decision: bp=1? if (BP==1) { //Calculation //Calculation: // bp_count = bp_count+1 BP_COUNT = BP_COUNT+1; //Loop //Loop: Loop 10 times for (_LOOP1=0; _LOOP1<10; _LOOP1++) { //Input //Input: B0 -> bp trisb = trisb | 0x01; BP = ((portb & 0x01) == 0x01); //Decision //Decision: bp=1? if (BP==1) { //Calculation 82

//Calculation: // bp_count = bp_count+1 BP_COUNT = BP_COUNT+1; }

} //Calculation //Calculation: // bp_count = bp_count*6 BP_COUNT = BP_COUNT*6;

//Decision //Decision: bp_count>80? if (BP_COUNT>80) { //Decision //Decision: count=0? if (COUNT==0) { //Calculation //Calculation: // count = 1 COUNT = 1; //Ca ll Component Macro //Call Component Macro: RS232(0)::SendRS232String("AT+CMGS=") RS2320_SendRS232String("AT+CMGS=",8);

83

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x22) RS2320_SendRS232Char(0x22); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char("9342182423") RS2320_SendRS232Char('9'); RS2320_SendRS232Char('3'); RS2320_SendRS232Char('4'); RS2320_SendRS232Char('2'); RS2320_SendRS232Char('1'); RS2320_SendRS232Char('8'); RS2320_SendRS232Char('2'); RS2320_SendRS232Char('4'); RS2320_SendRS232Char('2'); RS2320_SendRS232Char('3'); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x22) RS2320_SendRS232Char(0x22); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x0d) RS2320_SendRS232Char(0x0d); //Delay //Delay: 20 ms delay_ms(20); //Call Component Macro //Call Component Macro: 84

RS232(0)::SendRS232String("Increase in heartbeat") RS2320_SendRS232String("Increase in heartbeat",21); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x1a) RS2320_SendRS232Char(0x1a); //Delay //Delay: 2 s delay_s(2); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("AT+CMGS=") RS2320_SendRS232String("AT+CMGS=",8);

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x22) RS2320_SendRS232Char(0x22);

//Call Component Macro //Call RS232(0)::SendRS232Char("9535424613") RS2320_SendRS232Char('9'); RS2320_SendRS232Char('5'); RS2320_SendRS232Char('3'); RS2320_SendRS232Char('5'); RS2320_SendRS232Char('4'); RS2320_SendRS232Char('2'); RS2320_SendRS232Char('4'); 85 Component Macro:

RS2320_SendRS232Char('6'); RS2320_SendRS232Char('1'); RS2320_SendRS232Char('3');

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x22) RS2320_SendRS232Char(0x22);

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x0d) RS2320_SendRS232Char(0x0d);

//Delay //Delay: 20 ms delay_ms(20);

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("Increase in heartbeat") RS2320_SendRS232String("Increase in heartbeat",21);

//Call Component Macro

86

//Call Component Macro: RS232(0)::SendRS232Char(0x1a) RS2320_SendRS232Char(0x1a); //Delay //Delay: 2 s delay_s(2); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("AT+CMGS=") RS2320_SendRS232String("AT+CMGS=",8); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x22) RS2320_SendRS232Char(0x22); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char("9538755508") RS2320_SendRS232Char('9'); RS2320_SendRS232Char('5'); RS2320_SendRS232Char('3'); RS2320_SendRS232Char('8'); RS2320_SendRS232Char('7'); RS2320_SendRS232Char('5'); RS2320_SendRS232Char('5'); RS2320_SendRS232Char('5'); RS2320_SendRS232Char('0'); RS2320_SendRS232Char('8'); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x22) 87

RS2320_SendRS232Char(0x22); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x0d) RS2320_SendRS232Char(0x0d); //Delay //Delay: 20 ms delay_ms(20); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("Increase in heartbeat") RS2320_SendRS232String("Increase in heartbeat",21);

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x1a) RS2320_SendRS232Char(0x1a); //Delay //Delay: 2 s delay_s(2); } } else { //Calculation //Calculation: // count = 0 COUNT = 0; } } //Decision 88

//Decision: temp>35? if (TEMP>35) { //Decision //Decision: count1=0? if (COUNT1==0) { //Calculation //Calculation: // count1 = 1 COUNT1 = 1;

//Call Component Macro //Call RS232(0)::SendRS232String("AT+CMGS=") RS2320_SendRS232String("AT+CMGS=",8); Component Macro:

//Call Component Macro //Call RS232(0)::SendRS232Char(0x22) RS2320_SendRS232Char(0x22); Component Macro:

//Call Component Macro //Call RS232(0)::SendRS232Char("9342182423") RS2320_SendRS232Char('9'); RS2320_SendRS232Char('3'); 89 Component Macro:

RS2320_SendRS232Char('4'); RS2320_SendRS232Char('2'); RS2320_SendRS232Char('1'); RS2320_SendRS232Char('8'); RS2320_SendRS232Char('2'); RS2320_SendRS232Char('4'); RS2320_SendRS232Char('2'); RS2320_SendRS232Char('3'); //Call Component Macro //Call RS232(0)::SendRS232Char(0x22) RS2320_SendRS232Char(0x22); Component Macro:

//Call Component Macro //Call RS232(0)::SendRS232Char(0x0d) RS2320_SendRS232Char(0x0d); //Delay //Delay: 20 ms delay_ms(20); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("Increase in Temperature") RS2320_SendRS232String("Increase in Temperature",23); Component Macro:

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x1a) 90

RS2320_SendRS232Char(0x1a); //Delay //Delay: 2 s delay_s(2); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("AT+CMGS=") RS2320_SendRS232String("AT+CMGS=",8); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x22) RS2320_SendRS232Char(0x22); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char("9535424613") RS2320_SendRS232Char('9'); RS2320_SendRS232Char('5'); RS2320_SendRS232Char('3'); RS2320_SendRS232Char('5'); RS2320_SendRS232Char('4'); RS2320_SendRS232Char('2'); RS2320_SendRS232Char('4'); RS2320_SendRS232Char('6'); RS2320_SendRS232Char('1'); RS2320_SendRS232Char('3'); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x22) RS2320_SendRS232Char(0x22); 91

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x0d) RS2320_SendRS232Char(0x0d); //Delay //Delay: 20 ms delay_ms(20); //Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("Increase in Temperature") RS2320_SendRS232String("Increase Temperature",23); in

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x1a) RS2320_SendRS232Char(0x1a);

//Delay //Delay: 2 s delay_s(2);

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("AT+CMGS=") RS2320_SendRS232String("AT+CMGS=",8);

92

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x22) RS2320_SendRS232Char(0x22);

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char("9538755508") RS2320_SendRS232Char('9'); RS2320_SendRS232Char('5'); RS2320_SendRS232Char('3'); RS2320_SendRS232Char('8'); RS2320_SendRS232Char('7'); RS2320_SendRS232Char('5'); RS2320_SendRS232Char('5'); RS2320_SendRS232Char('5'); RS2320_SendRS232Char('0'); RS2320_SendRS232Char('8');

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x22) RS2320_SendRS232Char(0x22);

//Call Component Macro

93

//Call Component Macro: RS232(0)::SendRS232Char(0x0d) RS2320_SendRS232Char(0x0d);

//Delay //Delay: 20 ms delay_ms(20);

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("Increase in Temperature") RS2320_SendRS232String("Increase in Temperature",23);

//Call Component Macro //Call Component Macro: RS232(0)::SendRS232Char(0x1a) RS2320_SendRS232Char(0x1a);

//Delay //Delay: 2 s delay_s(2);

94

} else { //Calculation //Calculation: // count1 = 0 COUNT1 = 0;

//Delay //Delay: 500 ms delay_ms(255); delay_ms(245);

mainendloop: goto mainendloop; }

95

96

7.16 Flow Chart

97

98

99

100

101

102

8. CONCLUSION AND FUTURE SCOPE

The project Patient Monitoring System and Data Acquisition Through GSM has been successfully designed and tested
It has been developed by integrating features of all the hardware components used. Presence of every module has been reasoned out and placed carefully thus contributing to the best working of the unit. Secondly, using highly advanced ICs and with the help of growing technology the project has been successfully implemented.

The Whole health monitoring system,which we have proposed can be integrated into a small compact unit as small as a cell phone or a wrist watch.This will help the patients to easily carry this device with them wherever

103

they go.The VLSI technologies will greatly come handy in this regard.

8.Bibliography
Customizing and programming ur pic microcontroller- Myke Predcko Micro controllers and applications -Ajay V Dehmukh Electronics measurement and instrumentation - Kalsi C programming for embedded systems- Kirk Zurell Teach yourself electronics and electricity- Stan Giblisco Embedded PIC microcontroller- John Peatman Wireless communications Theodore S. Rappaport Embedded C Michael J.Pont Developing Embedded Software in C Janathan.W.Valvano PIC Microcontroller Project Book John Lovine

Fundamentals of Micro processors and Micro computers -B.Ram Micro processor Architecture, Programming & Applications

104

-Ramesh S.Gaonkar Wireless Communications -Theodore S. Rappaport Mobile Tele Communications -William C.Y. Lee References on the Web: [1]Analog Temperature Sensors. www.national.com [2]pic18f77a Architecture. www.microsoftsearch.com [3]modems. www.howstuffworks.com [4].Current GSM Constellations http://tycho.usno.navy.mil/gsmcurr.html

105

APPENDIX AT Commands
AT commands are instructions used to control a modem. AT is the abbreviation of ATtention. Every command line starts with "AT" or "at". That's why modem commands are called AT commands. Many of the commands that are used to control wired dial-up modems, such as ATD (Dial), ATA (Answer), ATH (Hook control) and ATO (Return to online data state), are also supported by GSM/GPRS modems and mobile phones. Besides this common AT command set, GSM/GPRS modems and mobile phones support an AT command set that is specific to the GSM technology, which includes SMS-related commands like AT+CMGS (Send SMS message), AT+CMSS (Send SMS message from storage), AT+CMGL (List SMS messages) and AT+CMGR (Read SMS messages). Note that the starting "AT" is the prefix that informs the modem about the start of a command line. It is not part of the AT command name. For example, D is the actual AT command name in ATD and +CMGS is the actual AT command name in AT+CMGS. However, some books and web sites use them interchangeably as the name of an AT command. Here are some of the tasks that can be done using AT commands with a GSM/GPRS modem or mobile phone:

106

Get basic information about the mobile phone or GSM/GPRS modem. For example, name of manufacturer (AT+CGMI), model number (AT+CGMM), IMEI number (International Mobile Equipment Identity) (AT+CGSN) and software version (AT+CGMR).

Get basic information about the subscriber. For example, MSISDN (AT+CNUM) and IMSI number (International Mobile Subscriber Identity) (AT+CIMI).

Get the current status of the mobile phone or GSM/GPRS modem. For example, mobile phone activity status (AT+CPAS), mobile network registration status (AT+CREG), radio signal strength (AT+CSQ), battery charge level and battery charging status (AT+CBC).

Establish a data connection or voice connection to a remote modem (ATD, ATA, etc). Send and receive fax (ATD, ATA, AT+F*). Send (AT+CMGS, AT+CMSS), read (AT+CMGR, AT+CMGL), write (AT+CMGW) or delete (AT+CMGD) SMS messages and obtain notifications of newly received SMS messages (AT+CNMI).

Read

(AT+CPBR),

write (AT+CPBW)

or search

(AT+CPBF)

phonebook entries.

Perform security-related tasks, such as opening or closing facility locks (AT+CLCK), checking whether a facility is locked (AT+CLCK) and changing passwords (AT+CPWD). (Facility lock examples: SIM lock [a password must be given to the SIM card every time the mobile phone is switched on] and PH-SIM lock [a certain SIM card is associated with the mobile phone. To use other SIM cards with the mobile phone, a password must be entered.])

Control the presentation of result codes / error messages of AT commands. For example, you can control whether to enable certain error messages (AT+CMEE) and whether error messages should be displayed in numeric format or verbose format (AT+CMEE=1 or AT+CMEE=2). 107

Get or change the configurations of the mobile phone or GSM/GPRS modem. For example, change the GSM network (AT+COPS), bearer service type (AT+CBST), radio link protocol parameters (AT+CRLP), SMS center address (AT+CSCA) and storage of SMS messages (AT+CPMS).

Save and restore configurations of the mobile phone or GSM/GPRS modem. For example, save (AT+CSAS) and restore (AT+CRES) settings related to SMS messaging such as the SMS center address.

108