Top Banner
1 A MAJOR PROJECT REPORT ON “PREPAID ENERGY METER” Submitted in partial fulfillment for the award of the degree of BACHELOR OF TECHNOLOGY IN ELECTRONICS & COMMUNICATION ENGINEERING 2014-15 SUBMITTED TO:- SUBMITTED BY:- Mr.Vishnu Kr. Sharma Neeraj Kumar,Kanhaiya Jha Asst. Prof. (ECE) JitendraAgrawal,Avkesh Joshi JIT,Jaipur Branch-ECE,(4 th Year) RAJASTHAN TECHNICAL UNIVERSITY, KOTA DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING JAIPUR INSTITUTE OF TECHNOLOGY, Group of Institution, Jaipur
136
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Project Report On "Prepaid Energy Meter"

1

A

MAJOR PROJECT

REPORT

ON

“PREPAID ENERGY METER”

Submitted in partial fulfillment for the award of the degree of

BACHELOR OF TECHNOLOGY

IN

ELECTRONICS & COMMUNICATION ENGINEERING

2014-15

SUBMITTED TO:- SUBMITTED BY:-

Mr.Vishnu Kr. Sharma Neeraj Kumar,Kanhaiya Jha

Asst. Prof. (ECE) JitendraAgrawal,Avkesh Joshi

JIT,Jaipur Branch-ECE,(4th Year)

RAJASTHAN TECHNICAL UNIVERSITY, KOTA

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

JAIPUR INSTITUTE OF TECHNOLOGY, Group of Institution, Jaipur

Page 2: Project Report On "Prepaid Energy Meter"

2

RAJASTHAN TECHNICAL UNIVERSITY, KOTA

JAIPUR INSTITUTE OF TECHNOLOGY, JAIPUR

(GROUP OF INSTITUTION)

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

CERTIFICATE

This is to certify that Project Report entitled “PREPAID ENERGY METER” that is submitted by “NEERAJ KUMAR,KANHAIYA JHA,JITENDRA AGRAWAL,AVKESH JOSHI”‖ in partial fulfillment of the requirement for the award of the degree B.Tech in Department of “ELECTRONICS & COMMUNICATION ENGNEERING”‖ of Rajsthan Technical University, is a record of the candidate own work carried out by him under my own supervision.The matter embodies in thesis is original and has not been submitted for the award of any other degree.

Mr. Vishnu Kr. Sharma Mr. Abhinash Sharma

(PTS Coordinator) (Lab. Technician)

Assistant Professor Assistant Professor

Dept. of ECE Dept. of ECE

JIT, Jaipur JIT, Jaipur

Ms. Priyanka Agrawal

Head, Dept. of Electronics & Communication Engineering,

JIT, Jaipur

Page 3: Project Report On "Prepaid Energy Meter"

3

DECLARATION I hereby declare that this submission is own work and that, to the best of my knowledge and belief, it contains no material previously published or written by another person nor material which to a substantial extend has been accepted for the award of the award of any other degree or diploma of the university or other institute of the higher leaning except where due acknowledgement has been made in the text.

Page 4: Project Report On "Prepaid Energy Meter"

4

ACKNOWLEDGEMENT

First and foremost, I am deeply indebted to my mentor Ast. Prof. Vishnu Sharma who inspiration has been unfailingly available to me at all stages of my training.This has fueled my enthusiasm even further and encouraged me to boldly step into what was a totally dark and unexplored expanse before me.I would like to thank Ms. Priyanka Agrawal H.O.D Jit,Jaipur for his efforts, who was always ready with a positive comment, whether it was an off-hand comment to encourage me or constructive piece of criticism.In course of present work it has been my privilege to receive help and assistance of my friends. I take great pleasure in acknowledge my debt to them.I wish to thank my parents for their undivided support and interest who inspired me and encouraged me to go my own way, without whom I would be unable to complete my project. At last but not the least I want to thank my friends who appreciated me for my work and motivated me and finally to God who made all the things possible.

Page 5: Project Report On "Prepaid Energy Meter"

5

INTODUCTION

The aim of this project is to design a prepaid energy meter to monitor the

consumption of electricity in domestic needs. The standard business model of

electricity retailing involves the electricity company billing the customer for the

amount of energy used in the previous month or quarter. In some countries, if

the retailer believes that the customer may not pay the bill for what ever

reason a prepayment meter may be installed. This requires the customer to

make advance payment before using the electricity. If the available credit is

exhausted then the supply of electricity is automatically cut off by a relay.

Here analog energy meter is replaced by a digital energy meter. The digital

energy meter used here is a high accuracy, low cost, single phase power meter

based on the ADE7757.The meter is designed for use in single phase 2 wire

distribution system. A relay is connected in between power lines and the load.

The relay is controlled by the primary controller.

Microcontroller 89C51 acts as the primary controller. The primary controller

collects information from digital energy meter as well as from the smart card.

Smart gives information about the limitation of units. The digital energy meter

reading is compared with the smart card information by the primary controller

and hence suitably primary controller controls the relay.

Page 6: Project Report On "Prepaid Energy Meter"

6

CIRCUIT DIAGRAM:-

Page 7: Project Report On "Prepaid Energy Meter"

7

FIG. 02.BLOCK DIAGRAM

COMPONENTS DESCRIPTION:-

1. I.C.’S:-

(A.) AT89S52:-

FIG. 03.I.C.AT89S52

Description:-

The ISL8200MMREP is a simple and easy to use high power, current-sharing DC\DC power

module for Datacom\Telecom\FPGA power hungry applications. All that is needed is the

ISL8200MMREP, a few passive components and one VOUT setting resistor to have a complete

10A design ready for market.The ease of use virtually eliminates the design and manufacturing

risks while dramatically improving time to market.Need more output current? Just simply

parallel up to six ISL8200MMREP modules to scale up to a 60A solution.The simplicity of the

ISL8200MMREP is in its Off The Shelf, unassisted implementation. Patented current sharing

in multi-phase operation greatly reduces ripple currents, BOM cost andcomplexity.

The ISL8200MMREPs thermally enhanced, compact QFN package, operates at full load and

over-temperature, without requiring forced air cooling. It's so thin it can even fit on the back

side of the PCB. Easy access to all pins with few external components, reduces the PCB design

to a component layer and a simple ground layer.

Page 8: Project Report On "Prepaid Energy Meter"

8

The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8Kbytes of

in-system programmable Flash memory. The device is manufactured usingAtmel’s high-

density nonvolatile memory technology and is compatible with the industry-standard 80C51

instruction set and pinout. The on-chip Flash allows the programmemory to be reprogrammed

in-system or by a conventional nonvolatile memory programmer.By combining a versatile 8-

bit CPU with in-system programmable Flash ona monolithic chip, the Atmel AT89S52 is a

powerful microcontroller which provides ahighly-flexible and cost-effective solution to many

embedded control applications.The AT89S52 provides the following standard features: 8K

bytes of Flash, 256 bytesof RAM, 32 I/O lines, Watchdog timer, two data pointers, three 16-bit

timer/counters, asix-vector two-level interrupt architecture, a full duplex serial port, on-chip

oscillator,and clock circuitry. In addition, the AT89S52 is designed with static logic for

operationdown 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,

andinterrupt system to continue functioning. The Power-down mode saves the RAM

contentsbut freezes the oscillator, disabling all other chip functions until the next interruptor

hardware reset.

Pin Description:-

Pin Description

Pin Number Description

1 - 8 P1.0 - P1.7 - Port 1

9 RST - Reset

10 - 17 P3.0 - P3.7 - Port 3

18 XTAL2 - Crystal

19 XTAL1 - Crystal

20 GND - Ground

21 - 28 P2.0 - P2.7 - Port 2

29 PSEN - Program Store Enable

30 ALE - Address Latch Enable

31 EA - External Access Enable

32 - 39 P0.7 - P0.1 - Port 0

40 Vcc - Positive Power Supply

Page 9: Project Report On "Prepaid Energy Meter"

9

TABLE 1. I.C.DESCRIPTION

Features:- 1. Specifications per DSCC VID V62/10608

2. Full Mil-Temp Electrical Performance from -55°C to +125°C

3. Full Traceability Through Assembly and Test by Date/Trace Code Assignment

4. Enhanced Process Change Notification

5. Enhanced Obsolescence Management

6. Complete Switch Mode Power Supply in One Package

7. Patented Current Share Architecture Reduces Layout Sensitivity When Modules are

Paralleled

8. Programmable Phase Shift (1, 2, 3, 4, and 6 phase)

9. Extremely Low Profile (2.2mm height)

10. Input Voltage Range +3.0 V to +20V at 10A, Current Share up to 60A

11. A Single Resistor Sets VOUT from +0.6V to +6V

(B.) IC AT24C02:-

Page 10: Project Report On "Prepaid Energy Meter"

10

FIG.4

Description:- T24C02 is an electrically erasable and programmable ROM. It has a 2Kbits of memory

size arranged in 32 pages of 8 byte each. There are 256 (32 x 8) words each of one

byte. The data is transferred and received serially through serial data (SDA) pin.

The SCL is clock input and is used to synchronize EEPROM with microcontroller for various

operations. When data is to be read or write, first a start condition is created followed by

device address, byte address and the data itself. Finally a stop condition is provided. The start

condition occurs when SDA and SCL get high to low simultaneously. The stop condition is

when SDA remains low while SCL goes from high to low. The data is read or written

between the start and stop conditions on every transition of SCL from high to low. For more

details on different operations and addressing, refer interfacing 24C02 with 8051.

A total of eight EEPROMs can be connected through a bus. There are three address pins in

AT24C02 for selecting a particular chip. The device can be addressed serially by the

software. It makes use of an internal register of the EEPROM whose 4 MSB bits are 1010,

the next three are the EEPROM address bits and the LSB signifies whether data is to be read

or written. This last bit is 1 for write and 0 for read operation.

For example, if in an EEPROM all address bits are grounded, then for write operation a hex

value 0xA1 (1010 0001) will be sent. Here 000, in last bits, addresses the EEPROM and 1 in

Page 11: Project Report On "Prepaid Energy Meter"

11

LSB indicates a write operation. Similarly for read operation the device address to be sent is

0xA0 (1010 0000).

Next, the byte or page address is sent followed by the data byte. This data byte is to be

written on or read by the microcontroller.

Pin Description:-

Pin

No Function Name

1 Address input pins; Provide addresses when more than

one EEPROM is interfaced to a single microcontroller;

Ground when only one EEPROM is used

AD0

2 AD1

3 AD2

4 Ground (0V) Ground

5 Bi-directional pin for serial data transfer Serial Data

6 Provides clock signals Serial Clock

7 Ground allows normal read/write functions;

Vcc enables write protection

Write protect

8 Supply voltage; 5V (up to 5.5V) Vcc

TABLE 2. (C.)ULN2003:-

Page 12: Project Report On "Prepaid Energy Meter"

12

FIG.5.1

Description:-

The ULN2002A, ULN2003A, ULN2003AI, ULN2004A, ULQ2003A, and ULQ2004A are

high-voltage high-current Darlington transistor arrays. Each consists of seven npn Darlington

pairs that feature high-voltage outputs with common-cathode clamp diodes for switching

inductive loads. The collector-current rating of a single Darlington pair is 500 mA. The

Darlington pairs can be paralleled for higher current capability. Applications include relay

drivers, hammer drivers, lamp drivers, display drivers (LED and gas discharge), line drivers,

and logic buffers.For 100-V (otherwise interchangeable) versions of the ULN2003A and

ULN2004A, see the SN75468 and SN75469, respectively.The ULN2001A is a general-

purpose array and can be used with TTL and CMOS technologies.

Features:-

500-mA-Rated Collector Current (Single Output)

High-Voltage Outputs: 50 V

Output Clamp Diodes

Inputs Compatible With Various Types of Logic

Relay-Driver Applications

Parametrics:-

Output Voltage(Max)(V) 50

Switching Voltage(Max)(V) 50

Peak Output Current(mA) 500

Drivers Per Package 7

Input Compatibility CMOS, TTL

Delay Time(Typ)(ns) 250

Operating Temperature Range(°C) -20 to 70

Pin/Package 16PDIP, 16SO, 16SOIC, 16TSSOP

Approx. Price (US$) 0.21 | 1ku

Rating Catalog

TABLE 3.1

Page 13: Project Report On "Prepaid Energy Meter"

13

The ULN2001A, ULN2002A, ULN2003 and ULN2004A are high voltage, high current

darlington arrays each containing seven open collector darlington pairs with common

emitters. Each channel rated at 500mA and can withstand peak currents of 600mA.

Suppression diodes are included for inductive load driving and the inputs are pinned opposite

the outputs to simplify board layout.

The four versions interface to all common logic families

1. ULN2001A General Purpose, DTL, TTL, PMOS,

2. CMOS

3. ULN2002A 14-25V PMOS

4. ULN2003A 5V TTL, CMOS

5. ULN2004A 6–15V CMOS, PMOS

These versatile devices are useful for driving a wide range of loads including solenoids,

relays DC motors, LED displays filament lamps, thermal printheads and high power buffers.

The ULN2001A/2002A/2003A and 2004A are supplied in 16 pin plastic DIP packages with a

copper leadframe to reduce thermal resistance. They are available also in small outline

package (SO-16) as ULN2001D/2002D/2003D/2004D.

Page 14: Project Report On "Prepaid Energy Meter"

14

:-

Page 15: Project Report On "Prepaid Energy Meter"

15

FIG.5.1.2

:-

Page 16: Project Report On "Prepaid Energy Meter"

16

TABLE 3.1.1

Page 17: Project Report On "Prepaid Energy Meter"

17

Page 19: Project Report On "Prepaid Energy Meter"

19

:-

FIG.5.1.4

Page 20: Project Report On "Prepaid Energy Meter"

20

FIG 5.1.5

Page 21: Project Report On "Prepaid Energy Meter"

21

Page 22: Project Report On "Prepaid Energy Meter"

22

Page 23: Project Report On "Prepaid Energy Meter"

23

(3.)RESISTOR:-

FIG. 6.1

