You are on page 1of 110

PREPAID ENERGY METER

Page |1

Chapter 1

INTRODUCTION

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

Page |2

1. INTRODUCTION
1.1 PROBLEM STATEMENT Indian power sector is facing serious problem of lean revenue collection as against energy supplied due to energy thefts and network losses. All the steps taken so far, regarding the improvement of the revenue collection did not yield satisfactory results. It is reported that the most faulty sub system is the metering and meter reading system.

The traditional billing systems are discrete, inaccurate, costly, slow, and lack flexibility as well as reliability. Therefore, several attempts were made to automate the billing systems. Even though accurate and fast readings are obtained, bill payment is still performed based on the old billing procedure. They require an individual/agent to physically come and take down the readings and report to house hold/office the amount one has to pay.

1.2 OBJECTIVE

To understand, analyse, design and develop an on line pre-paid energy meter which provides both the suppliers and the consumers with better services regarding meter billing and payment.

1.3 METHODOLOGY

This is a very good microcontroller based application. This unit will accept the number of units recharged by the concerned department person, counts the number of units consumed by the customer and as soon as the customer exceeds the recharged amount, it will disconnect the power supply to the customer until the next recharge.

Whenever the number of units in microcontroller becomes zero microcontroller sends a signal to Contact Maker /Breaker circuit which is nothing but the relay and this relay cuts off the power supply to the consumer until next recharge.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

Page |3

1.4 WHY PREPAID:


The taught of introducing prepaid energy meter is a trendy one. This process is having many advantages. These advantages are described from two views. From the view of service provider and from the view of customer. The views are listed below.

1.4.1 Supplier View:


Pay before use Keep customers on supply Recover money owed (debt) Lower Overheads No bill production No bill distribution No need to chase payments No further actions such as disconnections Social Acceptability Customer responsible for Disconnection Load and Demand Side Management Limit load Load based Time based This method can reduce manpower and save money.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

Page |4

1.4.2 Customers View:


>80% Mobile phones used in India are prepaid Flexible Payment Solution Pay to suit your income status Daily, Weekly , Monthly Budgeting Show true cost of consumption and money Left Reduce consumption when income is tight make money last Reduce waste conserve energy No Bills No hidden surprises No having to find the money No billing errors No socially unacceptable disconnections

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

Page |5

Chapter 2

BLOCK DIAGRAM AND CIRCUIT DIAGRAM

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

Page |6

2. BLOCK DIAGRAM AND CIRCUIT DIAGRAM


2.1 BLOCK DIAGRAM:-

Fig: 2-1 Block diagram.

The above shown is the block diagram of the prepaid energy meter. It uses AT89S52 microcontroller. Its the heart of the entire system. Initially electricity passes through power supply line to loads in household. There are few problems like revenue collection and huge manpower in present post-paid system. Our project gives an excellent answer for the current problem. In this system the customer buy recharge chards to recharge the system using the provision called card reader in the system. LCD is provides to display the meter readings to the customer. The current driver ULN2803IC is used to amplify the current from the microcontroller. ULN2803IC is used to run the peripherals like relays, printers, motors etc.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

Page |7

A buzzer is used to intimate the user if the balance in the system is low. We can also use LED indications to indicate the balance in the users account. The buzzer by ringing indicates if the balance in the system is below 10%. The GREEN LED glows if the balance is upto 60%. The ORANGE led glows if the balance is between 61-85%. The RED LED is used to indicate last 10-15% balance.

2.2 CIRCUIT DIAGRAM:


This circuit consists of a card reader which consists of 5 IR-Sensors. The outputs of the IR-Sensors are connected to the pins p0.0, p0.1, p0.2, p0.3, p0.4 of microcontroller AT89S52. The other IR-Sensor is used for power meter to count the units. The units are counted with the help of Dc Motor. The dc motor cuts the infrared radiation forming pulses. These pulses are counted by microcontroller. The microcontroller consists of a crystal oscillator for giving controlled clock pulses for the controller and a reset circuit to reset or restart the microcontroller. A 16x2 LCD is used to display the data required to the user. The LCD consists of 8 data pins 3 control pins. The data pins are connected to the port 2 of the microcontroller and the control pins are connected to ports p3.5, p3.6, and p3.7. The circuit consists of the current driver ULN 2803. It is used to amplify the current coming from the pins of microcontroller. Usually the current coming from the pins of microcontroller is very low i.e., 25ma. It is not enough to activate devices like buzzer, relay, printer hammers etc. ULN 2803 amplifies the 25mA current to 500mA. The output voltage for current driver or ULN 2803 is used to access relay and buzzer in the project. In this project we used relays. In this project we used substitute for ULN 2803. We created a circuit with transistor and resistor. A relay is an electrical switch which opens and closed upon excitation provided by the supporting circuit. The relay activated the DC motor and the final load i.e., bulb when the meter is having balance in it. We used a transistor in the circuit for better result at the relays. The recharge cards used in this project are termed as smart cards. These smart cards can also be termed as punch cards. These are termed so as they contain punches or holes. The data of the punches in the smart card are stored previously in the microcontroller. When the card is inserted in the reader the card reader senses the data and this data is compared with the pre stored data in the microcontroller and the recharge is made. If the data doesnt match the LCD displays INVALID DATA ENTERED. The descriptions of the used components are discussed in detail in further chapters.
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

Page |8

Fig: 2-2 Circuit diagram.


VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

Page |9

2.3 HARDWARE USED:


Hardware components used in this project are listed below. Microcontroller AT89S52. LCD Display LEDs. Buzzer. Relays. IR Sensor Module. Smart Card reader and cards. 230v Bulb. Dc Motor. Miscellaneous items. 16x2 LCD.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 10

Chapter 3

EMBEDDED SYSTEM

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 11

3. EMBEDDED SYSTEM
3.1 INTRODUCTION:
An Embedded System is a combination of computer hardware and software, and perhaps additional mechanical or other parts, designed to perform a specific function. A good example is the microwave oven. Almost every household has one, and tens of millions of them are used every day, but very few people realize that a processor and software are involved in the preparation of their lunch or dinner. This is in direct contrast to the personal computer in the family room. It too is comprised of computer hardware and software and mechanical components (disk drives, for example). However, a personal computer is not designed to perform a specific function rather; it is able to do many different things. Many people use the term general-purpose computer to make this distinction clear. As shipped, a general-purpose computer is a blank slate; the manufacturer does not know what the customer will do wish it. One customer may use it for a network file server another may use it exclusively for playing games, and a third may use it to write the next great American novel. Frequently, an embedded system is a component within some larger system. For example, modern cars and trucks contain many embedded systems. One embedded system controls the anti-lock brakes, other monitors and controls the vehicle's emissions, and a third displays information on the dashboard. In some cases, these embedded systems are connected by some sort of a communication network, but that is certainly not a requirement. At the possible risk of confusing you, it is important to point out that a generalpurpose computer is itself made up of numerous embedded systems. For example, my computer consists of a keyboard, mouse, video card, modem, hard drive. For example, the modem is designed to send and receive digital data over analog telephone line. That's it and all of the other devices can be summarized in a single sentence as well. If an embedded system is designed well, the existence of the processor and software could be completely unnoticed by the user of the device. Such is the case for a microwave oven, VCR, or alarm clock. In some cases, it would even be possible to build an equivalent device that does not contain the processor and software. This could be done by replacing the

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 12

combination with a custom integrated circuit that performs the same functions in hardware. However, a lot of flexibility is lost when a design is hard-cooled in this way. It is much easier, and cheaper, to change a few lines of software than to redesign a piece of custom hardware.

3.2 HISTORY AND FUTURE:


Given the definition of embedded systems earlier is this chapter; the first such systems could not possibly have appeared before 1971. That was the year Intel introduced the world's first microprocessor. This chip, the 4004, was designed for use in a line of business calculators produced by the Japanese Company Busicom. In 1969, Busicom asked Intel to design a set of custom integrated circuits-one for each of their new calculator models. The 4004 was Intel's response rather than design custom hardware for each calculator, Intel proposed a general-purpose circuit that could be used throughout the entire line of calculators. Intel's idea was that the software would give each calculator its unique set of features. The microcontroller was an overnight success, and its use increased steadily over the next decade. Early embedded applications included unmanned space probes, computerized traffic lights, and aircraft flight control systems. In the 1980s, embedded systems quietly rode the waves of the microcomputer age and brought microprocessors into every part of our kitchens (bread machines, food processors, and microwave ovens), living rooms (televisions, stereos, and remote controls), and workplaces (fax machines, pagers, laser printers, cash registers, and credit card readers). It seems inevitable that the number of embedded systems will continue to increase rapidly. Already there are promising new embedded devices that have enormous market potential; light switches and thermostats that can be central computer, intelligent air-bag systems that don't inflate when children or small adults are present, pal-sized electronic organizers and personal digital assistants (PDAs), digital cameras, and dashboard navigation systems. Clearly, individuals who possess the skills and desire to design the next generation of embedded systems will be in demand for quite some time.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 13

3.3 Characteristics of Embedded Systems:

Embedded systems do a very specific task; they can't be programmed to do different things. Embedded systems have limited resources, particularly the memory. Generally, they do not have secondary storage device such as the CDROM or the floppy disk. Embedded systems have to work against some deadlines. A specific job has to complete with in the specific time. Embedded systems are constrained for power. As many embedded systems operate through a battery, the power consumption has to be very low. Embedded systems need to be highly reliable. Once in a while, pressing ALT+CRTL+DEL is ok in your desktops, but you can't afford to reset your embedded system. Some embedded systems have to operate in the extreme environmental conditions such as very high temperatures and humidity.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 14

Chapter 4

MICROCONTROLLER

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 15

4. MICROCONTROLLER 4.1 WHAT IS A MICROCONTROLLER:

Fig: 4-1 Block diagram of microcontroller.

A microcontroller is an integrated chip that is often part of an embedded system. The microcontroller includes a CPU, ALU, PC, SP and registers, RAM, ROM, I/O ports and timers like a standard computer but they are designed to execute only a single specific task to control a single system. They are much smaller and simplified so that they can include all the functions required on a single chip. Like the microprocessor, a microcontroller is a general-purpose device, but one that is meant to read data, performs limited calculations on that data, and control its environment based on its calculations. Most microcontrollers will also combine other devices such as: A Timer module to allow the microcontroller to perform tasks for certain periods. time

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 16

