Sunteți pe pagina 1din 43

ABSTRACT

This paper presents a single phase digital prepaid energy meter based on
microcontrollers and a single phase energy meter. This digital prepaid energy meter
does not have any rotating parts. The energy consumption is calculated using the
output pulses of the energy meter chip and the internal counter of microcontroller
(Atmel controller). A microcontroller (Atmel) is used as a smart card and the numbers
of units recharged by the consumers are written in it. A relay system has been used
which either isolates or establishes the connection between the electrical load and
energy meter through the supply mains depending upon the units present in the smart
card. Energy consumption (kWh), maximum demand (kW), total unit recharged
(kWh) and rest of the units (kWh) are stored in the Atmel to ensure the accurate
measurement even in the event of an electrical power outage that can be easily read
from a LCD. As soon as the supply is restored, energy meter restarts with the stored
values. A single phase prepaid energy meter prototype has been implemented to
provide measurement up to 40A load current and 230V line to neutral voltage.
Necessary program for microcontrollers are written in assembly-language and
compiled by AEMW-Atmel compiler.

CHAPTER ONE
INTRODUCTION
Preamble
The present system of energy metering as well as billing in Nigeria which uses
electromechanical and somewhere digital energy meter is error prone and it consumes
more time and labor. The conventional electromechanical meters are being replaced
by new electronic meters to improve accuracy in meter reading. Still, the Nigerian
power sector faces a serious problem of revenue collection for the actual electric
energy supplied owing to energy thefts and network losses.
Introduction
Energy Meter is a device that measures the amount of electrical energy consumed by
a residence, business, or an electrically powered device. They are typically calibrated
in billing units and the most common one is the kilowatt hour, which is equal to the
amount of energy used by a load of one kilowatt over a period of one hour, or
3,600,000 joules. Electricity meters operate by continuously measuring the
instantaneous voltage (volts) and current (amperes) .The product of which gives the
instantaneous electrical power (watts) which is then integrated against time to give
energy used.
A Prepaid Energy Meter enables power utilities to collect electricity bills from the
consumers prior to its consumption. The prepaid meter is also attributed with prepaid
recharging ability and information exchange with the utilities pertaining to
customers consumption details. Literature has witnessed quite an amount of work in
this area (Nwaoko, 2006; Omijeh, 2012)
Differing from the conventional postpaid system; this is a boon for middle class
people, who can reduce the consumption of energy by having certain limit. The pay
system is similar to the prepaid cellular connection given by several providers. Smart
energy meter consists of the static energy/watt-hour meter, , MCU, LCD display,
circuit breaker. The static watt-hour meter doesnt have any kinetic/mechanical

operational part to measure the electricity like in induction type energy meter, what
we have in our premises. The static energy meter produces the pulse according to the
load connected. For example here we are using 6400 Pulse/KWh rating meter. That
means the meter produce 6400 pulse blink for 1000 watts per hour. Our energy meter
setup uses probe to sense the pulse according to the energy utilization by the energy
meter. The received pulse is given to the Atmel microcontroller controller. The
number of pulse is calculated using the counter. According to the pulse count, the
power consumed is calculated in the microcontroller unit MCU. The Atmel
controller holds the unit-recharged value depending on the power consumed the
recharged amount value is reduced. Once the amount reaches the minimum limit
warning indication will be displayed in LCD and buzzer will produce the sound. If
the value gets reduced to zero then the circuit breaker gets energized and opens the
supply to the metering unit and power will be cut-off. Once the user recharges his
account, the amount will be encoded in the microcontroller. New amount is added
with the old value and proceed the above mentioned procedure.
Aim
Prepaid Energy Meter Using Microcontroller main idea is to develop a micro
controller based application which is used to pay bills using an onboard encoded
billing system technology.
Objectives
One of the prime reasons is the traditional billing system which is inaccurate
many times, slow, costly, and lack in flexibility as well as reliability. Meters, in
the past and today in a few countries, were electromechanical devices with
poor accuracy and lack of configurability. With the implementation of a low
cost design energy metering, this anomaly will be stopped if not reduce to the
barest minimum.
Theft detection was also a challenge. Recent developments in this direction
seem to provide opportunities in implementing energy efficient metering

technologies that are more precise, accurate, error free, etc. with this
innovation the issue of theft will be a thing of the past.
A Prepaid Energy Meter enables power utilities to collect electricity bills from
the consumers prior to its consumption. The prepaid meter is not only limited
to Automated Meter Reading but is also attributed with prepaid recharging
ability and information exchange with the utilities pertaining to customers
consumption details.
The use of electronic token prepayment metering has been widely used in
Nigerian for customers with poor record of payment. A paper suggests a design
of a system which can be used for data transmission between the personal
computer and smart card.
Advantages
This intelligent smart metering system facilitates high flexibility, robustness, multi
tariff billing, power factor detecting and imparting, accurate, reliable Provides
security, Saves time, Highly reliable with low power consumption and less human
involvement.
Scope
This project uses regulated 5V, 750mA power supply. 7805 three terminal voltage
regulator is used for voltage regulation. Bridge type full wave rectifier is used to
rectify the ac output of secondary of 230/18V step down transformer. It will focus on
overcoming the past procedure of electricity bill payment methods by an onboard
encoded billing system technology. This system will provide reliability and increase
security.

Block diagram

Power Supply

Description
The conventional Electrical billing system where the Electric Power bill given at the
end of the month can be paid at Power distribution offices centers. This billing system
is quite time consuming and even expensive (in issuing bills at door to door). This
traditional Electrical billing system can be replaced with Prepaid Electricity billing
system. This Prepaid billing system is based on a microcontroller embedded system
technology.
A microcontroller is used as an energy card just as a SIM card in mobile phones.
Before using this card we have to recharge it. Whenever we want to use the power
then we have to place this card in the card reader, which is interfaced to the
microcontroller with the serial interfacing. The microcontroller reads the data from

