Você está na página 1de 58

Chapter1:Introduction

INTRODUCTION
Electricity is one of the vital requirement for sustainment of comforts of life. IT should be used very judiciously for its proper utilization. But in our country we have lot of localities where we have surplus supply for the electricity while many areas do not even have access to it. Our policies of its distribution are also partially responsible for this because we are still not able to correctly estimate our exact requirements and still power theft is prevailing. On the other hand consumers are also not satisfied with the services of power companies. Most of the time they have complaints regarding statistical errors in their monthly bills. Thus we are trying to present an idea towards the minimization of technical errors and to reduce human dependency at the same time. With the help of this project we are aiming to receive the monthly energy consumption from a remote location directly to a centralized office. In this way we can reduce human efforts needed to record the meter readings which are till now recorded by visiting every home individually. This results in considerable loss of human hours and also provides considerable details regarding the average consumption of a locality so that power supply can be made according to these data. This will help the officials in deciding the specifications of transformers and other instruments required in power transmission. This idea is economically efficient as well because we can get the meter reading at a very low cost. The implementation is done in such a way that a SMS is delivered to the Modem whose reading is to be noted and then that meter replies to the server in the SMS format and it is known that SMS costs are very low.

The purpose of this project is to remote monitoring and control of the Domestic Energy meter. This system enables the Electricity Department to read the meter readings regularly without the person visiting each house.

This can be achieved by the use of Microcontroller unit that continuously monitors and records the Energy Meter readings in its permanent (non-volatile) memory location. This system also
1

makes use of a GSM modem for remote monitoring and control of Energy Meter.

The Microcontroller based system continuously records the readings and the live meter reading can be sent to the Electricity department on request. This system also can be used to disconnect the power supply to the house in case of non-payment of electricity bills. A dedicated GSM modem with SIM card is required for each energy meter.

The GSM AMR takes the advantage of available GSM infrastructure nationwide coverage and the Short Messaging System (SMS) cell broadcasting feature to request and retrieve individual houses and building power consumption reading back to the energy provider wirelessly.

The Store and Forwarding feature of SMS allow reliable meter reading delivery when GSM signsl is affected by the poor weather conditions. The stored message is archive in the mobile operator and can be later retrieve for billing purposes.

History of Meters:
Over the past years electric energy meters have undergone phenomenal changes and are expected to become even more sophisticated , offering more and more services.

The electromechanical based energy meters are rapidly being replaced by digital energy meters which offer high accuracy and precision. Now the generation of electric energy meters is that of AMRs. Various features offered by AMR are given below:

1) Higher speed 2) Improved load profile 3) Automatic billing invoice 4) Real time energy cost 5) Alarm warning 6) Remote power switches ON/OFF

OBJECTIVES OF ENERGY METER:


Programming of remote modem with AT commands Interfacing programming chip with the computer Interfacing programming chip with energy meter Sending message from the MODEM to remote mobile phone.

Messaging Over GSM Network:

Global System for Mobile Communication (GSM) is the worlds most popular standard for mobile telephony systems. GSM is used by over 1.5 billion people all over the world. GSM also pioneered the low cost implementation of the Short Message Service (SMS) which allows parties to exchange delay tolerant short text messages. The popularity and coverage of cellular networks allows the use of SMS service.

However there are certain questionable issues regarding the GSM network such as scalability, reliability and security especially under high load. According to the analysis of real data taken from a real GSM network in India, SMS delivery success rate is found to be 94.3%. Of these successfully delivered messages, 73.3 arrived to their destination within 10 seconds. About 5% of them required more than 1 hour to reach the destination.

Using SMS for AMR will certainly increase the flow of messages tremendously. GSM uses several cryptographic algorithms for security. The development of UMTS introduces an optional Universal Subscriber Identity Module (USIM), which uses a longer authentication key to give greater security, as well as mutually authenticating the network and the user.

Methodology:
The method used to carry out this project is the principle of serial communication in collaboration with embedded system. The project has a electric meter which will work and a GSM modem which is the latest technology used for communication between MODEM and embedded systems. The modem will send a message as and when desired to the electricity officials through Subscriber Identity Module inserted inside the MODEM.

System Overview:
The complete overview of GSM AMR system is shown below and consists of GSM energy meter with installed in every individual unit. On the other hand SMS gateway, application terminal and database server are present at the energy provider side. This AMR system works in conjunction with the GSM network to retrieve the power meter reading using SMS. The GSM energy meter is an integration of an electric meter with a GSM modem. A SIM card with a unique special number is required for meter to receive and reply its energy meter readings to the energy provider using SMS. The SIM number is identical to the one used for mobile phones except it is not used for voice communications. The SIM card is also used to identify and retrieve owner or consumer details from the database server for billing purposes. An automatic power reading takes place automatically on request by the energy provider. SMS gateway performs cell broadcasting of request through SMS to all meters to request for meter reading. The meter will immediately respond in the form of meter readings upon receiving the request from the energy provider.

Figure-1

BLOCK DIAGRAM:

Figure-2

LITERATURE SURVEY:
In order to overcome the problems of the existing traditional meter reading system , efforts are underway around the world to automate the meter reading systems and to provide comprehensive information to the consumer for efficient use of utilities. Researchers have proposed different implementation techniques for AMR. One is the SMS-based Reconfigurable Automatic Meter Reading System which uses the GSM network for sending the ARM data. The other technique is secure and scalable automated reading system which uses the existing local ISPs instead of requiring its own proprietary set communication infrastructure. The gateway node basically consists of an embedded microprocessor system, based on embedded linux, and a modem. The remote real time automatic reading system employs distributed structure based on wireless sensor networks which consists of measure units, sensor nodes, data collectors, server and wireless communication network.