DESCRIPTION:-

Resistor is a passive component used to control current in a circuit. Its resistance is given by

theratio of voltage applied across its terminals to the current passing through it. Thus a

particularvalue of resistor, for fixed voltage, limits the current through it. They are

omnipresent in electronic circuits.

The different value of resistances are used to limit the currents or get the desired voltage

drop according to the current-voltage rating of the device to be connected in the circuit. For

example, if an LED of rating 2.3V and 6mA is to be connected with a supply of 5V, a voltage

drop of 2.7V (5V-2.3V) and limiting current of 6mA is required. This can be achieved by

providing a resistor of 450 connected in series with the LED.

Resistors can be either fixed or variable. The low power resistors are comparatively smaller

in size than high power resistors. The resistance of a resistor can be estimated by their colour

codes or can be measured by a multimeter. There are some non linear resistors also whose

resistance changes with temperature or light. Negative temperature coefficient (NTC),

positive temperature coefficient (PTC) and light dependent resistor (LDR) are some such

resistors. These special resistors are commonly used as sensors.

Resistors, like diodes and relays, are another of the electronic parts that should have a section

in the installer's parts bin. They have become a necessity for the mobile electronics installer,

whether it be for door locks, praking lights, timing circuits, remote starts, LED's, or just to

Page 24: Project Report On "Prepaid Energy Meter"

24

discharge a stiffening capacitor. Resistors "resist" the flow of electrical current. The higher

the value of resistance (measured in ohms) the lower the current will be. Resistors are color

coded. To read the color code of a common 4 band 1K ohm resistor with a 5% tolerance, start

at the opposite side of the GOLD tolerance band and read from left to right. Write down the

corresponding number from the color chart below for the 1st color band (BROWN). To the

right of that number, write the corresponding number for the 2nd band (BLACK) . Now

multiply that number (you should have 10) by the corresponding multiplier number of the 3rd

band (RED)(100). Your answer will be 1000 or 1K. It's that easy.

* If a resistor has 5 color bands, write the corresponding number of the 3rd band to the right

of the 2nd before you multiply by the corresponding number of the multiplier band. If you

only have 4 color bands that include a tolerance band, ignore this column and go straight to

the multiplier.

The tolerance band is usually gold or silver, but

some may have none. Because resistors are not

the exact value as indicated by the color bands,

manufactures have included a tolorance color

band to indicate the accuracy of the resistor.

Gold band indicates the resistor is within 5% of

what is indicated. Silver = 10% and None = 20%. Others are shown in the chart below. The

1K ohm resistor in the example (left), may have an actual measurement any where from 950

ohms to 1050 ohms.

If a resistor does not have a tolerance band, start from the band closest to a lead. This will be

the 1st band. If you are unable to read the color bands, then you'll have to use your

multimeter. Be sure to zero it out first!

Resistor Color Codes

Band Color 1st Band # 2nd Band # *3rd Band # Multiplier x Tolerances ± %

Black 0 0 0 1

Brown 1 1 1 10 ± 1%

Red 2 2 2 100 ± 2 %

Orange 3 3 3 1000

Yellow 4 4 4 10,000

Green 5 5 5 100,000 ± 0.5 %

Blue 6 6 6 1,000,000 ± 0.25 %

Violet 7 7 7 10,000,000 ± 0.10 %

Grey 8 8 8 100,000,000 ± 0.05 %

White 9 9 9 1,000,000,000

Gold 0.1 ± 5 %

Silver 0.01 ± 10 %

None ± 20 %

TABLE-4

Page 25: Project Report On "Prepaid Energy Meter"

25

(4.) CRYSTAL OSCILLATOR:-

FIG.7.1

DESCRIPTION:-

A crystal oscillator is an electronic oscillator circuit that uses the mechanical resonance of a

vibrating crystal of piezoelectric material to create an electrical signal with a very precise

frequency. This frequency is commonly used to keep track of time (as in quartz

wristwatches), to provide a stable clock signal for digital integrated circuits, and to stabilize

frequencies for radio transmitters and receivers. The most common type of piezoelectric

resonator used is the quartz crystal, so oscillator circuits designed around them became

known as "crystal oscillators."

Quartz crystals are manufactured for frequencies from a few tens of kilohertz to tens of

megahertz. More than two billion (2×109) crystals are manufactured annually. Most are small

devices for consumer devices such as wristwatches, clocks, radios, computers, and

cellphones. Quartz crystals are also found inside test and measurement equipment, such as

counters, signal generators,and oscilloscopes.

Pierce Oscillator:-

A simplified schematic of the oscillator circuit used in Figure 1. Note that the typical 2-pin

crystal has been replaced by its equivalent circuit model.

• Co is the pin-to-pin capacitance. Its value is associated with the crystal electrode design and

the crystal holder.

Page 26: Project Report On "Prepaid Energy Meter"

26

• Rs is the motion resistance. Its value is specified by the crystal manufacturer.

• Cs is the motion capacitance and Ls is the motion inductance, which are not specified, and

are functions of the crystal frequency.

• Rbias is a feedback resistor, implemented on-chip in Chrontel products, which provides DC

bias to the inverting amplifier.

• C1 and C2 are total capacitance-to-ground at the input and output nodes of the amplifier,

respectively. If external capacitance is not added, the values of the internal capacitance C1

and C2, including pin parasitic capacitance, are each approximately 15pF to 20pF.

Page 27: Project Report On "Prepaid Energy Meter"

27

Series and Parallel Resonance:- There is no such thing as a “series cut” crystal as opposed to a “parallel cut” crystal. The

same crystal can be made to oscillate in series resonance mode or parallel resonance mode.

The frequency of osillation of a crystal is usually specified by the manufacturer as either the

series resonance frequency or the parallel resonance frequency. A crystal can oscillate in

series resonance, meaning that Ls is resonating with Cs, and the resonance frequency is then

simply

Some oscillator circuits are designed for series resonance and the oscillation frequency shall

equal the specified series resonance value. These series mode oscillators, however, are more

sensitive to temperature and component variations. In fact, most crystals oscillators in today's

ICs are of the parallel resonance type. The oscillation frequency of a parallel mode oscillator

is always higher than fseries. The actual oscilation frequency of a parallel mode oscillator is

dependent on the equivalent capacitance seen by the crystal.

Page 28: Project Report On "Prepaid Energy Meter"

28

Where

At parallel resonance, the crystal behaves inductively and resonates with capacitance

shunting the crystal terminals. Depending on the application, especially in microprocessors

where Pierce oscillators are used predominantly, a crystal manufacturer may specify parallel

resonance frequency instead of series resonance frequency. Since fparallel is a function of the

load capacitance Ceq, it should also be specified along with fparallel.

For PC CPU clock and VGA clock applications, the frequency accuracy required is usually

not very stringent and can easily be satisfied with a 14.318 MHz crystal that has been

specified for operation in either series or parallel resonance modes.

Crystal Power Dissipation:-

This is one of the more important specifications for a crystal. In operation, if the power

dissipated in the crystal exceeds the specified drive level, the crystal may have long term

reliability problems. The oscillation frequency may shift from the desired value, and in

extreme cases the crystal may crack and stop oscillating altogether. For the circuit in Figure

1, crystal dissipation is given by

Using typical values for Rs, Ceq and V equals 5V, P equals approximately 876 W.

Since increasing the value of C1 and C2 would result in increased power dissipation in the crystal, it

is not recommended that extra capacitance be added to pins XTAL1 and XTAL2 of the clock chip unless

it is absolutely necessary to tune the frequency to a desired value. In the case that additional

capacitances are added, a crystal with a higher drive level should be chosen according to the above

equation.

Page 29: Project Report On "Prepaid Energy Meter"

29

(5.) RELAY:-

FIG.8.1

DESCRIPTION:-

Relay is an electromagnetic device which is used to isolate two circuits electrically and

connect them magnetically. They are very useful devices and allow one circuit to switch

another one while they are completely separate. They are often used to interface an electronic

circuit (working at a low voltage) to an electrical circuit which works at very high voltage.

For example, a relay can make a 5V DC battery circuit to switch a 230V AC mains circuit.

Thus a small sensor circuit can drive, say, a fan or an electric bulb.

A relay can be divided into two parts: input and output. The input section has a coil which

generates magnetic field when a small voltage from an electronic circuit is applied to it. This

voltage is called the operating voltage. Commonly used relays are available in different

configuration of operating voltages like 6V, 9V, 12V, 24V etc. The output section consists of

contactors which connect or disconnect mechanically. In a basic relay there are three

contactors: normally open (NO), normally closed (NC) and common (COM). At no input

state, the COM is connected to NC. When the operating voltage is applied the relay coil gets

energized and the COM changes contact to NO. Different relay configurations are available

Page 30: Project Report On "Prepaid Energy Meter"

30

like SPST, SPDT, DPDT etc, which have different number of changeover contacts. By using

proper combination of contactors, the electrical circuit can be switched on and off.

An electromagnetic switch, consist of a coil (terminals 85 & 86), 1 common terminal (30), 1

normally closed terminal (87a), and one normally open terminal (87) (Figure 1). When the

coil of an SPDT relay (Figure 1) is at rest (not energized), the common terminal (30) and the

normally closed terminal (87a) have continuity. When the coil is energized, the common

terminal (30) and the normally open terminal (87) have continuity.

The diagram below center (Figure 2) shows an SPDT relay at rest, with the coil not

energized. The diagram below right (Figure 3) shows the relay with the coil energized. As

you can see, the coil is an electromagnet that causes the arm that is always connected to the

common (30) to pivot when energized whereby contact is broken from the normally closed

terminal (87a) and made with the normally open terminal (87).

When energizing the coil of a relay, polarity of the coil does not matter unless there is

a diode across the coil. If a diode is not present, you may attach positive voltage to either

terminal of the coil and negative voltage to the other, otherwise you must connect positive to

the side of the coil that the cathode side (side with stripe) of the diode is connected and

negative to side of the coil that the anode side of the diode is connected.

FIG.8.1.1

SPST Relay : (Single Pole Single Throw Relay) an electromagnetic switch, consist of a

coil (terminals 85 & 86), 1 common terminal (30), and one normally open terminal (87).

It does not have a normally closed terminal like the SPDT relay, but may be used in place of

SPDT relays in all diagrams shown on this site where terminal 87a is not used.

Dual Make SPST Relay : (Single Pole Single Throw Relay) an electromagnetic switch,

consist of a coil (terminals 85 & 86), 1 common terminal (30), and two normally open

terminals (87 and 87b). Dual make SPST relays (Figure 4) are used to power two circuits at

Page 31: Project Report On "Prepaid Energy Meter"

31

the same time that are normally isolated from each other, such as parking lamp circuits on

German automobiles.

The diagram below center (Figure 5) shows a dual make SPST relay at rest, with the coil not

energized. The diagram below right (Figure 6) shows the relay with the coil energized. The

coil is an electromagnet that causes the arms that are always connected to the common (30) to

pivot when energized whereby contact is made with the normally open terminals (87 and

87b).

Diodes are most often used across the coil to provide a path for current when the current path

to the relay is interrupted (i.e. switched off, coil no longer energized). This allows the coil

field to collapse without the voltage spike that would otherwise be generated. The diode

protects switch or relay contacts and other circuits that may be sensitive to voltage spikes.

Page 32: Project Report On "Prepaid Energy Meter"

32

(6.) L.C.D(Liquid Crystal Display ):-

FIG.9

LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of

applications. A 16x2 LCD display is very basic module and is very commonly used in

various devices and circuits. A 16x2 LCD means it can display 16 characters per line and

there are 2 such lines. In this LCD each character is displayed in 5x7 pixel matrix. This LCD

has two registers, namely, Command and Data.The command register stores the command

instructions given to the LCD. A command is an instruction given to LCD to do a predefined

task like initializing it, clearing its screen, setting the cursor position, controlling display etc.

The data register stores the data to be displayed on the LCD. The data is the ASCII value of

the character to be displayed on the LCD.

Page 33: Project Report On "Prepaid Energy Meter"

33

Pin Description:-

Pin

No Function Name

1 Ground (0V) Ground

2 Supply voltage; 5V (4.7V – 5.3V) Vcc

3 Contrast adjustment; through a variable VEE

Page 34: Project Report On "Prepaid Energy Meter"

34

4 Selects command register when low; and data register

when high

Register

Select

5 Low to write to the register; High to read from the

register

Read/write

6 Sends data to data pins when a high to low pulse is

given

Enable

7

8-bit data pins

DB0

8 DB1

9 DB2

10 DB3

11 DB4

12 DB5

13 DB6

14 DB7

15 Backlight VCC (5V) Led+

16 Backlight Ground (0V) Led-

TABLE.6

Page 35: Project Report On "Prepaid Energy Meter"

35

Page 36: Project Report On "Prepaid Energy Meter"

36

Page 37: Project Report On "Prepaid Energy Meter"

37

Schematic

Circuit Description

Above is the quite simple schematic. The LCD panel's Enable and Register Select is

connected to the Control Port. The Control Port is an open collector / open drain output.

While most Parallel Ports have internal pull-up resistors, there are a few which don't.

Therefore by incorporating the two 10K external pull up resistors, the circuit is more portable

for a wider range of computers, some of which may have no internal pull up resistors.

We make no effort to place the Data bus into reverse direction. Therefore we hard wire

the R/W line of the LCD panel, into write mode. This will cause no bus conflicts on the data

lines. As a result we cannot read back the LCD's internal Busy Flag which tells us if the LCD

has accepted and finished processing the last instruction. This problem is overcome by

inserting known delays into our program.

The 10k Potentiometer controls the contrast of the LCD panel. Nothing fancy here. As with

all the examples, I've left the power supply out. You can use a bench power supply set to 5v

or use a onboard +5 regulator. Remember a few de-coupling capacitors, especially if you

have trouble with the circuit working properly.

Page 38: Project Report On "Prepaid Energy Meter"

38

Programming - Source Code

/* LCD Module Software */

/* 17th May 1997 */

/* Copyright 1997 Craig Peacock */