the smartcard reader and asks how many KWh you require, which is displayed on the
LCD display.
Another advantage of this project is that the electricity department can overcome the
illegal power consumption due to the theft identification system. If anyone tries to
remove the smart card and tries to connect the supply directly, then the theft
identification circuit identifies it and do not supply the power. By this we can save the
power from illegal consumption. This is the main advantage of this project with the
theft circuit and to save power.
Technology
Smart cards are secure tokens that have provided security services to a wide range of
applications for over thirty years. Along with other technology advances, smart card
technology has changed dramatically as well. For nearly a decade, researchers have
sought to connect smart cards to the Internet. The benefits are more including
providing services over the Internet and eliminating smart card specific infrastructure.
A smart card is an integrated circuit card that forms a part of a circuit or system when
engaged with a smart card interface. Smart cards are becoming increasingly more
popular for security and personal identification applications. Smart cards have one or
more microcontrollers embedded in them which manage access to, and storage of,
sensitive data that is actually stored in memory devices on the smart card. The smart
chip included on a smart card provides a means for secured electronic transactions
and a means for identification. The integrated chip is embedded in the smart card and
operates to process specific transactions. The smart card uses a serial interface and
receives its power from an external source such as a smart card reader.

CHAPTER TWO
LITERATURE
Related Works
The use of electronic token prepayment metering has been widely used in UK for
customers with poor record of payment. Shwehdi and Jackson (1996) in their paper
presented the Digital Tele-wattmeter System as an example of a microcontrollerbased meter. The meter was implemented to transmit data on a monthly basis to a
remote central office through dedicated telephone line and a pair of modems. It is
only a stand- alone metering system.
Zhang et al (1998) utilized a DSP-based meter to measure the electricity consumption
of multiple users in a residential area. A Personal Computer (PC) at the control centre
was used to send commands to a remote meter, which in turn transmitted data back,
using the power Line Communication (PLC) technique. The major problem with this
system is that it cannot detect tampering by consumers.
A paper suggests a design of a system which can be used for data transmission
between the personal computer and smart card. The device will transmit the data in
half duplex mode (Kwan et al, 2002). In this paper, an Intelligent Prepaid Energy
Meter has been designed, modeled and simulated using matlab/simulink tools. Koay
et al (2003) in their work, designed and implemented a Bluetooth energy meter where
several meters are in close proximity, communicated wirelessly with a Master PC.
Distance coverage is a major set-back for this kind of system because the Bluetooth
technology works effectively at close range.
In their paper, Scaradozzi and Conte (2003) viewed home- automation systems as
Multiple Agent Systems (MAS). Home automation system was proposed whereby
home appliances and devices are controlled and maintained for home management. It
is only a home management system and does not measure the amount of energy
consumed by users.

Hong and Ning (2005) in their paper, proposed the use of Automatic Meter Reading
(AMR) using wireless networks. Some commercial AMR products use the internet
for data transmission. Stanescu et al(2006) present a design and implementation of
SMS -based control for monitoring systems. The paper has three modules involving
sensing unit for monitoring the complex applications. The SMS is used for status
reporting such as power failure. Issues on billing system for electricity board usage
were not considered.Prepaid meters can also make use of state of art technologies like
WiMAX owing to the idea of centralized accounting, monitoring and charging. It
brings telecommunication to the core of its activities to support more Smart Grid
applications such as Demand Response and Plug-in electric vehicles (Khan et al,
2007). Prepayment polyphase electricity metering systems have also been developed
consisting of local prepayment and a card reader based energy meter (Ling et al,
2010).
Malik et al (2009) in their paper mainly focused on the controlling of home
appliances remotely and providing security when the user is away from the place
using an SMS- based wireless Home Appliance Control.
In their paper, Maheswari and Sivakumar (2009) aimed to develop an energy efficient
and low cost solution for street lighting system using Global System for Mobile
communication [GSM] and General Packet Radio Service [GPRS]. The whole set-up
provides the remote operator to turn off the lights when not required, regulate the
voltage supplied to the streetlights and prepare daily reports on glowing hours
Sharma and Shoeb (2011), in their paper suggested a method where we utilize
telecommunication systems for automated transmission of data to facilitate bill
generation at the server end and also to the customer via SMS, Email.
Amit. and Mohnish (2011) suggested in their paper, a prepaid energy meter behaving
like a prepaid mobile phone.
The meter contains a prepaid card analogous to mobile SIM card. The prepaid card
communicates with the power utility using mobile communication infrastructure.
Once the prepaid card is out of balance, the consumer load is disconnected from the

utility supply by the contactor. The power utility can recharge the prepaid card
remotely through mobile communication based on customer requests.
The present scenario
This project focuses on the design of Intelligent Prepaid Energy Meter (IPEM) has
been presented. The design methodology makes use of low cost electrical
components in other to put together a more realistic energy metering device.
If fully implemented, on one hand, the estimated bills or irregular billing imposed by
Power Holding Company of Nigeria (PHCN) on her customers will stop; and on the
other hand, revenue loss through unpaid bills suffered by PHCN will greatly reduce.
This will have an overall effect on the nations economy as revenue collection will
increase.

CHAPTER THREE
RESEARCH AND DESIGN METHODOLOGY
RESEARCH METHOD
Basically, research on this project was done both on the internet and on various
Electrical/Electronic textbooks. The circuit is built around discrete electronics
components including resistors, capacitors, transistors and as the microcontroller as
the core.
COMPONENTS DESCRIPTION
RESISTOR
Resistors are one of the most common components in an electronic circuit. The basic
operation is to limit the flow of current in the circuit. Many resistor values were used
in this project. Some of them include 1K, 10k, 100 and the 330 used to limit
the current that flows to the seven segment display.
How to read Resistor Color Codes

Fig 3.1 Resistor color code

First find the tolerance band, it will typically be gold (5%) and sometimes silver
(10%). Starting from the other end, identify the first band - write down the number
associated with that color; in this case Brown is 1. Now 'read' the next color, here it is
Black so write down as '0' next to the red. (You should have '10' so far.) Now read the
third or 'multiplier exponent' band and write down that as the number of zeros. In this
example it is two so we get '1000'. If the 'multiplier exponent' band is Black (for zero)
don't write any zeros down.

If the 'multiplier exponent' band is Gold move the decimal point one to the left. If the
'multiplier exponent' band is Silver move the decimal point two places to the left. If
the resistor has one more band past the tolerance band it is a quality band.
BS 1852 Coding for resistor values
The letter R is used for Ohms and K for Kohms M for Megohms and placed where
the decimal point would go.
At the end is a letter that represents tolerance Where M=20%, K=10%, J=5%, G=2%,
and F=1% D=.5% C=.25 B=.1%
CAPACITOR
Capacitors store electric charge. They are used with resistors in timing circuits
because it takes time for a capacitor to fill with charge. They are used to smooth
varying DC supplies by acting as a reservoir of charge. They are also used in filter
circuits because capacitors easily pass AC (changing) signals but they block DC
(constant) signals. There are many types of capacitor but they can be split into two
groups, polarized and unpolarised. Each group has its own circuit symbol.
Electrolytic Capacitors