Chapter2: GSM Modem


Introduction To GSM Network
GSM (Global System for Mobile Communication)
GSM has been the backbone of the phenomenal success of mobile communication in the previous decade. Now at the dawn of true broadband services, GSM continues to evolve to meet new demands. GSM is an open, non proprietary system with international roaming capability. GSM was originally known as Groupe Speciale Mobile but nowadays it is commonly referred as Global System for Mobile Communication. It is a set of standards developed by the European Telecommunications Standards Institute (ETSI) to describe technologies used for second generation digital communications, commonly referred as 2G technologies. It was developed as a replacement to the first generation analog communications. It originally described a digital circuit switched network optimised for full duplex voice communications. The standard was expanded over time to include first circuit switched data transfer, then packet data transport via GPRS (General Packet Radio Service). Packet data transmission speed were later increased with the help of EDGE (Enhanced Data Rate for GSM evolution) technology. The GSM standard is succeeded by third generation (3G) UMTS standard developed by the 3GPP.

TECHNICAL DETAILS:
GSM is a cellular network which means that compatible devices connect to it by searching for cells in the immediate vicinity. There are five different cell sizes in a GSM network viz. Macro, 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 base station is installed on a mast or building above roof top level.

Micro cells are those in which base station is installed below the average roof top level. They are typically used in urban areas. Pico cells are the cells whose coverage area is a few dozen metres in diameter and are mainly used indoors. Femto cells are cells designed for use in residential or small business environment and connect to the service providers network via a broadband internet connection. Umbrella cells are used to cover shadowed reasons of smaller cells and fill in gaps in coverage between those cells.

MODULATION USED:
The modulation used in GSM is Gaussian Minimum Phase Shift Keying (GMSK), a kind of continuous phase frequency shift keying. In GMSK the signal to be modulated on the carrier is first smoothed with a Gaussian low-pass filter prior to being fed into a frequency modulator which greatly reduces the interference to neighbouring channels (adjacent channel interference).

GSM Carrier Frequencies used:


GSM networks operate in a number of frequency bands (separated into GSM frequency range for 2G and UMTS frequency range for 3G). Most 2G GSM networks operate in the 900 MHz or 1800 MHz frequency bands. Where these bands are already occupied 850 MHz or 1950 MHz frequency bands are used e.g. in USA and Canada. In rare cases 400 and 450 MHz bands are allocated because they were earlier used for first generation communications. Most of the 3G GSM networks operate in the 2100 MHz frequency band. Regardless of frequency selected by an operator, it is divided into time slots for individual users to use. This allows eight full rate or sixteen half rate speech channels per radio frequency. These eight radio slots are grouped into a TDMA frame. The channel data rate for all 8 channels is 270.833 Kbps and the time duration is 4.615 ms.
9

GSM Network structure:

Figure-3

(GSM Network structure)

10

Figure-4 The network is structured into a number of discrete sections: 1) The base station subsystem (base stations and their controllers) 2) The network and switching subsystem (part of network most similar to fixed network) 3) The GPRS core network (optional part which allow packet based internet connections) 4) Operations support system (OSS) for system maintenance.

Working of Modem:
Modems are devices that let computers transmit information over ordinary telephone lines. The word explains how the device works: modem is an acronym for "modulator/demodulator." Modems translate a stream of information into a series of tones (modulation) at one end of the telephone line, and translate the tones back into the serial stream at the other end of the connection (demodulation). Most modems are bidirectional?every modem contains both a modulator and a demodulator, so a data transfer can take place in both directions simultaneously. Modems have a flexibility that is unparalleled by other communications technologies. Because modems work with standard telephone lines, and use the public telephone network to route their conversations, any computer that is equipped with a modem and a telephone line can
11

communicate with any other computer that has a modem and a telephone line, anywhere in the world. Modems thus bypass firewalls, packet filters, and intrusion detection systems. What's more, even in this age of corporate LANs, cable modems, and DSL links, dialup modems are still the single most common way that people access the Internet. This trend is likely to continue through the first decade of the 21st century because dialup access is dramatically cheaper to offer than high-speed, always-on services. Information inside most computers moves in packets of 8, 16, 32, or 64 bits at a time, using 8, 16, 32, or 64 individual wires. When information leaves a computer, however, it is often organized into a series of single bits that are transmitted sequentially. Often, these bits are grouped into 8-bit bytes for purposes of error checking or special encoding. Serial interfaces transmit information as a series of pulses over a single wire. A special pulse called the start bit signifies the start of each character. The data is then sent down the wire, one bit at a time, after which another special pulse called the stop bit is sent .

Figure-5
Because a serial interface can be set up with only three wires (transmit data, receive data, and ground), it's often used with terminals. With additional wires, serial interfaces can be used to control modems, allowing computers to make and receive telephone calls.

12

Testing of GSM Modem:


To use MS HyperTerminal to send AT commands to the GSM modem, the following procedure is followed 1. I put a valid SIM (MTN) card into the GSM modem. I obtain a SIM card by subscribing to the GSM service of a wireless network operator. 2. No need to install any driver for the GSM modem 3. Then I set up MS HyperTerminal by selecting Start -> Programs -> Accessories -> Communications -> HyperTerminal. 4. In the Connection Description dialog box (as shown in the screenshot given below), I enter any file name and choose an icon I like for the connection. Then I click the OK button. In the Connect To dialog box, choose the COM port that your mobile phone or GSM modem is connecting to in the Connect using combo box. I choose COM1 because my mobile phone is connected to the COM1 port. Then click the OK button. Type "AT" in the main window. A response "OK" will be returned from the mobile phone or GSM modem. Type "AT+CPIN?" in the main window. The AT command "AT+CPIN?" is used to query whether the mobile phone or GSM modem is waiting for a PIN (personal identification number, i.e. password). If the response is "+CPIN: READY", it means the SIM card does not require a PIN and it is ready for use. If my SIM card requires a PIN, you need to set the PIN with the AT command "AT+CPIN=<PIN>". After successfully testing the MODEM for its correct operational state, I then set the MODEM parameters like Baud rate, Echo off etc to enable easier access via a microcontroller which I used in this project. The following are the ATCOMMAND used for programming the gsm modem

RS-232 Serial Protocol


One of the most common serial interfaces is based on the RS-232 standard. This standard was developed to allow individuals to use remote computer systems over dialup telephone lines with remote terminals. The standard includes provisions for a remote terminal that is connected to a modem that places a telephone call, a modem that answers the telephone call, and a computer that is connected to that modem. The terminal can be connected directly to the computer, eliminating the need for two modems, through the use of a special device called a null modem adapter. Sometimes this device is built directly into a cable, in which case the cable is called a null modem cable. 13

PCB Layout:

Figure-6

14

List of Important AT Commands: Overview of AT Commands AT+CMGD AT+CMGF AT+CMGL AT+CMGR AT+CMGS AT+CMGW AT+CMSS AT+CMGC AT+CNMI AT+CPMS AT+CRES AT+CSAS AT+CSCA AT+CSCB AT+CSDH AT+CSMP AT+CSMS Description DELETE SMS MESSAGE SELECT SMS MESSAGE FORMAT LIST SMS MESSAGES FROM PREFERRED STORE READ SMS MESSAGE SEND SMS MESSAGE WRITE SMS MESSAGE TO MEMORY SEND SMS MESSAGE FROM STORAGE SEND SMS COMMAND NEW SMS MESSAGE INDICATIONS PREFERRED SMS MESSAGE STORAGE RESTORE SMS SETTINGS SAVE SMS SETTINGS SMS SERVICE CENTER ADDRESS SELECT CELL BROADCAST SMS MESSAGES SHOW SMS TEXT MODE PARAMETERS SET SMS TEXT MODE PARAMETERS SELECT MESSAGE SERVICE

15

Chapter3:Microcontroller
Introduction
A microcontroller (sometimes abbreviated C, uC or MCU) is a small computer on a single integrated circuit containing a processor core, memory, and programmable input/output peripherals. Program memory in the form of NOR flash or OTP ROM is also often included on chip, as well as a typically small amount of RAM. Microcontrollers are designed for embedded applications, in contrast to the microprocessors used in personal computers or other general purpose applications. Microcontrollers are used in automatically controlled products and devices, such as automobile engine control systems, implantable medical devices, remote controls, office machines, appliances, power tools, toys and other embedded systems. By reducing the size and cost compared to a design that uses a separate microprocessor, memory, and input/output devices, microcontrollers make it economical to digitally control even more devices and processes. Mixed signal microcontrollers are common, integrating analog components needed to control nondigital electronic systems. Some microcontrollers may use four-bit words and operate at clock rate frequencies as low as 4 kHz, for low power consumption (milliwatts or microwatts). They will generally have the ability to retain functionality while waiting for an event such as a button press or other interrupt; power consumption while sleeping (CPU clock and most peripherals off) may be just nanowatts, making many of them well suited for long lasting battery applications. Other microcontrollers may serve performance-critical roles, where they may need to act more like a digital signal processor (DSP), with higher clock speeds and power consumption. Intel 8051 and 80C51 are members of Intel MCS-51 family of 8-bit microcontrollers. In addition to on-chip clock oscillator, 2 16-bit timers, 4 I/O ports and a serial port, all 8051 and 80C51 chips have 128 bytes of RAM and 4 KB masked ROM. If necessary, 8051 memory can be expanded up to 128 KB by adding up to 64 KB of external program and data memory.

16

AT89S52- 8 bit Microcontroller with 8k Bytes Flash Features:


Photograph Features
Compatible with MCS-51 Products 8K Bytes of In-System Reprogrammable Flash Memory Fully Static Operation: 0 Hz to 33 MHz Three-level Program Memory Lock 256 x 8-bit Internal RAM 32 Programmable I/O Lines Three 16-bit Timer/Counters Eight Interrupt Sources Programmable Serial Channel Low-power Idle and Power-down Modes 4.0V to 5.5V Operating Range Full Duplex UART Serial Channel Interrupt Recovery from Power-down Mode Watchdog Timer Dual Data Pointer Power-off Flag Fast Programming Time Flexible ISP Programming (Byte and Page Mode)

Figure-7

17

Pin Description:

Figure-8 VCC Supply voltage.

GND Ground.

Port 0 Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high-impedance inputs. Port 0 can also be configured to be the multiplexed low-order address/data bus during accesses to external program and data memory. In this mode, P0 has internal pull-ups. Port 0 also

18

receives the code bytes during Flash programming and outputs the code bytes dur-ing program verification. External pull-ups are required during program verification.