/* WWW - http://www.senet.com.au/~cpeacock */

/* Email - [email protected] */

/* */

/* Register Select must be connected to Select Printer (PIN 17) */

/* Enable must be connected to Strobe (PIN1) */

/* DATA 0:7 Connected to DATA 0:7 */

#include <dos.h>

#include <string.h>

#define PORTADDRESS 0x378 /* Enter Your Port Address Here */

#define DATA PORTADDRESS+0

#define STATUS PORTADDRESS+1

#define CONTROL PORTADDRESS+2

void main(void)

{

char string[] = {"Testing 1,2,3 "

"It' Works ! "};

char init[10];

int count;

int len;

init[0] = 0x0F; /* Init Display */

init[1] = 0x01; /* Clear Display */

init[2] = 0x38; /* Dual Line / 8 Bits */

outportb(CONTROL, inportb(CONTROL) & 0xDF); /* Reset Control Port - Make sure

Forward Direction */

outportb(CONTROL, inportb(CONTROL) | 0x08); /* Set Select Printer (Register Select) */

The 2 line x 16 character LCD modules are

available from a wide range of manufacturers and

should all be compatible with the HD44780. The

one I used to test this circuit was a Powertip PC-

1602F and an old Philips LTN211F-10 which was

extracted from a Poker Machine! The diagram to

the right, shows the pin numbers for these devices.

When viewed from the front, the left pin is pin 14

and the right pin is pin 1.

Page 39: Project Report On "Prepaid Energy Meter"

39

for (count = 0; count <= 2; count++)

{

outportb(DATA, init[count]);

outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe (Enable)*/

delay(20); /* Larger Delay for INIT */

outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe (Enable)*/

delay(20); /* Larger Delay for INIT */

}

outportb(CONTROL, inportb(CONTROL) & 0xF7); /* Reset Select Printer (Register

Select) */

len = strlen(string);

for (count = 0; count < len; count++)

{

outportb(DATA, string[count]);

outportb(CONTROL,inportb(CONTROL) | 0x01); /* Set Strobe */

delay(2);

outportb(CONTROL,inportb(CONTROL) & 0xFE); /* Reset Strobe */

delay(2);

}

}

Above is the source code to get this example running. It's been written for Borland C, so if

you are using a Microsoft compiler, then you will have to change the outportb() function

to outp() and inportb() to inp().

The LCD panel requires a few instructions to be sent, to order to turn on the display and

initialise it. This is what the first for loop does. These instructions must be sent to the

LCD's Instruction Register which is controlled by the Register Select (Pin 4). When pin 4 is

low the instruction register is selected, thus when high the data register must be selected. We

connect this to the Parallel Port's Select Printer line which happens to be hardware inverted.

Therefore if we write a '1' to bit 3 of the Control Register the Select Printer line goes low.

We want to first send instructions to the LCD module. Therefore the Register Select line must

be low. As it is hardware inverted, we will want to set bit 3 of the Control Register to '1'.

However we don't want to upset any other bits on the Control Port. We achieve this by

reading the Control Port and OR'ing 0x80 to it. e.g. outportb(CONTROL,

inportb(CONTROL) | 0x08);This will only set bit 3.

After we place a data byte on the data lines, we must then signal to the LCD module to read

the data. This is done using theEnable line. Data is clocked into the LCD module on the high

to low transition. The Strobe is hardware inverted, thus by setting bit 0 of the Control

Register we get a high to low transition on the Strobe line. We then wait for a delay, and

return the line to a high state ready for the next byte.

After we initialize the LCD Module, we want to send text to it. Characters are sent to the

LCD's Data Port, thus we want to clear bit 3. Once again we must only change the one bit,

thus we use outportb(CONTROL, inportb(CONTROL) & 0xF7);. Then we set up

Page 40: Project Report On "Prepaid Energy Meter"

40

another for loop to read a byte from the string and send it to the LCD panel. This is repeated

for the length of the string.

The delays should be suitable for most machines. If the LCD panel is not initializing

properly, you can try increasing the delays. Likewise if the panel is skipping characters,

e.g. Tst ,2. On the other hand, If the LCD module is repeating characters

e.g.TTTeessttiinngg then you may have a faulting Enable connection. Check

your Enable to Strobe connection.

(7.) BUZZER:-

FIG.10.1

Description:-

The piezo buzzer produces sound based on reverse of the piezoelectric effect. The generation

of pressure variation or strain by the application of electric potential across a piezoelectric

material is the underlying principle. These buzzers can be used alert a user of an event

corresponding to a switching action, counter signal or sensor input. They are also used in

alarm circuits.

Page 41: Project Report On "Prepaid Energy Meter"

41

FIG.10.1

This novel buzzer circuit uses a relay in series with a small audio transformer and speaker.

When the switch is pressed, the relay will operate via the transformer primary and closed

relay contact. As soon as the relay operates the normally closed contact will open, removing

power from the relay, the contacts close and the sequence repeats, all very quickly...so fast

that the pulse of current causes fluctuations in the transformer primary, and hence secondary.

The speakers tone is thus proportional to relay operating frequency. The capacitor C can be

Page 42: Project Report On "Prepaid Energy Meter"

42

used to "tune" the note. The nominal value is 0.001uF, increasing capacitance lowers the

buzzers tone.

The buzzer produces a same noisy sound irrespective of the voltage variation applied to it. It

consists of piezo crystals between two conductors. When a potential is applied across these

crystals, they push on one conductor and pull on the other. This, push and pull action, results

in a sound wave. Most buzzers produce sound in the range of 2 to 4 kHz.

The Red lead is connected to the Input and the Black lead is connected to Ground.

(8.)Energy meters:-

Energy meters, the only direct revenue interface between utilities and the consumers, have

undergone several advancements in the last decade. The conventional electro-mechanical

meters are being replaced with electronic meters to improve accuracy in meter reading. Asian

countries are currently looking to introduce prepaid electricity meters across their distribution

network, buoyed up by the success of this novel methodology in South Africa. The existing

inherent problems with the post-paid system and privatization of state held power distribution

companies are the major driving factors for this market in Asia.

Over 40 countries have implemented prepaid meters in their

markets. In United Kingdom the system, has been in use for

well over 70 years with about 3.5 million consumers. The

prepaid program in South Africa was started in 1992, since

then they have installed over 6 million meters. Other

African counties such as Sudan, Madagascar are following

the South African success. The concept has found ground in

Argentina and New Zealand with few thousands of

installations.

The prepaid meters in the market today are coming up with

smart cards to hold information on units consumed or

equivalent money value. When the card is inserted, the

energy meter reads it, connects the supply to the consumer

loads, and debits the value. The meters are equipped with

light emitting diodes (LED) to inform consumers when 75 percent of the credit energy has

been consumed. The consumer then recharges the prepaid card from a sales terminal or

distribution point, and during this process any changes in the tariff can also be loaded in the

smart card.

(9.) OPTOCOUPLERS

DESCRIPTION

Page 43: Project Report On "Prepaid Energy Meter"

43

The general purpose optocouplers consist of a gallium arsenide infrared emitting diode

driving a silicon phototransistor in a 6-pin dual in-line package.

FEATURES • Also available in white package by specifying -M suffix

• UL recognized

• VDE recognized

- Add option V for white package

- Add option 300 for black package

APPLICATIONS • Power supply regulators

• Digital logic inputs

• Microprocessor inputs

Page 44: Project Report On "Prepaid Energy Meter"

44

Page 45: Project Report On "Prepaid Energy Meter"

45

Page 46: Project Report On "Prepaid Energy Meter"

46

FIG12.1.1

Page 47: Project Report On "Prepaid Energy Meter"

47

Page 48: Project Report On "Prepaid Energy Meter"

48

Page 49: Project Report On "Prepaid Energy Meter"

49

Page 50: Project Report On "Prepaid Energy Meter"

50

FIG.12.1.2

Page 51: Project Report On "Prepaid Energy Meter"

51

Page 52: Project Report On "Prepaid Energy Meter"

52

Page 53: Project Report On "Prepaid Energy Meter"

53

Page 54: Project Report On "Prepaid Energy Meter"

54

(10.)card reader:-

A card reader is a data input device that reads data from a card-shaped storage medium.

Historically, paper or cardboard punched cardswere used throughout the first several decades

of the computer industry to store information and write programs for computer system, and

these were read by punched card readers. More modern card readers are electronic devices

that use plastic cards imprinted with barcodes, magnetic strips, computer chips or other

storage medium.

A memory card reader is a device used for communication with a smart card or a memory

card. A magnetic card reader is a device used to read magnetic stripe cards, such as credit

cards. A business card reader is a device used to scan and electronically save

printedbusiness cards.

Smart card readers

A smart card reader is an electronic device that reads smart cards. Some keyboards have

a built-in card reader. There are external devices and internal drive bay card reader

devices for PC. Some laptops have built-in smart card reader.

Some have a flash upgradeable firmware. The card reader supplies the integrated circuit

on the smart card with electricity. Communication is done via protocols and you can

read and write to a fixed address on the card.

If the card is not using any standard transmission protocol, but uses a custom/proprietary

protocol it has the communication protocol designation T=14.[1]

The latest PC/SC CCID specifications has defined a new smart card framework. It works

with USB devices with the specific device class 0x0B. Readers with this class do not

need device drivers when used with PC/SC-compliant operating systems, because the

OS supplies it by default.

PKCS#11 is an API, designed to be platform independent, defining a generic interface to

cryptographic tokens such as smart cards, allowing applications to work without

knowledge of the reader details.

[edit]Memory card readers

Page 55: Project Report On "Prepaid Energy Meter"

55

FIG.13

A USB card reader like this one, will typically implement the USB mass storage

device class.

A memory card reader is a device, typically having a USB interface, for accessing the

data on amemory card such as a CompactFlash (CF), Secure Digital (SD)

or MultiMediaCard (MMC). Most card readers also offer write capability, and together

with the card, this can function as a pen drive.

[edit]Access control card reader

Access control card readers are used in physical security systems to read

a credential that allows access through access control points, typically a locked door. An

access control reader can be amagnetic stripe reader, a bar code reader, a proximity

reader, a smart card reader, or a biometricreader.

Access control readers may be classified by functions they are able to perform and by

identification technology:

Barcode

A barcode is a series of alternating dark and light stripes that are read by an optical

scanner. The organization and width of the lines is determined by the bar code protocol

selected. There are many different protocols but Code 39 is the most popular in the

security industry. Sometimes the digits represented by the dark and light bars are also

printed to allow people to read the number without an optical reader. The advantage of

using bar code technology is that it is cheap and easy to generate the credential, and it

can easily be applied to cards or other items. However the same affordability and

simplicity makes the technology susceptible to fraud, because fake barcodes can also be

created cheaply and easily, for example by photocopying real ones. One attempt to

reduce fraud is to print the bar code using carbon-based ink and then cover the bar code

with a dark red overlay. The bar code can then be read with an optical reader tuned to

the infrared spectrum, but can not easily be copied by a copy machine. This does not

Page 56: Project Report On "Prepaid Energy Meter"

56

address the ease with which bar code numbers can be generated from a computer using

almost any printer.

Biometric

There are several forms of biometric identification employed in access

control: fingerprint, hand geometry, iris and face recognition. The use of biometric

technology significantly increases security level of systems because it eliminates such

problems as lost, stolen or loaned ID cards, and forgotten or guessed PINs[citation needed].

The operation of all biometric readers is alike: they compare the template stored in

memory to the scan obtained during the process of identification. If the probability that

the template in the memory and the live scan belong to the same person is high enough,

the ID number of that person is sent to a control panel. The control panel then checks

permissions of the user and makes the decision whether to grant access or not. The

communication between the reader and the control panel is usually done in the industry

standard Wiegand protocol. The only exception is intelligent biometric readers that do

not require any panels and directly control all door hardware.

Biometric templates may be stored in the memory of readers, in which case the number

of users is limited by reader memory size. Readers currently available in the market may

store up to 50,000 templates. Template of each user may also be stored in the memory of

his/her smart card. This option removes all limits to the number of system users, but it

requires each user to have a card and makes finger-only identification impossible.

Biometric templates may also be stored in the memory of a central server PC. This

option is called "server-based verification". Readers simply read biometric data of users

and forward it to the main computer for processing. Such systems support large number

of users, but they are very much dependent on the reliability of the central server and

communication lines.

1-to-1 and 1-to-many are the two possible modes of operation of a biometric reader.

In the 1-to-1 mode a user must first identify himself/herself to the reader by either

presenting an ID card or entering a PIN. The reader then looks up the template of the

user in the database and compares it with the live scan. The 1-to-1 method is

considered more secure and is generally faster as the reader needs to perform only

one comparison. Most 1-to-1 biometric readers are "dual-technology" readers: they

either have a built-in proximity, smart card or keypad reader, or they have an input

for connecting an external card reader.

In the 1-to-many mode a user presents his finger (or hand, eye, etc.) and reader needs

to compare the live scan to all the templates stored in the memory. This method is

preferred by most end-users, because it eliminates the need to carry ID cards or use

PINs. On the other hand this method is slower, because the reader may have to

perform thousands of comparison operations until it finds the match. An important

technical characteristic of 1-to-many readers is the number of comparisons that can

be performed in one second, which is considered the maximum time that users can

wait at a door without noticing a delay. Currently most 1-to-many readers are

capable of performing 2000–3000 matching operations per second.

[edit]Magnetic stripe

See also: Magnetic stripe card

Magnetic stripe technology, usually called mag-stripe, is so named because of the stripe

of magnetic oxide tape that is laminated on a card. There are three tracks of data on the

Page 57: Project Report On "Prepaid Energy Meter"

57

magnetic stripe. Typically the data on each of the tracks follows a specific encoding

standard, but it is possible to encode any format on any track. A mag-stripe card is cheap

compared to other card technologies and is easy to program. The magnetic stripe holds

more data than a bar code can in the same space. While a mag-stripe is more difficult to

generate than a bar code, the technology for reading and encoding data on a mag-stripe

is widespread and easy to acquire. Magnetic stripe technology is also susceptible to