Fig 1.5 Electrolytic

Electrolytic capacitors are polarized and they must be connected the correct way
round, at least one of their leads will be marked + or -. They are not damaged by heat
when soldering.
There are two designs of electrolytic capacitors; axial where the leads are attached to
each end (220F in picture) and radial where both leads are at the same end (10F in
picture). Radial capacitors tend to be a little smaller and they stand upright on the

circuit board. It is easy to find the value of electrolytic capacitors because they are
clearly printed with their capacitance and voltage rating. The voltage rating can be
quite low (6V for example) and it should always be checked when selecting an
electrolytic capacitor.
Non-polarized capacitors

Small value capacitors are non-polarized and may be connected either way round.
They are not damaged by heat when soldering, except for one unusual type
(polystyrene). They have high voltage ratings of at least 50V, usually 250V or so. It
can be difficult to find the values of these small capacitors because there are many
types of them and several different labeling systems!
Many small value capacitors have their value printed but without a multiplier, so you
need to use experience to work out what the multiplier should be.
TRANSISTORS
Transistors are made from semiconductors. These are materials, such as silicon or
germanium, that are doped (have minute amounts of foreign elements added) so
that either an abundance or a lack of free electrons exists. In the former case, the
semiconductor is called n-type, and in the latter case, p-type. By combining n-type
and p-type materials, a diode can be produced. When this diode is connected to a
battery so that the p-type material is positive and the n-type negative, electrons are
repelled from the negative battery terminal and pass unimpeded to the p-region,
which lacks electrons. With battery reversed, the electrons arriving in the p-material
can pass only with difficulty to the n-material, which is already filled with free
electrons, and the current is almost zero.
The bipolar transistor was invented in 1948 as a replacement for the triode vacuum
tube. It consists of three layers of doped material, forming two p-n (bipolar) junctions

with configurations of p-n-p or n-p-n. One junction is connected to a battery so as to


allow current flow (forward bias), and the other junction has a battery connected in
the opposite direction (reverse bias). If the current in the forward-biased junction is
varied by the addition of a signal, the current in the reverse-biased junction of the
transistor will vary accordingly. The principle can be used to construct amplifiers in
which a small signal applied to the forward-biased junction causes a large change in
current in the reverse-biased junction.
Another type of transistor is the field-effect transistor (FET). Such a transistor
operates on the principle of repulsion or attraction of charges due to a superimposed
electric field. Amplification of current is accomplished in a manner similar to the grid
control of a vacuum tube. Field-effect transistors operate more efficiently than bipolar
types, because a large signal can be controlled by a very small amount of energy.
Transistors function majorly as switch or amplifiers. To function as a switch, the
transistor has to be biased into saturation i.e. the base voltage exceeds 0.7v for silicon
type and 0.3v for germanium type. On the other hand, the base voltage can be varied
continually by an input signal for the transistor to function as an amplifier. The
transistors in this circuit are all Field Effect Transistors (FET) and they function as
high speed switches.
DIODE
This is an electronic device that allows the passage of current in only one direction.
The first such devices were vacuum-tube diodes, consisting of an evacuated glass or
steel envelope containing two electrodesa cathode and an anode. Because electrons
can flow in only one direction, from cathode to anode, the vacuum-tube diode could
be used as a rectifier. The diodes most commonly used in electronic circuits today are
semiconductor diodes. The simplest of these, the germanium point-contact diode,
dates from the early days of radio, when the received radio signal was detected by
means of a germanium crystal and a fine, pointed wire that rested on it. In modern
germanium (or silicon) point-contact diodes, the wire and a tiny crystal plate are
mounted inside a small glass tube and connected to two wires that are fused into the
ends of the tube.

Microcontroller Unit (MCU)


The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with
8K bytes of in-system programmable Flash memory. The device is manufactured
using Atmels high-density nonvolatile memory technology and is compatible with
the industry- standard 80C51 instruction set and pin out. The on-chip Flash allows the
program memory to be reprogrammed in-system or by a conventional nonvolatile
memory programmer. By combining a versatile 8-bit CPU with in-system
programmable Flash on a monolithic chip, the Atmel AT89S52 is a powerful
microcontroller which provides a highly-flexible and cost-effective solution to many
embedded control applications. The AT89S52 provides the following standard
features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, Watchdog timer, two
data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture,
a full duplex serial port, on-chip oscillator, and clock circuitry.
In this design the microcontroller forms the core of the system, meaning that all
mathematical and logical operation of the system is executed from within it.

Pin Configuration of Atmel 89s52


Microcontroller
Microcontroller's
Pins

Pins 1-8: Port 1 Each of these pins can be configured as input or output.
Pin 9: RS Logical one on this pin stops microcontrollers operating and erases the
contents of most registers. By applying logical zero to this pin, the program starts
execution from the beginning. In other words, a positive voltage pulse on this pin
resets the microcontroller.
Pins10-17: Port 3 Similar to port 1, each of these pins can serve as universal input or
output. Besides, all of them have alternative functions:
Pin 10: RXD Serial asynchronous communication input or Serial synchronous
communication output.
Pin 11: TXD Serial asynchronous communication output or Serial synchronous
communication clock output.
Pin 12: INT0 Interrupt 0 input
Pin 13: INT1 Interrupt 1 input
Pin 14: T0 Counter 0 clock input
Pin 15: T1 Counter 1 clock input
Pin 16: WR Signal for writing to external (additional) RAM
Pin 17: RD Signal for reading from external RAM
Pin 18, 19: X2 X1 Internal oscillator input and output. A quartz crystal which
determines operating frequency is usually connected to these pins. Instead of quartz
crystal, the miniature ceramics resonators can be also used for frequency
stabilization. Later versions of the microcontrollers operate at a frequency of 0 Hz up
to over 50 Hz.
Pin 20: GND Ground
Pin 21-28: Port 2 If there is no intention to use external memory then these port pins
are configured as universal inputs/outputs. In case external memory is used then the
higher address byte, i.e. addresses A8-A15 will appear on this port.
Pin 29: PSEN if external ROM is used for storing program then it has a logic-0 value
every time the microcontroller reads a byte from memory.
Pin 30: ALE Prior to each reading from external memory, the microcontroller will set
the lower address byte (A0-A7) on P0 and immediately after that activates the output
ALE.

