Prepaid Energy Meter: Visit Us, Choose The Project You Like and Click The Download Button
Prepaid Energy Meter: Visit Us, Choose The Project You Like and Click The Download Button
Prepaid Energy Meter: Visit Us, Choose The Project You Like and Click The Download Button
uiopasdfghjklzxcvbnmqwertyuiopasd
fghjklzxcvbnmqwertyuiopasdfghjklzx
cvbnmqwertyuiopasdfghjklzxcvbnmq
PREPAID ENERGY METER
wertyuiopasdfghjklzxcvbnmqwertyui
www.BEProjectReport.com
opasdfghjklzxcvbnmqwertyuiopasdfg
hjklzxcvbnmqwertyuiopasdfghjklzxc
vbnmqwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqwertyui
opasdfghjklzxcvbnmqwertyuiopasdfg
hjklzxcvbnmqwertyuiopasdfghjklzxc
vbnmqwertyuiopasdfghjklzxcvbnmq
wertyuiopasdfghjklzxcvbnmqwertyui
opasdfghjklzxcvbnmqwertyuiopasdfg
hjklzxcvbnmrtyuiopasdfghjklzxcvbn
mqwertyuiopasdfghjklzxcvbnmqwert
yuiopasdfghjklzxcvbnmqwertyuiopas
VISIT US, CHOOSE THE PROJECT YOU LIKE AND
CLICK THE DOWNLOAD BUTTON
CHAPTER 1
INTRODUCTION
1.1 EMBEDDED SYSTEMS
An embedded system is a combination of software and hardware to perform a dedicated task.
One of the most critical needs of an embedded system is to decrease power consumption and
space. Some of the main devices used in embedded products are Microprocessors and
Microcontrollers. Microprocessors are commonly referred to as general purpose processors as they
simply accept the inputs, process it and give the output. These microprocessors contain no RAM, no
ROM, and no I/O ports on the chip itself .For this reason, they are commonly referred to as generalpurpose microprocessors. In contrast, a microcontroller has a CPU (microprocessor) in addition to a
fixed amount of RAM, ROM, I/O ports, and a timer all are embedded together on one chip. A
microcontroller not only accepts the data as inputs but also manipulates it, interfaces the data with
various devices, controls the data and thus finally gives the result.
1.2 MICROCONTROLLERS:
1.2.1 INTRODUCTION:
A Micro controller is a computer-on-a-chip or a single-chip computer. Micro
suggests that the device is small and Controller tells that the device might be used to control
objects, processes or events.
The core of many specialized computers is the micro controller. The computers program is
typically stored permanently in semiconductor memory such as ROM or EPROM. The interfaces
between the micro controller and the outside world vary with application, and may include a small
display, a keypad or switches, sensors, relays, motors and so on. These small, special purpose
computers are sometimes called Single Board Computers or SBCs.
A micro controller is similar to the microprocessor inside a personal computer. Examples
are Intels 8086, Zilogs Z80. Both microprocessors and micro controllers contain CPU. The CPU
executes instructions that perform the basic logic, math, and data-moving functions of a computer.
To make a complete computer, a microprocessor requires memory for storing data and programs, and
I/O interfaces for connecting external devices like keyboard and displays. In contrast, micro
controllers are a single-chip computer because it contains memory and I/O interfaces in addition to
the CPU. It tends to limit the amount of memory and interfaces that can fit on single chip, micro
controllers tend to be used in smaller system. Examples of popular micro controllers are Intels 8052,
89C052, AT89s52, Motorolas 68HC11 and Zilogs Z80.
www.BEProjectReport.com
Page 2
Microcontrollers are little more than a carefully designed array of logic gates and
memory cells, but modern fabrication processes allow thousands of these to fit on a single chip. By
using a microcontroller can reduce the number or components and thus the amount of design work
and wiring required for the project.
1.2.2 FEATURES:
Microcontrollers are special purpose computers. These are a number of
common characteristics that define microcontrollers:
Microcontrollers are embedded inside some other device (often a consumer product) so that
they can control the features or actions of the product. Another name for a microcontroller,
therefore, is embedded controller.
Microcontrollers are dedicated to one task and run one specific program. The program is
stored in ROM (Read Only Memory) and generally does not change.
Microcontrollers are often low-power devices. A battery-operated microcontroller might
consume 50 milli watts.
A microcontroller has a dedicated input device and often has a small LED or LCD display for
output. A microcontroller also takes input from the device it is controlling and controls the
device by sending signals to different components in the device.
A microcontroller is often small and low cost. The components are chosen to minimize size
and to be as inexpensive as possible.
www.BEProjectReport.com
Page 3
Page 4
To recharge the system the user has to place the EEPROM based recharge card in slot
provided. After pressing the recharge key, the system will be loaded with the units corresponding to
that recharge value. After successful recharge, the load automatically gets ON.
This system uses 5V regulated power supply for microcontroller, LCD, EEPROM and driver
IC and 12V supply for relay which is supplied form a step down transformer.
www.BEProjectReport.com
Page 5
CHAPTER 2
COMPONENTS USED IN THE MODEL
AT89S52 MICROCONTROLLER
www.BEProjectReport.com
Page 6
www.BEProjectReport.com
Page 7
2.1.3 DESCRIPTION:
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.
Block diagram of AT89S52 microcontroller is given in fig 2.1 and Pin diagram in fig
2.2
Micro controller has 4 ports namely
1. Port 0
2. Port 1
3. Port 2
4. Port3
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 twolevel interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry
www.BEProjectReport.com
Page 8
. In addition, the AT89S52 is designed with static logic for operation down to zero frequency
and supports two software selectable power saving modes. The Idle Mode stops the CPU while
allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning. The
Power-down mode saves the RAM contents but freezes the oscillator, disabling all other chip
functions until the next interrupt or hardware reset.
www.BEProjectReport.com
Page 9
Page 10
RESET
Pin9 is the reset pin. It is an input and is active high. Upon applying a high pulse to this pin, the
microcontroller will reset and terminate all the activities. This is often referred to as a power-on
reset.
PSEN (Program store enable)
This is an output pin.
ALE (Address latch enable)
This is an output pin and is active high
www.BEProjectReport.com
Page 11
EA (External access)
Pin 31 is EA. It is an active low signal. It is an input pin and must be connected to either VCC or
GND but it cannot be left unconnected.
The 8051 family members all come with on-chip ROM to store programs. In such cases, the
EA pin is connected to VCC. If the code is stored on an external ROM, the EA pin must be
connected to GND to indicate that the code is stored externally.
Ports 0, 1, 2 and 3
The four ports P0, P1, P2 and P3 each use 8 pins, making them 8-bit ports. All the ports upon
RESET are configured as input, since P0-P3 have value FFH on them.
Port 0(P0)
Port 0 is also designated as AD0-AD7, allowing it to be used for both address and data. ALE
indicates if P0 has address or data. When ALE=0, it provides data D0-D7, but when ALE=1, it has
address A0-A7. Therefore, ALE is used for demultiplexing address and data with the help of an
internal latch.
When there is no external memory connection, the pins of P0 must be connected to a 10Kohm pull-up resistor. This is due to the fact that P0 is an open drain. With external pull-up resistors
connected to P0, it can be used as a simple I/O, just like P1 and P2. But the ports P1, P2 and P3 do
not need any pull-up resistors since they already have pull-up resistors internally. Upon reset, ports
P1, P2 and P3 are configured as input ports.
www.BEProjectReport.com
Page 12
www.BEProjectReport.com
Page 13
The assembly language program is written and this program has to be dumped into the
microcontroller for the hardware kit to function according to the software. The program dumped in
the microcontroller is stored in the Flash memory in the microcontroller. Before that, this Flash
memory has to be programmed and is discussed in the next section.
ALE/PROG
Address Latch Enable is an output pulse for latching the low byte of the address during
accesses to external memory. This pin is also the program pulse input (PROG) during Flash
programming. In normal operation, ALE is emitted at a constant rate of 1/6 the oscillator frequency
and may be used for external timing or clocking purposes. If desired, ALE operation can be disabled
by setting bit 0 of SFR location 8EH. With the bit set, ALE is active only during a MOVX or MOVC
instruction. Otherwise, the pin is weakly pulled high. Setting the ALE-disable bit has no effect if the
microcontroller is in external execution mode.
PSEN (Program Store Enable)
It is the read strobe to external program memory. When the AT89S8252 is executing code
from external program memory, PSEN is activated twice each machine cycle, except that two PSEN
activations are skipped during each access to external data memory.
EA/VPP (External Access Enable)
EA must be strapped to GND in order to enable the device to fetch code from external program
memory locations starting at 0000H up to FFFFH. Note, however, that if lock bit 1 is programmed,
EA will be internally latched on reset. EA should be strapped to VCC for internal program
executions. This pin also receives the 12-volt programming enable voltage (VPP) during Flash
programming when 12-volt programming is selected.
Ports 0, 1, 2 and 3
The four ports P0, P1, P2 and P3 each use 8 pins, making them 8-bit ports. All the ports upon
RESET are configured as input, since P0-P3 have value FFH on them.
Port 0(P0)
Port 0 is also designated as AD0-AD7, allowing it to be used for both address and data. ALE
indicates if P0 has address or data. When ALE=0, it provides data D0-D7, but when ALE=1, it has
address A0-A7. Therefore, ALE is used for demultiplexing address and data with the help of an
internal latch.
When there is no external memory connection, the pins of P0 must be connected to a 10K-ohm pullup resistor. This is due to the fact that P0 is an open drain. With external pull-up resistors connected
to P0, it can be used as a simple I/O, just like P1 and P2. But the ports P1, P2 and P3 do not need any
www.BEProjectReport.com
Page 14
pull-up resistors since they already have pull-up resistors internally. Upon reset, ports P1, P2 and P3
are configured as input ports.
Port 1
Port 1 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 1 output buffers can
sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the internal
pull-ups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled low will
source current because of the internal pull-ups.
Some Port 1 pins provide additional functions. P1.0 and P1.1 can be configured to be the
timer/counter 2 external count input (P1.0/T2) and the timer/counter 2 trigger input (P1.1/T2EX),
respectively. Furthermore, P1.4, P1.5, P1.6, and P1.7 can be configured as the SPI slave port select,
data input/output and shift clock input/output pins. Port 1 also receives the low-order address bytes
during Flash programming and verification.
www.BEProjectReport.com
Page 15
Port 2 also receives the high-order address bits and some control signals during Flash
programming and verification.
Port 3
Port 3 is an 8-bit bi-directional I/O port with internal pull-ups. The Port 3 output buffers can
sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the internal
pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled low will
source current because of the pull-ups. Port 3 receives some control signals for Flash programming
and verification.
Port 3 also serves the functions of various special features of the AT89S8252, as shown in
the following table.
2.2 EEPROM
2.2.1 INTRODUCTION:
EEPROM has several advantages over other memory devices, such as the fact that its method
of erasure is electrical and therefore instant. In addition, in EEPROM one can select which byte to be
erased, in contrast to flash, in which the entire contents of ROM are erased. The main advantage of
EEPROM is that one can program and erase its contents while it is in system board. It does not
require physical removal of the memory chip from its socket. In general, the cost per bit for
EEPROM is much higher when compared to other devices.
This project requires the data such as the total number of available units and the pulse count
to be stored permanently and this data modifies upon the power consumption. Thus this data has to
be stored in such a location where it cannot be erased when power fails and also the data should be
allowed to make changes in it without the system interface i.e., there should be a provision in such a
way that the data should be accessed (or modified) while it is in system board but not external
www.BEProjectReport.com
Page 16
erasure and programming. The flash memory inbuilt in the microcontroller can erase the entire
contents in less than a second and the erasure method is electrical.
Fig2.6 .EEPROM
But the major drawback of Flash memory is that when flash memorys contents are erased, the entire
device will be erased but not a desired section or byte. For this purpose, we prefer EEPROM in our
project. The EEPROM used in this project is 24C04 type.
www.BEProjectReport.com
Page 17
www.BEProjectReport.com
Page 18
2.2.3 DESCRIPTION
The 24C04 is a 4Kbit electrically erasable programmable memory (EEPROM), organized as
2 blocks of 256 x8 bits. They are manufactured in ST Microelectronics Hi-Endurance Advanced
CMOS technology which guarantees an endurance of one million erase/write cycles with data
retention of 40 years. Both Plastic Dual-in-Line and Plastic Small Outline packages are available.
The memories are compatible with the I2C standard, two wire serial interface which uses a bidirectional data bus and serial clock. The memories carry a built-in 4 bit, unique device identification
code (1010) corresponding to the I2C bus definition. This is used together with 2 chip enable inputs
(E2, E1) so that up to 4 x 4K devices may be attached to the I2C bus and selected individually. The
memories behave as a slave device in the I2C protocol with all memory operations synchronized by
the serial clock. Read and write operations are initiated by a START condition generated by the bus
master. The START condition is followed by a stream of 7 bits (identification code 1010), plus one
read/write bit and terminated by an acknowledge bit. When writing data to the memory it responds to
the 8 bits received by asserting an acknowledge bit during the 9th bit time. When data is read by the
bus master, it acknowledges the receipt of the data bytes in the same way. Data transfers are
terminated with a STOP condition.
Power on Reset: VCC locks out write protect.
In order to prevent data corruption and inadvertent write operations during power up, a Power on
Reset (POR) circuit is implemented. Until the VCC voltage has reached the POR threshold value, the
internal reset is active, all operations are disabled and the device will not respond to any command.
In the same way, when VCC drops down from the operating voltage to below the POR threshold
value, all operations are disabled and the device will not respond to any command. A stable VCC
must be applied before applying any logic signal.
SIGNAL DESCRIPTIONS
Serial Clock (SCL).
The SCL input pin is used to synchronize all data in and out of the memory. A resistor can be
connected from the SCL line to VCC to act as a pull up.
Serial Data (SDA).
The SDA pin is bi-directional and is used to transfer data in or out of the memory. It is an open drain
output that may be wire-ORed with other open drain or open collector signals on the bus. A resistor
must be connected from the SDA bus line to VCC to act as pull up.
Chip Enable (E1 - E2).
These chip enable inputs are used to set the 2 least significant bits (b2, b3) of the 7 bit device select
code. These inputs may be driven dynamically or tied to VCC or VSS to establish the device select
code.
www.BEProjectReport.com
Page 19
2.3 RELAY
A relay is an electrically controllable switch widely used in industrial controls, automobiles and
appliances.
The relay allows the isolation of two separate sections of a system with two different voltage
sources i.e., a small amount of voltage current on one side can handle a large amount of voltage
current on the other side but there is no chance that these two voltages mix up.
www.BEProjectReport.com
Page 20
Inductor
2.3.1 OPERATION
When a current flow through the coil, a magnetic field is created around the coil i.e., the coil is
energized. This causes the armature to be attracted to the coil. The armatures contact acts like a
switch and closes or opens the circuit. When the coil is not energized, a spring pulls the armature to
its normal state of open or closed. There are all types of relays for all kinds of applications.
Transistors and ICs must be protected from the brief high voltage 'spike' produced when the relay
coil is switched off. The above diagram shows how a signal diode (e.g. 1N4148) is connected across
the relay coil to provide this protection. The diode is connected 'backwards' so that it will normally
not conduct. Conduction occurs only when the relay coil is switched off, at this moment the current
tries to flow continuously through the coil and it is safely diverted through the diode. Without the
diode no current could flow and the coil would produce a damaging high voltage 'spike' in its attempt
to keep the current flowing.
www.BEProjectReport.com
Page 21
1. The contacts can be normally open (NO) or normally closed (NC). In the NC type, the contacts are
closed when the coil is not energized. In the NO type, the contacts are closed when the coil is
energized.
2. There can be one or more contacts. i.e. different types like SPST (single pole single throw), SPDT
(single pole double throw) and DPDT (double pole double throw) relays.
3. The voltage and current required to energize the coil. The voltage can vary from a few volts to 50
volts, while the current can be from a few milliamps to 20milliamps. The relay has a minimum
voltage, below which the coil will not be energized. This minimum voltage is called the pull-in
voltage.
4. The minimum DC/AC voltage and current that can be handled by the contacts. This is in the range
of a few volts to hundreds of volts, while the current can be from a few amps to 40A or more,
depending on the relay.
An SPDT relay consists of five pins, two for the magnetic coil, one as the common terminal
and the last pins as normally connected pin and normally closed pin. When the current flows through
this coil, the coil gets energized. Initially when the coil is not energized, there will be a connection
between the common terminal and normally closed pin. But when the coil is energized, this
connection breaks and a new connection between the common terminal and normally open pin will
be established.
Thus when there is an input from the microcontroller to the relay, the relay will be switched
on. Thus when the relay is on, it can drive the loads connected between the common terminal and
normally open pin. Therefore, the relay takes 5V from the microcontroller and drives the loads which
consume high currents. Thus the relay acts as an isolation device.
Digital systems and microcontroller pins lack sufficient current to drive the relay. While the
relays coil needs around 10milli amps to be energized, the microcontrollers pin can provide a
maximum of 1-2milli amps current. For this reason, a driver such as a power transistor is placed in
between the microcontroller and the relay.
www.BEProjectReport.com
Page 22
LOAD
AT 89C51
DRIVER
RELAY
CIRCUIT
P1.0
Fig.2.12
www.BEProjectReport.com
Page 23
A model described here is for its low price and great possibilities most frequently used in
practice. It is based on the HD44780 microcontroller (Hitachi) and can display messages in two lines
with 16 characters each. It displays all the alphabets, Greek letters, punctuation marks, mathematical
symbols etc. In addition, it is possible to display symbols that user makes up on its own. Automatic
shifting message on display (shift left and right), appearance of the pointer, backlight etc. are
considered as useful characteristics.
www.BEProjectReport.com
Page 24
Function
Pin
Number
Name
Logic
State
Description
Ground
VSS
0V
Power supply
Vdd
+5V
Contrast
Vee
0 - Vdd
RS
0
1
D0 D7 are interpreted as
commands
D0 D7 are interpreted as data
0
1
Control of
operating
R/W
0
Access to LCD disabled
1
Normal operating
From 1 to Data/commands are transferred to
0
LCD
D0
0/1
Bit 0 LSB
D1
0/1
Bit 1
D2
0/1
Bit 2
10
D3
0/1
Bit 3
11
D4
0/1
Bit 4
12
D5
0/1
Bit 5
13
D6
0/1
Bit 6
14
D7
0/1
Bit 7 MSB
Data / commands
www.BEProjectReport.com
Page 25
www.BEProjectReport.com
Page 26
0 = Display off
U 1 = Cursor on
0 = Cursor off
B 1 = Cursor blink on
0 = Cursor blink off
www.BEProjectReport.com
Page 27
Vcc
P2.0
4 (RS)
P2.1
5 (R/W)
P2.2
6(EN)
Gnd
PRESET
(CONTRAST
CONTROL)
LCD
Vcc
Gnd
89C51
P1.0
D0
P1.1
D1
P1.2
FOR
BACKLIGHT
PURPOSE
D2 Commands to LCD
Fig. 2.13 Sending
P1.3
D3
P1.4
D4
P1.5
D5
15
P1.6
D6
16
P1.7
D7
www.BEProjectReport.com
Page 28
www.BEProjectReport.com
Page 29
www.BEProjectReport.com
Page 30
Page 31
The Darlington driver IC ULN2003 can be used to provide both the NOT and Darlington driver
circuits. It also contains the back emf suppression diodes so no external diodes are required. The
complete circuit is shown above.
Before programming, there is another pattern to notice in the stepping sequence. Look at
this table, which just shows coil 1 and coil 3.
www.BEProjectReport.com
Page 32
www.BEProjectReport.com
Page 33
BLOCK DIAGRAM
For the positive half cycle of the input ac voltage, diodes D1 and D3 conduct, whereas diodes
D2 and D4 remain in the OFF state. The conducting diodes will be in series with the load resistance
RL and hence the load current flows through RL.
For the negative half cycle of the input ac voltage, diodes D2 and D4 conduct whereas, D1
and D3 remain OFF. The conducting diodes D2 and D4 will be in series with the load resistance
www.BEProjectReport.com
Page 34
RL and hence the current flows through RL in the same direction as in the previous half cycle. Thus a
bi-directional wave is converted into a unidirectional wave.
FILTER:
Capacitive filter is used in this project. It removes the ripples from the output of rectifier and
smoothens the D.C. Output received from this filter is constant until the mains voltage and load is
maintained constant. However, if either of the two is varied, D.C. voltage received at this point
changes. Therefore a regulator is applied at the output stage.
www.BEProjectReport.com
Page 35
CHAPTER 3
SOFTWARE REQUIREMENTS
SOFTWARE TOOLS
Softwares used in our project are
1. Kiel vision
2. Pro load
WHAT IS VISION3?
Vision3 is an IDE (Integrated Development Environment) that helps you write, compile,
and debug embedded programs. It encapsulates the following components:
A project manager.
A make facility.
Tool configuration.
Editor.
A powerful debugger.
www.BEProjectReport.com
Page 36
1.
2.
3.
Page 37
4.
Save the Project by typing suitable project name with no extension in u r own folder
Then Click on OK
Then Click either YES or NOmostly NO
Now double click on the Target1, you would get another option
www.BEProjectReport.com
Page 38
11.
12.
13.
Click on the file option from menu bar and select new.
Now start writing program in either in C or ASM
For a program written in Assembly, then save it with extension . asm and for C
based program save it with extension .C
Now right click on Source group 1 and click on Add files to Group Source
15.
16.
17.
Now you will get another window, on which by default C files will appear.
Now select as per your file extension given while saving the file
Click only one time on option ADD
www.BEProjectReport.com
Page 39
18.
Now Press function key F7 to compile. Any error will appear if so happen.
19.
20.
21.
22.
23.
24.
25.
Then Click OK
Now click on the Peripherals from menu bar.
Drag the port a side and click in the program file.
Now keep Pressing function key F11 slowly and observe.
You are running your program successfully
www.BEProjectReport.com
Page 40
4.2 PROLOAD:
Proload is software which accepts only hex files. Once the machine code is converted into
hex code, that hex code has to be dumped into the microcontroller placed in the programmer kit and
this is done by the Proload. Programmer kit contains a microcontroller on it other than the one which
is to be programmed. This microcontroller has a program in it written in such a way that it accepts
the hex file from the keil compiler and dumps this hex file into the microcontroller which is to be
programmed. As this programmer kit requires power supply to be operated, this power supply is
given from the power supply circuit designed above. It should be noted that this programmer kit
contains a power supply section in the board itself but in order to switch on that power supply, a
source is required. Thus this is accomplished from the power supply board with an output of 12volts
or from an adapter connected to 230 V AC.
1.
2.
3.
4.
5.
www.BEProjectReport.com
Page 41
CHAPTER 4
WORKING PROCEDURE OF PROJECT
WORKING PROCEDURE:
The working of this project starts when the user tries to consume the power i.e. when he
switches on any of the electrical appliances in his house. When these electrical appliances are
switched on, they consume some power. The meter fixed outside the house will display the number
of consumed units.
The main concept of the project lies in buying the energy card from the electrical department,
inserting it into the energy card fixed in the house; consume it according to the number of units
available in the card. The product that we developed uses 89S52 Microcontroller to control all the
functions.
This project consists of two EEPROMs, one to store the no. of units consumed and second is to load
the units into EEPROM just as similar to recharge card. Initially the units in EEPROM are zero. The
system will be in OFF state until and unless the user recharges. Here the system is connected to a
lamp load. Now, as the power consumption increases the rate of pulses from the optocoupler output
of the energy meter increases and the microcontroller counts these pulses , when these pulses reaches
a specific number which depends on the meter constant of energy meter one unit is decremented
from the total units stored in EEPROM and these values are displayed on 16X2 LCD. In this process
at every instant the count value and units values are stored in EEPROM. Under POWER OFF or
RESET conditions these values are not lost and can be regained by the EEPROM and the count starts
from the updated value only. On decrementing each and every unit the system gives a beep sound
indicating that the unit value has been decremented. System will give a continuous beep sound as the
unit value reaches to zero. When the number of units becomes zero the relay operates and interrupts
supply.
www.BEProjectReport.com
Page 42
CIRCUIT DIAGRAM
www.BEProjectReport.com
Page 43
At this instant the user has to purchase another EEPROM based recharge card or the
user has to recharge by inserting the EEPROM based recharge card in the slots provided for the
recharge in Recharging unit. Here recharging means loading a new units value to the EEPROM
based recharge card. After recharge, the user has to place the EEPROM based recharge card in the
main system slots, if the recharge card is valid then a message is displayed as Recharge successful
and the system automatically turns ON. If it is Invalid then a message is displayed as Invalid card
and gives a continuous beep sound.
www.BEProjectReport.com
Page 44
CHAPTER 5
CONCLUSION
CONCLUSION
In this project Prepaid Energy Meter, energy consumption calculation based on the
counting of pulses is designed and implemented using Atmel 89S52 MCU in embedded system
domain. An LCD is provided to display the number of units remaining, so controlled usage of energy
is possible and this system eliminates burden of electricity billing and saves money and time for
electricity department and consumers respectively.
Presence of every module has been reasoned out and placed carefully thus
contributing to the best working of the unit. Secondly, using highly advanced ICs and with the help
of growing technology the project has been successfully implemented.
This system can be replaced with the GSM Modems, by which tracking of the consumers
load on a timely basis is possible, which will help in tracking maximum demand, detect online theft
and more over instead of recharging the chip, the readily available recharge cards (smart cards) used
in cell phones can be introduced. Using these other mechanisms, consumers can recharge their
meters at their convenience and making the system much more user friendly.
www.BEProjectReport.com
Page 45
CHAPTER 6
SOURCE CODE
INCLUDE REG_51.PDF
RB0
EQU
000H
RB1
EQU
008H
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
;
PORT DECLERATION
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
SDA1 EQU
P2.1
;SDA=PIN5
SCL1 EQU
P2.0
;SCL=PIN6
WTCMD EQU
RDCMD EQU
10100110B
10100111B
WTCMD1 EQU
RDCMD1 EQU
10100000B
10100001B
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
BLINKCUR
EQU
EQU
0CH
0DH
EQU
EQU
01H
0CH
; ***SYSTEM INSTRUCTIONS***
CONFIG
EQU
ENTRYMODE EQU
DSEG
ORG
20H
FLAGS1:
DS
BCDCARRY
CARRY
28H
6
BIT
BIT
1
FLAGS1.0
FLAGS1.1
www.BEProjectReport.com
Page 46
BIT
BIT
READING:
AMOUNT:
COUNTER:
TEMP:
PRICE:
BALANCE:
BUZZ_COUNT:
READ_BYTE:
F1:
F2:
F3:
DS
DS
DS
DS
DS
DS
DS
DS
DS
DS
DS
STACK:
CSEG
DS
;
;
;
FLAGS1.2
FLAGS1.3
2
3
2
1
2
1
1
3
1
1
1
1
; Code begins here
MAIN:
MOV SP,#50H
MOV PSW,#RB0
; Select register bank 0
MOV IE,#10000001B
CALL RESETLCD4
CALL TITLE1
CLR BUZZER
SETB RELAY
CLR TBIT1
MOV BUZZ_COUNT,#00H
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
www.BEProjectReport.com
Page 47
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
CJNE A,#00H,AZX1
CLR BUZZER
AJMP AZX2
DEC BUZZ_COUNT
AZX1:
AZX2:
MOV R1,#READING
;GET DATA IN
MOV R4,#05H
;DATA ADDRESS IN
MOV R6,#2
CALL READ_EEPROM
CALL DISP_READING
MOV TEMP,READING
CALL SEP_DISP
MOV TEMP,READING+1
CALL SEP_DISP
;NUMBER OF BYTES
BYTES(RAM)
EEPROM
CALL DELAYY
MOV R1,#AMOUNT
;GET DATA IN
MOV R4,#0AH
;DATA ADDRESS IN
BYTES(RAM)
EEPROM
MOV R6,#3
CALL READ_EEPROM
CALL AMT_READING
MOV TEMP,AMOUNT
CALL SEP_DISP
MOV TEMP,AMOUNT+1
CALL SEP_DISP
MOV R4,#'.'
CALL WRLCDDATA
www.BEProjectReport.com
;NUMBER OF BYTES
Page 48
CALL DELAYY
MOV R1,#COUNTER
;GET DATA IN
MOV R4,#0EH
;DATA ADDRESS IN
MOV R6,#2
CALL READ_EEPROM
CALL COUNT_READING
MOV TEMP,COUNTER
CALL SEP_DISP
MOV TEMP,COUNTER+1
CALL SEP_DISP
;NUMBER OF BYTES
BYTES(RAM)
EEPROM
;
;
CALL DELAYY
MOV R1,#PRICE
;GET DATA IN
MOV R4,#10H
;DATA ADDRESS IN
MOV R6,#2
CALL READ_EEPROM
;NUMBER OF BYTES
BYTES(RAM)
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
;
INCREMENT COUNTER BY 1
;
IF COUNT=3200 THEN INCREMENT READING
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
INC_COUNTER:
MOV A,COUNTER+1
ADD A,#01
DA A
www.BEProjectReport.com
Page 49
REPPA1:
REPPA2:
REPPA3:
REPPA4:
REPPA:
DCV2:
DVB1:
DCS1:
MOV COUNTER+1,A
CJNE A,#01H,REPPA1
AJMP DCV2
CJNE A,#02H,REPPA2
AJMP DCV2
CJNE A,#03H,REPPA3
AJMP DCV2
CJNE A,#04H,REPPA4
AJMP DCV2
CJNE A,#05H,REPPA
AJMP DCV2
MOV COUNTER,#00H
MOV COUNTER+1,#01H
MOV R1,#COUNTER
MOV R4,#0EH
MOV R6,#2
CALL STORE_EEPROM
CALL DELAY
AJMP DVB1
MOV R1,#COUNTER
MOV R4,#0EH
MOV R6,#2
CALL STORE_EEPROM
CALL DELAY
RET
;store COUNT
;Starting Address IN EEPROM
;STORE 2 BYTES
;store COUNT
;Starting Address IN EEPROM
;STORE 2 BYTES
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
MOV R1,#READING
;store READING
MOV R4,#05H
;Starting Address IN EEPROM
MOV R6,#2
;STORE 2 BYTES
CALL STORE_EEPROM
CALL DELAY
MOV A,AMOUNT+2
CLR C
SUBB A,PRICE+1
CALL BCD_CONV
MOV AMOUNT+2,A
MOV A,AMOUNT+1
TOTAL0
TOTAL1
SUBB A,PRICE
CALL BCD_CONV
MOV AMOUNT+1,A
www.BEProjectReport.com
Page 50
TOTAL2
SUBB A,#00h
CALL BCD_CONV
MOV AMOUNT,A
MOV R1,#AMOUNT
MOV R4,#0AH
MOV R6,#3
CALL STORE_EEPROM
CALL DELAY
FCX1:
CJNE
FAX1:
CJNE
FAAX1:
CJNE
FCX2:
CJNE
FAX2:
CJNE
FAAX2:
CJNE
FCX3:
CJNE
FCX4:
CJNE
;store AMOUNT
;Starting Address IN EEPROM
;STORE 2 BYTES
MOV A,AMOUNT+1
CJNE A,#40H,FCX1
MOV BUZZ_COUNT,#02H
SETB BUZZER
A,#38H,FAX1
MOV BUZZ_COUNT,#02H
SETB BUZZER
A,#41H,FAAX1
MOV BUZZ_COUNT,#02H
SETB BUZZER
A,#20H,FCX2
MOV BUZZ_COUNT,#03H
SETB BUZZER
A,#19H,FAX2
MOV BUZZ_COUNT,#03H
SETB BUZZER
A,#21H,FAAX2
MOV BUZZ_COUNT,#03H
SETB BUZZER
A,#10H,FCX3
MOV BUZZ_COUNT,#04H
SETB BUZZER
A,#11H,FCX4
MOV BUZZ_COUNT,#04H
SETB BUZZER
A,#09H,FAX4
MOV BUZZ_COUNT,#04H
SETB BUZZER
FAX4:
MOV A,AMOUNT+2
CLR C
SUBB A,PRICE+1
CALL BCD_CONV
MOV A,AMOUNT+1
TOTAL0
TOTAL1
SUBB A,PRICE
MOV A,AMOUNT
CLR TBIT
JNC POP1
www.BEProjectReport.com
Page 51
SETB TBIT
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
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
;%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%5
POP1:
READ_BALANCE:
MOV R1,#BALANCE
;GET DATA IN
MOV R4,#15H
;DATA ADDRESS IN
MOV R6,#1
CALL READ_EEPROM
RET
;NUMBER OF BYTES
MOV R1,#COUNTER
;GET DATA IN
MOV R4,#0EH
;DATA ADDRESS IN
MOV R6,#2
CALL READ_EEPROM
RET
;NUMBER OF BYTES
BYTES(RAM)
EEPROM
READ_COUNTER:
BYTES(RAM)
EEPROM
READ_PRICE:
www.BEProjectReport.com
Page 52
;GET DATA IN
MOV R4,#10H
;DATA ADDRESS IN
BYTES(RAM)
EEPROM
MOV R6,#2
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:
DAP2:
DAP4:
DAP5:
ADD A,#30H
MOV R4,A
CALL WRLCDDATA
CALL MDELAY
MOV A,AMOUNT
ANL A,#0FH
ADD A,#30H
MOV R4,A
CALL WRLCDDATA
CALL MDELAY
MOV A,AMOUNT+1
ANL A,#0F0H
SWAP A
ADD A,#30H
MOV R4,A
CALL WRLCDDATA
CALL MDELAY
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
ADD A,#30H
www.BEProjectReport.com
;NUMBER OF BYTES
Page 53
CJNE A,#00H,DAP2
MOV A,AMOUNT+1
ANL A,#0F0H
SWAP A
CJNE A,#00H,DAP4
AJMP DAP5
;CHK 2 DIGIT
;CHK 3 DIGIT
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
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:
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
www.BEProjectReport.com
Page 54
BALP:
CALL OUTS
MOV A,#20H
CALL OUT
MOV A,@R1
CALL OUT
INC R1
DJNZ R6,BALP
CALL STOP
CALL DELAY
RET
;SEND IT
;GET LOW BYTE ADDRESS
;SEND IT
;GET DATA
;SEND IT
;INCREMENT DATA POINTER
;LOOP TILL DONE
;SEND STOP CONDITION
RESET_BALANCE:
MOV BALANCE,#0FFH
MOV R1,#BALANCE
MOV R4,#15H
MOV R6,#1
CALL STORE_EEPROM
CALL DELAY
RET
;store COUNT
;Starting Address IN EEPROM
;STORE 2 BYTES
RESET_PRICE:
MOV PRICE,#01H
MOV PRICE+1,#80H
MOV R1,#PRICE
MOV R4,#10H
MOV R6,#2
CALL STORE_EEPROM
CALL DELAY
RET
;store COUNT
;Starting Address IN EEPROM
;STORE 2 BYTES
RESET_COUNTER:
MOV COUNTER,#00H
MOV COUNTER+1,#03H
MOV R1,#COUNTER
MOV R4,#0EH
MOV R6,#2
CALL STORE_EEPROM
CALL DELAY
RET
;store COUNT
;Starting Address IN EEPROM
;STORE 2 BYTES
RESET_AMT:
MOV AMOUNT,#00H ;
MOV AMOUNT+1,#05H
MOV AMOUNT+2,#00H
MOV R1,#AMOUNT
MOV R4,#0AH
MOV R6,#3
CALL STORE_EEPROM
CALL DELAY
RET
;store READING
;Starting Address IN EEPROM
;STORE 2 BYTES
RESET_READING:
MOV READING,#00H
MOV READING+1,#13H
MOV R1,#READING
www.BEProjectReport.com
;store READING
Page 55
www.BEProjectReport.com
;store COUNT
;Starting Address IN EEPROM
;STORE 2 BYTES
NEW RECHARGE
;GET DATA IN BYTES(RAM)
;DATA ADDRESS IN EEPROM
;NUMBER OF BYTES
;store READING
Page 56
RESETX_CHIP:
BBLP:
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
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:
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
www.BEProjectReport.com
Page 57
BTLP:
MOV A,#WTCMD
CALL OUTS
MOV A,R4
CALL OUT
MOV A,@R1
CALL OUT
INC R1
DJNZ R6,BTLP
CALL STOP
RET
www.BEProjectReport.com
Page 58
;##########################################################
;
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:
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
www.BEProjectReport.com
Page 59
www.BEProjectReport.com
Page 60
www.BEProjectReport.com
Page 61
www.BEProjectReport.com
Page 62
RET
; Return to Caller
; **********************************************************
; 1 MILLISECOND DELAY ROUTINE
; **********************************************************
MDELAY:
PUSH
MOV
ACC
A,#0A6H
INC
NOP
NOP
NOP
NOP
NOP
NOP
NOP
NOP
JNZ
NOP
POP
RET
PUSH
MOV
ACC
A,#036H
INC
NOP
MD_OLP:
MD_OLP
ACC
MADELAY:
MAD_OLP:
www.BEProjectReport.com
Page 63
MOV
SETB
SETB
NOP
NOP
NOP
CLR
NOP
NOP
R2,#8
SDA1
SCL1
SDA1
www.BEProjectReport.com
Page 64
OTSLP:
BITLS:
OTSL1:
NOP
CLR
RLC
JNC
SETB
JMP
CLR
SETB
NOP
NOP
NOP
SCL1
A
BITLS
SDA1
OTSL1
SDA1
SCL1
;CLOCK = 0
;SHIFT BIT
CLR
DJNZ
SETB
NOP
SCL1
R2,OTSLP
SDA1
;CLOCK LOW
;DECREMENT COUNTER
;TURN PIN INTO INPUT
;NOTE 1
SETB
NOP
NOP
NOP
SCL1
;CLOCK ACK
;NOTE 1
CLR
RET
SCL1
;DATA = 1
;CONTINUE
;DATA = 0
;CLOCK HI
;NOTE 1
;**********************************************************************
; THIS ROUTINE SENDS OUT CONTENTS OF ACCUMLATOR TO EEPROM
; without sending a START condition.
;**********************************************************************
OUT:
OTLP:
BITL:
OTL1:
MOV
RLC
JNC
SETB
JMP
CLR
SETB
NOP
NOP
NOP
R2,#8
A
BITL
SDA1
OTL1
SDA1
SCL1
CLR
DJNZ
SETB
NOP
SCL1
R2,OTLP
SDA1
;CLOCK LOW
;DECREMENT COUNTER
;TURN PIN INTO INPUT
;NOTE 1
SETB
NOP
NOP
NOP
SCL1
;CLOCK ACK
;NOTE 1
CLR
RET
SCL1
www.BEProjectReport.com
;DATA = 1
;CONTINUE
;DATA = 0
;CLOCK HI
;NOTE 1
Page 65
STOP:
CLR
NOP
NOP
NOP
SDA1
SETB
NOP
NOP
NOP
SCL1
;SET CLOCK HI
;NOTE 1
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:
INLP:
INL1:
MOV
SETB
CLR
NOP
NOP
NOP
NOP
R2,#8
SDA1
SCL1
;LOOP COUNT
;SET DATA BIT HIGH FOR INPUT
;CLOCK LOW
;NOTE 1
SETB
CLR
JNB
CPL
RLC
DJNZ
CLR
RET
SCL1
C
SDA1,INL1
C
A
R2,INLP
SCL1
;CLOCK HIGH
;CLEAR CARRY
;JUMP IF DATA = 0
;SET CARRY IF DATA = 1
;ROTATE DATA INTO ACCUMULATOR
;DECREMENT COUNTER
;CLOCK LOW
;*********************************************************************
; 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
www.BEProjectReport.com
Page 66
AKTLP:
AKTLS:
AKTL1:
EXIT:
CLR
RLC
JNC
SETB
JMP
CLR
SETB
NOP
NOP
NOP
SCL1
A
AKTLS
SDA1
AKTL1
SDA1
SCL1
;CLOCK = 0
;SHIFT BIT
CLR
DJNZ
SETB
NOP
SCL1
R2,AKTLP
SDA1
;CLOCK LOW
;DECREMENT COUNTER
;TURN PIN INTO INPUT
;NOTE 1
SETB
NOP
NOP
NOP
SCL1
;CLOCK ACK
;NOTE 1
JNB
JMP
CLR
CLR
NOP
NOP
NOP
SDA1,EXIT
ACKTST
SCL1
SDA1
;DATA = 1
;CONTINUE
;DATA = 0
;CLOCK HI
;NOTE 1
SETB
SCL1
;CLOCK HIGH
NOP
NOP
SETB
SDA1
;STOP CONDITION
RET
;*********************************************************************
END
www.BEProjectReport.com
Page 67
BIBLIOGRAPHY
WEBSITES:
www.8051projects.com/projects/prepaidenergymeter
www.datasheetcatalog.com/datasheets_pdf/A/T/8/9/AT89S52.shtml
http://www.datasheetcatalog.org/datasheet/atmel/doc1919.pdf
www.howstuffworks.com
www.keil.com
www.alldatasheets.com
www.atmel.databook.com
www.BEProjectReport.com
Page 68