A serial I/O port to allow data to flow between the microcontroller and other devices such as a PC or another microcontroller.

An ADC to allow the microcontroller to accept analogue input data for processing.

4.2 ADVANTAGES OF MICROCONTROLLERS:


Their powerful, cleverly chosen electronics is able to control a variety of processes and devices (industrial automatics, voltage, temperature, engines, etc) independently or by means of I/O instruments such as switches, buttons, sensors, LCD screens, relays etc. Their low cost makes them suitable for installing in places, which attracted no such interest in the past. This is the fact accountable for today's market being swamped with cheap automatons and "intelligent" toys. Writing and loading a program into microcontroller requires practically no previous knowledge. All that is required is: any PC (software is very friendly and intuitive) and one simple device (programmer) for loading a written program into microcontroller.

4.3 TYPES OF 8051 MICROCONTROLLER:


The 8051 has the widest range of variants of any embedded controller on the market. The smallest device is the Atmel 89C51, a 20 Pin FLASH variant with 2 timers, USART. The fastest parts are from Dallas, with performance close to 10 MIPS! The most powerful chip is the Infineon Technologies 80C517A, with 32 bit ALU, 2 UARTS, 2K RAM, PLCC84 package, 8 x 16 Bit PWMs, and other features. The microcontroller used in this project is AT89S8252. Atmel Corporation introduced this 89S51 microcontroller. The present project is implemented on 8051 IDE. In order to program the device, preload tool has been used to burn the program onto the microcontroller. We used handy proj software for burning the code into the microcontroller. The features, pin description of the microcontroller and the software tools used are discussed in the following sections.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 17

Among the MAJOR manufacturers are: AMD Atmel Cygnal Dallas Intel ISSI Matra OKI Enhanced 8051 parts (no longer producing 8051 parts) FLASH and semi-custom parts Fastest 8051 with Flash memory. 20MH internal clock. Fast variant. Also battery backed 8051 through 80C51GB / 80C51Sl. They invented the 8051 IS80C51/31 runs up to 40MHz 80C154, low voltage static variants 80C154, mask parts.

Table: 4-1 Manufacturers of Microcontrollers.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 18

Fig: 4-2 Family Tree Of Microcontroller

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 19

4.4 DISCRIPTION:
The AT89S8252 is a low-power, high-performance CMOS 8-bit microcontroller with 8K bytes of downloadable Flash programmable and erasable read-only memory and 2K bytes of EEPROM. The device is manufactured using Atmels high-density nonvolatile memory technology and is compatible with the industry-standard 80C51 instruction set and pin out. The on-chip downloadable Flash allows the program memory to be reprogrammed through an SPI serial interface or by a conventional nonvolatile memory programmer. By combining a versatile 8-bit CPU with downloadable Flash on a monolithic chip, the Atmel AT89S8252 is a powerful microcontroller, which provides a highly-flexible and costeffective solution to many embedded control applications. The AT89S8252 provides the following standard features: 8K bytes of downloadable Flash, 2K bytes of EEPROM, 256 bytes of RAM, 32 I/O lines, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S8252 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The Power-down mode saves the RAM contents but freezes the oscillator, disabling all other chip functions until the next external interrupt or hardware reset. The downloadable Flash can be changed a single byte at a time and is accessible through the SPI serial interface. Holding RESET active forces the SPI bus into a serial programming interface and allows the program memory to be written to or read from unless lock bits have been activated.

4.5 FEATURES OF AT89S52:


8K Bytes of In-System Reprogrammable Downloadable Flash Memory 2K Bytes EEPROM Endurance: 100,000 Write/Erase Cycles 4V to 6V Operating Range Fully Static Operation: 0 Hz to 24 MHz
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 20

Three-level Program Memory Lock 256 x 8-bit Internal RAM 32 Programmable I/O Lines Three 16-bit Timer/Counters Nine Interrupt Sources SPI Serial Interface Programmable UART Serial Channel Interrupt Recovery from Power-down Dual Data Pointer Power-off Flag

4.6 DEVICE OVERVIEW:


This document contains device specific information the AT89S52device come in 40 pin packages. The AT89C51 block diagram is shown in Fig: 4-2

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 21

Fig: 4-3 internal diagrams.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 22

4.7 TYPES OF MEMORY:


The 8051 has three very general types of memory. To effectively program the 8051 it is necessary to have a basic understanding of these memory types.

Fig: 4-4 Types of memory

4.7.1 On-Chip Memory:


This memory refers to any memory (Code, RAM, or other) that physically exists on the microcontroller itself. On-chip memory can be of several types.

4.7.2 External Code Memory:


It is code (or program) memory that resides off-chip. This is often in the form of an external EPROM.

4.7.2.1 External RAM:


It is RAM memory that resides off-chip. This is often in the form of standard static RAM or flash RAM.

As mentioned at the beginning of this chapter, the 8051 include a certain amount of on chip memory. On-chip memory is really one of two (SFR) memories. The layout of the 8051's internal memory is presented in the following memory map:

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 23

Fig: 4-5 Memory bank.

As is illustrated in this map, the 8051 has a bank of 128 bytes of Internal RAM. This Internal RAM is found on-chip on the 8051 so it is the fastest RAM available, and it is also the most flexible in terms of reading, writing, and modifying its contents. Internal RAM is volatile, so when the 8051 is reset this memory is cleared. The 128 bytes of internal RAM is subdivided as shown on the memory map. The first 8 bytes (00H 07H) are "register bank 0". By manipulating certain SFRs, a program may choose to use register banks 1, 2, or 3. These alternative register banks are located in internal RAM in addresses 08h through 1FH. Bit Memory also lives and is part of internal RAM. Keep in mind that bit memory actually resides in internal RAM, from addresses 20H through 2FH. The 80 bytes remaining of Internal RAM, from addresses 30h through 7Fh, may be used by user variables that need to be accessed frequently or at high-speed. This area is also utilized by the microcontroller as a storage area for the operating stack. This fact severely limits the 8051s stack since, as illustrated in the memory map, the area reserved for the stack is only 80 bytes--and usually it is less since these 80 bytes has to be shared between the stack and user variables.

4.7.2.2 Register Banks:


The 8051 use 8 "R" registers, which are used in many of its instructions. These "R" registers are numbered from 0 through 7 (R0, R1, R2, R3, R4, R5, R6, and R7). These

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 24

registers are generally used to assist in manipulating values and moving data from one memory location to another.

4.7.2.3 Bit Memory:


The 8051, being a communications oriented microcontroller, gives the user the ability to access a number of bit variables. These variables may be either 1 or 0. There are 128 bit variables available to the user, numbered 00h through 7Fh. The user may make use of these variables with commands such as SETB and CLR. It is important to note that Bit Memory is really a part of Internal RAM. In fact, the 128 bit variables occupy the 16 bytes of Internal RAM from 20h through 2Fh. Thus, if you write the value FFh to Internal RAM address 20h youve effectively set bits 00h through 07h.

4.8 REGISTER SETS IN 89S52:


4.8.1 SFR:
Special Function Registers (SFRs) are areas of memory that control specific functionality of the 8051 processor. For example, four SFRs permit access to the 8051s 32 input/output lines. Another SFR allows a program to read or write to the 8051s serial port. Other SFRs allow the user to set the serial baud rate, control and access timers, and configure the 8051s interrupt system. When programming, SFRs have the illusion of being Internal Memory. The 8051 has four I/O ports of 8 bits, for a total of 32 I/O lines. Whether a given I/O line is HIGH or LOW and the value read from the line are controlled by the SFRs in green. The SFRs with yellow backgrounds are SFRs that in some way control the operation or the configuration of some aspect of the 8051. For example, TCON controls the timers, SCON controls the serial port. The remaining SFRs, with green backgrounds, are "other SFRs." These SFRs can be thought of as auxiliary SFRs in the sense that they don't directly configure the 8051 but obviously the 8051 cannot operate without them. For example, once the serial port has been configured using SCON, the program may read or write to the serial port using the SBUF register.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 25