misreads, card wear, and data corruption.

[edit]Wiegand card

Wiegand card technology is a patented technology using embedded ferromagnetic wires

strategically positioned to create a unique pattern that generates the identification

number. Like magnetic stripe or bar code, this card must be swiped through a reader to

be read. Unlike those other technologies the identification media is embedded in the card

and not susceptible to wear. This technology once gained popularity because of the

difficulty in duplicating the technology creating a high perception of security. This

technology is being replaced by proximity cards because of the limited source of supply,

the relatively better tamper resistance of proximity readers, and the convenience of the

touch-less functionality in proximity readers.

[edit]Proximity card

The Wiegand effect was used in early access cards. This method was abandoned in favor

of other technologies. Card readers are still referred to as "Wiegand output readers" but

no longer use the Wiegand effect. The new technologies retained the Wiegand upstream

data so that the new readers were compatible with old systems. A proximity reader

radiates a 1" to 20" electrical field around itself. Cards use a simple LC circuit. When a

card is presented to the reader, the reader's electrical field excites a coil in the card. The

coil charges a capacitor and in turn powers an integrated circuit (IC). The integrated

circuit outputs the card number to the coil which transmits it to the reader.

A common proximity format is 26-bit Wiegand. This format uses a facility code,

sometimes also called a site code. The facility code is a unique number common to all of

the cards in a particular set. The idea is that an organization will have their own facility

code and a set of numbered cards incrementing from 1. Another organization has a

different facility code and their card set also increments from 1. Thus different

organizations can have card sets with the same card numbers but since the facility codes

differ, the cards only work at one organization. This idea worked fine for a while but

there is no governing body controlling card numbers, and different manufacturers can

supply cards with identical facility codes and identical card numbers to different

organizations. Thus there is a problem of duplicate cards. To counteract this problem

some manufacturers have created formats beyond 26-bit Wiegand that they control and

issue to organizations.

In the 26-bit Wiegand format, bit 1 is an even parity bit. Bits 2–9 are a facility code. Bits

10–25 are the card number. Bit 26 is an odd parity bit. 1/8/16/1. Other formats have a

similar structure of a leading facility code followed by the card number and including

parity bits for error checking, such as the 1/12/12/1 format used by some American

access control companies.

1/8/16/1 gives as facility code limit of 255 and 65535 card number

1/12/12/1 gives a facility code limit of 4095 and 4095 card number.

Wiegand was also stretched to 34 bits, 56 bits and many others.

Page 58: Project Report On "Prepaid Energy Meter"

58

[edit]Smart card

There are two types of smart cards: contact and contactless. Both have an embedded

microprocessor and memory. The smart card differs from the card typically called a

proximity card in that the microchip in the proximity card has only one function: to

provide the reader with the card's identification number. The processor on the smart card

has an embedded operating system and can handle multiple applications such as a cash

card, a pre-paid membership card, and even an access control card. The difference

between the two types of smart cards is found in the manner with which the

microprocessor on the card communicates with the outside world. A contact smart card

has eight contacts, which must physically touch contacts on the reader to convey

information between them. Since contact cards must be inserted into readers carefully

and the orientation has be observed the speed and convenience of such transaction is not

acceptable for most access control applications. The use of contact smart cards is

physical access control is limited mostly to parking applications when payment data is

stored in card memory and when the speed of transactions is not important. A

contactless smart card uses the same radio-based technology as the proximity card with

the exception of the frequency band used: higher frequency (13.56 MHz instead of

125 kHz) allows to transferring more data and communicating with several cards at the

same time. A contactless card does not have to touch the reader or even be taken out

from a wallet or purse. Most access control systems only read serial numbers of

contactless smart cards and do not utilize the available memory. Card memory may be

used for storing biometric data (i.e. fingerprint template) of a user. In such case a

biometric reader first reads the template on the card and then compares it to the finger

(hand, eye, etc.) presented by the user. This way biometric data of users does not have to

be distributed and stored in the memory of controllers or readers, which simplifies the

system and reduces memory requirements.

Smartcard readers have been targeted successfully by criminals in what is termed

a supply chain attack, in which the readers are tampered with during manufacture or in

the supply chain before delivery. The rogue devices capture customers' card details

before transmitting them to criminals.

Page 59: Project Report On "Prepaid Energy Meter"

59

(11.)Capacitor:-

FIG.14.1

Introduction to Capacitors

Just like the Resistor, the Capacitor, sometimes referred to as a Condenser, is a passive

device, and one which stores its energy in the form of an electrostatic field producing a

potential difference (Static Voltage) across its plates. In its basic form a capacitor consists of

two or more parallel conductive (metal) plates that do not touch or are connected but are

electrically separated either by air or by some form of insulating material such as paper, mica

or ceramic called the Dielectric. The conductive plates of a capacitor can be either square,

circular or rectangular, or be of a cylindrical or spherical shape with the shape and

construction of a parallel plate capacitor depending on its application and voltage rating.

When used in a direct-current or DC circuit, a capacitor blocks the flow of current through it,

but when it is connected to an alternating-current or AC circuit, the current appears to pass

straight through it with little or no resistance. If a DC voltage is applied to the capacitors

conductive plates, a current flows charging up the plates with electrons giving one plate a

positive charge and the other plate an equal and opposite negative charge. This flow of

electrons to the plates is known as the Charging Current and continues to flow until the

voltage across both plates (and hence the capacitor) is equal to the applied voltage Vc. At

thispoint the capacitor is said to be fully charged with electrons with the strength of this

charging current at its maximum when the plates are fully discharged and slowly reduces in

value to zero as the plates charge up to a potential difference equal to the applied supply

voltage and this is illustrated below.

Page 60: Project Report On "Prepaid Energy Meter"

60

Capacitor Construction

FIG.14.1.1

The parallel plate capacitor is the simplest form of capacitor and its capacitance value is fixed

by the surface area of the conductive plates and the distance or separation between them.

Altering any two of these values alters the the value of its capacitance and this forms the

basis of operation of the variable capacitors. Also, because capacitors store the energy of the

electrons in the form of an electrical charge on the plates the larger the plates and/or smaller

their separation the greater will be the charge that the capacitor holds for any given voltage

across its plates. In other words, larger plates, smaller distance, more capacitance.

By applying a voltage to a capacitor and measuring the charge on the plates, the ratio of the

charge Q to the voltage V will give the capacitance value of the capacitor and is therefore

given as: C = Q/V this equation can also be re-arranged to give the more familiar formula for

the quantity of charge on the plates as: Q = C x V

Although we have said that the charge is stored on the plates of a capacitor, it is more correct

to say that the energy within the charge is stored in an "electrostatic field" between the two

plates. When an electric current flows into the capacitor, charging it up, the electrostatic field

becomes more stronger as it stores more energy. Likewise, as the current flows out of the

capacitor, discharging it, the potential difference between the two plates decreases and the

electrostatic field decreases as the energy moves out of the plates.

Page 61: Project Report On "Prepaid Energy Meter"

61

The property of a capacitor to store charge on its plates in the form of an electrostatic field is

called theCapacitance of the capacitor. Not only that, but capacitance is also the property of

a capacitor which resists the change of voltage across it.

The Capacitance of a Capacitor

The unit of capacitance is the Farad (abbreviated to F) named after the British physicist

Michael Faraday and is defined as a capacitor has the capacitance of One Farad when a

charge of One Coulomb is stored on the plates by a voltage of One volt. Capacitance, C is

always positive and has no negative units. However, the Farad is a very large unit of

measurement to use on its own so sub-multiples of the Farad are generally used such as

micro-farads, nano-farads and pico-farads, for example.

Units of Capacitance

Microfarad (μF) 1μF = 1/1,000,000 = 0.000001 = 10-6 F

Nanofarad (nF) 1nF = 1/1,000,000,000 = 0.000000001 = 10-9 F

Picofarad (pF) 1pF = 1/1,000,000,000,000 = 0.000000000001 = 10-12 F

The capacitance of a parallel plate capacitor is proportional to the area, A of the plates and

inversely proportional to their distance or separation, d (i.e. the dielectric thickness) giving us

a value for capacitance of C = k( A/d ) where in a vacuum the value of the constant k is 8.84

x 10-12 F/m or 1/4.π.9 x 109, which is the permittivity of free space. Generally, the conductive

plates of a capacitor are separated by air or some kind of insulating material or gel rather than

the vacuum of free space.

Page 62: Project Report On "Prepaid Energy Meter"

62

The Dielectric of a Capacitor

As well as the overall size of the conductive plates and their distance or spacing apart from

each other, another factor which affects the overall capacitance of the device is the type of

dielectric material being used. In other words the "Permittivity" (ε) of the dielectric. The

conductive plates are generally made of a metal foil or a metal film but the dielectric material

is an insulator. The various insulating materials used as the dielectric in a capacitor differ in

their ability to block or pass an electrical charge. This dielectric material can be made from a

number of insulating materials or combinations of these materials with the most common

types used being: air, paper, polyester, polypropylene, Mylar, ceramic, glass, oil, or a variety

of other materials.

The factor by which the dielectric material, or insulator, increases the capacitance of the

capacitor compared to air is known as the Dielectric Constant, k and a dielectric material

with a high dielectric constant is a better insulator than a dielectric material with a lower

dielectric constant. Dielectric constant is a dimensionless quantity since it is relative to free

space. The actual permittivity or "complex permittivity" of the dielectric material between the

plates is then the product of the permittivity of free space (εo) and the relative permittivity (εr)

of the material being used as the dielectric and is given as:

Complex Permittivity

As the permittivity of free space, εo is equal to one, the value of the complex permittivity will

always be equal to the relative permittivity. Typical units of dielectric permittivity, ε or

dielectric constant for common materials are: Pure Vacuum = 1.0000, Air = 1.0005, Paper =

2.5 to 3.5, Glass = 3 to 10, Mica = 5 to 7, Wood = 3 to 8 and Metal Oxide Powders = 6 to 20

etc.

This then gives us a final equation for the capacitance of a capacitor as:

One method used to increase the overall capacitance of a capacitor is to "interleave" more

plates together within a single capacitor body. Instead of just one set of parallel plates, a

capacitor can have many individual plates connected together thereby increasing the

area, A of the plate. For example, a capacitor with 10 interleaved plates would produce 9 (10

- 1) mini capacitors with an overall capacitance nine times that of a single parallel plate.

Page 63: Project Report On "Prepaid Energy Meter"

63

Modern capacitors can be classified according to the characteristics and properties of their

insulating dielectric:

Low Loss, High Stability such as Mica, Low-K Ceramic, Polystyrene.

Medium Loss, Medium Stability such as Paper, Plastic Film, High-K Ceramic.

Polarized Capacitors such as Electrolytic's, Tantalum's.

Voltage Rating of a Capacitor

All capacitors have a maximum voltage rating and when selecting a capacitor consideration

must be given to the amount of voltage to be applied across the capacitor. The maximum

amount of voltage that can be applied to the capacitor without damage to its dielectric

material is generally given in the data sheets as: WV, (working voltage) or as WV DC, (DC

working voltage). If the voltage applied across the capacitor becomes too great, the dielectric

will break down (known as electrical breakdown) and arcing will occur between the capacitor

plates resulting in a short-circuit. The working voltage of the capacitor depends on the type of

dielectric material being used and its thickness.

The DC working voltage of a capacitor is just that, the maximum DC voltage and NOT the

maximum AC voltage as a capacitor with a DC voltage rating of 100 volts DC cannot be

safely subjected to an alternating voltage of 100 volts. Since an alternating voltage has an

r.m.s. value of 100 volts but a peak value of over 141 volts!. Then a capacitor which is

required to operate at 100 volts AC should have a working voltage of at least 200 volts. In

practice, a capacitor should be selected so that its working voltage either DC or AC should be

at least 50 percent greater than the highest effective voltage to be applied to it.

Another factor which affects the operation of a capacitor is Dielectric Leakage. Dielectric

leakage occurs in a capacitor as the result of an unwanted leakage current which flows

through the dielectric material. Generally, it is assumed that the resistance of the dielectric is

extremely high and a good insulator blocking the flow of DC current through the capacitor

(as in a perfect capacitor) from one plate to the other. However, if the dielectric material

becomes damaged due excessive voltage or over temperature, the leakage current through the

dielectric will become extremely high resulting in a rapid loss of charge on the plates and an

overheating of the capacitor eventually resulting in premature failure of the capacitor. Then

never use a capacitor in a circuit with higher voltages than the capacitor is rated for otherwise

it may become hot and explode.

Page 64: Project Report On "Prepaid Energy Meter"

64

Introduction to Capacitors Summary

The job of a capacitor is to store charge onto its plates. The amount of electrical charge that a

capacitor can store on its plates is known as its Capacitance value and depends upon three

main factors.

The surface area, A of the two conductive plates which make up the capacitor, the larger the

area the greater the capacitance.

The distance, d between the two plates, the smaller the distance the greater the capacitance.

The type of material which separates the two plates called the "dielectric", the higher the

permittivity of the dielectric the greater the capacitance.

The dielectric of a capacitor is a non-conducting insulating material, such as waxed paper,

glass, mica different plastics etc, and provides the following advantages.

The dielectric constant is the property of the dielectric material and varies from one material

to another increasing the capacitance by a factor of k.

The dielectric provides mechanical support between the two plates allowing the plates to be

closer together without touching.

Permittivity of the dielectric increases the capacitance.

The dielectric increases the maximum operating voltage compared to air.

All capacitors have a maximum working voltage rating, its WV DC so select a capacitor with

a rating at least 50% more than the supply voltage.

There are a large variety of capacitor styles and types, each one having its own particular

advantage, disadvantage and characteristics. To include all types would make this tutorial

section very large so in the next tutorial about The Introduction to Capacitors I shall limit

them to the most commonly used types.

(12.)CARD PROGRAMMING:-

SDA1 EQU P3.4 ;SDA=PIN5

SCL1 EQU P3.3 ;SCL=PIN6

WTCMD EQU 10100000B ;WRITE DATA COMMAND Note 3

RDCMD EQU 10100001B ;READ DATA COMMAND Note 3