Pin 31: EA By applying logic zero to this pin, P2 and P3 are used for data and
address transmission with no regard to whether there is internal memory or not. That
means that even there is a program written to the microcontroller, it will not be
executed, the program written to external ROM will be used instead. Otherwise, by
applying logic one to the EA pin, the microcontroller will use both memories, first
internal and afterwards external (if it exists), up to end of address space.
Pin 32-39: Port 0 Similar to port 2, if external memory is not used, these pins can be
used as universal inputs or outputs.
Pin 40: VCC Power supply +5V
Obviously, all this is about very simple circuits, but it does not have to be always like
that. If device is used for handling expensive machines or for maintaining vital
functions, everything becomes more and more complicated! This kind of solution is
quite enough for the time being.
Visual Display Unit
The visual display unit is used to show the current value of calculated instantaneous
parameters of the data collection unit.It is built around the microcontroller which
serves as the core for the system by outputting the desired values of information unto
the display and a multiplexed seven segment display.
Basically, LED displays are nothing else but several LEDs molded in the same plastic
case. Diodes are arranged so that different marks-commonly digits: 0, 1, and 2...9 are
displayed by activating them. There are many types of displays composed of several
dozens of built in diodes which can display different symbols.

The most commonly used are so called 7-segment displays. They are composed of 8
LEDs, 7 segments are arranged as a rectangle for symbol displaying and there is

additional segment for decimal point displaying. In order to simplify connecting,


anodes and cathodes of all diodes are connected to the common pin so that there are
common cathode displays and common anode displays. Segments are marked with
the litters A to G as shown on the figure on the left. When connecting, each diode is
treated independently, which means that each must have its own conductor for current
limitation.
When connecting displays to the microcontroller, the greatest problem is a great deal
of valuable I/O pins which they occupy, especially if it is needed to display severaldigit numbers. Problem is more than obvious if for example it is needed to display
two 6-digit numbers (a simple calculation shows that 96 output pins are needed)!The
solution on this problem is called MULTIPLEXING. This is how optical illusion
based on the same operating principle as film camera occurs. The principle is that
only one digit is active but by quick changing one gets impression that all digits of a
number are active at the same time.
Energy Measuring Unit
This unit is made up of an analog-to-digital converter (abbreviated ADC, A/D or A to
D) is a device which converts continuous signals to discrete digital numbers. The
reverse operation is performed by a digital-to-analog converter (DAC) and an
analogue multiplex.
Typically, an ADC is an electronic device that converts an input analog voltage (or
current) to a digital number proportional to the magnitude of the voltage or current.
However, some non-electronic or only partially electronic devices, such as rotary
encoders, can also be considered ADCs. The digital output may use different coding
schemes, such as binary, Gray code or two's complement binary.
Its prime function in this circuit is to digitize the analog quantity that is gotten
from the transducer (sensor) or the instantaneous voltage that is to be logged
to the system unit to a form that will be easily processed by the
microcontroller.

The accuracy of the converter depends on these factors resolution, Accuracy,


Quantization error, Aperture error, and Non-linearity.
Resolution
The resolution of the converter indicates the number of discrete values it can produce
over the range of analog values. Here we have decided to use an 8-Bit Analog-Digital
converter for its low cost and simplicity hence at expense of lower performance when
it comes to step size or resolution. The values are usually stored electronically in
binary form, so the resolution is usually expressed in bits. In consequence, the
number of discrete values available, or "levels", is usually a power of two. For
example, an ADC with a resolution of 8 bits can encode an analog input to one in 256
different levels. The values can represent the ranges from 0 to 255 (i.e. unsigned
integer) or from -128 to 127 (i.e. signed integer), depending on the application.
Resolution can also be defined electrically, and expressed in volts. The voltage
resolution of an ADC is equal to its overall voltage measurement range divided by the
number of discrete intervals as in the formula:

Where:
Q is resolution in volts per step (volts per output codes less one),
EFSR is the full scale voltage range =,
M is the ADC's resolution in bits.
N is the number of intervals, (one less than the number of available levels, or
output codes), which is:
Some examples may help:

Example 1
o

Full scale measurement range = 0 to 10 volts

ADC resolution is 12 bits: 212 = 4096 quantization levels (codes)

ADC voltage resolution is: (10V - 0V) / 4095 steps = 10V / 4095 steps
0.00244 V/step

2.44 mV/step

Example 2
o

Full scale measurement range = 0 to 7 volts

ADC resolution is 3 bits: 23 = 8 quantization levels (codes)

ADC voltage resolution is: (7 V 0 V)/7 steps = 7 V/7 steps = 1 V/ step


= 1000 mV/step

In practice, the smallest output code ("0" in an unsigned system) represents a voltage
range which is 0.5Q, that is, half the ADC voltage resolution (Q), as does the largest
output code. The other N 2 codes are all equal in width and represent the ADC
voltage resolution (Q) calculated above. Doing this centers the code on an input
voltage that represents the Mth division of the input voltage range. For example, in
Example 3, with the 3-bit ADC spanning a 7 V range, each of the N divisions would
represent 1 V, except the 1st ("0" code) and the last ("7" code) which are 0.5 V wide.
Doing this the "1" code spans a voltage range from 0.5 to 1.5 V, the "2" code spans a
voltage range from 1.5 to 2.5 V, etc. Thus, if the input signal is at 3/8ths of the fullscale voltage, then the ADC outputs the "3" code, and will do so as long as the
voltage stays within the range of 2.5/8ths and 3.5/8ths. This practice is called "midtread" operation.
Accuracy
An ADC has several sources of errors. Quantization error and (assuming the ADC is
intended to be linear) non-linearity is intrinsic to any analog-to-digital conversion.
There is also a so-called aperture error which is due to a clock jitter and is revealed
when digitizing a time-variant signal (not a constant value).
These errors are measured in a unit called the LSB, which is an abbreviation for least
significant bit. In the above example of an eight-bit ADC, an error of one LSB is
1/256 of the full signal range, or about 0.4%.
Quantization error
Quantization error is due to the finite resolution of the ADC, and is an unavoidable
imperfection in all types of ADC. The magnitude of the quantization error at the
sampling instant is between zero and half of one LSB.