4.8.2 P0 (Port 0, Address 80h, and 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.

4.8.3 SP (Stack Pointer, Address 81h):


This is the stack pointer of the microcontroller. This SP indicates where the next value to be taken from the stack will be read from Internal RAM. If we 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 that modify the stack, such as PUSH, POP, and LCALL, RET, RETI, and whenever interrupts are provoked by the microcontroller.

4.8.3 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 0000Hto FFFFH (0 through 65,535 decimal).

4.8.4 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 that 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.

4.8.5 TCON (Timer Control, Addresses 88H, and 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

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 26

the external interrupts are activated and also contain the external interrupt flags which are set when an external interrupt has occurred.

4.8.6 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 be a 16-bit timer, an 8-bit auto reload timer, a 13-bit timer, or two separate timers. Additionally, we may configure the timers to only count when an external pin is activated or to count "events" that are indicated on an external pin.

4.8.7 TL0/TH0 (Timer0 Low/High, Addresses 8AH/8BH):


These two SFRs, taken together, represent timer0. Their exact behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up.

4.8.8 TL1/TH1 (Timer1 Low/High, Addresses 8CH/8DH):


These two SFRs, taken together, represent timer1. Their exact behavior depends on how the timer is configured in the TMOD SFR; however, these timers always count up.

4.8.9 P1 (Port1, Address 90H, and Bit-Addressable):


This is input/output port1. 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.

4.8.10 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.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 27

In most cases the program will wish to use one of the timers to establish the serial port's baud rate. In this case, it is necessary to configure timer1 by initializing TCON and TMOD.

4.8.11 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.

4.8.12 P2 (Port 2, Address A0H, and Bit-Addressable):


This is input/output port 2. Each bit of this SFR corresponds to one of the pins on the microcontroller. For example, bit0 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.

4.8.13 IE (Interrupt Enable, Addresses A8H):


The Interrupt Enable SFR is used to enable and disable specific interrupt. The lower 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.

4.8.14 P3 (Port 3, Address B0H, and 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.

4.8.15 IP (Interrupt Priority, Addresses B8h, and 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
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 28

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.

4.8.16 PSW (Program Status Word, Addresses D0H, and 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.

4.8.17 ACC (Accumulator, Addresses E0H, and 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 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.

4.8.18 B (B Register, Addresses F0H, Bit-Addressable):


The "B" register is used in two instructions: the multiply and divide operations. Programmers also commonly use the B register as an auxiliary register to temporarily store values.

4.9 BASIC REGISTERS:


4.9.1 The Accumulator:
The Accumulator, as its name suggests, is used as a general register to accumulate the results of a large number of instructions. It can hold an 8-bit (1-byte) value and is the most versatile register. More than half of the 8051s instructions manipulate or use the

accumulator in some way.


VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 29

4.9.2 The "R" registers:


The "R" registers are a set of eight registers that are named R0, R1R7. These registers are used as auxiliary registers in many operations. We may think of the R registers as very important auxiliary, or "helper", registers. The Accumulator alone would not be very useful if it were not for these "R" registers. The "R" registers are also used to temporarily store values.

4.9.3 The B Registers:


The "B" register is very similar to the Accumulator in the sense that it may hold an 8bit (1-byte) value. The "B" register is only used by two 8051 instructions: MUL AB and DIV AB. Thus, if we want to quickly and easily multiply or divide A by another number, we may store the other number in "B" and make use of these two instructions. Aside from the MUL and DIV instructions, the B register are often used as yet another temporary storage register much like a ninth "R" register.

2.9.4 The Data Pointer (DPTR):


The Data Pointer (DPTR) is the 8051s only user-accessible 16-bit (2-byte) register. The Accumulator, "R" registers, and "B" register are all 1-byte values. DPTR, as the name suggests, is used to point to data. It is used by a number of commands, which allow the 8051 to access external memory. When the 8051 accesses external memory it will access external memory at the address indicated by DPTR. While DPTR is most often used to point to data in external memory, many programmers often take advantage of the fact that its the only true 16- bit register available. It is often used to store 2- byte values, which have nothing to do with memory locations.

4.9.5 The Program Counter (PC):


The Program Counter (PC) is a 2-byte address, which tells the 8051 where the next instruction to be executed is found in memory. When the 8051 is initialized PC always starts at 0000H and is incremented each time an instruction is executed. It is important to note that PC isnt always incremented by one. Since some instructions require 2 or 3 bytes the PC will be incremented by 2 or 3 in these cases. The Program Counter is special in that there is no way to directly modify its value.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 30

4.9.6 The Stack Pointer (SP):


The Stack Pointer, like all registers except DPTR and PC, may hold an 8-bit (1-byte) value. The Stack Pointer is used to indicate where the next value to be removed from the stack should be taken from. When we push a value onto the stack, the 8051 first increments the value of SP and then stores the value at the resulting memory location. When we pop a value off the stack, the 8051 returns the value from the memory location indicated by SP and then decrements the value of SP. SP is modified directly by the 8051 by six instructions: PUSH, POP, ACALL, LCALL, RET, and RETI. It is also used intrinsically whenever an interrupt is triggered.

4.10 UART:
One of the 8051s many powerful features is its integrated UART, otherwise known as serial port. An UART, universal asynchronous receiver /transmitter is responsible for performing the main task in serial communications with computers. The device changes incoming parallel information to serial data, which can be sent on a communication line. A second UART can be used to receive the information. The UART performs all the tasks, timing, parity checking, etc. Needed for the communication. The only extra devices attached are line driver chips capable of transforming the TTL level signals to line voltages and vice versa. The fact that the 8051 has an integrated serial port means that we may very easily read and write to the serial port we need to configure the serial ports operation mode and baud rate once configured all we have to do is to write to SFR to write a value to the serial port or the read same SFR to read a value from a serial port.

4.10.1 Setting the serial port mode:


The first thing we have to do is to configure the serial port this tells the serial baud rate we are using. Lets present the serial control (SCON) SFR and define what each bit of the SFR represent.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 31

Table: 1

BIT

NAME

BIT ADDRESS

EXPLANATION OF THE FUNCTION

7 6 5

SM0 SM1 SM2

9FH 9EH 9DH

SERIAL PORT MODE BIT 0 SERIAL PORT MODE BIT 1 MULTIPROCESSOR COMMUNIATION ENABLE

4 3 2 1 0

REN B8 RB8 T1 R1

9CH 9BH 9AH 99H 98H

RECIVER ENABLE TRANSMIT BIT 8 RECEIVE BIT 8 TRANSMIT FLAG RECIVE FLAG

Table: 4-2 Setting The Serial Mode.


The SCON SFR allows us to configure the serial port. The first four bits are configuration bits. The both bits SM0 and SM1 set the serial mode to a value between 0 and 3, the four modes are The next bit is a SM2 is a flag for multiprocessor communication generally when a byte has been received the 8051 will set the RI flag this lets the program know that a byte has been received and that it needs to be processed. However if SM2 is set and a byte is received whose 9th bit is received the RI flag will never set. The next bit REN is receiver enable this bit is straight forward if we want to receive data via serial port set this bit. The last four bits are operational bits they are used when data is actually sent or received

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 32

Table: 2

SM0 SM1

SERIAL MODE
0

EXPLIANATION
8BIT SHIFT REGISTER 8 BIT UART

BAUD RATE
OSCILATOR FREQUENCY BY 12 SET BY TIMER1 OSCILATOR FREQUENCY BY 32 SET BY TIMER1

8 BIT UART

8 BIT UART

Table: 4-3 Baud Rate.

The next bit is a SM2 is a flag for multiprocessor communication generally when a byte has been received the 8051 will set the RI flag this lets the program know that a byte has been received and that it needs to be processed. However if SM2 is set and a byte is received whose 9th bit is received the RI flag will never set. The next bit REN is receiver enable this bit is straight forward if we want to receive data via serial port set this bit. The last four bits are operational bits they are used when data is actually sent or received The Tb8 bit is used in modes 2 and 3. in modes 2 and 3 a total of 9 bits are transmitted first 8 are the data bits and the 9th bit is taken from Tb8 bit If Tb8 is set and the value is written to the serial port the data bits will be written to the serial line followed by a set 9th bit is if Tb8 is clear the 9th bit is clear. The Rb8 also operates in modes 2 and 3 and functions same way as Tb8 but on the reception side. TI means transmit interrupt. When a program writes a value to the serial port certain amount of time will pass before the individual bits of the byte are clocked out the serial port. When the TI bit is set, the program may assume that the serial port is free to send the next bit.
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 33

Finally the RI bit means receive interrupt. It functions are similar to that of a TI bit but it indicates the byte has been received.

4.10.2 Setting the serial port baud rate:


Once the serial port mode has been configured, the program must configure the serial port baud rate. This applies to serial port in modes 1and 3. The baud rate is determined based on the oscillators frequency when in mode 0 and 2, the baud rate is always the oscillator frequency is divided by 12.In modes 1 and 3, the baud rate is determined by how frequently timer1 overflows. The more frequently timer1 overflows, the higher the baud rate. The most common method is to cause timer1 overflow and put timer1 in 8 bit auto reload mode (timer mode2) and set a reload value (TH1) that causes timer1 to overflow at a frequency appropriate to generate a baud rate. To determine the value that must be placed in TH1 to generate a given baud rate we use the following equation. TH1=256-((Crystal/384)/baud) when (PCON.7 is clear) TH1=256-((Crystal/192)/baud) when (PCON.7 is set) Here we are able to calculate event TH1 value to obtain 19,200 baud with an 11.059 MHz crystal we must configure the serial port in modes 1and 3, configure timer1 to timer mode 2. Set TH1 to 253 to reflect the correct frequency for 19,200 baud Set PCON.7 to double the baud rate.

4.10.3 Writing to Serial Port:


Once the serial port has been configured properly the serial port is ready to send and receive data. If we thought that configuring the serial port was simple, using the serial port will be a breeze. To write a byte to the serial port one must simply write the value to the SBUF (99h) SFR for example, if we wanted to send the letter A to the serial port, it could be accomplished as easily as: MOV SBUF, #A Upon execution of the above instruction the

8051 will begin transmitting the character via the serial port. Obviously transmission is not
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 34

instantaneous; it takes a measurable amount of time to transmit. And since the 8051 do not have a serial output buffer we need to be sure that a character is completely be transmitted before we try to transmit the next character. The 8051 lets us know when it is done transmitting a character by setting the TI bit in SCON. When this bit is set we know that the character has been transmitted and that we may send the next character, if any. Consider the following code segment: CLR TI; be sure the bit is initially clear MOV SBUF, #A; sends the letter A to the serial port JNB TI, $; pause until the TI bit is set These three instructions will successfully transmit the character and wait for the TI bit to be set before continuing. The last instruction says jump if the TI bit is not set to $-- $, in most assemblers meansthe same address of the current instruction. Thus the 8051 will pause on the JNB instruction until the TI bit is set by the 8051 upon successful transmission of the character.

4.10.4 Reading the serial port:


Reading data received by serial port is equally easy. To read a byte from a serial port one just needs to read the value stored in the SBUF (99h) SFR after the 8051 has the automatically set RI flag in SCON. For example, if our program wants to wait for a character to be received and subsequently read it on the accumulator, the following code segment may be used JNB RI, $; Wait for 8051 to set the RI flag MOV A, SBUF; Read the character from the serial port The first line of the above code segment waits for the 8051 to set the RI flag;

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 35

Again, the 8051 sets the RI flag automatically when it receives the character via the serial port. So as long as the bit is not set the program repeats the JNB instruction continuously. Once the RI bit is set upon character reception the above condition automatically fails and program flow falls through to the MOV instruction, which reads the value.

4.11 INTERRUPTS:
As stated earlier, program flow is always sequential, being altered only by those instructions, which especially cause program flow to deviate in some way. However, interrupts give us a mechanism to "put on hold" the normal program flow, execute a subroutine, and then resume normal program flow as if we had never left it. The event may be one of the timers "overflowing," receiving a character via the serial port, transmitting a character via the serial port, or one of two "external events." The 8051 may be configured so that when any of these events occur the main program is temporarily suspended and control passed to a special section of code, which presumably would execute some function, related to the event that occurred. Once complete, control would be returned to the original

program. The main program never knows it was interrupted. The ability to interrupt normal program execution when certain events occur makes it much easier and much more efficient to handle certain conditions. If it were not for interrupts we would have to manually check in our main program whether the timers had overflow, whether we had received another character via the serial port, or if some external event had occurred. Besides making the main program complex and hard to read, such a situation would make our program inefficient since wed be burning precious "instruction cycles" checking for events that usually dont happen. The microcontroller itself will check for the condition automatically and when the condition is met will jump to a subroutine, execute the code, then returns. With interrupts, the 8051 will put the main program "on hold" and call our special routine to handle the reception of a character. Thus, we neither has to put a complex check in our main code nor we will lose characters.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 36

4.12 PIN DESCRIPTION:

Fig: 2.6 Pin diagram 4.12.1 VCC: Supply voltage. 4.12.2 GND: Ground. 4.12.3 Port 0: Port 0 is an 8-bit open-drain bi-directional 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 may 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 receives the code bytes during Flash programming, and outputs the code bytes during program verification. External pull-ups are required during program verification.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 37

4.12.4 Port 1: Port 1 is an 8-bit bi-directional 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 internal 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. Port1 also receives the low-order address bytes during Flash programming and verification. 4.12.5 Port 2: Port 2 is an 8-bit bi-directional 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 internal 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. Port2 emits the high-order address byte during fetches from external program memory and during accesses to external data memory that uses 16-bit addresses. In this application, it uses strong internal pull-ups when emitting 1s. During accesses to external data memory that uses 8-bit addresses, 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 programming and verification. 4.12.6 Port 3: Port 3 is an 8-bit bi-directional 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 internal 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 also serves the functions of various special features of the AT89C51 as listed below: Port 3 also receives some control signals for Flash programming and verification. 4.12.7 RST: Reset input. A high on this pin for two machine cycles while the oscillator is running resets the device.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 38

4.12..8 Port Pin Alternate Functions: P3.0 P3.1 P3.2 P3.3 P3.4 P3.5 P3.6 P3.7 RXD (serial input port) TXD (serial output port) INT0 (external interrupt 0) INT1 (external interrupt 1) T0 (timer 0 external input) T1 (timer 1 external input) WR (external data memory write strobe) RD (external data memory read strobe)

Port 3 also receives some control signals for Flash programming and verification. 4.12.9 ALE/PROG: Address Latch Enable 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 that one ALE pulse is skipped during 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 ALEdisable bit has no effect if the microcontroller is in external execution mode. 4.12.11 PSEN: Program Store Enable is the read strobe to external program memory. When the AT89C51 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 external data memory.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 39

4.12.12 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, for parts that require12-volt VPP. 4.12.13 XTAL1: Input to the inverting oscillator amplifier and input to the internal clock operating circuit. 4.12.14 XTAL2: Output from the inverting oscillator amplifier.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 40

Chapter 5

COMPONENTS

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 41

5. COMPONENTS
5.1 RESISTOR:
Resistors "Resist" the flow of electrical current. The higher the value of resistance (measured in ohms) the lower the current will be. Resistance is the property of a component which restricts the flow of electric current. Energy is used up as the voltage across the component drives the current through it and this energy appears as heat in the component.

5.1.1 Colour Code:

Fig: 5-1

Resistor

Fig: 5-2 Resister Color Combination

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 42

5.2 CAPACITOR:
Capacitors store electric charge. They are used with resistors

in timing circuits because it takes time for a capacitor to fill with charge. They are used to smooth varying DC supplies by acting as a reservoir of charge. They are also used in filter circuits because capacitors easily pass AC (changing) signals but they block DC (constant) signals.

Fig: 5-3 Capacitor Symbol Electrolytic capacitors are polarized and they must be connected the correct way round, at least one of their leads will be marked + or -.

Examples: Fig: 5-4 Capacitors in market.

5.3 DIODES:
Diodes allow electricity to flow in only one direction. The arrow of the circuit symbol shows the direction in which the current can flow. Diodes are the electrical version of a valve and early diodes were actually called valves.

Circuit symbol:
Fig: 5-5 Diode Symbol Diodes must be connected the correct way round, the diagram may be labeled a or + for anode and k or - for cathode (yes, it really is k, not c, for cathode!). The cathode is marked by a line painted on the body. Diodes are labeled with their code in small print; you may need a magnifying glass to read this on small signal diodes.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 43

Example:

Fig: 5-6 Diode.

5.4 BUZZER:

Fig: 5-7 Buzzer An electric coil is wound on a plastic bobbin, the latter having a central sleeve within which a magnetic core is sliceable positioned. One end of the sleeve is closed and projects beyond the coil. An inverted cup-shaped housing surrounds the coil and bobbin and has a central opening through which the closed end of the sleeve projects. The core projects into the closed end of the sleeve beyond the margin of the opening in the housing to augment the magnetic coupling between the housing and the core. The open end of the housing is attached to a support bracket of magnetic material, there being a spring between the bracket and bobbin normally urging the core toward the closed end of the sleeve.

Fig: 5.8 Top View of Buzzer

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 44

5.5 LIGHT-EMITTING DIODE (LED):


The longer lead is the anode (+) and the shorter lead is the cathode (&minus). In the schematic symbol for an LED (bottom), the anode is on the left and the cathode is on the right. Light-emitting diodes are elements for light signalization in electronics.

Fig: 5.9 LED View They are manufactured in different shapes, colors and sizes. For their low price, low consumption and simple use, they have almost completely pushed aside other light sourcesbulbs at first place.

Fig: 5.10 Typical LEDS It is important to know that each diode will be immediately destroyed unless its current is limited. This means that a conductor must be connected in parallel to a diode. In
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 45

order to correctly determine value of this conductor, it is necessary to know diodes voltage drop in forward direction, which depends on what material a diode is made of and what colors it is. Values typical for the most frequently used diodes are shown in table below: As seen, there are three main types of LEDs. Standard ones get full brightness at current of 20mA. Low Current diodes get full brightness at ten times lower current while Super Bright diodes produce more intensive light than Standard ones. Since the 8051 microcontrollers can provide only low input current and since their pins are configured as outputs when voltage level on them is equal to 0, direct confectioning to LEDs is carried out as it is shown on figure (Low current LED, cathode is connected to output pin).

5.6 SWITCHES AND PUSHBUTTONS:


A push button switch is used to either close or open an electrical circuit depending on the application. Push button switches are used in various applications such as industrial equipment control handles, outdoor controls, mobile communication terminals, and medical equipment, and etc. Push button switches generally include a push button disposed within a housing. The push button may be depressed to cause movement of the push button relative to the housing for directly or indirectly changing the state of an electrical contact to open or close the contact. Also included in a pushbutton switch may be an actuator, driver, or plunger of some type that is situated within a switch housing having at least two contacts in communication with an electrical circuit within which the switch is incorporated.

Fig: 5-11 Switch Typical actuators used for contact switches include spring loaded force cap actuators that reciprocate within a sleeve disposed within the canister. The actuator is typically coupled to the movement of the cap assembly, such that the actuator translates in a direction that is

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 46

parallel with the cap. A push button switch for a data input unit for a mobile communication device such as a cellular phone, a key board for a personal computer or the like is generally constructed by mounting a cover member directly on a circuit board. Printed circuit board (PCB) mounted pushbutton switches are an inexpensive means of providing an operator interface on industrial control products. In such push button switches, a substrate which includes a plurality of movable sections is formed of a rubber elastomeric. The key top is formed on a top surface thereof with a figure, a character or the like by printing, to thereby provide a cover member. Push button switches incorporating lighted displays have been used in a variety of applications. Such switches are typically comprised of a pushbutton, an opaque legend plate, and a back light to illuminate the legend plate.

5.7 Transistor:

Fig: 5-12 Different Transistors. A transistor is a semiconductor device used to amplify and switch electronic signals. It is made of a solid piece of semiconductor material, with at least three terminals for connection to an external circuit. A voltage or current applied to one pair of the transistor's terminals changes the current flowing through another pair of terminals. Because the controlled (output) power can be much more than the controlling (input) power, the transistor provides amplification of a signal. Some transistors are packaged individually but many more are found embedded in integrated circuits.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 47

The transistor is the fundamental building block of modern electronic devices, and its presence is ubiquitous in modern electronic systems. Physicist Julius Edgar Lilienfeld filed the first patent for a transistor in Canada in 1925, describing a device similar to a Field Effect Transistor or "FET".[1] However, Lilienfeld did not publish any research articles about his devices,[citation needed] nor did his patent cite any examples of devices actually constructed. In 1934, German inventor Oskar Heil patented a similar device. . The transistor is the key active component in practically all modern electronics, and is considered by many to be one of the greatest inventions of the twentieth century.[8] Its importance in today's society rests on its ability to be mass produced using a highly automated process (semiconductor device fabrication) that achieves astonishingly low pertransistor costs. The transistor's low cost, flexibility, and reliability have made it a ubiquitous device. Transistorized mechatronic circuits have replaced electromechanical devices in controlling appliances and machinery. It is often easier and cheaper to use a standard microcontroller and write a computer program to carry out a control function than to design an equivalent mechanical control function.

Fig: 5-13 NPN And PNP Transistors.

5.7.1 USAGE:
The bipolar junction transistor, or BJT, was the most commonly used transistor in the 1960s and 70s. Even after MOSFETs became widely available, the BJT remained the transistor of choice for many analog circuits such as simple amplifiers because of their
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 48

greater linearity and ease of manufacture. Desirable properties of MOSFETs, such as their utility in low-power devices, usually in the CMOS configuration, allowed them to capture nearly all market share for digital circuits; more recently MOSFETs have captured most analog and power applications as well, including modern clocked analog circuits, voltage regulators, amplifiers, power transmitters, motor drivers, etc.

5.7.2 Transistor as a switch


Transistors are commonly used as electronic switches, for both high power applications including switched-mode power supplies and low power applications such as logic gates. In a grounded-emitter transistor circuit, such as the light-switch circuit shown, as the base voltage rises the base and collector current rise exponentially, and the collector voltage drops because of the collector load resistor. The relevant equations: VRC = ICE RC, the voltage across the load (the lamp with resistance RC) VRC + VCE = VCC, the supply voltage shown as 6V If VCE could fall to 0 (perfect closed switch) then Ic could go no higher than VCC / RC, even with higher base voltage and current. The transistor is then said to be saturated. Hence, values of input voltage can be chosen such that the output is either completely off,[12] or completely on. The transistor is acting as a switch, and this type of operation is common in digital circuits where only "on" and "off" values are relevant.

5.7.3 Transistor as an amplifier


The common-emitter amplifier is designed so that a small change in voltage in (Vin) changes the small current through the base of the transistor and the transistor's current amplification combined with the properties of the circuit mean that small swings in Vin produce large changes in Vout. Various configurations of single transistor amplifier are possible, with some providing current gain, some voltage gain, and some both. From mobile phones to televisions, vast numbers of products include amplifiers for sound reproduction, radio transmission, and signal processing. The first discrete transistor audio amplifiers barely supplied a few hundred milliwatts, but power and audio fidelity gradually increased as better transistors became available and amplifier architecture
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 49

evolved.Modern transistor audio amplifiers of up to a few hundred watts are common and relatively inexpensive. The transistors used in this project are BC547. We use transistors as switching circuit to activate relays.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 50

Chapter 6

POWER SUPPLY CIRCUIT

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 51

6. POWER SUPPLY CIRCUIT:

Fig 6.1 Power supply circuit:


Any invention of latest technology cannot be activated without the source of power. So in this fast moving world we deliberately need a proper power source, which will be apt for a particular requirement. All the electronic components starting from diode to ICs only work with a DC supply ranging from 5V to 12V. and regulating the voltage to get an output of 5V to 12V. We are utilizing the cheapest and

commonly available energy source of 230V-50Hz and stepping down, rectifying, filtering

6.1 TRANSFORMER:
A bridge rectifier coupled with a step down transformer is used for our design. The voltage rating of transformer used is 0-12V and the current rating is 500mA. When AC voltage of 230V is applied across the primary winding an output AC voltage of 12V is obtained. One alteration of input causes the top of transformer to be positive and the bottom negative. The next alteration will temporarily cause the reverse.

6.2 RECTIFIER:
In the power supply unit, rectification is normally achieved using a solid-state diode. Diode has the property that will let the electron flow easily at one direction at proper biasing condition. Bridge rectifiers of 4 diodes are used to achieve full wave rectification. Two

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 52

diodes will conduct during the negative cycle and the other two will conduct during the positive half cycle.

6.3 FILTERING UNIT:


Filter circuit, which is usually a capacitor, acts as a surge arrester and always follows the rectifier unit. This capacitor is also called as a decoupling capacitor or a bypass capacitor, is used not only to short the ripple associated with frequency to ground but also leave the frequency of the DC to appear at the output.

6.4 REGULATORS:
The voltage regulators play an important role in any power supply unit. The primary purpose of a regulator is to aid the rectifier and filter circuit in providing a constant DC voltage to the device. Power supplies without regulators have an inherent problem of changing DC voltage values due to variations in the load or due to fluctuations in the AC line voltage. With a regulator connected to DC output, the voltage can be maintained within a close tolerant region of the desired output. IC 7805 and 7812 regulators are used in this project for providing a DC voltage of +5V and +12V respectively. 6.4.1 LM78XX General Description: The LM78XX series of three terminal regulators is available with several fixed output voltages making them useful in a wide range of applications. One of these is local on card regulation, eliminating the distribution problems associated with single point regulation etc. The voltages available, allow these regulators to be used in logic systems, instrumentation, HiFi, and other solid-state electronic equipment. Although designed primarily as fixed voltage regulators these devices can be used with external components to obtain adjustable voltages and currents. The LM78XX series is available in an aluminum TO-3 package that will allow over 1.0A load current if adequate heat sinking is provided. Current limiting is included to limit the peak output current to a safe value. Safe area protection for the output transistor is provided to limit internal power dissipation. If internal power dissipation becomes too high for the heat sinking provided, the thermal shutdown circuit prevents the IC from

overheating. Considerable effort was expanded to make the LM78XX series of regulators
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 53

easy to use and minimize the number of external components. It is not necessary to bypass the output, although this does improve transient response. Input bypassing is needed only if the regulator is located far from the filter capacitor of the power supply. For output voltage other than 5V, 12V and 15V the LM117 series provides an output voltage range from 1.2V to 57V. 6.4.2 FEATURES: Output current in excess of 1A. Internal thermal overload protection. No external components required. Output transistor safe area protection. Internal short circuit current limit Available in the aluminum TO-3 package

6.4.3 Types of ICs and their Voltage Range: Types of ICs Voltage Range

LM7805 LM7812 LM7815 Table: 6-1 Types Of Voltage Regulator.

5V 12V 15V

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 54

6.4.4 Connection diagrams:

Fig: 6-2 Connection Diagram

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 55

Chapter 7

INTERFACING

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 56

7. INTERFACING
7.1 INTERFACING WITH 2x16 CHARACTER LCD

Fig: 7-1 16x2 LCD. LCDs are typically used for displaying outputs from a Micro controller or for debugging purposes LCDs come in varying sizes some of the typical ones are 16 X 1= one line 16 characters per line 16 X 2= Two lines 16 characters per line 20 X 4= Four lines 20 characters per line To display on LCD characters should be sent in ASCII format

7.1.1 PIN DESCRIPTION:


PIN 1 2 3 4 SYM vss vcc vee RS DESCRIPTION Ground Supply , +5v Supply to control contrast RS=0 to select Command REG RS=1 to select DATA REG 5 R/W R/W = 1 to Read from LCD R/W = 0 to Write to LCD

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 57

6 7-14

EN D0-D7

Enable Pin 8 bit DATA Bus

Table: 7-1 Pin Discription.


There are three important control pins for the LCD 7.1.2. RS, Register Select: There are two registers inside LCD one is the command register and the second is Data register RS is used to select between the two RS =0 Command Register RS =1 Data Register Typical Commands include Clear Display, Set cursor etc. These commands should be sent to command register. The Data which is to displayed should be sent to the data register.

7.1.3. R/W Pin: R/W =1 Read information from LCD R/W =0 Write information to LCD 7.1.4. EN Enable pin: It is used by LCD to latch information presented on data pins. When data/command is supplied to the LCD a HI to LO pulse must be applied to this pin in order for the LCD to latch the data/command present on the pins.

7.1.2 Sending Commands to LCD:


There are some codes for Lcd display. These are called commands. There are many such commands. They are displayed below. The typical commands sent to the LCD are as follows:

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 58

Code 01h 02h 06h 0Ch 0Fh C0h 38h Clear Display screen Return Home

Command

Increment Cursor after write Display on Cursor Off Display on Cursor blinking Force cursor to beginning of 2nd line 2 lines 5X7 font (initialization code)

Table: 7-2 LCD Commands.

7.1.3 Putting data at Locations:


Scope is there to put data at any location of our choice, to accomplish this we need to place the cursor at the desired Location. Address locations in a 16X2 LCD:
80h 81h 82h 83h 84h 85h 86h 87h 88h 89h 8ah 8bh 8ch 8dh 8eh 84h

c0h

c1h

c2h

c3h

c4h

c5h

c6h

c7h

c8h

c9h

cah

cbh

cch

cdh

Ceh

cfh

Table: 7-3 Address Locations in 16x2 LCD

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 59

7.1.4 Lcd Connection Diagram:

Fig: 7-2 LCD Interface Diagram.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 60

7.2 CURRENT DRIVER ULN 2803:


A ULN2803 is an Integrated Circuit (IC) chip with a High Voltage/High Current Darlington Transistor Array. It allows you to interface TTL signals with higher voltage/current loads. In English, the chip takes low level signals (TLL, CMOS, PMOS, NMOS - which operate at low voltages and low currents) and acts as a relay of sorts itself, switching on or off a higher level signal on the opposite side. A TTL signal operates from 0-5V, with everything between 0.0 and 0.8V considered "low" or off, and 2.2 to 5.0V being considered "high" or on. The maximum power available on a TTL signal depends on the type, but generally does not exceed 25mW (~5mA @ 5V), so it is not useful for providing power to something like a relay coil. Computers and other electronic devices frequently generate TTL signals. On the output side the ULN2803 is generally rated at 50V/500mA, so if can operate small loads directly. Alternatively, it is frequently used to power the coil of one or more relays, which in turn allow even higher voltages/currents to be controlled by the low level signal. In electrical terms, the ULN2803 uses the low level (TTL) signal to switch on/turn off the higher voltage/current signal on the output side. The ULN2803 comes in an 18-pin IC configuration and includes eight (8) transistors. Pins 1-8 receive the low level signals, pin 9 is grounded (for the low level signal reference). Pin 10 is the common on the high side and would generally be connected to the positive of the voltage you are applying to the relay coil. Pins 11-18 are the outputs (Pin 1 drives Pin 18, Pin 2 drives 17, etc.). ULN2803 chips are available from many sources (check www.newark.com if you are not familiar with IC sources) and should cost a couple of dollars or less. The pin diagram and input output specifications are given below.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 61

7.2.1 PIN DIAGRAM:

Fig: 7-3 ULN 2803 PIN Diagram.

7.2.2 SPECIFICATIONS

RATING Output Voltage Input Voltage (Except ULN2801) Collector Current Continuous Base Current Continuous Operating Ambient Temperature Range Storage Temperature Range Junction Temperature

SYMBOL VO VI IC IB TA Tstg TJ

VALUE 50 30 500 25 0 to +70 55 to +150 125

UNIT V V Ma mA C C C

Table: 7-4 Specifications Of Current Driver.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 62

7.2.3 Interfacing ULN 2803 with Microcontroller.

Fig: 7-4 Interfacing ULN 2803 With Microcontroller.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 63

7.3 INTERFACING RELAYS:


7.3.1 History: Electromagnetic relays are the main ingredient in automated machinery. Factories used to control everything from conveyors to robots with huge panels filled with hundreds of relays clacking away, each in turn. This method had several drawbacks, but for years it was the only method available. Recently, Programmable Logic Controllers (PLCs) have replaced banks of relays for automation needs. Relays are still used in small applications where a PLC would be overkill. They come in several varieties to suit a wide range of applications. Relays have a huge number of uses, but a few very common ones constitute the vast majority. Holding circuits are used to hold power on until the connection is broken by another signal. This is achieved by connecting one of the relay's own contacts to its coil, once the relay is turned on, it stays on. . Relays are also useful for allowing one signal to switch connections at two or more different voltages since the contacts are isolated from each other. But most often, they are used to switch connections that are at different voltages than the control power. In many cases, control power and signals generated by sensors are generated at low voltages. This is for reasons of safety and efficiency. Low voltage signals, however, are inefficient for doing high-wattage work, so a relay is used to allow the low voltage signal to switch a higher-voltage connection to do work, such as pull in a large solenoid, run a motor. 7.3.2 What is Relay? A relay is an electrical switch that opens and closes under the control of another electrical circuit. Relays are one of the oldest, simplest, and yet, easiest and most useful devices. Before the advent of the mass-produced transistor, computers were made from either relays or vacuum tubes, or both. The classic electromagnetic relay is a switch, which is thrown by an electromagnet. A relatively low current applied to the magnet can throw the switch, allowing a higher current to flow through that switch. The solenoid of most automobiles can be considered an electromagnetic relay.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 64

Figure: 7-5 A Typical Relay

In digital applications, it has been surpassed by the solid-state relay. These relays have no moving parts, so they can switch very quickly in response to a control signal. They are built from semiconductors, and they cannot handle the current that an electromagnetic relay could but their advantage is speed. High current solid-state relays often require heat sinks to drain excess heat. 7.3.3 Relay Construction: Relays are amazingly simple devices. There are four parts in every relay: Electromagnet Armature that can be attracted by the electromagnet Spring Switching contacts.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 65

Fig: 7-6 Relay constructions 7.4.4 Relay Contact Information: Relay contacts on most of our kits and in the industrial world are labeled with NO (Normally Open), NC (Normally Closed), and CT (Common Terminal). A relay contact is a switch, nothing more, nothing less. It does not provide

power; it simply opens and closes an electrical circuit, just like the light switch on a wall. 7.4.4.1 Poles and Throws: Relays rarely have only one switch. This would be called as: Single Pole Single Throw (SPST) relay, and would operate similar to a light switch. It would make or break one electrical connection when turned on. Some other combinations for contacts are: Single Pole Double Throw (SPDT), Double Pole Single Throw (DPST), and Double Pole Double Throw (DPDT).

The number of poles indicates how many separate sets of contacts are present. The number of throws indicates whether the contact only makes a single connection in one state (on or off) or if both states have a connection.. It is very common to see a 24 Volt DC coil

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 66

switching 120 Volt AC contacts. This allows safe, low voltage control power to switch more dangerous, higher voltage power that does work. Single throw relays are only connected in one position. While relays are limited to being single throw or double throw (having only two states to choose from, on or off), they can have any arbitrary number of poles. When there are more than 2 poles, we switch from using the SPDT / DPDT format to #PDT, where # is the number of poles. 7.4.4.2 Magnetic Field: The solenoid, or coil, is the part of the relay that activates the switch. When the correct voltage is applied to the coil, it creates a magnetic field which moves the contacts, making or breaking connections. Relay coils come in a variety of voltages to suit a the varies control power standards used in different places: sometimes 5, 12, 24, or 48 Volts DC; sometimes 24, 120, or 240 Volts AC; and others are used as well. Relay coils are rated at those voltages, but it actually takes much less than their rated voltage to activate them. This is to desensitize them to voltage fluctuations in control power common in large factories (large motors starting up can cause voltage dips in other electrical systems connected to them) 7.4.5 Relay working: When a current flows through the coil, the resulting magnetic field attracts an armature that is mechanically linked to a moving contact. The movement either makes or breaks a connection with a fixed contact. When the current to the coil is switched off, the armature is returned by a force approximately half as strong as the magnetic force to its relaxed position. Usually this is a spring, but gravity is also used commonly in industrial motor starters. Most relays are manufactured to operate quickly. In a low voltage application, this is to reduce noise. In a high voltage or high current application, this is to reduce arcing. If the coil is energized with DC, a diode is frequently installed across the coil, to dissipate the energy from the collapsing magnetic field at deactivation, which would otherwise generate a spike of voltage and might cause damage to circuit components. If the coil is designed to be energized with AC, a small copper ring can be crimped to the end of the solenoid. This shading ring creates a small out-of-phase current, which increases the minimum pull on the armature during the AC cycle.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 67

Fig:7-7 Relay operation 7.4.6 Choosing of relay: 1.Physical size and pin arrangement :

If you are choosing a relay for an existing PCB you will need to ensure that its dimensions and pin arrangement are suitable. You should find this information in the supplier's catalogue. 2.Coil voltage The relay's coil voltage rating and resistance must suit the circuit powering the relay coil. Many relays have a coil rated for a 12V supply but 5V and 24V relays are also readily available. Some relays operate perfectly well with a supply voltage which is a little lower than their rated value. 3.Coil resistance The circuit must be able to supply the current required by the relay coil. We can use Ohm's law to calculate the current: Ex:- A 12V supply relay with a coil resistance of 400 passes a current of 30mA.

This is OK for a 555 timer IC (maximum output current 200mA), but it is too much for most ICs and they will require a transistor to amplify the current. 4. Switch ratings (voltage and current)

The relay's switch contacts must be suitable for the circuit they are to control. You will need to check the voltage and current ratings. Note that the voltage rating is usually higher for AC, for example: "5A at 24V DC or 125V AC".

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 68

5. Switch

contact

arrangement (SPDT, DPDT etc)

Most relays are SPDT or DPDT which are often described as "single pole changeover" (SPCO) or "double pole changeover" (DPCO). 7.4.7 Advantages of relays: The complete electrical isolation improves safety by ensuring that high voltages and currents cannot appear where they should not be. Relays come in all shapes and sizes for different applications and they have various switch contact configurations. Double Pole Double Throw (DPDT) relays are common and even 4-pole types are available. You can therefore control several circuits with one relay or use one relay to control the direction of a motor. It is easy to tell when a relay is operating - you can hear a click as the relay switches on and off and you can sometimes see the contacts moving. 7.4.8. Disadvantages of Relays: Being mechanical though, relays do have some disadvantages over other methods of electrical isolation. Their parts can wear out as the switch contacts become dirty, high voltages and

currents cause sparks between the contacts. They cannot be switched on and off at high speeds because they have a slow response

and the switch contacts will rapidly wear out due to the sparking. Their coils need a fairly high current to energize, which means some micro-electronic

circuits can't drive them directly without additional circuitry. The back-emf created when the relay coil switches off can damage the components

that are driving the coil. To avoid this, a diode can be placed across the relay coil, as will be seen in any Electronics in Mecca no circuits that use relays with sensitive components.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 69

7.4.9 Applications:

Fig: 7-8 A DPDT AC coil relay with ice cube packaging Relays are used: To control a high-voltage circuit with a low-voltage signal, as in some types of

modems. To control a high-current circuit with a low-current signal, as in the starter

solenoid of an automobile. To detect and isolate faults on transmission and distribution lines by opening and

closing circuit breakers (protection relays). To isolate the controlling circuit from the controlled circuit when the two are at

different potentials, for example when controlling a mains-powered device from a lowvoltage switch. The latter is often applied to control office lighting as the low voltage wires are easily installed in partitions, which may be often moved as needs change. They may also be controlled by room occupancy detectors in an effort to conserve energy. To perform logic functions. For example, the Boolean AND function is realized by

connecting NO relay contacts in series, the OR function by connecting NO contacts in parallel. The change-over or Form C contacts perform the XOR (exclusive or) function. Similar functions for NAND and NOR are accomplished using NC contacts. Due to the failure modes of a relay compared with a semiconductor, they are widely used in safety critical logic, such as the control panels of radioactive waste handling machinery.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 70

To perform time delay functions. Relays can be modified to

delay opening or delay

closing a set of contacts. A very shorts (a fraction of a second) delay would use a copper disk between the armature and moving blade assembly. Current flowing in the disk maintains magnetic field for a short time, lengthening release time. For a slightly longer (up to a minute) delay, a dashpot is used. A dashpot is a piston filled with fluid that is allowed to escape slowly. The time period can be varied by increasing or decreasing the flow rate. For longer time periods, a mechanical clockwork timer is installed

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 71

Chapter 8

CARD READER AND SMART CARD

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 72

8. CARD READER AND SMARTCARD


8.1 CARD READOR AND SMART-CARD CONSTRUCTION:
In this project we are using card reader to recharge the prepaid electric meter. The card reader is constructed with five IR-SENSORS. Let us study about infrared sensors first.

Fig: 8-1 Typical Commercial Smart Card

8.2 INFRARED SENSORS:.


8.2.1 Infrared radiation: Electromagnetic radiation in which wavelength lies in the range from 1 micrometer to 1 millimeter. This radiation therefore has wavelengths just a little than those of visible light and cannot be seen with the unaided eye. The radiation was discovered in 1800 by William Herschel.Relating to the invisible part of the electromagnetic spectrum with wavelengths longer than those of visible red light but shorter than those of microwaves.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 73

Fig: 8-2 Infrared Wavelength

A Closer Look In 1800 the astronomer Sir William Herschel discovered infrared light while exploring the relationship between heat and light. Herschel used a prism to split a beam of sunlight into a spectrum and then placed a thermometer in each of the bands of light. When he placed the thermometer just outside the red band, where there was no visible colour, the temperature rose, as if light were shining on the thermometer. Further experiment showed that this invisible radiation behaved like visible light in many ways; for example, it could be reflected by a mirror. Infrared radiation is simply electromagnetic radiation with a lower frequency than visible light, having longer wavelengths of 0.7 micrometre to 1 millimetre. Ultraviolet radiation, like infrared radiation, lies just outside the visible part of the spectrum, but with higher frequencies; some animals, such as bees, are capable of seeing such radiation. Both infrared and ultraviolet radiations are often referred to as forms of light, though they cannot be seen by human beings. Heat energy is often transferred in the form of infrared radiation, which is given off from an object as a result of molecular collisions within it. Molecules typically have a characteristic infrared absorption spectrum, and infrared spectroscopy is a common technique for identifying the molecular structure of substances. Astronomers similarly analyse the infrared radiation emitted by celestial bodies to determine their temperature and composition.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 74

Fig: 8-3 Graph of Wavelength. An infrared source can be described by the spectral distribution of power emitted by an ideal body (a blackbody curve). This distribution is characteristic of the temperature of the body. A real body is related to it by a radiation efficiency factor or emissivity which is the ratio at every wavelength of the emission of a real body to that of a blackbody under identical conditions. The illustration shows curves for these ideal blackbodies radiating at a number of different temperatures. The higher the temperature, the greater the total amount of radiation. See also Emissivity. 8.2.2 IR- SENSOR DISCRIPTION: In this project we are using infrared sensor. This sensor is used in card reader. The construction and working of card reader is explained later. The circuit and working of IRSENSOR is shown below.

8.2.3 Sensors:
The emitter and the receiver module of the IR Sensors can be placed on either side of the card reader to sense the smart card. When the entered card blocks the infrared beam, an input is given to the circuit board and the logic works accordingly.

8.3 WORKING OF THE SENSORS:


Infrared sensors are phototransistors, which are set up across the card reader from an infrared LED light. The arrangement of the sensors is shown as below:
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 75

Fig: 8-4 Ir Sensor Circuit Diagram.

Infra-red transmitter sensor gives the infra-red rays; this wavelength depends upon the input frequency of the sensor. If frequency is high, wavelength is high .IR receiver sensor resistance depends upon the receiving IR signal. If receiver receives signal from transmitter, the resistance of the resistor will be low .If receiver does not get signal from the transmitter, its resistance will be high .So we get some voltage drop across the receiver depending upon the resistance of the receiver. Comparator compares the signal given to the inverting and non-inverting terminal ,it will give output in terms of saturation level .If inverting terminal input is high comparator output will be at negative saturation(-12v).If non inverting terminal then input

comparator output saturation is positive(+12v). One input of comparator is from IR sensor and other input is reference signal. So we have to convert +12v to -12v pulse into TTL logic (0&5). The IR Sensors in our project can be better understood by the following analysis of the case studies: When no card cuts the sensors.
DEPARTMENT OF E.C.E

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

PREPAID ENERGY METER

P a g e | 76

When card cuts the sensors.

8.3.1 When no card cuts the sensors


Suppose if the card does not pass through the sensors then the signal from the IR sensor will be high. This is because the photo diode would be in forward bias when light keeps falling on it. Hence as there is conduction is taking place the signal will be high.

8.3.2 Working of Photo Diode when no card cuts the sensors


A photodiode is a PN junction .When a photon of sufficient energy strikes the diode; it excites an electron, thereby creating a mobile electron and a positively charged electron hole. If the absorption occurs in the junction's depletion region, or one diffusion length away from it, these carriers are swept from the junction by the built-in field of the depletion region. Thus holes move toward the anode, and electrons toward the cathode, and a photocurrent is produced. They are normally biased in the reverse, or blocking, direction; the current therefore is quite small in the dark. When they are illuminated, the current is proportional to the amount of light falling on the photodiode

Fig: 8-5 Photo Diode Without Card.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 77

8.3.3 When card passes the sensors


Suppose if the card passes through the sensors then the signal from the IR sensor will be low. This is because the photo diode would be in reverse bias when no light falls on it. Hence as there is no conduction is taking place the signal will be low.

8.3.4 Working of Photo Diode when card passes the sensors

The reference signal which is one of the inputs fed to the comparator is always maintained low. This is done with the help of a variable resistance which is adjusted such that the resistance is negligible. The resistance is adjusted accordingly so that the voltage at the variable resistance is equal to the voltage at the IR receiver (Photo Diode) when it is in the reverse bias. Now when the card is not passing through the sensors, the signal from the IR receiver is high as light is falling on it. The other reference signal is low. These both are fed as the inputs to the comparator. The comparator gives output signal as low because both the signal are not equal. As one of the signals is high and the other is low the output will be low from the comparator.

Fig: 8-6 Photo Diode With Card

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 78

8.4 CONSRTUCTION OF SMART CARDS:

Fig: 8-7 Sample Card.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 79

Chapter 9

SOFTWARE

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 80

9. SOFTWARE:
9.1 What is software :
Anything that can be stored electrically is called as software or data. Software consists of instructions that we give to the computer.

9.2 WHY SOFTWARE:


The hardware of the computer or a system cannot work by itself. So it is essential to use software. There are two types of software. 1. Application software 2. System software. 9.2.1 Application software: It consists of program used for various purpose such as word processor of a data base management system (DBMS). Ex; Ms Office 2010 is application software. 9.2.2 System software: It is used to control the hardware of the the computer or to help convert instructions written in a high level language to machine language. These are again 2 types. 1. Operation system 2. Compiler software. 9.2.2.1 OPERATING SYSTEM:

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 81

In computing, an operating system (OS) is software (programs and data) that provides an interface between the hardware and other software. The OS is responsible for management and coordination of processes and allocation and sharing of hardware resources such as RAM and disk space, and acts as a host for computing applications running on the OS. An operating system may also provide orderly accesses to the hardware by competing software routines. This relieves the application programmers from having to manage these details. Operating systems offer a number of services to application programs. Applications access these services through application programming interfaces (APIs) or system calls. By invoking these interfaces, the application can request a service from the operating system, pass parameters, and receive the results of the operation. On large systems such as Unix-like systems, the user interface is always implemented as software that runs outside the operating system. In some other systems like Windows, the Window manager can be part of the operating system itself. While servers generally run Unix or some Unix-like operating system, embedded system markets are split amongst several operating systems. Although the Microsoft Windows line of operating systems has almost 90% of the client PC market. Example: Linux UNIX-SOLARIS Ms Dos, Ms Windows 95, Ms Windows NT Ms Windows XP Ms Windows 7.

9.2.2.2 COMPILER SOFTWARE:

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 82

A compiler is a computer program (or set of programs) that transforms source code written in a computer language (the source language) into another computer language (the target language, often having a binary form known as object code). The most common reason for wanting to transform source code is to create an executable program. The name "compiler" is primarily used for programs that translate source code from a high-level programming language to a lower level language (e.g., assembly language or machine code). A program that translates from a low level language to a higher level one is a de-compiler. A program that translates between high-level languages is usually called a language translator, source to source translator, or language converter. A language rewriter is usually a program that translates the form of expressions without a change of language. A compiler is likely to perform many or all of the following operations: lexical analysis, pre-processing, parsing, semantic analysis, code generation, and code optimization. Program faults caused by incorrect compiler behaviour can be very difficult to track down and work around and compiler implementors invest a lot of time ensuring the correctness of their software. The term compiler-compiler is sometimes used to refer to a parser generator, a tool often used to help create the lexer and parser.

9.3 SOFTWARE USED:


The software that is used in this project to write the code is 8051 IDE. MCU 8051 IDE is a free software integrated development environment for microcontrollers based on 8051. MCU 8051 IDE has its own simulator and assembler (support for some external assemblers is also available). This IDE supports 2 programming languages. 1.C Language 2. Assemble language For C language it uses SDCC. In our project we are using assemble language.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 83

9.3.1 Microcontrollers Supporting 8051 IDE ARE:

The current version 1.3 supports many microcontrollers including: 8051, 80C51, 8052, AT89C2051, AT89C4051, AT89C51, AT89C51RC, AT89C52, AT89C55WD,AT89LV51, AT89LV52 AT89LV55, AT89S52, AT89LS51, AT89LS52, AT89S8253, AT89S2051, AT89S4051, T87C5101, T83C5101, T83C5102, TS80C32X2, TS80C52X2, AT80C58X2, TS87C52X2, AT87C54X2, AT80C32X2, AT87C58X2, AT80C52X2, TS80C54X2, AT87C52X2, TS80C58X2, AT80C54X2, TS87C54X2,

TS87C58X2, TS80C31X2, AT80C31X2, 8031, 8751, 8032, 8752, 80C31, 87C51, 80C52, 87C52, 80C32, 80C54, 87C54, 80C58, 87C58.

9.3.2 KEY FEAUTES: MCU simulator with many debugging features: register status, step by step, interrupt viewer, external memory viewer, code memory viewer, etc. Simulator for simple electronic peripherals: leds, displays, matrices, etc. Support for C language. Native macro-assembler. Support for ASEM-51. Advanced text editor with syntax highlighting and validation. Support for vim and nano embedded in the IDE. Simple hardware programmer for certain AT89Sxx MCUs. Scientific calculator: time delay calculation and code generation, base converter, etc. Hexadecimal editor.

In this software we wrote the code in assembly language. While saving it is saved with the file extinction .asm. After compiling the assembly language code 8051IDE generates 3 files.

.asm written code. .hex machine language code.


VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 84

.lst Detailed info.

9.4 BURNER USED:

Fig: 9-1 A Typical Burner

Writing code should be burn to the microcontroller with the help of the burner. Usually pins 5,6,7,8 are used to burn the code to the microcontroller. The compiler converts the high level language code written by the user to the machine language code. The .hex file is burnt to the microcontroller with the help of the burner. REQUIREMENTS TO BURN: 1. COMPILER SOFTWARE. 2. MICROCONTROLLAR. 3. BURNER.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 85

Chapter 10

ALGORITHM

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 86

10. ALGORITHM:

Step 1 : Start Step 2 : Insert the card. Step 3 : If the card is not valid go to step1. Otherwise go to step 4. Step 4 : Recharged successful. Step 5 : Power supply is on. Step 6 : The energy meter counts the consumed units. Step 7 : Compete total recharge consumption units with pre-stored value 5. If yes go to step 8. Else go to step 6. Step 8 : Buzzer rings. Step 9 : If the comparison equals to zero the go to step 10. Else go to step 8. Step 10: Power supply is switched off. Step 11: Go to step 1.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 87

Chapter 11

FLOWCHART

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 88

11. FLOW CHART

Fig: 11.1 Flow Chart

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 89

Chapter 12

ASSEMBLY LANGUAGE SOURCE CODE

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 90

12. ASSEMBLY LANGUAGE SOURCE CODE

CARD_INFO EQU 30H RS RW EN PDATA BUZZER RELAY EQU P3.5 EQU P3.6 EQU P3.7 EQU P2 EQU P0.1 EQU P0.0

MAIN:

mov sp,#50h mov p1,#0ffh setb p3.0 SETB BUZZER CLR P0.0 CLR P0.2 mov p0,#00h MOV TMOD,#06H MOV TL0,#00H MOV TH0,#00H LCALL LCDINIT LCALL INSERT_CARD

AGAIN:

MOV A,P1 CJNE A,#11111100B,NEXT1 LJMP FIFTY_RS_CARD

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 91

NEXT1:

CJNE A,#11111000B,NEXT2 LJMP HUND_RS_CARD

NEXT2:

CJNE A,#11111001B,NEXT3 LJMP ONE_FIFTY_RS_CARD

NEXT3:

CJNE A,#11100110B,NEXT4 LJMP TWO_HUND_RS_CARD

NEXT4:

CJNE A,#11101111B,NEXT5 LJMP TWO_FIFTY_RS_CARD

NEXT5:

lcall lcdinit LCALL INVALID_CARD lcall delay LJMP MAIN

FIFTY_RS_CARD: SETB RELAY lcall lcdinit LCALL DISP_RS_FIFTY lcall lcdinit LCALL UNITS_1 lcall lcdinit
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 92

LJMP COUNT1

HUND_RS_CARD: SETB RELAY lcall lcdinit LCALL DISP_RS_HUND lcall lcdinit LCALL UNITS_2 lcall lcdinit LJMP COUNT2 ONE_FIFTY_RS_CARD: SETB RELAY lcall lcdinit LCALL DISP_RS_ONE_FIFTY lcall lcdinit LCALL UNITS_3 lcall lcdinit LJMP COUNT3 TWO_HUND_RS_CARD: SETB RELAY lcall lcdinit LCALL DISP_RS_TWO_HUND lcall lcdinit LCALL UNITS_4 lcall lcdinit LJMP COUNT4 TWO_FIFTY_RS_CARD: SETB RELAY
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 93

lcall lcdinit LCALL DISP_RS_TWO_FIFTY lcall lcdinit LCALL UNITS_5 lcall lcdinit LJMP COUNT5

;************************************************************************** ***** COUNT1: SETB TR0 CONT1: MOV A,TL0

CJNE A,#40,CONT1 CLR BUZZER LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY SETB BUZZER UP1: MOV A,TL0 CJNE A,#50,UP1
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 94

CLR RELAY LCALL LCDINIT LCALL UNITS_COMPT LJMP MAIN

COUNT2: SETB TR0 CONT2: MOV A,TL0

CJNE A,#80,CONT2 CLR BUZZER LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY SETB BUZZER UP2: MOV A,TL0 CJNE A,#100,UP2 CLR RELAY LCALL LCDINIT LCALL UNITS_COMPT LJMP MAIN

COUNT3:
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 95

SETB TR0 CONT3: MOV A,TL0

CJNE A,#130,CONT3 CLR BUZZER LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY SETB BUZZER UP3: MOV A,TL0 CJNE A,#150,UP3 CLR RELAY LCALL LCDINIT LCALL UNITS_COMPT LJMP MAIN

COUNT4: SETB TR0 CONT4: MOV A,TL0

CJNE A,#180,CONT4 CLR BUZZER LCALL DELAY LCALL DELAY


VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 96

LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY SETB BUZZER UP4: MOV A,TL0 CJNE A,#200,UP4 CLR RELAY LCALL LCDINIT LCALL UNITS_COMPT LJMP MAIN

COUNT5: SETB TR0 CONT5: MOV A,TL0

CJNE A,#245,CONT5 CLR BUZZER LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY LCALL DELAY
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 97

LCALL DELAY SETB BUZZER UP5: MOV A,TL0 CJNE A,#250,UP5 CLR RELAY LCALL LCDINIT LCALL UNITS_COMPT LJMP MAIN

INSERT_CARD: MOV R2,#16 MOV DPTR,#INST_CARD LOOP1:MOV A,#00H MOVC A,@A+DPTR LCALL WRTDAT INC DPTR DJNZ R2,LOOP1 RET

DISP_RS_FIFTY: MOV R2,#16 MOV DPTR,#FIFTY_CARD LOOP2: MOV A,#00H MOVC A,@A+DPTR LCALL WRTDAT INC DPTR DJNZ R2,LOOP2 RET
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 98

UNITS_1: MOV R2,#16 MOV DPTR,#FIFTY_UNITS LOOP3: MOV A,#00H MOVC A,@A+DPTR LCALL WRTDAT INC DPTR DJNZ R2,LOOP3 RET

DISP_RS_HUND: MOV R2,#16 MOV DPTR,#HUND_CARD LOOP4:MOV A,#00H MOVC A,@A+DPTR LCALL WRTDAT INC DPTR DJNZ R2,LOOP4 RET

UNITS_2: MOV R2,#16 MOV DPTR,#HUND_UNITS LOOP5: MOV A,#00H MOVC A,@A+DPTR

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 99

LCALL WRTDAT INC DPTR DJNZ R2,LOOP5 RET

DISP_RS_ONE_FIFTY: MOV R2,#16 MOV DPTR,#ONE_FIFTY_CARD LOOP6: MOV A,#00H MOVC A,@A+DPTR LCALL WRTDAT INC DPTR DJNZ R2,LOOP6 RET

UNITS_3: MOV R2,#16 MOV DPTR,#ONE_FIFTY_UNITS LOOP7: MOV A,#00H MOVC A,@A+DPTR LCALL WRTDAT INC DPTR DJNZ R2,LOOP RET

DISP_RS_TWO_HUND:
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 100

MOV R2,#16 MOV DPTR,#TWO_HUND_CARD LOOP8: MOV A,#00H MOVC A,@A+DPTR LCALL WRTDAT INC DPTR DJNZ R2,LOOP8 RET

UNITS_4: MOV R2,#16 MOV DPTR,#TWO_HUND_UNITS LOOP9: MOV A,#00H MOVC A,@A+DPTR LCALL WRTDAT INC DPTR DJNZ R2,LOOP9 RET

DISP_RS_TWO_FIFTY: MOV R2,#16 MOV DPTR,#TWO_FIFTY_CARD LOOP10: MOV A,#00H MOVC A,@A+DPTR LCALL WRTDAT INC DPTR DJNZ R2,LOOP10
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 101

RET

UNITS_5: MOV R2,#16 MOV DPTR,#TWO_FIFTY_UNITS LOOP11: MOV A,#00H MOVC A,@A+DPTR LCALL WRTDAT INC DPTR DJNZ R2,LOOP11 RET

UNITS_COMPT: MOV R2,#15 MOV DPTR,#DATA LOOP15: MOV A,#00H MOVC A,@A+DPTR LCALL WRTDAT INC DPTR DJNZ R2,LOOP15 RET

INVALID_CARD: MOV R2,#02 MOV DPTR,#INVALID LOOP12: MOV A,#00H


DEPARTMENT OF E.C.E

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

PREPAID ENERGY METER

P a g e | 102

MOVC A,@A+DPTR LCALL WRTDAT INC DPTR DJNZ R2,LOOP12 RET

LCDINIT:MOV A,#36H LCALL WRTCMD MOV A,#1AH LCALL WRTCMD MOV A,#0Eh LCALL WRTCMD MOV A,#0A6H LCALL WRTCMD RET

WRTCMD:LCALL DELAY MOV PDATA,A CLR RS CLR RW CLR EN RET

WRTDAT:LCALL DELAY MOV PDATA,A


VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 103

SETB RS CLR RW SETB EN RET

DELAY: NEXT:

MOV R6,#250 MOV R7,#200 AGAIN2: NOP NOP DJNZ R7,AGAIN2 DJNZ R6,NEXT RET

INSTCARD: FIFTY_CARD: FIFTY_UNITS: HUND_CARD:

DB 'INSERT YOUR CARD' DB 'RS 50/- ACCESSED' DB 'RECHRGD 50 UNITS' DB 'RS 100/-ACCESSED' DB 'RCHRGD 100 UNITS'

HUND_UNITS:

ONE_FIFTY_CARD: DB 'RS 150/-ACCESSED' ONE_FIFTY_UNITS: DB 'RCHRGD 150 UNITS' TWO_HUND_CARD: DB 'RS 200/-ACCESSED' TWO_HUND_UNITS: DB 'RCHRGD 200 UNITS' TWO_FIFTY_CARD: TWO_FIFTY_UNITS: DB 'RS 250/-ACCESSED' DB 'RCHRGD 250 UNITS'

INVALID: DB 'CARD NOT VALID' DATA: DB 'UNITS COMPLETED'

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 104

Chapter 13

ADVANTAGES AND DISADVANTAGES

13. ADVANTAGES AND DISADVANTAGES

13.1 ADVANTAGES:
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 105

1. Accuracy 2. Low Current Performance 3. Low Voltage Performance 4. Installation 5. Tamper

1.2 DISADVANTAGES:

1. The main disadvantage of the system is, because of huge electronic hardware involved in the system, the overall system consumes more electric energy. Remedy: When the system is converted into engineering module, the bulky hardware can be converted into a smallintegrated chip. When the hardware is minimized naturally the system consumes less power. 2. Since it is a prototype module, because of huge hardware the system occupies more space. 3. The consumer or the electrical department has to spend more amounts for installing this kind of smart energy meters. Economically it is not advised.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 106

Chapter 14

APPLICATIONS AND FUTURE ASPECTS

14. APPLICATIONS AND FUTURE ASPECTS


14.1 APPLICATIONS:
1. Prepaid electricity meters that generate consumption data enabling customers to see when they are using energy, to manage that use more efficiently
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 107

2. To save money by adjusting energy use in response to price signals. 3. To save money, the consumed energy corresponding price is displayed for the consumer benefits. 4. This project work has been taken up which serves the purpose of energy monitoring and controlling by implementing prepaid system. 5. It is hoped that this work helps the electrical engineers for better energy management and its utility in the distribution system for economic liability of the electrical companies.

14.2 FUTURE ASPECTS:


In future by implementing this on large scale it is used very widely for many purposes. Such as:1. To save electricity.

2. With the help of this project work lot of Manpower can be reduced and power
pilferage can be controlled.

3. Server technology can be implemented to make the system completely wireless and automatic.

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 108

Chapter 15

REFERENCES

15. REFERENCES
1. http://www.8051projects.net/downloads134.html
VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 109

http://indianengineer.wordpress.com/2008/09/21/prepaid-energy-meter-at89s52-8051microcontroller/

3. http://www.scribd.com/doc/18208165/How-to-Make-an-Automated-Prepaid-Energy-Meter 4. http://wiki.answers.com/Q/Circuit_diagram_of_prepaid_energy_meter 5. http://en.wikipedia.org/wiki/Infrared


6. http://www.atmel.com/dyn/Products/product_card.asp?part_id=1918 7. http://www.keil.com/dd/chip/3411.htm 8. http://www.doc.ic.ac.uk/~ih/doc/stepper/control2/2803.html 9. http://www.futurlec.com/LCDDisp.shtml 10. 8051 Microcontroller and Embedded Systems --Muhammad Ali Mazidi 11. The 8051 Microcontroller Architecture, Programming and Applications -- Kenneth J Ayala 12. Advanced Microprocessors & peripherals --A.K.Ray and K.M Burchandi

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

PREPAID ENERGY METER

P a g e | 110

APPENDIX

VIGNANS INSTITUTE OF INFORMATION AND TECHNOLOGY

DEPARTMENT OF E.C.E

You might also like