Port 1 Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1 output buffers can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the inter-nal pull-ups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will source current (IIL) because of the internal pull-ups. In addition, P1.0 and P1.1 can be configured to be the timer/counter 2 external count input (P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX), respectively, as shown in the follow-ing table. Port 1 also receives the low-order address bytes during Flash programming and verification.

Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 2 output buffers can sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by the inter-nal pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled low will source current (IIL) because of the internal pull-ups. Port 2 emits the high-order address byte during fetches from external program memory and dur-ing accesses to external data memory that use 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses strong internal pull-ups when emitting 1s. During accesses to external data memory that use 8-bit addresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register. Port 2 also receives the high-order address bits and some control signals during Flash program-ming and verification.

Port 3 Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3 output buffers can sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the inter-nal pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will source current (IIL) because of the pull-ups. Port 3 receives some control signals for Flash programming and verification.

19

RST Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device. This pin drives high for 98 oscillator periods after the Watchdog times out. The DISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. In the default state of bit DISRTO, the RESET HIGH out feature is enabled.

ALE/PROG Address Latch Enable (ALE) is an output pulse for latching the low byte of the address during accesses to external memory. This pin is also the program pulse input (PROG) during Flash programming. In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator frequency and may be used for external timing or clocking purposes. Note, however, that one ALE pulse is skipped dur-ing each access to external data memory. If desired, ALE operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the microcontroller is in external execution mode.

PSEN Program Store Enable (PSEN) is the read strobe to external program memory. When the AT89S52 is executing code from external program memory, PSEN is activated twice each machine cycle, except that two PSEN activations are skipped during each access to exter-nal data memory.

20

EA/VPP External Access Enable. EA must be strapped to GND in order to enable the device to fetch code from external program memory locations starting at 0000H up to FFFFH. Note, however, that if lock bit 1 is programmed, EA will be internally latched on reset. EA should be strapped to VCC for internal program executions. This pin also receives the 12-volt programming enable voltage (VPP) during Flash programming.

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

XTAL2 Output from the inverting oscillator amplifier.

Figure-9

21

Special Function Registers:


P0 (Port 0, Address 80h, Bit-Addressable): This is input/output port 0. Each bit of this SFR corresponds to one of the pins on the microcontroller. For example, bit 0 of port 0 is pin P0.0, bit 7 is pin P0.7. Writing a value of 1 to a bit of this SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to a low level. SP (Stack Pointer, Address 81h): This is the stack pointer of the microcontroller. This SFR indicates where the next value to be taken from the stack will be read from in Internal RAM. If you push a value onto the stack, the value will be written to the address of SP + 1. That is to say, if SP holds the value 07h, a PUSH instruction will push the value onto the stack at address 08h. This SFR is modified by all instructions which modify the stack, such as PUSH, POP, LCALL, RET, RETI, and whenever interrupts are provoked by the microcontroller. DPL/DPH (Data Pointer Low/High, Addresses 82h/83h):The SFRs DPL and DPH work together to represent a 16-bit value called the Data Pointer. The data pointer is used in operations regarding external RAM and some instructions involving code memory. Since it is an unsigned two-byte integer value, it can represent values from 0000h to FFFFh (0 through 65,535 decimal). PCON (Power Control, Addresses 87h): The Power Control SFR is used to control the 8051's power control modes. Certain operation modes of the 8051 allow the 8051 to go into a type of "sleep" mode which requires much less power. These modes of operation are controlled through PCON. Additionally, one of the bits in PCON is used to double the effective baud rate of the 8051's serial port. TCON (Timer Control, Addresses 88h, Bit-Addressable): The Timer Control SFR is used to configure and modify the way in which the 8051's two timers operate. This SFR controls whether each of the two timers is running or stopped and contains a flag to indicate that each timer has overflowed. Additionally, some non-timer related bits are located in the TCON SFR. These bits are used to configure the way in which the external interrupts are activated and also contain the external interrupt flags which are set when an external interrupt has occured. TMOD (Timer Mode, Addresses 89h): The Timer Mode SFR is used to configure the mode of operation of each of the two timers. Using this SFR your program may configure each timer to
22

be a 16-bit timer, an 8-bit autoreload timer, a 13-bit timer, or two separate timers. Additionally, you may configure the timers to only count when an external pin is activated or to count "events" that are indicated on an external pin. TL0/TH0 (Timer 0 Low/High, Addresses 8Ah/8Ch): These two SFRs, taken together, represent timer 0. Their exact behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up. What is configurable is how and when they increment in value. TL1/TH1 (Timer 1 Low/High, Addresses 8Bh/8Dh):These two SFRs, taken together, represent timer 1. Their exact behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up. What is configurable is how and when they increment in value. P1 (Port 1, Address 90h, Bit-Addressable): This is input/output port 1. Each bit of this SFR corresponds to one of the pins on the microcontroller. For example, bit 0 of port 1 is pin P1.0, bit 7 is pin P1.7. Writing a value of 1 to a bit of this SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to a low level. SCON (Serial Control, Addresses 98h, Bit-Addressable): The Serial Control SFR is used to configure the behavior of the 8051's on-board serial port. This SFR controls the baud rate of the serial port, whether the serial port is activated to receive data, and also contains flags that are set when a byte is successfully sent or received. SBUF (Serial Control, Addresses 99h): The Serial Buffer SFR is used to send and receive data via the on-board serial port. Any value written to SBUF will be sent out the serial port's TXD pin. Likewise, any value which the 8051 receives via the serial port's RXD pin will be delivered to the user program via SBUF. In other words, SBUF serves as the output port when written to and as an input port when read from. P2 (Port 2, Address A0h, Bit-Addressable): This is input/output port 2. Each bit of this SFR corresponds to one of the pins on the microcontroller. For example, bit 0 of port 2 is pin P2.0, bit 7 is pin P2.7. Writing a value of 1 to a bit of this SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to a low level.