Page 65: Project Report On "Prepaid Energy Meter"

65

RED EQU P3.7

GREEN EQU P1.0

KEYS EQU P1

ROW1 EQU P1.1

ROW2 EQU P1.2

ROW3 EQU P1.3

ROW4 EQU P1.4

COL1 EQU P1.7

COL2 EQU P1.6

COL3 EQU P1.5

DSEG ; This is internal data memory

ORG 20H ; Bit adressable memory

KEY: DS 1

N0: DS 1

N1: DS 1

N2: DS 1

N3: DS 1

N4: DS 1

N5: DS 1

Page 66: Project Report On "Prepaid Energy Meter"

66

COUNT: DS 1

PASS0: DS 1

PASS1: DS 1

PASS2: DS 1

CHANGE: DS 1

CSEG ; Code begins here

; ---------==========----------==========---------=========---------

; Main routine. Program execution starts here. 8889

; ---------==========----------==========---------=========---------

ORG 00H ; Reset

MOV SP,#60H

CLR RED

CLR GREEN

CALL DELAY

CALL DELAY

SETB RED

SETB GREEN

MOV N1,#01H

MOV N2,#0FFH

Page 67: Project Report On "Prepaid Energy Meter"

67

MOV N3,#0FFH

MOV N4,#0FFH

MOV N5,#0FFH

MOV R3,#01H

; MOV N2,#23H

; MOV N4,#45H

; CALL SAX

KEYBOARD:

MOV KEY,#00H

SETB COL1

SETB COL2

SETB COL3

K11: CLR ROW1

CLR ROW2

CLR ROW3

CLR ROW4

MOV A,KEYS

ANL A,#11100000B

CJNE A,#11100000B,K11 ;check till all keys released

K2: ACALL DEALAY ;call 20 msec delay

MOV A,KEYS ;see if any key is pressed

ANL A,#11100000B ;mask unused bits

Page 68: Project Report On "Prepaid Energy Meter"

68

CJNE A,#11100000B,OVER ;key pressed, await closure

SJMP K2

OVER: ACALL DEALAY

MOV A,KEYS

ANL A,#11100000B

CJNE A,#11100000B,OVER1

SJMP K2

OVER1: MOV A,KEYS

ORL A,#11111110B

MOV KEYS,A

CLR ROW1

MOV A,KEYS

ANL A,#11100000B

CJNE A,#11100000B,ROW_1

MOV A,KEYS

ORL A,#11111110B

MOV KEYS,A

CLR ROW2

MOV A,KEYS

ANL A,#11100000B

CJNE A,#11100000B,ROW_2

MOV A,KEYS

ORL A,#11111110B

MOV KEYS,A

CLR ROW3

Page 69: Project Report On "Prepaid Energy Meter"

69

MOV A,KEYS

ANL A,#11100000B

CJNE A,#11100000B,ROW_3

MOV A,KEYS

ORL A,#11111110B

MOV KEYS,A

CLR ROW4

MOV A,KEYS

ANL A,#11100000B

CJNE A,#11100000B,ROW_4

LJMP K2

ROW_1: RLC A

JC MAT1

MOV KEY,#01H

AJMP K1

MAT1: RLC A

JC MAT2

MOV KEY,#02H

AJMP K1

MAT2: RLC A

JC K1

MOV KEY,#03H

AJMP K1

Page 70: Project Report On "Prepaid Energy Meter"

70

ROW_2: RLC A

JC MAT3

MOV KEY,#04H

AJMP K1

MAT3: RLC A

JC MAT4

MOV KEY,#05H

AJMP K1

MAT4: RLC A

JC K1

MOV KEY,#06H

AJMP K1

ROW_3: RLC A

JC MAT5

MOV KEY,#07H

AJMP K1

MAT5: RLC A

JC MAT6

MOV KEY,#08H

AJMP K1

MAT6: RLC A

JC K1

MOV KEY,#09H

Page 71: Project Report On "Prepaid Energy Meter"

71

AJMP K1

ROW_4: RLC A

JC MAT7

MOV KEY,#0AH

AJMP K1

MAT7: RLC A

JC MAT8

MOV KEY,#00H ;for 0

AJMP K1

MAT8: RLC A

JC K1

MOV KEY,#0FH

K1:

CLR RED

CALL DELAY

CALL DELAY

SETB RED

MOV A,KEY

CJNE A,#0FH,G0

Page 72: Project Report On "Prepaid Energy Meter"

72

CJNE R3,#07H,G0

AJMP G8

G0: CJNE R3,#01H,G11

INC R3

MOV N0,KEY

AJMP KEYBOARD

G11: CJNE R3,#02H,G1

INC R3

MOV N1,KEY

AJMP KEYBOARD

G1: CJNE R3,#03H,G2

INC R3

MOV N2,KEY

AJMP KEYBOARD

G2: CJNE R3,#04H,G3

INC R3

MOV N3,KEY

AJMP KEYBOARD

G3: CJNE R3,#05H,G4

INC R3

MOV N4,KEY

AJMP KEYBOARD

G4: CJNE R3,#06H,G5

INC R3

Page 73: Project Report On "Prepaid Energy Meter"

73

MOV N5,KEY

G5: AJMP KEYBOARD

G8:

MOV A,N2

SWAP A

ORL A,N3

MOV N2,A ;HIGHER DIGITSS IN N2

MOV A,N4

SWAP A

ORL A,N5

MOV N3,A ;LOWER DISITS IN N3

MOV A,N0

CJNE A,#01H,STR_AMT

MOV N1,#00H

MOV R1,#N1 ;store COUNT

MOV R4,#20H ;Starting Address IN

EEPROM

MOV R6,#3 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAY

Page 74: Project Report On "Prepaid Energy Meter"

74

CALL DELAY

AJMP CHK_DATA

BV1S: AJMP BV1

STR_AMT:

CJNE A,#02H,BV1S

MOV N1,#01H

MOV R1,#N1 ;store COUNT

MOV R4,#20H ;Starting Address IN

EEPROM

MOV R6,#3 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAY

CALL DELAY

; ---------==========----------==========---------=========---------

;CHECK WITH DATA STORED IN MEMORY

; ---------==========----------==========---------=========---------

CHK_DATA:

MOV R1,#PASS0 ;GET DATA IN

BYTES(RAM)

MOV R4,#20H ;DATA

ADDRESS IN EEPROM

Page 75: Project Report On "Prepaid Energy Meter"

75

MOV R6,#3 ;NUMBER OF BYTES

CALL READ_EEPROM

MOV A,N1

CJNE A,PASS0, BV1

MOV A,N2

CJNE A,PASS1,BV1

MOV A,N3

CJNE A,PASS2,BV1

CLR GREEN

CALL DELAY1

CALL DELAY1

SETB GREEN

CALL DELAY1

CALL DELAY1

CLR GREEN

CALL DELAY1

CALL DELAY1

SETB GREEN

MOV R3,#01H

MOV N0,#0FFH

MOV N1,#0FFH

MOV N2,#0FFH

MOV N3,#0FFH

MOV N4,#0FFH

Page 76: Project Report On "Prepaid Energy Meter"

76

MOV N5,#0FFH

AJMP KEYBOARD

BV1: CLR RED

CALL DELAY1

CALL DELAY1

SETB RED

CALL DELAY1

CALL DELAY1

CLR RED

CALL DELAY1

CALL DELAY1

SETB RED

MOV R3,#01H

MOV N0,#0FFH

MOV N1,#0FFH

MOV N2,#0FFH

MOV N3,#0FFH

MOV N4,#0FFH

MOV N5,#0FFH

AJMP KEYBOARD