In the general case, the original signal is much larger than one LSB. When this
happens, the quantization error is not correlated with the signal, and has a uniform
distribution. Its RMS value is the standard deviation of this distribution, given by. In
the eight-bit ADC example, this represents 0.113% of the full signal range.
At lower levels the quantizing error becomes dependent of the input signal, resulting
in distortion with amplitude of 1 quantization step added to the signal. This slightly
reduces signal to noise ratio, but completely eliminates the distortion. It is known as
dither.
Non-linearity
All ADCs suffer from non-linearity errors caused by their physical imperfections,
resulting in their output to deviate from a linear function (or some other function, in
the case of a deliberately non-linear ADC) of their input. These errors can sometimes
be mitigated by calibration, or prevented by testing.
Important parameters for linearity are integral non-linearity (INL) and differential
non-linearity (DNL). These non-linearities reduce the dynamic range of the signals
that can be digitized by the ADC, also reducing the effective resolution of the ADC.

CHAPTER FOUR
Methodology and Principle of Operation
The energy consumption is being calculated using the energy meter IC and
Microcontroller (ATmega32). In order to prevent unauthorized connection, a

tampering detection unit is present in the Energy Meter IC. The hardware architecture
of Microcontroller based digital prepaid energy meter is shown below.

The Microcontroller based digital prepaid energy meter system can be divided into
eight parts as Voltage sensor, Current sensor, Energy Meter IC, Microcontroller,
Smart Card, Relay Control Unit, Display Unit and Power Supply Unit. In the
following circuit diagram, Vcc represents the positive supply and Gnd represents
ground. The hardware description of eight parts is separately introduced as follows
Voltage Sensor
In this scheme, energy meter IC (AD7751) is biased around the neutral wire
and a resistor divider is used to provide a voltage signal that is proportional to

the line voltage. A voltage divider is made in combination of 1 M resistor and


1 k resistor. The output voltage across the 1 k resistor is applied to the
voltage channel of the energy meter IC.

Current Sensor
The voltage outputs from a calibrated resistor of 3.335 m connected with the
neutral wire is applied to the current channel of the energy meter IC. Current
channel has a programmable gain amplifier with gains of 1, 2, 8, or 16. The
maximum peak differential voltage is 660 mV divided by the gain selection.

Energy Meter IC
Energy meter IC has two ADCs that digitizes the voltage and current signals
from the supply main. These ADCs are 16-bit second order sigma-delta
converters with an over sampling rate of 900 kHz. A high-pass filter in the
current channel removes any dc component from the current signal. This
eliminates any inaccuracies in the real- power calculation due to offsets in the
voltage or current signals. The real-power calculation is derived from the
instantaneous power signal. The instantaneous power signal is generated by a
direct multiplication of the current and voltage signals. In order to extract
the real-power component, the instantaneous power signal is low-pass
filtered. The low frequency output of the energy meter IC is generated by
accumulating this real-power information. The output frequency is therefore
proportional to the average real-power. This average real-power information
can in turn be accumulated by a counter to generate real-energy information.

Microcontroller
Microcontroller is a programmable device which contains a microprocessor,
memory, input-output ports etc which can be compared with the
microcomputer. Microcontroller is a single chip computer. As microcontroller
is a low cost programmable device. It is used in the automatic control

application. Now the pulses produced at the pin CF is directly applied to the
counter pin of the microcontroller. The microcontroller counts the pulses that
appear at pin 1 of Microcontroller (ATmega32) within every 20 seconds. The
number of pulses per second appeared at pin 22 of Energy Meter IC is directly
proportional to the instantaneous real power information for a particular load.
Information such as power, energy, and maximum demand are stored at the
EEPROM of the Microcontroller (ATmega32).
Smart and Energy Metering System
A microcontroller (ATtiny13) is used as a smart card in which the numbers of
units to be recharged are loaded by interfacing with the USB port and the user
operated PC of server terminal. The ATtiny13 will send the information
contained on it to the microcontroller (ATmega32), when the DIP switch
connected with the two microcontrollers is switched on. Then the information
of microcontroller (ATtiny13) will be transferred to the microcontroller
(ATmega32) and stored in the EEPROM of the microcontroller (ATmega32)
while erasing the content of the ATtiny13. The numbers of recharged units are
contained in the EEPROM of the microcontroller (ATmega32) and will be
gradually decreased with the increment of the energy consumption by the load.
The updated value after the execution of the every step will be stored in the
EEPROM of the microcontroller (ATmega32). Now the consumers have to
recharge the smart card from server terminal for further use of energy after
finishing the previously recharged units.

Relay Control Unit


Five relays each of rating 10A are used. One relay is only used to provide the
coil current. When this relay will conduct then it energizes the rest of the relays
and consequently the load current will flow through the four relays only which
acts as one relay of rating 40A. When the number of units stored in the
EEPROM reaches zero, the microcontroller (ATmegs32) initiates a pulse to the

base of the transistor. Then the transistor will be switched on which initiates the
operation of the relay and consequently the relay will be off. When the credit
card is again recharged, the ATmega32 will send a pulse for which the relay
establishes a connection between the load and the supply mains.
Display Unit
The liquid crystal display controller displays alphanumeric characters and
symbols. It can be configured to drive a dot-matrix liquid crystal display under
the control of microcontroller. In this paper, LCD is mainly used to display
energy consumption of the laod, the number of units recharged by the
consumer, rest units, maximum demand of consumer.
Power Supply Unit
Every electronic circuit needs appropriate power supply for its operation.
Basically Microcontrollers, Energy Meter ICs, Liquid crystal display and
relays operate on 5 volts supply. For this reason, we have used a 5 volt
power supply. We have taken into consideration the small energy consumed by
the power supply itself that will be paid by the consumers.

Basic Data Acquisition and Energy Calculation


Data Acquisition for Calculating Power
The Energy Meter IC AD7751 produces an output frequency that is proportional to
the time average value of the product of two voltage signals. The input voltage
signals are applied across pin 4, 6 and pin 8, 7 of Energy Meter IC. The Energy

Meter IC also provides an output frequency at pin 22 of Energy Meter IC equal to


