Beruflich Dokumente
Kultur Dokumente
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.
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
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
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.
TEMP SENSOR
OP-AMP
MICROCONTROLLER
GSM
LED
L D R
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.
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.
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
SENSORS
A sensor is a transducer which converts physical quantities to electrical quantities.
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
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.
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
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.
17
18
19
4.4 Architecture
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.
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.
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.
28
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.
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
33
34
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
(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
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
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.
40
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.
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
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.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:
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.
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
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.
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.
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
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.
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
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
Input
Source
Program Lexical Analyzer Syntax Analyzer Symbol Table Manager Semantic Analyzer Intermediate Code Generator Code Optimizer Code Generator Out Target Program Error Handler
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.
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
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
//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 } }
#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
//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
//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 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:
//Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("Increase in heartbeat") RS2320_SendRS232String("Increase in heartbeat",21);
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;
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:
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
92
//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');
93
//Call Component Macro //Call Component Macro: RS232(0)::SendRS232String("Increase in Temperature") RS2320_SendRS232String("Increase in Temperature",23);
94
95
96
97
98
99
100
101
102
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