Gsm energy meter


Published on

Published in: Education, Business, Technology
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Gsm energy meter

  1. 1. Chapter1:IntroductionINTRODUCTIONElectricity is one of the vital requirement for sustainment of comforts of life. IT should be usedvery judiciously for its proper utilization. But in our country we have lot of localities where wehave surplus supply for the electricity while many areas do not even have access to it. Ourpolicies of its distribution are also partially responsible for this because we are still not able tocorrectly 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. Mostof 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 reducehuman dependency at the same time. With the help of this project we are aiming to receive themonthly energy consumption from a remote location directly to a centralized office. In this waywe can reduce human efforts needed to record the meter readings which are till now recorded byvisiting every home individually.This results in considerable loss of human hours and also provides considerable details regardingthe 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 instrumentsrequired in power transmission.This idea is economically efficient as well because we can get the meter reading at a very lowcost. The implementation is done in such a way that a SMS is delivered to the Modem whosereading is to be noted and then that meter replies to the server in the SMS format and it is knownthat SMS costs are very low.The purpose of this project is to remote monitoring and control of the DomesticEnergy meter. This system enables the Electricity Department to read the meter readingsregularly without the person visiting each house.This can be achieved by the use of Microcontroller unit that continuously monitors and recordsthe Energy Meter readings in its permanent (non-volatile) memory location. This system also 1
  2. 2. 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 readingcan be sent to the Electricity department on request. This system also can be used to disconnectthe power supply to the house in case of non-payment of electricity bills. A dedicated GSMmodem with SIM card is required for each energy meter.The GSM AMR takes the advantage of available GSM infrastructure nationwide coverage andthe Short Messaging System (SMS) cell broadcasting feature to request and retrieve individualhouses and building power consumption reading back to the energy provider wirelessly.The Store and Forwarding feature of SMS allow reliable meter reading delivery when GSMsignsl is affected by the poor weather conditions. The stored message is archive in the mobileoperator and can be later retrieve for billing purposes.History of Meters:Over the past years electric energy meters have undergone phenomenal changes and are expectedto become even more sophisticated , offering more and more services.The electromechanical based energy meters are rapidly being replaced by digital energy meterswhich offer high accuracy and precision. Now the generation of electric energy meters is that ofAMRs. 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 2
  3. 3. 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 world‟s most popular standard formobile telephony systems. GSM is used by over 1.5 billion people all over the world. GSM alsopioneered the low cost implementation of the Short Message Service (SMS) which allows partiesto exchange delay tolerant short text messages. The popularity and coverage of cellular networksallows 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 takenfrom a real GSM network in India, SMS delivery success rate is found to be 94.3%. Of thesesuccessfully 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 usesseveral cryptographic algorithms for security. The development of UMTS introduces an optionalUniversal Subscriber Identity Module (USIM), which uses a longer authentication key to givegreater security, as well as mutually authenticating the network and the user. 3
  4. 4. Methodology:The method used to carry out this project is the principle of serial communication incollaboration with embedded system. The project has a electric meter which will work and aGSM modem which is the latest technology used for communication between MODEM andembedded systems.The modem will send a message as and when desired to the electricity officials throughSubscriber Identity Module inserted inside the MODEM.System Overview:The complete overview of GSM AMR system is shown below and consists of GSM energymeter with installed in every individual unit. On the other hand SMS gateway, applicationterminal and database server are present at the energy provider side.This AMR system works in conjunction with the GSM network to retrieve the power meterreading using SMS. The GSM energy meter is an integration of an electric meter with a GSMmodem. A SIM card with a unique special number is required for meter to receive and reply itsenergy meter readings to the energy provider using SMS. The SIM number is identical to the oneused for mobile phones except it is not used for voice communications. The SIM card is alsoused to identify and retrieve owner or consumer details from the database server for billingpurposes.An automatic power reading takes place automatically on request by the energy provider. SMSgateway performs cell broadcasting of request through SMS to all meters to request for meterreading. The meter will immediately respond in the form of meter readings upon receiving therequest from the energy provider. 4
  5. 5. Figure-1 5
  6. 6. BLOCK DIAGRAM:Figure-2 6
  7. 7. LITERATURE SURVEY:In order to overcome the problems of the existing traditional meter reading system , efforts areunderway around the world to automate the meter reading systems and to provide comprehensiveinformation to the consumer for efficient use of utilities.Researchers have proposed different implementation techniques for AMR. One is the SMS-basedReconfigurable Automatic Meter Reading System which uses the GSM network for sending theARM data.The other technique is secure and scalable automated reading system which uses the existinglocal ISPs instead of requiring its own proprietary set communication infrastructure. Thegateway node basically consists of an embedded microprocessor system, based on embeddedlinux, and a modem.The remote real time automatic reading system employs distributed structure based on wirelesssensor networks which consists of measure units, sensor nodes, data collectors, server andwireless communication network. 7
  8. 8. Chapter2: GSM ModemIntroduction To GSM NetworkGSM (Global System for Mobile Communication)GSM has been the backbone of the phenomenal success of mobile communication in theprevious decade. Now at the dawn of true broadband services, GSM continues to evolve to meetnew 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 asGlobal System for Mobile Communication. It is a set of standards developed by the EuropeanTelecommunications Standards Institute (ETSI) to describe technologies used for secondgeneration digital communications, commonly referred as 2G technologies.It was developed as a replacement to the first generation analog communications. It originallydescribed 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 packetdata transport via GPRS (General Packet Radio Service). Packet data transmission speed werelater 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 the3GPP.TECHNICAL DETAILS:GSM is a cellular network which means that compatible devices connect to it by searching forcells in the immediate vicinity.There are five different cell sizes in a GSM network viz. Macro, Micro, pico, femto and umbrellacells. 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 aboveroof top level. 8
  9. 9. Micro cells are those in which base station is installed below the average roof top level. They aretypically used in urban areas.Pico cells are the cells whose coverage area is a few dozen metres in diameter and are mainlyused indoors.Femto cells are cells designed for use in residential or small business environment and connect tothe service provider‟s network via a broadband internet connection.Umbrella cells are used to cover shadowed reasons of smaller cells and fill in gaps in coveragebetween those cells.MODULATION USED:The modulation used in GSM is Gaussian Minimum Phase Shift Keying (GMSK), a kind ofcontinuous phase frequency shift keying. In GMSK the signal to be modulated on the carrier isfirst smoothed with a Gaussian low-pass filter prior to being fed into a frequency modulatorwhich 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 for2G and UMTS frequency range for 3G).Most 2G GSM networks operate in the 900 MHz or 1800 MHz frequency bands. Where thesebands are already occupied 850 MHz or 1950 MHz frequency bands are used e.g. in USA andCanada. In rare cases 400 and 450 MHz bands are allocated because they were earlier used forfirst 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 usersto use. This allows eight full rate or sixteen half rate speech channels per radio frequency. Theseeight radio slots are grouped into a TDMA frame. The channel data rate for all 8 channels is270.833 Kbps and the time duration is 4.615 ms. 9
  10. 10. GSM Network structure:Figure-3 (GSM Network structure) 10
  11. 11. Figure-4The 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. Theword 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 thetelephone line, and translate the tones back into the serial stream at the other end of theconnection (demodulation). Most modems are bidirectional?every modem contains both amodulator 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. Becausemodems work with standard telephone lines, and use the public telephone network to route theirconversations, any computer that is equipped with a modem and a telephone line can 11
  12. 12. communicate with any other computer that has a modem and a telephone line, anywhere in theworld. Modems thus bypass firewalls, packet filters, and intrusion detection systems.Whats more, even in this age of corporate LANs, cable modems, and DSL links, dialup modemsare still the single most common way that people access the Internet. This trend is likely tocontinue through the first decade of the 21st century because dialup access is dramaticallycheaper 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 oftenorganized into a series of single bits that are transmitted sequentially. Often, these bits aregrouped into 8-bit bytes for purposes of error checking or special encoding. Serialinterfaces transmit information as a series of pulses over a single wire. A special pulse calledthe start bit signifies the start of each character. The data is then sent down the wire, one bit at atime, after which another special pulse called the stop bit is sent .Figure-5Because a serial interface can be set up with only three wires (transmit data, receive data, and ground), itsoften used with terminals. With additional wires, serial interfaces can be used to control modems,allowing computers to make and receive telephone calls. 12
  13. 13. Testing of GSM Modem:To use MS HyperTerminal to send AT commands to the GSM modem, the following procedureis followed1. I put a valid SIM (MTN) card into the GSM modem. I obtain a SIM card by subscribing to theGSM service of a wireless network operator.2. No need to install any driver for the GSM modem3. 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 enterany file name and choose an icon I like for the connection. Then I click the OK button. In theConnect To dialog box, choose the COM port that your mobile phone or GSM modem isconnecting to in the Connect using combo box. I choose COM1 because my mobile phone isconnected to the COM1 port. Then click the OK button. Type "AT" in the main window. Aresponse "OK" will be returned from the mobile phone or GSM modem. Type "AT+CPIN?" inthe main window. The AT command "AT+CPIN?" is used to query whether the mobile phone orGSM modem is waiting for a PIN (personal identification number, i.e. password). If theresponse is "+CPIN: READY", it means the SIM card does not require a PIN and it is ready foruse. 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 MODEMparameters like Baud rate, Echo off etc to enable easier access via a microcontroller which I usedin this project. The following are the ATCOMMAND used for programming the gsm modemRS-232 Serial ProtocolOne of the most common serial interfaces is based on the RS-232 standard. This standard was developedto 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 atelephone call, a modem that answers the telephone call, and a computer that is connected tothat modem. The terminal can be connected directly to the computer, eliminating the need for twomodems, through the use of a special device called a null modem adapter. Sometimes this device is builtdirectly into a cable, in which case the cable is called a null modem cable. 13
  14. 14. PCB Layout:Figure-6 14
  16. 16. Chapter3:MicrocontrollerIntroductionA microcontroller (sometimes abbreviated µC, uC or MCU) is a small computer on asingle integrated circuit containing a processor core, memory, andprogrammable input/output peripherals. Program memory in the form of NOR flash or OTPROM 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 usedin personal computers or other general purpose applications.Microcontrollers are used in automatically controlled products and devices, such as automobileengine control systems, implantable medical devices, remote controls, office machines,appliances, power tools, toys and other embedded systems. By reducing the size and costcompared 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. Mixedsignal microcontrollers are common, integrating analog components needed to control non-digital electronic systems.Some microcontrollers may use four-bit words and operate at clock rate frequencies as low as4 kHz, for low power consumption (milliwatts or microwatts). They will generally have theability 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 microcontrollersmay serve performance-critical roles, where they may need to act more like a digital signalprocessor (DSP), with higher clock speeds and power consumption.Intel 8051 and 80C51 are members of Intel MCS-51 family of 8-bit microcontrollers. In additionto on-chip clock oscillator, 2 16-bit timers, 4 I/O ports and a serial port, all 8051 and 80C51chips have 128 bytes of RAM and 4 KB masked ROM. If necessary, 8051 memory can beexpanded up to 128 KB by adding up to 64 KB of external program and data memory. 16
  17. 17. AT89S52- 8 bit Microcontroller with 8k Bytes FlashFeatures: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
  18. 18. Pin Description:Figure-8VCC 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 sinkeight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high-impedanceinputs. Port 0 can also be configured to be the multiplexed low-order address/data bus duringaccesses to external program and data memory. In this mode, P0 has internal pull-ups. Port 0 also 18
  19. 19. receives the code bytes during Flash programming and outputs the code bytes dur-ing programverification. 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 bufferscan sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by theinter-nal pull-ups and can be used as inputs. As inputs, Port 1 pins that are externally beingpulled low will source current (IIL) because of the internal pull-ups. In addition, P1.0 and P1.1can be configured to be the timer/counter 2 external count input (P1.0/T2) and the timer/counter2 trigger input (P1.1/T2EX), respectively, as shown in the follow-ing table. Port 1 also receivesthe 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 cansink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by theinter-nal pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally beingpulled low will source current (IIL) because of the internal pull-ups. Port 2 emits the high-orderaddress byte during fetches from external program memory and dur-ing accesses to external datamemory that use 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses stronginternal pull-ups when emitting 1s. During accesses to external data memory that use 8-bitaddresses (MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register. Port 2also receives the high-order address bits and some control signals during Flash program-mingand verification.Port 3 Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3 output bufferscan sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by theinter-nal pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally beingpulled low will source current (IIL) because of the pull-ups. Port 3 receives some control signalsfor Flash programming and verification. 19
  20. 20. RST Reset input. A high on this pin for two machine cycles while the oscillator is running resetsthe device. This pin drives high for 98 oscillator periods after the Watchdog times out. TheDISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. In the default stateof 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 theaddress 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 theoscillator 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, ALEoperation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is activeonly during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting theALE-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 theAT89S52 is executing code from external program memory, PSEN is activated twice eachmachine cycle, except that two PSEN activations are skipped during each access to exter-nal datamemory. 20
  21. 21. EA/VPP External Access Enable. EA must be strapped to GND in order to enable the device tofetch 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 bestrapped to VCC for internal program executions. This pin also receives the 12-voltprogramming enable voltage (VPP) during Flash programming.XTAL1 Input to the inverting oscillator amplifier and input to the internal clock operatingcircuit.XTAL2 Output from the inverting oscillator amplifier.Figure-9 21
  22. 22. Special Function Registers:P0 (Port 0, Address 80h, Bit-Addressable): This is input/output port 0. Each bit of this SFRcorresponds to one of the pins on the microcontroller. For example, bit 0 of port 0 is pin P0.0, bit7 is pin P0.7. Writing a value of 1 to a bit of this SFR will send a high level on the correspondingI/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 SFRindicates where the next value to be taken from the stack will be read from in Internal RAM. Ifyou 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 worktogether to represent a 16-bit value called the Data Pointer. The data pointer is used inoperations regarding external RAM and some instructions involving code memory. Since it is anunsigned two-byte integer value, it can represent values from 0000h to FFFFh (0 through 65,535decimal).PCON (Power Control, Addresses 87h): The Power Control SFR is used to control the 8051spower 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 throughPCON. Additionally, one of the bits in PCON is used to double the effective baud rate of the8051s serial port.TCON (Timer Control, Addresses 88h, Bit-Addressable): The Timer Control SFR is used toconfigure and modify the way in which the 8051s two timers operate. This SFR controlswhether each of the two timers is running or stopped and contains a flag to indicate that eachtimer 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 alsocontain 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 ofoperation of each of the two timers. Using this SFR your program may configure each timer to 22
  23. 23. 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 TMODSFR; however, these timers always count up. What is configurable is how and when theyincrement 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 TMODSFR; however, these timers always count up. What is configurable is how and when theyincrement in value.P1 (Port 1, Address 90h, Bit-Addressable): This is input/output port 1. Each bit of this SFRcorresponds to one of the pins on the microcontroller. For example, bit 0 of port 1 is pin P1.0, bit7 is pin P1.7. Writing a value of 1 to a bit of this SFR will send a high level on the correspondingI/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 toconfigure the behavior of the 8051s on-board serial port. This SFR controls the baud rate of theserial port, whether the serial port is activated to receive data, and also contains flags that are setwhen a byte is successfully sent or received.SBUF (Serial Control, Addresses 99h): The Serial Buffer SFR is used to send and receive datavia the on-board serial port. Any value written to SBUF will be sent out the serial ports TXDpin. Likewise, any value which the 8051 receives via the serial ports RXD pin will be deliveredto the user program via SBUF. In other words, SBUF serves as the output port when written toand as an input port when read from.P2 (Port 2, Address A0h, Bit-Addressable): This is input/output port 2. Each bit of this SFRcorresponds to one of the pins on the microcontroller. For example, bit 0 of port 2 is pin P2.0, bit7 is pin P2.7. Writing a value of 1 to a bit of this SFR will send a high level on the correspondingI/O pin whereas a value of 0 will bring it to a low level. 23
  24. 24. IE (Interrupt Enable, Addresses A8h):The Interrupt Enable SFR is used to enable and disablespecific 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 is0 all interrupts are disabled regardless of whether an individual interrupt is enabled by setting alower bit.P3 (Port 3, Address B0h, Bit-Addressable): This is input/output port 3. Each bit of this SFRcorresponds to one of the pins on the microcontroller. For example, bit 0 of port 3 is pin P3.0, bit7 is pin P3.7. Writing a value of 1 to a bit of this SFR will send a high level on the correspondingI/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 usedto 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. Forexample, if we configure the 8051 so that all interrupts are of low priority except the serialinterrupt, the serial interrupt will always be able to interrupt the system, even if another interruptis currently executing. However, if a serial interrupt is executing no other interrupt will be able tointerrupt 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 isused to store a number of important bits that are set and cleared by 8051 instructions. The PSWSFR 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 selectwhich of the "R" register banks are currently selected.ACC (Accumulator, Addresses E0h, Bit-Addressable): The Accumulator is one of the most-used SFRs on the 8051 since it is involved in so many instructions. The Accumulator resides asan SFR at E0h, which means the instruction MOV A,#20h is really the same as MOVE0h,#20h. However, it is a good idea to use the first method since it only requires two byteswhereas 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 anauxiliary register to temporarily store values. 24
  25. 25. Chapter4:Circuit diagram and workingPower SupplyIn alternating current the electron flow is alternate, i.e. the electron flow increases to maximumin one direction, decreases back to zero. It then increases in the other direction and thendecreases to zero again. Direct current flows in one direction only. Rectifier converts alternatingcurrent to flow in one direction only. When the anode of the diode is positive with respect to itscathode, it is forward biased, allowing current to flow. But when its anode is negative withrespect to the cathode, it is reverse biased and does not allow current to flow. This unidirectionalproperty of the diode is useful for rectification. A single diode arranged back-to-back mightallow 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 theelectron flow during both positive and negative half cycles. Four diodes can be arranged to makea full wave bridge rectifier. Different types of filter circuits are used to smooth out the pulsationsin amplitude of the output voltage from a rectifier. The property of capacitor to oppose anychange in the voltage applied across them by storing energy in the electric field of the capacitorand of inductors to oppose any change in the current flowing through them by storing energy inthe magnetic field of coil may be utilized. To remove pulsation of the direct current obtainedfrom the rectifier, different types of combination of capacitor, inductors and resistors may be alsobe used to increase to action of filtering.RECTIFICATIONRectification 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 onlyduring the positive half cycles of the applied AC voltage by eliminating the negative half cyclesor alternations of the applied AC voltage. Thus pulsating DC is obtained. To obtain smooth DCpower, additional filter circuits are required. 25
  26. 26. A diode can be used as rectifier. There are various types of diodes. But, semiconductor diodesare very popularly used as rectifiers. A semiconductor diode is a solid-state device consisting oftwo 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 tocollector- the diode provides the unilateral conduction necessary for rectification. Out of thesemiconductor 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 thecircuit arrangement. Assume 6.3 V rms (18 V p-p) is applied to the circuit. Assume further thattwo equal-valued series-connected resistors R are placed in parallel with the ac source. The 18 Vp-p appears across the two resistors connected between points AC and CB, and point C is theelectrical midpoint between A and B. Hence 9 V p-p appears across each resistor. At anymoment during a cycle of vin, if point A is positive relative to C, point B is negative relative toC. When A is negative to C, point B is positive relative to C. The effective voltage in proper timephase which each diode "sees" is in Fig. The voltage applied to the anode of each diode is equalbut 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. HenceD1 will conduct but D2 will not. During the second alternation, B is positive relative to C. Theanode of D2 is therefore positive with respect to its cathode, and D2 conducts while D1 is cutoff.There is conduction then by either D1 or D2 during the entire input-voltage cycle.Since the twodiodes have a common-cathode load resistor RL, the output voltage across RL will result fromthe alternate conduction of D1 and D2. The output waveform vout across RL, therefore has nogaps 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 equalresistors R across the input voltage are necessary to provide a voltage midpoint C for circuitconnection and zero reference. Note that the load resistor R L is connected from the cathodes to 26
  27. 27. this center reference point C.An interesting fact about the output waveform vout is that its peakamplitude is not 9 V as in the case of the half-wave rectifier using the same power source, but isless 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 theconduction gaps, it delivers less than half the peak output voltage that results from half-waverectification.CIRCUIT DIAGRAMFigure-10 27
  28. 28. VOLTAGE REGULATOROne can get a constant high-voltage power supply using inexpensive 3-terminal voltageregulators through some simple techniques described below. Depending upon the currentrequirement, a reasonable load regulation can be achieved. Line regulation in all cases is equal tothat of the voltage regulator used.Though high voltage can be obtained with suitable voltage boost circuitry using ICs like LM723, some advantages of the circuits presented below are: simplicity, low cost, and practicallyreasonable regulation characteristics. For currents of the order of 1A or less, only one zener andsome resistors and capacitors are needed. For higher currents, one pass transistor such asECP055 is needed.Before developing the final circuits, let us first understand the 3-terminal type constant voltageregulators. 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 appearsbetween 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
  29. 29. LCD Interfacing:LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range ofapplications. A 16x2 LCD display is very basic module and is very commonly used in various devicesand circuits. These modules are preferred over seven segments and other multi segment LEDs. Thereasons 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 eachcharacter 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 instructiongiven 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 theASCII value of the character to be displayed on the LCD.Figure-12 29
  30. 30. Pin No Function Name 1 Ground (0V) Ground 2 Supply voltage; 5V (4.7V – 5.3V) Vcc 3 Contrast adjustment; through a variable resistor VEE 4 Selects command register when low; and data register when high Register Select 5 Low to write to the register; High to read from the register Read/write 6 Sends data to data pins when a high to low pulse is given Enable 7 DB0 8 DB1 9 DB2 10 DB3 8-bit data pins 11 DB4 12 DB5 13 DB6 14 DB7 15 Backlight VCC (5V) Led+ 16 Backlight Ground (0V) Led- 30
  31. 31. Figure-13 31
  32. 32. CIRCUIT DIAGRAM 32
  33. 33. Figure-14 33
  34. 34. Working of projectThe energy meter records the amount of power consumption.It does so by an electromechanicalsystem.The system is provided with such a mechanism that an increament in amount of currentflow through circuit causes the disc to rotate faster,means that the rotational speed of disc isdirectly proportional to the amount of current flowing through circuit.This rotation effect of disccauses the gear mechanism to work accordingly and in similar fashion rate of powerconsumption increases the blinking rate of LED integrated within the meter.The pulses from thisLED are fed to microcontroller for count operation i.e. these pulses are counted bymicrocontroller and readings are stored into external memory.External memory used here ,isEEPROM .This memory is able to store previous database as well in case one needs to checkpast consumption status.LCD is connected with microcontroller so as to show the current statusof GSM Modem.GSM modem is the means to communicate over wireless systems.GSM modemis connected with microcontroller via MAX 232 IC.GSM modem communicates at RS232standard voltage levels while uC understands TTL logic levels so MAX 232 serves as voltagelevel converter.It converts Rs232 levels into TTL and vice-versa.Whenever a command is sent to the GSM modem ,it decodes the commands and worksaccordingly.e.g. if Meter Read command is sent to modem then it captures the status of memory and picksonly integral value and sends the same information via wireless network to another modemwhose address has been cited in the program written inside the ROM. 34
  35. 35. Chapter5:Chip Programming:Flowchart: 35
  36. 36. Keil Software:KEIL Micro Vision is an integrated development environment used to create software to be runon embedded systems (like a microcontroller). It allows for such software to be written either inassembly or C programming languages and for that software to be simulated on a computerbefore being loaded onto the microcontroller. The software used is c programming.μVision3 is an IDE (Integrated Development Environment) that helps write, compile, anddebug 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 pull–down menus. In the file dialog that appears, a filename and directory was chosenfor 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 thefigure 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 themicrocontroller.In the “Project Workspace” pane at the left, right–click on “Target 1” and select “Options for„Target 1‟ ”.Under the “Output” tab of the resulting options dialog, ensure that both the “CreateExecutable” 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, right–click 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 “SourceGroup 1” folder.Double-click on the newly created file to open it in the editor. To compile the program, first saveall source files by clicking on the “Save All” button, and then click on the “Rebuild All TargetFiles” 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 windowat the bottom of the screen.All errors and warnings will reference the line and column number in which they occur alongwith 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 integrateddebugger in Keil Micro Vision. To start the debugger, select “Debug”=>”Start/Stop 36
  37. 37. Debug Session” from the pull–down menus.At the left side of the debugger window, a table is displayed containing several key parametersabout the simulated microcontroller, most notably the elapsed time (circled in thefigure 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 currentposition in the program is indicated by a yellow arrow to the left of the code). 37
  38. 38. 38
  39. 39. Electronic meters advantages:High accuracy over a wide current dynamic rangeReliability and robustnessAutomatic Meter Reading (AMR)More easily enable new functionalitiesTamper proofingPower out range detectionPower factor detectionEasily reconfiguration, upgradeDo not use gears that wear out or magnets that saturate with DCcurrentDo not require precision mechanics or have large tolerancevariations over temperature 39
  40. 40. 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
  41. 41. TROUBLESHOOTING MANUAL FOR THE GSM ENERGYMETERSYSTEM DOES NOT POWER : check If the GREEN led IS POWER on andalso check if the output voltage from the power supply is 5V or approximately1. SYSTEM POWER BUT NO DISPLAY ON THE LCD: press the reset buttonon the system. The reset button is indicated with red color2. NO MESSAGES ON THE LCD: check if the headphone is connected to thephone and also check if the phone is power3. SYSTEM HANGED: press the rest button to re-initialize the memory of theembedded system4. SYSTEM SHOWS SPECIAL CHARACTER: changed the max232 driverinside the system. Max232 is a receiver transmitter driver that is having 16pins5. LCD CONTRAST IS FADED: rotate the potentiometer in the front panel ofthe LCD to see the text clearly.6. BLANK OUTPUT DISPLAY: open the entire system and locate crystaloscillator.Crystal oscillator is harsh in colour. Replace the crystal oscillator with exactly11.0592 MHz. 41
  42. 42. 7. FAILS TO CONTROL DEVICE: Ensure that there is no messages on thephone memory and then reset the LCD also make sure the character send does notexceed 16 characters. Also make sure you put security code before the messagesand you are sending the messages to the appropriate number. The format of themessages is “12345fanon.8. NO WELCOME MESSAGE AS YOU POWER ON: The system shoulddisplay a scrolling welcome message as you power on the system. The welcomemessage 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 totouch the headphone9. NO RESPONSE FROM THE HEADPHONE: You can change the headphoneand locate the RX, TX, and GND from the headphone before connecting it to theentire system. 42
  43. 43. SNAPSHOT:Figure-15 43
  44. 44. 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 rateTH1=0xFD;SCON=0x50;TR1=1;lcdinit(); // Initialize LCDinitdisplay();DelayMs(5000);InitModem(); // Initialize Modem 44
  45. 45. 54while(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 sendingTI=0;lcdData(a[i]);i++;} 45
  46. 46. lcdData( ); // EnterSBUF=0x0d;while(TI==0);TI=0;55for(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
  47. 47. }goto retry;}//---------------------------------------// Modem initialization subroutine//---------------------------------------void InitModem(void){unsigned int j=0;unsigned char i=0,k=0;unsigned char d[6];56ReInit://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 echoTI=0;lcdData(a[i]);i++;}lcdData( ); // EnterSBUF=0x0d;while(TI==0); 47
  48. 48. 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 locationTI=0;57lcdData(b[i]);i++;}lcdData( ); // EnterSBUF=0x0d;while(TI==0);TI=0;for(i=0;i<5;i++) //command to recv data{j=0;while(RI==0){ 48
  49. 49. 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
  50. 50. 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;59lcdData(g); 50
  51. 51. 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
  52. 52. DelayMs(1);60j++;}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
  53. 53. for(i=0;i<102;i++){c[i]=0x00;}61SBUF=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
  54. 54. lcdData(d);SBUF=d;while(TI==0);TI=0;lcdData(=);SBUF==;62while(TI==0);TI=0;lcdData(1);SBUF=1;while(TI==0);TI=0;lcdData(0x0d); // EnterSBUF=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
  55. 55. RI=0;lcdData(c[i]);}DelayMs(1000);return ret;}//---------------------------------------// Lcd initialization subroutine//---------------------------------------void lcdinit(void){63lcdcmd(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
  56. 56. return;}//---------------------------------------// Lcd command//---------------------------------------void lcdcmd(unsigned char k){P1=k;DelayMs(1);EN=0;return;}//---------------------------------------// Delay mS function//---------------------------------------void DelayMs(unsigned int count){ // mSec Delay11.0592 Mhz64unsigned int i; // Keil v7.5awhile(count) {i = 115; // 115 exact valuewhile(i>0) i--;count--;}}void initdisplay(void){ 56
  57. 57. 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
  58. 58. REFERENCES: 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