the output power that can be calculated using an equation as

Where, Vref= Nominal reference voltage for Energy Meter IC =2.5 volts
F1-4=1.7, Gain=1
V1= Voltage applied across pin 4 and 6 which is proportional to load current
V2= Voltage applied across pin 8 and 7 which is proportional to line to neutral
voltage
This output frequency is proportional to the real power information. During
calibration we have got the frequency F=0.5 Hz against 1.5 kW load. When F= 0.5
Hz, then power=1500 Watt. So for any value of the frequency at F (say F= X Hz),
Power, P will be

Energy Calculation
The complete equation for determining the energy or units consumed from Power, P
is obtained as follows

Software Development for Prepaid Energy Meter


The system software is implemented by C language and the developed code is
edited, compiled and debugging by Win-AVR software.
Algorithm for Energy Metering system at consumers end
Start
Initialize the display.
Decide whether the number of units in Microcontroller is sufficient or not. If
the balance is insufficient then disconnects the load from supply otherwise
connect to the load to supply.
Count the number of pulses initiated from Energy Meter IC AD7751 with
the help of counter0 when the load consumes power.
Measure time with the help of timer1.
Calculate power, P = 3000 X using this equation, where X denotes the
Frequency of pulses that is produced by the Energy Meter IC.

Calculate energy using the following equation,

Store energy and power reading into the EEPROM of ATmega32


Microcontroller for future use.
Check whether the button for number of units recharge is pressed or not. If the
button is pressed check whether a valid smart card is inserted or not. If the
inserted card is valid then read, store and update the recharge information and
display the update status on the LCD.
If the valid smart card is not inserted then repeat the step 3

Results and Analysis


An Electric Heater of 1.2 kW rating was used as a load that draws currents of up to
5.5A. The supply voltage was between 210 V and 230 V. Energy measurement
process is described step by step. At first, a wattmeter was used to measure the power
consumed by the load. Then energy consumption was measured after every 20
seconds using the obtained power information from the load. The computed energy
consumption is read from the Liquid Crystal Display. The experimental result for the
testing of prepaid energy meter is summarized in Table 1.
The results shown in Table 1 are the expected energy output in kW-sec obtained from
the load power, 1.2 kW and time and energy output from measurement that is
displayed by LCD after every 20 sec. A certain amount of power is supplied to the
load, this power is maintained over a certain period of time and the energy
consumption is calculated and finally displayed. The tests were done over a 3 minute
period, measurements were taken every 20 sec and a very high accuracy level is
observed particularly after longer periods of time.

MECHANICAL CONSTRUCTION OF THE ELECTRONIC BILLING


SYSTEM
After finalizing the construction of the circuit, what remains now is the mechanical
outlook of the enclosed system. In this design, consideration on price and usage in
real time application was taken note of since the aim of this project is to show a
prototype Electronic Billing System.

CHAPTER FIVE
CONCLUSION AND RECOMMENDATION
CONCLUSION
This seminar has demonstrated for measuring the electrical energy consumption of an
electrical load for two wire distribution systems with the proposed energy meter as an
alternative to the conventional electromechanical meters. This microcontroller based
energy meter prototype has been implemented to provide measurement up to 20 A
load current from a 230 V line to neutral voltage. The proposed energy meter is
capable of measuring energy consumption for all loads conditions i.e. power factor
and non-sinusoidal voltage and current waveforms. It does not possess any rotating
parts that help in the prevention of meter tempering, which is an attractive feature for
the utilities. The proposed energy meter includes a no load threshold feature that
will eliminate any creeping effects in the meter. In addition, the process of reading the
energy consumption is facilitated by the LCD display that is simpler than that for the
analog meters which reduces human errors while noting down the meter reading. This
energy meter has the potential to change the future of the energy billing system in
Nigeria. The energy billing system may help the energy distribution companies to
reduce costs and increase profits, to improve metering and billing accuracy and
efficiency, and to contribute the energy in a sustainable way. To recharge the
microcontroller chip, it must be taken to the server terminal or unit. The energy
billing system provides employment for nearly 2-3 people in every server terminal for
jobs like recharging smartcard and processing the distribution of power in a
convenient way.
RECOMMENDATION
There is no man made perfect design on this planet earth hence the need for daily
upgrade of our intellect. This design features a static user account that has been
coded internally during the course of the firm ware development and this makes it
awkward when upgrading the database users.

Since we have limited our sample

to 4(four) digit count any call for upgrade will certainly mean recoding the MCU.

In subsequent design there should be an upgrade in the dynamism of the user account
control so that it could be dynamically changed without the need to recode the MCU.
With this upgrade, the Billing system can be applied in any working environment
without the need for unnecessary modifications. In future, mode of recharging the
smart card can be improved by wireless communication between the server terminal
and energy meter unit.

REFERENCES
[1] Devidas, A.R., Ramesh, M.V. Wireless Smart Grid Design for Monitoring and
Optimizing Electric Transmission in India, 2010 Fourth International Conference on
Sensor Technologies and Applications (SENSORCOMM), pp.637-640,
2010.
[2] Shoeb S. Sheikh, et al., Design and Implementation of Wireless Automatic Meter
Reading System," International Journal of Engineering Science and Technology, Vol.
3, No. 3, pp. 2329-2334, March 2011.
[3] Amit Jain and Mohnish Bagree, "A Prepaid Meter Using Mobile
Communication," International Journal of Engineering, Science and Technology, Vol.
3, No. 3, pp. 160-166, Apr 2011.
[4] Kwan, B.H., Moghavvemi, M., PIC Based Smart Card Prepayment System,
Student Conference on Research and Development, pp. 440- 443, 2002.
[5] Khan R.H., T.F. Aditi, V. Sreeram and H.H.C. lu, A Prepaid Smart Metering
Scheme Based on WiMAX Prepaid Accounting Model, Smart Grid and Renewable
Energy, Vol. 1, No. 2, pp. 63-69, 2010.
[6] Ling Zou, Sihong Chu and Biao Guo.,The Design of Prepayment Polyphase
Smart Electricity Meter System, International Conference on Intelligent Computing
and Integrated Systems (ICISS), pp. 430-432, 22-24, Dec 2010.
[7] Richa Shrivastava and Nipun Kumar Mishra, "An Embedded System for Wireless
Prepaid Billing of Digital Energy Meter," International Journal of Advances in
Electronics Engineering, pp. 322-324.
[8] M.C. Ndinechi, O.A. Ogungbenro and K.C. Okafor, "Digital Metering System: A
Better Alternative for Electromechanical Energy Meter in Nigeria,"International
Journal of Academic Research , Vol. 3, No. 5, pp. 189-192, Sep 2011.
[9] Loss, P et al., A Single Phase Microcontroller Based Energy Meter, IEEE
Instrumentation and Measurement Technology Conference. St. Paul Minnesota, USA,
May 18-21, 1998.
[10]. Atmel Corporation- Interfacing AT24CXX Serial EEPROMs with AT89CX051
Microcontrollers, www.atmel.com/, accessed on 11 March 2006