23

IE (Interrupt Enable, Addresses A8h):The Interrupt Enable SFR is used to enable and disable specific interrupts. The low 7 bits of the SFR are used to enable/disable the specific interrupts, where as the highest bit is used to enable or disable ALL interrupts. Thus, if the high bit of IE is 0 all interrupts are disabled regardless of whether an individual interrupt is enabled by setting a lower bit. P3 (Port 3, Address B0h, Bit-Addressable): This is input/output port 3. Each bit of this SFR corresponds to one of the pins on the microcontroller. For example, bit 0 of port 3 is pin P3.0, bit 7 is pin P3.7. Writing a value of 1 to a bit of this SFR will send a high level on the corresponding I/O pin whereas a value of 0 will bring it to a low level. IP (Interrupt Priority, Addresses B8h, Bit-Addressable): The Interrupt Priority SFR is used to specify the relative priority of each interrupt. On the 8051, an interrupt may either be of low (0) priority or high (1) priority. An interrupt may only interrupt interrupts of lower priority. For example, if we configure the 8051 so that all interrupts are of low priority except the serial interrupt, the serial interrupt will always be able to interrupt the system, even if another interrupt is currently executing. However, if a serial interrupt is executing no other interrupt will be able to interrupt the serial interrupt routine since the serial interrupt routine has the highest priority. PSW (Program Status Word, Addresses D0h, Bit-Addressable):The Program Status Word is used to store a number of important bits that are set and cleared by 8051 instructions. The PSW SFR contains the carry flag, the auxiliary carry flag, the overflow flag, and the parity flag. Additionally, the PSW register contains the register bank select flags which are used to select which of the "R" register banks are currently selected. ACC (Accumulator, Addresses E0h, Bit-Addressable): The Accumulator is one of the mostused SFRs on the 8051 since it is involved in so many instructions. The Accumulator resides as an SFR at E0h, which means the instruction MOV A,#20h is really the same as MOV E0h,#20h. However, it is a good idea to use the first method since it only requires two bytes whereas the second option requires three bytes. B (B Register, Addresses F0h, Bit-Addressable): The "B" register is used in two instructions: the multiply and divide operations. The B register is also commonly used by programmers as an auxiliary register to temporarily store values.

24

Chapter4:Circuit diagram and working

Power Supply

In alternating current the electron flow is alternate, i.e. the electron flow increases to maximum in one direction, decreases back to zero. It then increases in the other direction and then decreases to zero again. Direct current flows in one direction only. Rectifier converts alternating current to flow in one direction only. When the anode of the diode is positive with respect to its cathode, it is forward biased, allowing current to flow. But when its anode is negative with respect to the cathode, it is reverse biased and does not allow current to flow. This unidirectional property of the diode is useful for rectification. A single diode arranged back-to-back might allow the electrons to flow during positive half cycles only and suppress the negative half cycles. Double diodes arranged back-to-back might act as full wave rectifiers as they may allow the electron flow during both positive and negative half cycles. Four diodes can be arranged to make a full wave bridge rectifier. Different types of filter circuits are used to smooth out the pulsations in amplitude of the output voltage from a rectifier. The property of capacitor to oppose any change in the voltage applied across them by storing energy in the electric field of the capacitor and of inductors to oppose any change in the current flowing through them by storing energy in the magnetic field of coil may be utilized. To remove pulsation of the direct current obtained from the rectifier, different types of combination of capacitor, inductors and resistors may be also be used to increase to action of filtering.

RECTIFICATION
Rectification is a process of rendering an alternating current or voltage into a unidirectional one. The component used for rectification is called Rectifier. A rectifier permits current to flow only during the positive half cycles of the applied AC voltage by eliminating the negative half cycles or alternations of the applied AC voltage. Thus pulsating DC is obtained. To obtain smooth DC power, additional filter circuits are required.

25

A diode can be used as rectifier. There are various types of diodes. But, semiconductor diodes are very popularly used as rectifiers. A semiconductor diode is a solid-state device consisting of two elements is being an electron emitter or cathode, the other an electron collector or anode. Since electrons in a semiconductor diode can flow in one direction only-from emitter to collector- the diode provides the unilateral conduction necessary for rectification. Out of the semiconductor diodes, copper oxide and selenium rectifier are also commonly used.

FULL WAVE RECTIFIER It is possible to rectify both alternations of the input voltage by using two diodes in the circuit arrangement. Assume 6.3 V rms (18 V p-p) is applied to the circuit. Assume further that two equal-valued series-connected resistors R are placed in parallel with the ac source. The 18 V p-p appears across the two resistors connected between points AC and CB, and point C is the electrical midpoint between A and B. Hence 9 V p-p appears across each resistor. At any moment during a cycle of vin, if point A is positive relative to C, point B is negative relative to C. When A is negative to C, point B is positive relative to C. The effective voltage in proper time phase which each diode "sees" is in Fig. The voltage applied to the anode of each diode is equal but opposite in polarity at any given instant. When A is positive relative to C, the anode of D1 is positive with respect to its cathode. Hence D1 will conduct but D2 will not. During the second alternation, B is positive relative to C. The anode of D2 is therefore positive with respect to its cathode, and D2 conducts while D1 is cut off. There is conduction then by either D1 or D2 during the entire input-voltage cycle.Since the two diodes have a common-cathode load resistor RL, the output voltage across RL will result from the alternate conduction of D1 and D2. The output waveform vout across RL, therefore has no gaps as in the case of the half-wave rectifier. The output of a full-wave rectifier is also pulsating direct current. In the diagram, the two equal resistors R across the input voltage are necessary to provide a voltage midpoint C for circuit connection and zero reference. Note that the load resistor R L is connected from the cathodes to