;((((((((((((((((((((((((((((((((

DEALAY:

MOV R1,#50

Page 77: Project Report On "Prepaid Energy Meter"

77

REPP2: NOP

DJNZ R1,REPP2

RET

;((((((((((((((((((((((((((((((((

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

; READ DATA FROM EEPROM

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

READ_EEPROM:

MOV A,#WTCMD ;LOAD WRITE COMMAND TO SEND

ADDRESS

CALL OUTS ;SEND IT

MOV A,R4 ;GET LOW BYTE ADDRESS

CALL OUT ;SEND IT

MOV A,#RDCMD ;LOAD READ COMMAND

CALL OUTS ;SEND IT

BRDLP: CALL IN ;READ DATA

MOV @R1,a ;STORE DATA

INC R1 ;INCREMENT DATA POINTER

DJNZ R6,AKLP ;DECREMENT LOOP COUNTER

CALL STOP ;IF DONE, ISSUE STOP CONDITION

RET ;DONE, EXIT ROUTINE

AKLP: CLR SDA1 ;NOT DONE, ISSUE ACK

SETB SCL1

Page 78: Project Report On "Prepaid Energy Meter"

78

NOP ;NOTE 1

NOP

NOP

NOP ;NOTE 2

NOP

CLR SCL1

JMP BRDLP ;CONTINUE WITH READS

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

; STORE DATA IN EEPROM

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

STORE_EEPROM:

MOV A,#WTCMD ;LOAD WRITE COMMAND

CALL OUTS ;SEND IT

MOV A,R4 ;GET LOW BYTE ADDRESS

CALL OUT ;SEND IT

BTLP: MOV A,@R1 ;GET DATA

CALL OUT ;SEND IT

INC R1 ;INCREMENT DATA POINTER

DJNZ R6,BTLP ;LOOP TILL DONE

CALL STOP ;SEND STOP CONDITION

RET

Page 79: Project Report On "Prepaid Energy Meter"

79

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

;***********************************************************************

; THIS ROUTINE SENDS OUT CONTENTS OF THE ACCUMULATOR

; to the EEPROM and includes START condition. Refer to the data sheets

; for discussion of START and STOP conditions.

;***********************************************************************

OUTS: MOV R2,#8 ;LOOP COUNT -- EQUAL TO BIT COUNT

SETB SDA1 ;INSURE DATA IS HI

SETB SCL1 ;INSURE CLOCK IS HI

NOP ;NOTE 1

NOP

NOP

CLR SDA1 ;START CONDITION -- DATA = 0

NOP ;NOTE 1

NOP

NOP

CLR SCL1 ;CLOCK = 0

OTSLP: RLC A ;SHIFT BIT

JNC BITLS

SETB SDA1 ;DATA = 1

JMP OTSL1 ;CONTINUE

BITLS: CLR SDA1 ;DATA = 0

OTSL1: SETB SCL1 ;CLOCK HI

Page 80: Project Report On "Prepaid Energy Meter"

80

NOP ;NOTE 1

NOP

NOP

CLR SCL1 ;CLOCK LOW

DJNZ R2,OTSLP ;DECREMENT COUNTER

SETB SDA1 ;TURN PIN INTO INPUT

NOP ;NOTE 1

SETB SCL1 ;CLOCK ACK

NOP ;NOTE 1

NOP

NOP

CLR SCL1

RET

;**********************************************************************

; THIS ROUTINE SENDS OUT CONTENTS OF ACCUMLATOR TO EEPROM

; without sending a START condition.

;**********************************************************************

OUT: MOV R2,#8 ;LOOP COUNT -- EQUAL TO BIT COUNT

OTLP: RLC A ;SHIFT BIT

JNC BITL

Page 81: Project Report On "Prepaid Energy Meter"

81

SETB SDA1 ;DATA = 1

JMP OTL1 ;CONTINUE

BITL: CLR SDA1 ;DATA = 0

OTL1: SETB SCL1 ;CLOCK HI

NOP ;NOTE 1

NOP

NOP

CLR SCL1 ;CLOCK LOW

DJNZ R2,OTLP ;DECREMENT COUNTER

SETB SDA1 ;TURN PIN INTO INPUT

NOP ;NOTE 1

SETB SCL1 ;CLOCK ACK

NOP ;NOTE 1

NOP

NOP

CLR SCL1

RET

STOP: CLR SDA1 ;STOP CONDITION SET DATA LOW

NOP ;NOTE 1

NOP

Page 82: Project Report On "Prepaid Energy Meter"

82

NOP

SETB SCL1 ;SET CLOCK HI

NOP ;NOTE 1

NOP

NOP

SETB SDA1 ;SET DATA HIGH

RET

;*******************************************************************

; THIS ROUTINE READS A BYTE OF DATA FROM EEPROM

; From EEPROM current address pointer.

; Returns the data byte in R1

;*******************************************************************

CREAD: MOV A,#RDCMD ;LOAD READ COMMAND

CALL OUTS ;SEND IT

CALL IN ;READ DATA

MOV R1,A ;STORE DATA

CALL STOP ;SEND STOP CONDITION

RET

;**********************************************************************

; THIS ROUTINE READS IN A BYTE FROM THE EEPROM

; and stores it in the accumulator

;**********************************************************************

Page 83: Project Report On "Prepaid Energy Meter"

83

IN: MOV R2,#8 ;LOOP COUNT

SETB SDA1 ;SET DATA BIT HIGH FOR INPUT

INLP: CLR SCL1 ;CLOCK LOW

NOP ;NOTE 1

NOP

NOP

NOP

SETB SCL1 ;CLOCK HIGH

CLR C ;CLEAR CARRY

JNB SDA1,INL1 ;JUMP IF DATA = 0

CPL C ;SET CARRY IF DATA = 1

INL1: RLC A ;ROTATE DATA INTO ACCUMULATOR

DJNZ R2,INLP ;DECREMENT COUNTER

CLR SCL1 ;CLOCK LOW

RET

;*********************************************************************

; This routine test for WRITE DONE condition

; by testing for an ACK.

; This routine can be run as soon as a STOP condition

; has been generated after the last data byte has been sent

; to the EEPROM. The routine loops until an ACK is received from

; the EEPROM. No ACK will be received until the EEPROM is done with

Page 84: Project Report On "Prepaid Energy Meter"

84

; the write operation.

;*********************************************************************

ACKTST: MOV A,#WTCMD ;LOAD WRITE COMMAND TO SEND ADDRESS

MOV R2,#8 ;LOOP COUNT -- EQUAL TO BIT COUNT

CLR SDA1 ;START CONDITION -- DATA = 0

NOP ;NOTE 1

NOP

NOP

CLR SCL1 ;CLOCK = 0

AKTLP: RLC A ;SHIFT BIT

JNC AKTLS

SETB SDA1 ;DATA = 1

JMP AKTL1 ;CONTINUE

AKTLS: CLR SDA1 ;DATA = 0

AKTL1: SETB SCL1 ;CLOCK HI

NOP ;NOTE 1

NOP

NOP

CLR SCL1 ;CLOCK LOW

DJNZ R2,AKTLP ;DECREMENT COUNTER

SETB SDA1 ;TURN PIN INTO INPUT

NOP ;NOTE 1

Page 85: Project Report On "Prepaid Energy Meter"

85

SETB SCL1 ;CLOCK ACK

NOP ;NOTE 1

NOP

NOP

JNB SDA1,EXIT ;EXIT IF ACK (WRITE DONE)

JMP ACKTST ;START OVER

EXIT: CLR SCL1 ;CLOCK LOW

CLR SDA1 ;DATA LOW

NOP ;NOTE 1

NOP

NOP

SETB SCL1 ;CLOCK HIGH

NOP

NOP

SETB SDA1 ;STOP CONDITION

RET

;*********************************************************************

DELAY: MOV R0,#0FFH

INLOP: MOV R1,#0FFH

DJNZ R1,$

DJNZ R0,INLOP

RET

Page 86: Project Report On "Prepaid Energy Meter"

86

DELAY1: MOV R0,#0FFH

INLOP1: MOV R1,#0FFH

DJNZ R1,$

DJNZ R0,INLOP1

RET

END

(13.)PRE-PAID ENERGY METER PROGRAMMING:-

RB0 EQU 000H ; Select Register Bank 0

RB1 EQU 008H ; Select Register Bank 1 ...poke to PSW to use

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

; PORT DECLERATION

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

SDA1 EQU P2.1 ;SDA=PIN5

SCL1 EQU P2.0 ;SCL=PIN6

Page 87: Project Report On "Prepaid Energy Meter"

87

WTCMD EQU 10100110B ;WRITE DATA COMMAND Note 3

RDCMD EQU 10100111B ;READ DATA COMMAND Note 3

WTCMD1 EQU 10100000B ;WRITE DATA COMMAND Note 3

RDCMD1 EQU 10100001B ;READ DATA COMMAND Note 3

RELAY EQU P2.7

BUZZER EQU P2.4

; ***LCD CONTROL***

LCD_RS EQU P0.0 ;LCD REGISTER SELECT LINE

LCD_E EQU P0.1 ;LCD ENABLE LINE

LCD_DB4 EQU P0.2 ;PORT 1 IS USED FOR DATA

LCD_DB5 EQU P0.3 ;USED FOR DATA

LCD_DB6 EQU P0.4 ;FOR DATA

LCD_DB7 EQU P0.5 ;FOR DATA

; ***CURSOR CONTROL INSTRUCTIONS***

OFFCUR EQU 0CH

BLINKCUR EQU 0DH

; ***DISPLAY CONTROL INSTRUCTIONS***

CLRDSP EQU 01H

ONDSP EQU 0CH

Page 88: Project Report On "Prepaid Energy Meter"

88

; ***SYSTEM INSTRUCTIONS***

CONFIG EQU 28H ; 4-BIT DATA,2 LINES,5X7 MATRIX LCD

ENTRYMODE EQU 6 ; INCREMENT CURSOR DON'T SHIFT DISPLAY

DSEG ; This is internal data memory

ORG 20H ; Bit adressable memory

FLAGS1: DS 1

BCDCARRY BIT FLAGS1.0

CARRY BIT FLAGS1.1

TBIT BIT FLAGS1.2

TBIT1 BIT FLAGS1.3

READING: DS 2

AMOUNT: DS 3

COUNTER: DS 2

TEMP: DS 1

PRICE: DS 2

BALANCE: DS 1

BUZZ_COUNT: DS 1

READ_BYTE: DS 3

F1: DS 1

F2: DS 1

F3: DS 1

Page 89: Project Report On "Prepaid Energy Meter"

89

STACK: DS 1

CSEG ; Code begins here

; ---------==========----------==========---------=========---------

; Main routine. Program execution starts here.

; ---------==========----------==========---------=========---------

ORG 00H ; Reset

AJMP MAIN

ORG 0003H

PUSH PSW

PUSH ACC

MOV PSW,#RB1 ; Select register bank 0

CALL INC_COUNTER

POP ACC

POP PSW

RETI

; ---------==========----------==========---------=========---------

MAIN:

MOV SP,#50H

MOV PSW,#RB0 ; Select register bank 0

MOV IE,#10000001B

CALL RESETLCD4

CALL TITLE1

Page 90: Project Report On "Prepaid Energy Meter"

90

CLR BUZZER

SETB RELAY

CLR TBIT1

MOV BUZZ_COUNT,#00H

MOV READ_BYTE,#0FFH

CALL READ_COUNTER

MOV A,COUNTER

CJNE A,#0FFH,BYPASS

CALL RESET_READING

CALL RESET_AMT

CALL RESET_COUNTER

CALL RESET_PRICE

CALL RESET_BALANCE ;RELAY ON/OFF BYTE

; CALL STORE_UNIT_PRICE

; CALL AMT_RECHARGE

CALL SYSTEM_RESET

CALL DELAYYS

BYPASS:

CALL READ_COUNTER

CALL READ_PRICE

CALL READ_BALANCE

Page 91: Project Report On "Prepaid Energy Meter"

91

MAINS: CALL TITLE1

CALL DELAYY

MOV A,BALANCE

CJNE A,#00H,FG1

CLR RELAY

CALL RECHAGRE

CALL DELAYY

SETB BUZZER

AJMP MAINS

FG1: SETB RELAY

MOV A,BUZZ_COUNT ;CHK TO SWITCH OFF

THE BUZZER

CJNE A,#00H,AZX1

CLR BUZZER

AJMP AZX2

AZX1: DEC BUZZ_COUNT

AZX2:

MOV R1,#READING ;GET

DATA IN BYTES(RAM)

MOV R4,#05H ;DATA

ADDRESS IN EEPROM

Page 92: Project Report On "Prepaid Energy Meter"

92

MOV R6,#2 ;NUMBER OF

BYTES

CALL READ_EEPROM

CALL DISP_READING

MOV TEMP,READING

CALL SEP_DISP

MOV TEMP,READING+1

CALL SEP_DISP

CALL DELAYY

MOV R1,#AMOUNT ;GET DATA IN

BYTES(RAM)

MOV R4,#0AH ;DATA

ADDRESS IN EEPROM

MOV R6,#3 ;NUMBER OF

BYTES

CALL READ_EEPROM

CALL AMT_READING

MOV TEMP,AMOUNT

CALL SEP_DISP

MOV TEMP,AMOUNT+1

CALL SEP_DISP

MOV R4,#'.'

CALL WRLCDDATA

Page 93: Project Report On "Prepaid Energy Meter"

93

CALL MDELAY

MOV TEMP,AMOUNT+2

CALL SEP_DISP

CALL DELAYY

MOV R1,#COUNTER ;GET

DATA IN BYTES(RAM)

MOV R4,#0EH ;DATA

ADDRESS IN EEPROM

MOV R6,#2 ;NUMBER OF

BYTES

CALL READ_EEPROM

CALL COUNT_READING

MOV TEMP,COUNTER

CALL SEP_DISP

MOV TEMP,COUNTER+1

CALL SEP_DISP

CALL DELAYY

MOV R1,#PRICE ;GET DATA IN

BYTES(RAM)

MOV R4,#10H ;DATA

ADDRESS IN EEPROM

Page 94: Project Report On "Prepaid Energy Meter"

94

MOV R6,#2 ;NUMBER OF

BYTES

CALL READ_EEPROM

CALL READ_PRICE

CALL UNIT_PRICE

MOV A,PRICE

ADD A,#30h

MOV R4,A

CALL WRLCDDATA

CALL MDELAY

MOV R4,#'.'

CALL WRLCDDATA

CALL MDELAY

MOV TEMP,PRICE+1

CALL SEP_DISP

CALL DELAYY

AJMP MAINS

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%5

Page 95: Project Report On "Prepaid Energy Meter"

95

; INCREMENT COUNTER BY 1

; IF COUNT=3200 THEN INCREMENT READING

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%5

INC_COUNTER:

MOV A,COUNTER+1

ADD A,#01

DA A

MOV COUNTER+1,A

JNC DCV2

MOV A,COUNTER

ADD A,#01

DA A

MOV COUNTER,A

CJNE A,#32h,DCV2

MOV COUNTER,#00H

MOV COUNTER+1,#00H

MOV R1,#COUNTER ;store COUNT

MOV R4,#0EH ;Starting Address

IN EEPROM

MOV R6,#2 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAY

AJMP DVB1

Page 96: Project Report On "Prepaid Energy Meter"

96

DCV2: MOV R1,#COUNTER ;store COUNT

MOV R4,#0EH ;Starting Address

IN EEPROM

MOV R6,#2 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAY

RET

DVB1: MOV A,READING+1 ;INCREMENT READING BY 1

ADD A,#01

DA A

MOV READING+1,A

JNC DCS1

MOV A,READING

ADD A,#01

DA A

MOV READING,A

DCS1: MOV R1,#READING ;store READING

MOV R4,#05H ;Starting Address

IN EEPROM

MOV R6,#2 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAY

Page 97: Project Report On "Prepaid Energy Meter"

97

MOV A,AMOUNT+2

;SUBTRACT AMT0 FROM TOTAL0

CLR C

SUBB A,PRICE+1

CALL BCD_CONV

MOV AMOUNT+2,A

MOV A,AMOUNT+1

;SUBTRACT AMT1 FROM TOTAL1

SUBB A,PRICE

CALL BCD_CONV

MOV AMOUNT+1,A

MOV A,AMOUNT ;SUBTRACT

AMT2 FROM TOTAL2

SUBB A,#00h

CALL BCD_CONV

MOV AMOUNT,A

MOV R1,#AMOUNT ;store AMOUNT

MOV R4,#0AH ;Starting Address

IN EEPROM

MOV R6,#3 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAY

MOV A,AMOUNT+1

Page 98: Project Report On "Prepaid Energy Meter"

98

CJNE A,#40H,FCX1

MOV BUZZ_COUNT,#02H

SETB BUZZER

FCX1: CJNE A,#38H,FAX1

MOV BUZZ_COUNT,#02H

SETB BUZZER

FAX1: CJNE A,#41H,FAAX1

MOV BUZZ_COUNT,#02H

SETB BUZZER

FAAX1: CJNE A,#20H,FCX2

MOV BUZZ_COUNT,#03H

SETB BUZZER

FCX2: CJNE A,#19H,FAX2

MOV BUZZ_COUNT,#03H

SETB BUZZER

FAX2: CJNE A,#21H,FAAX2

MOV BUZZ_COUNT,#03H

SETB BUZZER

FAAX2: CJNE A,#10H,FCX3

MOV BUZZ_COUNT,#04H

SETB BUZZER

FCX3: CJNE A,#11H,FCX4

MOV BUZZ_COUNT,#04H

SETB BUZZER

FCX4: CJNE A,#09H,FAX4

Page 99: Project Report On "Prepaid Energy Meter"

99

MOV BUZZ_COUNT,#04H

SETB BUZZER

FAX4:

MOV A,AMOUNT+2

;SUBTRACT AMT0 FROM TOTAL0

CLR C

SUBB A,PRICE+1

CALL BCD_CONV

MOV A,AMOUNT+1

;SUBTRACT AMT1 FROM TOTAL1

SUBB A,PRICE

MOV A,AMOUNT

CLR TBIT

JNC POP1

SETB TBIT

POP1: CJNE A,#00H,BACK

JNB TBIT, BACK

MOV BALANCE,#00H

MOV R1,#BALANCE ;store COUNT

MOV R4,#15H ;Starting Address

IN EEPROM

MOV R6,#1 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAY

Page 100: Project Report On "Prepaid Energy Meter"

100

CLR RELAY

SETB BUZZER

BACK: RET

;&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&

&&&&&&

BCD_CONV:

CLR BCDCARRY

CLR CARRY

JNC LOP2

SETB CARRY

LOP2: JNB AC,LOP1

SETB BCDCARRY

CLR C

SUBB A,#06H

LOP1: JNB CARRY,LOP3

CLR C

SUBB A,#60H

LOP3: CLR C

JNB CARRY,LOP4

SETB C

LOP4: RET

;#################################################

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%5

; READ PULSE COUNTER FROM MEMORY

Page 101: Project Report On "Prepaid Energy Meter"

101

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%5

READ_BALANCE:

MOV R1,#BALANCE ;GET

DATA IN BYTES(RAM)

MOV R4,#15H ;DATA

ADDRESS IN EEPROM

MOV R6,#1 ;NUMBER OF

BYTES

CALL READ_EEPROM

RET

READ_COUNTER:

MOV R1,#COUNTER ;GET

DATA IN BYTES(RAM)

MOV R4,#0EH ;DATA

ADDRESS IN EEPROM

MOV R6,#2 ;NUMBER OF

BYTES

CALL READ_EEPROM

RET

READ_PRICE:

MOV R1,#PRICE ;GET DATA IN

BYTES(RAM)

MOV R4,#10H ;DATA

ADDRESS IN EEPROM

Page 102: Project Report On "Prepaid Energy Meter"

102

MOV R6,#2 ;NUMBER OF

BYTES

CALL READ_EEPROM

RET

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%5

SEP_DISP1:

MOV A,AMOUNT

ANL A,#0F0H

SWAP A

CJNE A,#00H,DAP1

MOV A,AMOUNT

ANL A,#0FH

AJMP DAP3

DAP1: ADD A,#30H ;BOTH NOT EQUAL TO ZERO

MOV R4,A

CALL WRLCDDATA

CALL MDELAY

DAP2: MOV A,AMOUNT

ANL A,#0FH

ADD A,#30H

MOV R4,A

CALL WRLCDDATA

CALL MDELAY

Page 103: Project Report On "Prepaid Energy Meter"

103

DAP4: MOV A,AMOUNT+1

ANL A,#0F0H

SWAP A

ADD A,#30H

MOV R4,A

CALL WRLCDDATA

CALL MDELAY

DAP5: MOV A,AMOUNT+1

ANL A,#0FH

ADD A,#30H

MOV R4,A

CALL WRLCDDATA

CALL MDELAY

MOV R4,#'.'

CALL WRLCDDATA

CALL MDELAY

MOV A,AMOUNT+2

ANL A,#0F0H

SWAP A

ADD A,#30H

MOV R4,A

CALL WRLCDDATA

CALL MDELAY

MOV A,AMOUNT+2

ANL A,#0FH

Page 104: Project Report On "Prepaid Energy Meter"

104

ADD A,#30H

MOV R4,A

CALL WRLCDDATA

CALL MDELAY

RET

DAP3: CJNE A,#00H,DAP2 ;CHK 2 DIGIT

MOV A,AMOUNT+1

ANL A,#0F0H

SWAP A

CJNE A,#00H,DAP4 ;CHK 3 DIGIT

AJMP DAP5

SEP_DISP:

MOV A,TEMP

ANL A,#0F0H

SWAP A

ADD A,#30H

MOV R4,A

CALL WRLCDDATA

CALL MDELAY

MOV A,TEMP

ANL A,#0FH

ADD A,#30H

Page 105: Project Report On "Prepaid Energy Meter"

105

MOV R4,A

CALL WRLCDDATA

CALL MDELAY

RET

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%5

AMT_RECHARGE:

MOV READ_BYTE,#01H

MOV READ_BYTE+1,#00H

MOV READ_BYTE+2,#10H

MOV R1,#READ_BYTE ;store COUNT

MOV R6,#3 ;STORE 2 BYTES

MOV A,#WTCMD1 ;LOAD WRITE COMMAND

CALL OUTS ;SEND IT

MOV A,#20H ;GET LOW BYTE ADDRESS

CALL OUT ;SEND IT

BXLP: MOV A,@R1 ;GET DATA

CALL OUT ;SEND IT

INC R1 ;INCREMENT DATA POINTER

DJNZ R6,BXLP ;LOOP TILL DONE

CALL STOP ;SEND STOP CONDITION

CALL DELAY

RET

STORE_UNIT_PRICE:

Page 106: Project Report On "Prepaid Energy Meter"

106

MOV READ_BYTE,#00H

MOV READ_BYTE+1,#01H

MOV READ_BYTE+2,#00H

MOV R1,#READ_BYTE ;store COUNT

MOV R6,#3 ;STORE 2 BYTES

MOV A,#WTCMD1 ;LOAD WRITE COMMAND

CALL OUTS ;SEND IT

MOV A,#20H ;GET LOW BYTE ADDRESS

CALL OUT ;SEND IT

BALP: MOV A,@R1 ;GET DATA

CALL OUT ;SEND IT

INC R1 ;INCREMENT DATA POINTER

DJNZ R6,BALP ;LOOP TILL DONE

CALL STOP ;SEND STOP CONDITION

CALL DELAY

RET

RESET_BALANCE:

MOV BALANCE,#0FFH

MOV R1,#BALANCE ;store COUNT

MOV R4,#15H ;Starting Address

IN EEPROM

MOV R6,#1 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAY

Page 107: Project Report On "Prepaid Energy Meter"

107

RET

RESET_PRICE:

MOV PRICE,#02H

MOV PRICE+1,#00H

MOV R1,#PRICE ;store COUNT

MOV R4,#10H ;Starting Address

IN EEPROM

MOV R6,#2 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAY

RET

RESET_COUNTER:

MOV COUNTER,#00H

MOV COUNTER+1,#10H

MOV R1,#COUNTER ;store COUNT

MOV R4,#0EH ;Starting Address

IN EEPROM

MOV R6,#2 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAY

RET

RESET_AMT:

MOV AMOUNT,#00H ;

Page 108: Project Report On "Prepaid Energy Meter"

108

MOV AMOUNT+1,#05H

MOV AMOUNT+2,#00H

MOV R1,#AMOUNT ;store READING

MOV R4,#0AH ;Starting Address

IN EEPROM

MOV R6,#3 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAY

RET

RESET_READING:

MOV READING,#00H

MOV READING+1,#05H

MOV R1,#READING ;store READING

MOV R4,#05H ;Starting Address

IN EEPROM

MOV R6,#2 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAY

RET

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DELAYY:

MOV F1,#0FH

SEP3: MOV F2,#0fFH

SEP2: MOV F3,#0FFH

Page 109: Project Report On "Prepaid Energy Meter"

109

SEP1: DJNZ F3,SEP1

DJNZ F2,SEP2

CALL CARD_READ

MOV A,READ_BYTE

CJNE A,#0FFH,DSP1

CLR TBIT1

DSP3A:DJNZ F1,SEP3

RET

DELAYYS:

MOV F1,#0FH

S5P3: MOV F2,#0fFH

S5P2: MOV F3,#0FFH

S5P1: DJNZ F3,S5P1

DJNZ F2,S5P2

DJNZ F1,S5P3

RET

DSP1: JB TBIT1,DSP3A

CALL TITLE3

CALL DELAYS

CALL DELAYS

CALL CARD_READ

MOV A,READ_BYTE

Page 110: Project Report On "Prepaid Energy Meter"

110

CJNE A,#00H,DSP2

CALL TITLE4 ; NEW UNIT PRICE

MOV PRICE,READ_BYTE+1

MOV PRICE+1,READ_BYTE+2

MOV R1,#PRICE ;store COUNT

MOV R4,#10H ;Starting Address IN

EEPROM

MOV R6,#2 ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAYS

SETB TBIT1

AJMP RESETX_CHIP

DSP2: CJNE A,#01H,DSP3

CALL TITLE5 ; NEW RECHARGE

; MOV R1,#AMOUNT ;GET DATA IN

BYTES(RAM)

; MOV R4,#0AH ;DATA

ADDRESS IN EEPROM

; MOV R6,#03h ;NUMBER OF

BYTES

; CALL READ_EEPROM

MOV A,AMOUNT

ADD A,READ_BYTE+1

Page 111: Project Report On "Prepaid Energy Meter"

111

DA A

MOV AMOUNT,A

MOV A,AMOUNT+1

ADDC A,READ_BYTE+2

DA A

MOV AMOUNT+1,A

MOV R1,#AMOUNT ;store READING

MOV R4,#0AH ;Starting Address IN

EEPROM

MOV R6,#03h ;STORE 2 BYTES

CALL STORE_EEPROM

CALL DELAYS

SETB TBIT1

CALL RESET_BALANCE

RESETX_CHIP:

MOV READ_BYTE,#0AAH ;ERASE AMOUNT

MOV READ_BYTE+1,#0FFH

MOV READ_BYTE+2,#0FFH

MOV R1,#READ_BYTE ;store COUNT

MOV R6,#3 ;STORE 2 BYTES

MOV A,#WTCMD1 ;LOAD WRITE COMMAND

CALL OUTS ;SEND IT

MOV A,#20H ;GET LOW BYTE ADDRESS

CALL OUT ;SEND IT

Page 112: Project Report On "Prepaid Energy Meter"

112

BBLP: MOV A,@R1 ;GET DATA

CALL OUT ;SEND IT

INC R1 ;INCREMENT DATA POINTER

DJNZ R6,BBLP ;LOOP TILL DONE

CALL STOP ;SEND STOP CONDITION

CALL DELAY

RET

DSP3: CJNE A,#0AAH,DSP4

CALL TITLE6 ; NEW RECHARGE

CALL DELAYS

SETB TBIT1

DSP4: RET

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DELAY:

MOV R6,#0FFH

RE1: MOV R7,#0FFH

RE: NOP

DJNZ R7,RE

DJNZ R6,RE1

RET

;**********************************************************

CARD_READ:

Page 113: Project Report On "Prepaid Energy Meter"

113

MOV R1,#READ_BYTE ;GET

DATA IN BYTES(RAM)

MOV R6,#3 ;NUMBER OF

BYTES

MOV A,#WTCMD1 ;LOAD WRITE COMMAND TO SEND

ADDRESS

CALL OUTS ;SEND IT

MOV A,#20H ;GET LOW BYTE ADDRESS

CALL OUT ;SEND IT

MOV A,#RDCMD1 ;LOAD READ COMMAND

CALL OUTS ;SEND IT

BXDLP: CALL IN ;READ DATA

MOV @R1,a ;STORE DATA

INC R1 ;INCREMENT DATA POINTER

DJNZ R6,AXLP ;DECREMENT LOOP COUNTER

CALL STOP ;IF DONE, ISSUE STOP CONDITION

RET ;DONE, EXIT ROUTINE

AXLP: CLR SDA1 ;NOT DONE, ISSUE ACK

SETB SCL1

NOP ;NOTE 1

NOP

NOP

NOP ;NOTE 2

NOP

CLR SCL1

Page 114: Project Report On "Prepaid Energy Meter"

114

JMP BXDLP ;CONTINUE WITH READS

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

; READ DATA FROM EEPROM

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

READ_EEPROM:

MOV A,#WTCMD ;LOAD WRITE COMMAND TO SEND

ADDRESS

CALL OUTS ;SEND IT

MOV A,R4 ;GET LOW BYTE ADDRESS

CALL OUT ;SEND IT

MOV A,#RDCMD ;LOAD READ COMMAND

CALL OUTS ;SEND IT

BRDLP: CALL IN ;READ DATA

MOV @R1,a ;STORE DATA

INC R1 ;INCREMENT DATA POINTER

DJNZ R6,AKLP ;DECREMENT LOOP COUNTER

CALL STOP ;IF DONE, ISSUE STOP CONDITION

RET ;DONE, EXIT ROUTINE

AKLP: CLR SDA1 ;NOT DONE, ISSUE ACK

SETB SCL1

NOP ;NOTE 1

NOP

NOP

Page 115: Project Report On "Prepaid Energy Meter"

115

NOP ;NOTE 2

NOP

CLR SCL1

JMP BRDLP ;CONTINUE WITH READS

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

; STORE DATA IN EEPROM

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

STORE_EEPROM:

MOV A,#WTCMD ;LOAD WRITE COMMAND

CALL OUTS ;SEND IT

MOV A,R4 ;GET LOW BYTE ADDRESS

CALL OUT ;SEND IT

BTLP: MOV A,@R1 ;GET DATA

CALL OUT ;SEND IT

INC R1 ;INCREMENT DATA POINTER

DJNZ R6,BTLP ;LOOP TILL DONE

CALL STOP ;SEND STOP CONDITION

RET

;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Page 116: Project Report On "Prepaid Energy Meter"

116

;##########################################################

; DISPLAY ROUTINES

;##########################################################

TITLE1:

MOV DPTR,#MSAG1

CALL LCD_MSG

RET

MSAG1:

DB 1H,84H,'PREPAID',0C2H,'ENERGY METER',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DISP_READING:

MOV DPTR,#MSAG2

CALL LCD_MSG

RET

MSAG2:

DB 1H,82H,'METER READING',0C6H,00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

AMT_READING:

MOV DPTR,#MSAG3

CALL LCD_MSG

RET

MSAG3:

DB 1H,81H,'BALANCE AMOUNT',0C3H,'Rs.',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

COUNT_READING:

Page 117: Project Report On "Prepaid Energy Meter"

117

MOV DPTR,#MSAG4

CALL LCD_MSG

RET

MSAG4:

DB 1H,82H,'PULSE COUNT',0C6H,00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

UNIT_PRICE:

MOV DPTR,#MSAG14

CALL LCD_MSG

RET

MSAG14:

DB 1H,83H,'UNIT PRICE',0C4H,'Rs ',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

RECHAGRE:

MOV DPTR,#MSAG5

CALL LCD_MSG

RET

MSAG5:

DB 1H,80H,'Please Recharge',0C2H,'your Account',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

TITLE3:

MOV DPTR,#MSAG6

CALL LCD_MSG

RET

MSAG6:

Page 118: Project Report On "Prepaid Energy Meter"

118

DB 1H,84H,'New Card',0C1H,'** DETECTED **',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

TITLE4:

MOV DPTR,#MSAG7

CALL LCD_MSG

RET

MSAG7:

DB 1H,81H,'NEW UNIT PRICE',0C1H,'** STORED **',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

TITLE5:

MOV DPTR,#MSAG8

CALL LCD_MSG

RET

MSAG8:

DB 1H,83H,'NEW AMOUNT',0C1H,'** RECHARGED **',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

TITLE6:

MOV DPTR,#MSAG9

CALL LCD_MSG

RET

MSAG9:

DB 1H,82H,'INVALID CARD',0C0H,'****************',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SYSTEM_RESET:

MOV DPTR,#MSAG91

Page 119: Project Report On "Prepaid Energy Meter"

119

CALL LCD_MSG

RET

MSAG91:

DB 1H,80H,'System Restored',0C0H,'****************',00H

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

;**********************************************************

; INITIALIZE THE LCD 4-BIT MODE

;**********************************************************

INITLCD4:

CLR LCD_RS ; LCD REGISTER SELECT LINE

CLR LCD_E ; ENABLE LINE

MOV R4, #CONFIG; FUNCTION SET - DATA BITS,

; LINES, FONTS

CALL WRLCDCOM4

MOV R4, #ONDSP ; DISPLAY ON

CALL WRLCDCOM4

MOV R4, #ENTRYMODE ; SET ENTRY MODE

CALL WRLCDCOM4 ; INCREMENT CURSOR RIGHT, NO SHIFT

MOV R4, #CLRDSP; CLEAR DISPLAY, HOME CURSOR

CALL WRLCDCOM4

RET

; **********************************************************

; SOFTWARE VERSION OF THE POWER ON RESET

; **********************************************************

RESETLCD4:

Page 120: Project Report On "Prepaid Energy Meter"

120

CLR LCD_RS ; LCD REGISTER SELECT LINE

CLR LCD_E ; ENABLE LINE

CLR LCD_DB7 ; SET BIT PATTERN FOR...

CLR LCD_DB6 ; ... POWER-ON-RESET

SETB LCD_DB5

SETB LCD_DB4

SETB LCD_E ; START ENABLE PULSE

CLR LCD_E ; END ENABLE PULSE

MOV A, #4 ; DELAY 4 MILLISECONDS

CALL MDELAY

SETB LCD_E ; START ENABLE PULSE

CLR LCD_E ; END ENABLE PULSE

MOV A, #1 ; DELAY 1 MILLISECOND

CALL MDELAY

SETB LCD_E ; START ENABLE PULSE

CLR LCD_E ; END ENABLE PULSE

MOV A, #1 ; DELAY 1 MILLISECOND

CALL MDELAY

CLR LCD_DB4 ; SPECIFY 4-BIT OPERATION

SETB LCD_E ; START ENABLE PULSE

CLR LCD_E ; END ENABLE PULSE

MOV A, #1 ; DELAY 1 MILLISECOND

CALL MDELAY

MOV R4, #CONFIG; FUNCTION SET

CALL WRLCDCOM4

Page 121: Project Report On "Prepaid Energy Meter"

121

MOV R4, #08H ; DISPLAY OFF

CALL WRLCDCOM4

MOV R4, #1 ; CLEAR DISPLAY, HOME CURSOR

CALL WRLCDCOM4

MOV R4,#ENTRYMODE ; SET ENTRY MODE

ACALL WRLCDCOM4

JMP INITLCD4

; **********************************************************

; SUB RECEIVES A COMMAND WORD TO THE LCD

; COMMAND MUST BE PLACED IN R4 BY CALLING PROGRAM

; **********************************************************

WRLCDCOM4:

CLR LCD_E

CLR LCD_RS ; SELECT READ COMMAND

PUSH ACC ; SAVE ACCUMULATOR

MOV A, R4 ; PUT DATA BYTE IN ACC

MOV C, ACC.4 ; LOAD HIGH NIBBLE ON DATA BUS

MOV LCD_DB4, C ; ONE BIT AT A TIME USING...

MOV C, ACC.5 ; BIT MOVE OPERATOINS

MOV LCD_DB5, C

MOV C, ACC.6

MOV LCD_DB6, C

MOV C, ACC.7

MOV LCD_DB7, C

Page 122: Project Report On "Prepaid Energy Meter"

122

SETB LCD_E ; PULSE THE ENABLE LINE

CLR LCD_E

MOV C, ACC.0 ; SIMILARLY, LOAD LOW NIBBLE

MOV LCD_DB4, C

MOV C, ACC.1

MOV LCD_DB5, C

MOV C, ACC.2

MOV LCD_DB6, C

MOV C, ACC.3

MOV LCD_DB7, C

CLR LCD_E

SETB LCD_E ; PULSE THE ENABLE LINE

CLR LCD_E

CALL MADELAY

POP ACC

RET

; **********************************************************

; SUB TO RECEIVE A DATA WORD TO THE LCD

; DATA MUST BE PLACED IN R4 BY CALLING PROGRAM

; **********************************************************

WRLCDDATA:

CLR LCD_E

SETB LCD_RS ; SELECT READ DATA

PUSH ACC ; SAVE ACCUMULATOR

MOV A, R4 ; PUT DATA BYTE IN ACC

Page 123: Project Report On "Prepaid Energy Meter"

123

MOV C, ACC.4 ; LOAD HIGH NIBBLE ON DATA BUS

MOV LCD_DB4, C ; ONE BIT AT A TIME USING...

MOV C, ACC.5 ; BIT MOVE OPERATOINS

MOV LCD_DB5, C

MOV C, ACC.6

MOV LCD_DB6, C

MOV C, ACC.7

MOV LCD_DB7, C

SETB LCD_E ; PULSE THE ENABLE LINE

CLR LCD_E

MOV C, ACC.0 ; SIMILARLY, LOAD LOW NIBBLE

MOV LCD_DB4, C

MOV C, ACC.1

MOV LCD_DB5, C

MOV C, ACC.2

MOV LCD_DB6, C

MOV C, ACC.3

MOV LCD_DB7, C

CLR LCD_E

SETB LCD_E ; PULSE THE ENABLE LINE

CLR LCD_E

NOP

NOP

POP ACC

RET

Page 124: Project Report On "Prepaid Energy Meter"

124

; **********************************************************

; SUB TAKES THE STRING IMMEDIATELY FOLLOWING THE CALL AND

; DISPLAYS ON THE LCD. STRING MUST BE TERMINATED WITH A

; NULL (0).

; **********************************************************

LCD_MSG:

CLR A ; Clear Index

MOVC A,@A+DPTR ; Get byte pointed by Dptr

INC DPTR ; Point to the next byte

JZ LCD_Msg9 ; Return if found the zero (end of stringz)

CJNE A,#01H,Lcd_Msg1 ; Check if is a Clear Command

MOV R4,A

CALL WRLCDCOM4 ;If yes, RECEIVE it as command to LCD

JMP LCD_MSG ;Go get next byte from stringz

Lcd_Msg1: CJNE A,#0FFH,FLL ;Check for displaying full character

MOV R4,A

CALL WRLCDDATA

JMP LCD_MSG

FLL: CJNE A,#080h,$+3 ; Data or Address? If => 80h then is address.

JC Lcd_Msg_Data ; Carry will be set if A < 80h (Data)

MOV R4,A

CALL WRLCDCOM4 ; Carry not set if A=>80, it is address

JMP Lcd_Msg ; Go get next byte from stringz

Page 125: Project Report On "Prepaid Energy Meter"

125

Lcd_Msg_Data: ;

MOV R4,A

CALL WRLCDDATA ; It was data, RECEIVE it to Lcd

JMP Lcd_Msg ; Go get next byte from stringz

Lcd_Msg9:

RET ; Return to Caller

; **********************************************************

; 1 MILLISECOND DELAY ROUTINE

; **********************************************************

MDELAY:

PUSH ACC

MOV A,#0A6H

MD_OLP:

INC A

NOP

NOP

NOP

NOP

NOP

NOP

NOP

Page 126: Project Report On "Prepaid Energy Meter"

126

NOP

JNZ MD_OLP

NOP

POP ACC

RET

MADELAY:

PUSH ACC

MOV A,#036H

MAD_OLP:

INC A

NOP

NOP

NOP

NOP

NOP

NOP

NOP

NOP

JNZ MAD_OLP

NOP

POP ACC

RET

;~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

DELAYS: ;One second delay routine

MOV R6, #00H ;put 0 in register R6 (R6 = 0)

Page 127: Project Report On "Prepaid Energy Meter"

127

MOV R5, #04H ;put 5 in register R5 (R5 = 4)

LOOPB:

INC R6 ;increase R6 by one (R6 = R6 +1)

ACALL DELAYMS ;call the routine above. It will run and return to here.

MOV A, R6 ;move value in R6 to A

JNZ LOOPB ;if A is not 0, go to LOOPB

DEC R5 ;decrease R5 by one. (R5 = R5 -1)

MOV A, R5 ;move value in R5 to A

JNZ LOOPB ;if A is not 0 then go to LOOPB.

RET

;**************************************************************************

DELAYMS: ;millisecond delay routine

; ;

MOV R7,#00H ;put value of 0 in register R7

LOOPA:

INC R7 ;increase R7 by one (R7 = R7 +1)

MOV A,R7 ;move value in R7 to Accumlator (also known as A)

CJNE A,#0FFH,LOOPA ;compare A to FF hex (256). If not equal go to LOOPA

RET ;return to the point that this routine was called from

;**************************************************************************

;***********************************************************************

; THIS ROUTINE SENDS OUT CONTENTS OF THE ACCUMULATOR

; to the EEPROM and includes START condition. Refer to the data sheets

; for discussion of START and STOP conditions.

Page 128: Project Report On "Prepaid Energy Meter"

128

;***********************************************************************

OUTS: MOV R2,#8 ;LOOP COUNT -- EQUAL TO BIT COUNT

SETB SDA1 ;INSURE DATA IS HI

SETB SCL1 ;INSURE CLOCK IS HI

NOP ;NOTE 1

NOP

NOP

CLR SDA1 ;START CONDITION -- DATA = 0

NOP ;NOTE 1

NOP

NOP

CLR SCL1 ;CLOCK = 0

OTSLP: RLC A ;SHIFT BIT

JNC BITLS

SETB SDA1 ;DATA = 1

JMP OTSL1 ;CONTINUE

BITLS: CLR SDA1 ;DATA = 0

OTSL1: SETB SCL1 ;CLOCK HI

NOP ;NOTE 1

NOP

NOP

CLR SCL1 ;CLOCK LOW

DJNZ R2,OTSLP ;DECREMENT COUNTER

Page 129: Project Report On "Prepaid Energy Meter"

129

SETB SDA1 ;TURN PIN INTO INPUT

NOP ;NOTE 1

SETB SCL1 ;CLOCK ACK

NOP ;NOTE 1

NOP

NOP

CLR SCL1

RET

;**********************************************************************

; THIS ROUTINE SENDS OUT CONTENTS OF ACCUMLATOR TO EEPROM

; without sending a START condition.

;**********************************************************************

OUT: MOV R2,#8 ;LOOP COUNT -- EQUAL TO BIT COUNT

OTLP: RLC A ;SHIFT BIT

JNC BITL

SETB SDA1 ;DATA = 1

JMP OTL1 ;CONTINUE

BITL: CLR SDA1 ;DATA = 0

OTL1: SETB SCL1 ;CLOCK HI

NOP ;NOTE 1

NOP

Page 130: Project Report On "Prepaid Energy Meter"

130

NOP

CLR SCL1 ;CLOCK LOW

DJNZ R2,OTLP ;DECREMENT COUNTER

SETB SDA1 ;TURN PIN INTO INPUT

NOP ;NOTE 1

SETB SCL1 ;CLOCK ACK

NOP ;NOTE 1

NOP

NOP

CLR SCL1

RET

STOP: CLR SDA1 ;STOP CONDITION SET DATA LOW

NOP ;NOTE 1

NOP

NOP

SETB SCL1 ;SET CLOCK HI

NOP ;NOTE 1

NOP

NOP

Page 131: Project Report On "Prepaid Energy Meter"

131

SETB SDA1 ;SET DATA HIGH

RET

;*******************************************************************

; THIS ROUTINE READS A BYTE OF DATA FROM EEPROM

; From EEPROM current address pointer.

; Returns the data byte in R1

;*******************************************************************

CREAD: MOV A,#RDCMD ;LOAD READ COMMAND

CALL OUTS ;SEND IT

CALL IN ;READ DATA

MOV R1,A ;STORE DATA

CALL STOP ;SEND STOP CONDITION

RET

;**********************************************************************

; THIS ROUTINE READS IN A BYTE FROM THE EEPROM

; and stores it in the accumulator

;**********************************************************************

IN: MOV R2,#8 ;LOOP COUNT

SETB SDA1 ;SET DATA BIT HIGH FOR INPUT

INLP: CLR SCL1 ;CLOCK LOW

NOP ;NOTE 1

NOP

Page 132: Project Report On "Prepaid Energy Meter"

132

NOP

NOP

SETB SCL1 ;CLOCK HIGH

CLR C ;CLEAR CARRY

JNB SDA1,INL1 ;JUMP IF DATA = 0

CPL C ;SET CARRY IF DATA = 1

INL1: RLC A ;ROTATE DATA INTO ACCUMULATOR

DJNZ R2,INLP ;DECREMENT COUNTER

CLR SCL1 ;CLOCK LOW

RET

;*********************************************************************

; This routine test for WRITE DONE condition

; by testing for an ACK.

; This routine can be run as soon as a STOP condition

; has been generated after the last data byte has been sent

; to the EEPROM. The routine loops until an ACK is received from

; the EEPROM. No ACK will be received until the EEPROM is done with

; the write operation.

;*********************************************************************

ACKTST: MOV A,#WTCMD ;LOAD WRITE COMMAND TO SEND ADDRESS

MOV R2,#8 ;LOOP COUNT -- EQUAL TO BIT COUNT

CLR SDA1 ;START CONDITION -- DATA = 0

NOP ;NOTE 1

Page 133: Project Report On "Prepaid Energy Meter"

133

NOP

NOP

CLR SCL1 ;CLOCK = 0

AKTLP: RLC A ;SHIFT BIT

JNC AKTLS

SETB SDA1 ;DATA = 1

JMP AKTL1 ;CONTINUE

AKTLS: CLR SDA1 ;DATA = 0

AKTL1: SETB SCL1 ;CLOCK HI

NOP ;NOTE 1

NOP

NOP

CLR SCL1 ;CLOCK LOW

DJNZ R2,AKTLP ;DECREMENT COUNTER

SETB SDA1 ;TURN PIN INTO INPUT

NOP ;NOTE 1

SETB SCL1 ;CLOCK ACK

NOP ;NOTE 1

NOP

NOP

JNB SDA1,EXIT ;EXIT IF ACK (WRITE DONE)

Page 134: Project Report On "Prepaid Energy Meter"

134

JMP ACKTST ;START OVER

EXIT: CLR SCL1 ;CLOCK LOW

CLR SDA1 ;DATA LOW

NOP ;NOTE 1

NOP

NOP

SETB SCL1 ;CLOCK HIGH

NOP

NOP

SETB SDA1 ;STOP CONDITION

RET

;*********************************************************************

END

(14.)Main manufacturer:-

Several companies have started high volume production of Pre-paid energy meter.

Some of the best known industry given below :-

TRADEKEY

Page 135: Project Report On "Prepaid Energy Meter"

135

INDOTECH

SKN GROUP OF COMPANY

KARIGHAR R&D CENTER

DAE INSTRUMENT CROP.

RAMA. LTD

Reference

Internet

www.how-an-pre-paid-energy-works.com

www.engineersgarage.com

www.ieeespectrum.com

www.en.wikipedia.org

www.pdf-search-engine.com

Page 136: Project Report On "Prepaid Energy Meter"

136