[11].

Atmel

Corporation-

AVR402:Hardware

design

considerations

www.atmel.com/, accessed on 28 March 2006


[12]. Future Technology Devices - AN232B-05 Configuring FT232R,FT2232C and
FT232BM Baud Rates , http://www.ftdichip.com ,accessed 16 March 2006
[13]. Future Technology Devices AN232R-02 FTDIChip-ID for the FT232R
and FT245R, http://www.ftdichip.com ,accessed 16 March 2006
[14].

Future

Technology

Devices

FT232R

http://www.ftdichip.com ,accessed 16 March 2006

USB

UART

I.C,

PROBLEMS ENCOUNTERED
Basically, the problems I encountered during the making of this project were the
unavailability of the core controller that is to be used in the project. This particular
problem introduced the highest bottle neck in the prototyping face of my project
because it forms the frame work.
Some of the semiconductors were out of specification and this made the mathematical
and electrical parameters deviate by about 15% at the initial stage of the bread
boarding. Thus making the time expended on a particular circuit block high. But
through careful adjustment of pre-calculated the error rate was reduced to about 2%.
Also, establishing a clearly defined protocol for data transfer to and from the energy
meter to the central hardware was not that rosy as it has to be in synch with the
hardware hence data may be lost thus leading to error in the data logging process.
Sending data unto the smart card is one of the most technical aspects of the project
because it makes use of an encrypted sequence of data. This problem was solved by
the use of Atmega32 microcontroller chip which has all the processing power for the
complex mathematics that the controller needs.
Developing a visual based application using an LCD that will meet technical standard
like; real time logging, setting up a data base etc. demands greater precision on the
part of program coding and this was not easy to come by because while keeping up
with the data received, the program should be able to multitask hence process
variation may be introduced.
Time , this plays a major factor in any given line of project, the time frame allocated
to develop a project of this standard is so small looking at the technicality so involved
and this made the sequences involved in the project a little bit unbearable for me.

APPENDIX

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;VARIABLE DECLARATION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
T2CON DATA 0C8H
RCAP2L

DATA 0CAHs

RCAP2H

DATA 0CBH

;;;;;;;;;;;;;;;;;;;;;;;;;
OUTPUT
SCAN

DATA
DATA

ADC_IN

080H
0A0H

DATA

090H

CONTROL

DATA

0B0H

WRITE

BIT

CONTROL.2

ADD_L

BIT

CONTROL.3

ADD_H

BIT

CONTROL.5

COUNTER

DATA

000H

STORE_1

DATA

001H

STORE_2

DATA

002H

STORE_3

DATA

003H

TEMPERATURE_STORE

DATA

004H

FREQUECNY_STORE

DATA

005H

AC_VOLTAGE_STORE DATA
CURRENT_STORE
POWER_STORE

006H
DATA

007H

DATA

008H

DC_VOLTAGE_STORE DATA

009H

DELAY_REG

DATA

00AH

DELAY_REG1

DATA

00BH

DELAY_REG2

DATA

00CH

RESTORE

DATA

00DH

SAMPLER

DATA

00EH

STATUS_1

DATA

00FH

STATUS_2

DATA

010H

STATUS_3

DATA

011H

LOG_COUNTER

DATA

012H

AUX_TEMP

DATA

013H

AUX_FREQ

DATA

014H

AUX_AC_VOL

DATA

015H

AUX_CURRE

DATA

016H

AUX_POW

DATA

017H

SAMPLER_1

DATA

018H

LOG_STORE

DATA

019H

FLAGS

DATA

020H

SAMPLE_FLAG

BIT

FLAGS.0

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;END OF VARIABLE DECLARATION;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

ORG 000H
AJMP BOOTSTRAP

ORG 023H
AJMP SETUP_DATA_LOGGING

ORG 02BH
AJMP SAMPLE

ORG 02FH

BOOTSTRAP:
MOV SP,#030H
CLR WRITE
MOV OUTPUT,#000
MOV COUNTER,#001
MOV LOG_COUNTER,#001
MOV ADC_IN,#255
MOV FREQUECNY_STORE,#000
MOV TEMPERATURE_STORE,#000
MOV AC_VOLTAGE_STORE,#000
MOV CURRENT_STORE,#000
MOV POWER_STORE,#000
MOV SAMPLER,#100
MOV SAMPLER_1,#025
MOV AUX_TEMP,#000
MOV AUX_FREQ,#000
MOV AUX_AC_VOL,#000
MOV AUX_CURRE,#000
MOV AUX_POW,#000
MOV SCAN,#000
MOV TL0,#000

MOV STATUS_1,#071H
MOV STATUS_2,#071H
MOV STATUS_3,#03FH
CLR ADD_L
CLR ADD_H
SETB WRITE
SETB TR0
MOV PCON,#080H
MOV TMOD,#025H
MOV TH1,#0FFH
MOV SCON,#050H
CLR TI
CLR RI
SETB TR1
MOV RCAP2L,#000H
MOV RCAP2H,#0DCH
MOV T2CON,#004
MOV IE,#10110000B
AJMP MAIN

MAIN:

MOV A,FREQUECNY_STORE
ACALL BIN_DEC
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_1
ACALL DISP_MASK
MOV SCAN,#000
MOV OUTPUT,A
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_2
ACALL DISP_MASK
MOV SCAN,#001
MOV OUTPUT,A
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOV A,TEMPERATURE_STORE
ACALL BIN_DEC
;;;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_1
ACALL DISP_MASK
MOV SCAN,#002