26

this center reference point C.An interesting fact about the output waveform vout is that its peak amplitude is not 9 V as in the case of the half-wave rectifier using the same power source, but is less than 4 V. The reason, of course, is that the peak positive voltage of A relative to C is 4 V, not 9 V, and part of the 4 V is lost across R.Though the full wave rectifier fills in the
conduction gaps, it delivers less than half the peak output voltage that results from half-wave rectification.

CIRCUIT DIAGRAM

Figure-10

27

VOLTAGE REGULATOR
One can get a constant high-voltage power supply using inexpensive 3-terminal voltage regulators through some simple techniques described below. Depending upon the current requirement, a reasonable load regulation can be achieved. Line regulation in all cases is equal to that of the voltage regulator used. Though high voltage can be obtained with suitable voltage boost circuitry using ICs like LM 723, some advantages of the circuits presented below are: simplicity, low cost, and practically reasonable regulation characteristics. For currents of the order of 1A or less, only one zener and some resistors and capacitors are needed. For higher currents, one pass transistor such as ECP055 is needed. Before developing the final circuits, let us first understand the 3-terminal type constant voltage regulators. Let us see the schematic in Fig. where 78XX is a 3-terminal voltage regulator. Schematic for obtaining low-voltage regulated output using 3-terminal voltage regulators. Rectified and filtered unregulated voltage is applied at VIN and a constant voltage appears between pins 2 and 2 of the voltage regulator. *The distribution of two currents in the circuit (IBIAS and ILOAD) is as shown.

Figure-11

28

LCD Interfacing:
LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments and other multi segment LEDs. The reasons being: LCDs are economical; easily programmable; have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. A 16x2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD has two registers, namely, Command and Data. The command register stores the command instructions given to the LCD. A command is an instruction given to LCD to do a predefined task like initializing it, clearing its screen, setting the cursor position, controlling display etc. The data register stores the data to be displayed on the LCD. The data is the ASCII value of the character to be displayed on the LCD.

Figure-12

29

Pin No

Function

Name

1 2 3 4

Ground (0V) Supply voltage; 5V (4.7V 5.3V) Contrast adjustment; through a variable resistor Selects command register when low; and data register when high

Ground Vcc VEE Register Select

5 6 7 8 9 10

Low to write to the register; High to read from the register Sends data to data pins when a high to low pulse is given

Read/write Enable DB0 DB1 DB2 DB3

8-bit data pins 11 12 13 14 15 16 Backlight VCC (5V) Backlight Ground (0V) DB4 DB5 DB6 DB7 Led+ Led-

30

Figure-13

31

CIRCUIT DIAGRAM

32

Figure-14

33

Working of project
The energy meter records the amount of power consumption.It does so by an electromechanical system.The system is provided with such a mechanism that an increament in amount of current flow through circuit causes the disc to rotate faster,means that the rotational speed of disc is directly proportional to the amount of current flowing through circuit.This rotation effect of disc causes the gear mechanism to work accordingly and in similar fashion rate of power consumption increases the blinking rate of LED integrated within the meter.The pulses from this LED are fed to microcontroller for count operation i.e. these pulses are counted by microcontroller and readings are stored into external memory.External memory used here ,is EEPROM .This memory is able to store previous database as well in case one needs to check past consumption status.LCD is connected with microcontroller so as to show the current status of GSM Modem.GSM modem is the means to communicate over wireless systems.GSM modem is connected with microcontroller via MAX 232 IC.GSM modem communicates at RS232 standard voltage levels while uC understands TTL logic levels so MAX 232 serves as voltage level converter.It converts Rs232 levels into TTL and vice-versa. Whenever a command is sent to the GSM modem ,it decodes the commands and works accordingly. e.g. if Meter Read command is sent to modem then it captures the status of memory and picks only integral value and sends the same information via wireless network to another modem whose address has been cited in the program written inside the ROM.

34

Chapter5:Chip Programming:
Flowchart:

35

Keil Software:
KEIL Micro Vision is an integrated development environment used to create software to be run on embedded systems (like a microcontroller). It allows for such software to be written either in assembly or C programming languages and for that software to be simulated on a computer before being loaded onto the microcontroller. The software used is c programming. Vision3 is an IDE (Integrated Development Environment) that helps write, compile, and debug embedded programs. It encapsulates the following components: A project manager. A make facility. Tool configuration. Editor. A powerful debugger. To create a new project, simply start micro vision and select Project=>New Project from the pulldown menus. In the file dialog that appears, a filename and directory was chosen for the project. It is recommended that a new directory be created for each project. As several files will be generated. Once the project has been named, the dialog shown in the figure below will appear, prompting the user to select a target device. The chip being used is the AT89S52, which is listed under the heading Atmel. Next, Micro Vision was instructed to generate a HEX file upon program compilation. A HEX file is a standard file format for storing executable code that is to be loaded onto the microcontroller. In the Project Workspace pane at the left, rightclick on Target 1 and select Options for Target 1 .Under the Output tab of the resulting options dialog, ensure that both the Create Executable and Create HEX File options are checked. Then click OK. Next, a file must be added to the project that will contain the project code. To do this, expand the Target 1 heading, rightclick on the Source Group 1 folder, and select Add files Create a new blank file (the file name should end in .c), select it, and click Add. The new file should now appear in the Project Workspace pane under the Source Group 1 folder. Double-click on the newly created file to open it in the editor. To compile the program, first save all source files by clicking on the Save All button, and then click on the Rebuild All Target Files to compile the program as shown in the figure below. If any errors or warnings occur during compilation, they will be displayed in the output window at the bottom of the screen. All errors and warnings will reference the line and column number in which they occur along with a description of the problem so that they can be easily located . When the program has been successfully compiled, it can be simulated using the integrated debugger in Keil Micro Vision. To start the debugger, select Debug=>Start/Stop
36

Debug Session from the pulldown menus. At the left side of the debugger window, a table is displayed containing several key parameters about the simulated microcontroller, most notably the elapsed time (circled in the figure below). Just above that, there are several buttons that control code execution. The Run button will cause the program to run continuously until a breakpoint is reached, whereas the Step Into button will execute the next line of code and then pause (the current position in the program is indicated by a yellow arrow to the left of the code).

37

38

Electronic meters advantages:


High accuracy over a wide current dynamic range Reliability and robustness Automatic Meter Reading (AMR) More easily enable new functionalities Tamper proofing Power out range detection Power factor detection Easily reconfiguration, upgrade Do not use gears that wear out or magnets that saturate with DC current Do not require precision mechanics or have large tolerance variations over temperature

39

SCOPE OF THE PROJECT:

1. Provides user friendly remote energy meter monitoring. 2. Supports controlling of meter. 3. Can be controlled any where in the world. 4. Non-volatile memory based energy-reading storing. 5. Auto disconnect feature.

40

TROUBLESHOOTING MANUAL FOR THE GSM ENERGY METER


SYSTEM DOES NOT POWER : check If the GREEN led IS POWER on and also check if the output voltage from the power supply is 5V or approximately

1. SYSTEM POWER BUT NO DISPLAY ON THE LCD: press the reset button on the system. The reset button is indicated with red color

2. NO MESSAGES ON THE LCD: check if the headphone is connected to the phone and also check if the phone is power

3. SYSTEM HANGED: press the rest button to re-initialize the memory of the embedded system

4. SYSTEM SHOWS SPECIAL CHARACTER: changed the max232 driver inside the system. Max232 is a receiver transmitter driver that is having 16pins

5. LCD CONTRAST IS FADED: rotate the potentiometer in the front panel of the LCD to see the text clearly.

6. BLANK OUTPUT DISPLAY: open the entire system and locate crystal oscillator. Crystal oscillator is harsh in colour. Replace the crystal oscillator with exactly 11.0592 MHz.

41

7. FAILS TO CONTROL DEVICE: Ensure that there is no messages on the phone memory and then reset the LCD also make sure the character send does not exceed 16 characters. Also make sure you put security code before the messages and you are sending the messages to the appropriate number. The format of the messages is 12345 fanon.

8. NO WELCOME MESSAGE AS YOU POWER ON: The system should display a scrolling welcome message as you power on the system. The welcome message to be display is WELCOME TO PROJECTS. If no welcome message, ensure to connect the headphone to the mobile phone or you can use your hand to touch the headphone

9. NO RESPONSE FROM THE HEADPHONE: You can change the headphone and locate the RX, TX, and GND from the headphone before connecting it to the entire system.

42

SNAPSHOT:

Figure-15

43

Program Code:

#include<reg52.h> sbit RS=P3^7; sbit EN=P3^6; //--------------------------------------// Forward function declaration //--------------------------------------void Retry(void); void Txmsg(unsigned char k); unsigned char Rxmsg(void); void lcdinit(void); void lcdData(unsigned char l); void lcdcmd(unsigned char k); //--------------------------------------// Main rotine //--------------------------------------void main() { unsigned char ret; TMOD=0x20; // Configure UART at 9600 baud rate TH1=0xFD; SCON=0x50; TR1=1; lcdinit(); // Initialize LCD initdisplay(); DelayMs(5000); InitModem(); // Initialize Modem
44

54 while(1) { ret=Rxmsg(); } } //---------------------------------------------------// Retry subroutine to check the connectivity of modem //---------------------------------------------------void Retry(void) { unsigned char i=0; retry: lcdcmd(0x01); DelayMs(10); lcdcmd(0x80); DelayMs(10); for(i=0;i<5;i++) b[i]=0x00; i=0; while(a[i]!='\0') { SBUF=a[i]; while(TI==0); // AT sending TI=0; lcdData(a[i]); i++; }
45

lcdData(' '); // Enter SBUF=0x0d; while(TI==0); TI=0; 55 for(i=0;i<5;i++) //command to recv data { j=0; while(RI==0) { if(j>=1000) goto retry; DelayMs(1); j++; } b[i]=SBUF; RI=0; lcdData(b[i]); } DelayMs(100); for(i=0;i<5;i++) //command to recv data { if(b[i]=='E' || b[i]=='R') goto retry; if(b[i]=='O' || b[i]=='K') { return; }
46

} goto retry; } //--------------------------------------// Modem initialization subroutine //--------------------------------------void InitModem(void) { unsigned int j=0; unsigned char i=0,k=0; unsigned char d[6]; 56 ReInit: //Retry(); for(i=0;i<6;i++) d[i]=0x00; i=0; while(a[i]!='\0') { SBUF=a[i]; while(TI==0); // ATE0 sending to turn off the echo TI=0; lcdData(a[i]); i++; } lcdData(' '); // Enter SBUF=0x0d; while(TI==0);
47