MOV OUTPUT,A
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_2
ACALL DISP_MASK
MOV SCAN,#003
MOV OUTPUT,A
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOV A,CURRENT_STORE
ACALL BIN_DEC
;;;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_1
ACALL DISP_MASK
MOV OUTPUT,A
MOV SCAN,#004
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_2
ACALL DISP_MASK
MOV OUTPUT,A
MOV SCAN,#005
SETB SCAN.4
ACALL DELAY_900_11
CLR SCAN.4
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOV A,FREQUECNY_STORE
CJNE A,#000,PROC
MOV AC_VOLTAGE_STORE,FREQUECNY_STORE
PROC:

MOV A,AC_VOLTAGE_STORE
ACALL BIN_DEC
;;;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_1
ACALL DISP_MASK
MOV OUTPUT,A
MOV SCAN,#006
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_2
ACALL DISP_MASK

MOV OUTPUT,A
MOV SCAN,#007
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_3
ACALL DISP_MASK
MOV OUTPUT,A
MOV SCAN,#008
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOV A,POWER_STORE
ACALL BIN_DEC
;;;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_1
ACALL DISP_MASK
MOV OUTPUT,A
MOV SCAN,#009
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_2
ACALL DISP_MASK
MOV OUTPUT,A
MOV SCAN,#010
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;
MOV A,STORE_3
ACALL DISP_MASK
MOV OUTPUT,A
MOV SCAN,#011
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
MOV OUTPUT,STATUS_1
MOV SCAN,#012
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;
MOV OUTPUT,STATUS_2
MOV SCAN,#013
ACALL DELAY_900_11

MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;
MOV OUTPUT,STATUS_3
MOV SCAN,#014
ACALL DELAY_900_11
MOV OUTPUT,#000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ACALL ADC_IN_ROUTINE
ACALL REFRESH_SCREEN
AJMP MAIN

REFRESH_SCREEN:

DJNZ SAMPLER_1,RETURN
MOV SAMPLER_1,#025
MOV TEMPERATURE_STORE,AUX_TEMP
MOV FREQUECNY_STORE,AUX_FREQ
MOV AC_VOLTAGE_STORE,AUX_AC_VOL
MOV CURRENT_STORE,AUX_CURRE
MOV POWER_STORE,AUX_POW

RETURN:

RET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
ADC_IN_ROUTINE:

CLR ADD_H
CLR ADD_L
ACALL DELAY_12KHz
ACALL GET_PARAMETER
MOV AUX_CURRE,ADC_IN
;;;;;;;;;;;;;;;;;;;;;;;;;;;
SETB ADD_L
CLR ADD_H
ACALL DELAY_12KHz
ACALL GET_PARAMETER
MOV AUX_AC_VOL,ADC_IN
;;;;;;;;;;;;;;;;;;;;;;;;;;;
CLR ADD_L
SETB ADD_H
ACALL DELAY_12KHz
ACALL GET_PARAMETER
MOV AUX_TEMP,ADC_IN
;;;;;;;;;;;;;;;;;;;;;;;;;;;
SETB ADD_H
SETB ADD_L
ACALL DELAY_12KHz
ACALL GET_PARAMETER

MOV AUX_POW,ADC_IN
;;;;;;;;;;;;;;;;;;;;;;;;;;;
RET
GET_PARAMETER:

CLR WRITE
NOP
NOP
NOP
NOP
SETB WRITE
ACALL DELAY_12KHz
RET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
LOG_TO_SYSTEM:

CLR SAMPLE_FLAG
CLR TI
MOV A,LOG_STORE

FREQUECNY_LOGGER:

CJNE A,#016,TEMPERATURE_LOGGER
MOV SBUF,FREQUECNY_STORE
JNB TI,$

CLR TI
AJMP MAIN
TEMPERATURE_LOGGER:

CJNE A,#008,AC_VOLTAGE_LOGGER
MOV SBUF,TEMPERATURE_STORE
JNB TI,$

CLR TI
AJMP MAIN
AC_VOLTAGE_LOGGER:

CJNE A,#128,POWER_LOGGER
MOV SBUF,AC_VOLTAGE_STORE
JNB TI,$

CLR TI
AJMP MAIN
POWER_LOGGER:

CJNE A,#032,CURRENT_LOGGER
MOV SBUF,POWER_STORE
JNB TI,$
CLR TI
AJMP MAIN

CURRENT_LOGGER:

CJNE A,#064,SHOW_STATUS
MOV SBUF,CURRENT_STORE
JNB TI,$
CLR TI

AJMP MAIN
SHOW_STATUS:

CJNE A,#099,SHOW_STATUS_1
MOV STATUS_1,#071H
MOV STATUS_2,#071H
MOV STATUS_3,#03FH
AJMP MAIN

SHOW_STATUS_1:

CJNE A,#199,SHOW_STATUS_EXIT
MOV STATUS_1,#037H
MOV STATUS_2,#03FH
MOV STATUS_3,#040H

SHOW_STATUS_EXIT:

AJMP MAIN

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
SETUP_DATA_LOGGING:

JNB RI,OUT
MOV LOG_STORE,SBUF
SETB SAMPLE_FLAG
CLR RI

OUT:

RETI

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DISP_MASKLAY MASK SUBROUTINE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


DISP_MASK:

INC A
MOVC A,@A+PC
RET
DB 03FH

; Digit 0 mask 0C0H

DB 006H

; Digit 1 mask 0F9H

DB 05BH

; Digit 2 mask 0A4H

DB 04FH

; Digit 3 mask 0B0H

DB 066H

; Digit 4 mask 099H

DB 06DH

; Digit 5 mask 092H

DB 07DH

; Digit 6 mask 082H

DB 007H

; Digit 7 mask 0F8H

DB 07FH

; Digit 8 mask 080H

DB 06FH

; Digit 9 mask 090H

BIN_DEC:

MOV B,#10
DIV AB
MOV STORE_1,B
MOV B,#10
DIV AB
MOV STORE_2,B

MOV STORE_3,A
RET

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;DELAY SUBROUTINE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
DELAY_900_11:

MOV DELAY_REG1,#02
MOV DELAY_REG2,#168

_150_12:

DJNZ DELAY_REG2,_150_12
DJNZ DELAY_REG1,_150_12
RET

DELAY_12KHz:

MOV DELAY_REG1,#18

Y_12KHz:

DJNZ DELAY_REG1,Y_12KHz
RET

END

S-ar putea să vă placă și