TI=0; } InitS: for(i=0;i<6;i++) d[i]=0x00; lcdcmd(0x01); DelayMs(10); lcdcmd(0x80); DelayMs(10); i=0; while(b[i]!='\0') { SBUF=b[i]; while(TI==0); // sending AT+CPMS to set the preffered memory location TI=0; 57 lcdData(b[i]); i++; } lcdData(' '); // Enter SBUF=0x0d; while(TI==0); TI=0; for(i=0;i<5;i++) //command to recv data { j=0; while(RI==0) {
48

if(j>=1000) goto ReInit; DelayMs(1); j++; } d[i]=SBUF; RI=0; lcdData(d[i]); } for(i=0;i<5;i++) //command to compare data { if((d[i]=='E') || (d[i]=='R')) goto ReInit; if((d[i]=='+') || (d[i]=='C')) goto InitS2; } InitS2: for(k=0;k<10;k++) { for(i=0;i<6;i++) d[i]=0x00; 58 } for(i=0;i<5;i++) //command to recv data { j=0; while(RI==0) {
49

if(j>=1000) goto ReInit; DelayMs(1); j++; } d[i]=SBUF; RI=0; lcdData(d[i]); } DelayMs(100); } return; } //--------------------------------------// Recieve message subroutine //--------------------------------------unsigned char Rxmsg(void) { lcdData('t'); SBUF='t'; while(TI==0); TI=0; lcdData('m'); SBUF='m'; while(TI==0); TI=0; 59 lcdData('g');
50

SBUF='g'; while(TI==0); TI=0; lcdData('r'); SBUF='r'; while(TI==0); TI=0; lcdData('='); SBUF='='; while(TI==0); TI=0; lcdData('1'); SBUF='1'; while(TI==0); TI=0; lcdData(0x0d); SBUF=0x0d; while(TI==0); TI=0; DelayMs(500); lcdcmd(0x80); for(i=0;i<102;i++) { j=0; while(RI==0) { if(j>=1000) goto timeout;
51

DelayMs(1); 60 j++; } c[i]=SBUF; RI=0; lcdData(c[i]); } timeout: for(i=0;i<5;i++) //command to recv data { if((c[i]=='E') || (c[i]=='R')) return ret; } for(i=0;i<102;i++) { goto sucess; } goto retry; i=i+8; while(c[i+4]!='O' && c[i+5]!='K') { lcdData(c[i]); i++; DelayMs(100); } DelayMs(10000); delete:
52

for(i=0;i<102;i++) { c[i]=0x00; } 61 SBUF='a'; while(TI==0); TI=0; lcdData('t'); SBUF='t'; while(TI==0); TI=0; lcdData('+'); SBUF='+'; while(TI==0); TI=0; lcdData('c'); SBUF='c'; while(TI==0); TI=0; lcdData('m'); SBUF='m'; while(TI==0); TI=0; lcdData('g'); SBUF='g'; while(TI==0); TI=0;
53

lcdData('d'); SBUF='d'; while(TI==0); TI=0; lcdData('='); SBUF='='; 62 while(TI==0); TI=0; lcdData('1'); SBUF='1'; while(TI==0); TI=0; lcdData(0x0d); // Enter SBUF=0x0d; while(TI==0); TI=0; for(i=0;i<5;i++) //command to recv data { j=0; while(RI==0) { if(j>=1000) goto delete; DelayMs(1); j++; } c[i]=SBUF;
54

RI=0; lcdData(c[i]); } DelayMs(1000); return ret; } //--------------------------------------// Lcd initialization subroutine //--------------------------------------void lcdinit(void) { 63 lcdcmd(0x38); DelayMs(250); lcdcmd(0x0E); DelayMs(250); lcdcmd(0x01); DelayMs(250);lcdcmd(0x06); DelayMs(250); lcdcmd(0x80); DelayMs(250); } //--------------------------------------// Lcd data display //--------------------------------------void lcdData(unsigned char l) { EN=0;
55

return; } //--------------------------------------// Lcd command //--------------------------------------void lcdcmd(unsigned char k) { P1=k; DelayMs(1); EN=0; return; } //--------------------------------------// Delay mS function //--------------------------------------void DelayMs(unsigned int count) { // mSec Delay 11.0592 Mhz 64 unsigned int i; // Keil v7.5a while(count) { i = 115; // 115 exact value while(i>0) i--; count--; } } void initdisplay(void) {
56

unsigned char d=0,a[]="Home Automation Modem Init..."; while(d!=15) { lcdData(a[d]); d++ ; } lcdcmd(0xc0); while(a[d]!='\0') { lcdData(a[d]); d++ ; } }

57

REFERENCES:
www.efymag.com www.alldatasheets.com Electronics For You Magazine Pradko, Programming and Customizing the 8051 Microcontroller , TMH Publications, 2008 John catsoulis, Designing Embedded Hardware , SHROFF PUB. & DISTR Mazidi, 8051 Microcontroller Programming ; Pearson Education , 2009

58

Você também pode gostar