Академический Документы
Профессиональный Документы
Культура Документы
CERTIFICATE
This is to certify that the mini project work entitled Smart Energy meter is
a bonafide work carried out by G.L.Prathusha, CH.Vinay kumar, J.Santosh kumar
bearing Reg. No 08D61A0439, 08D61A0424, 08D61A0446 respectively in partial
fulfillment for the award of Degree of BACHELOR OF TECHNOLOGY IN
ELECTRONICS AND COMMUNICATION ENGINEERING of Jawaharlal
Nehru Technological University, Hyderabad during the year 2011-12. It is also
certified that all corrections and suggestions indicating for internal assessment have
been incorporated in the report deposited in department library. The project report has
been approved as it satisfies the academic requirement in respect of project work for
the said degree.
_________________________ ___________________________
RMCE . RMCE .
2)
1
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
KEYWORDS
ACC : Accumulator
B : B Register
PSW : Program Status Word
SP : Stack Pointer
DPTR : Data Pointer
DPL : Low byte
DPH : High byte
P0 : Port 0
P1 : Port 1
P2 : Port 2
P3 : Port 3
IE : Interrupt Enable control
IP : Interrupt Priority control
TMOD : Timer/counter Mode control
TCON : Timer/counter control
T2CON : Timer/counter 2 control
T2MOD : Timer/counter mode2 control
TH0 : Timer/counter 0high byte
TL0 : Timer /counter 0low byte
TH1 : Timer/counter 1high byte
TL1 : Timer/counter 1low byte
TH2 : Timer/counter 2 high byte
TL2 : Timer/counter 2 low byte
SCON : Serial control
SBUF : Serial data buffer
PCON : Power control
IR : Infra Red
2
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
INDEX
ACKNOWLEDGE ------------------------------------ 6
ABSTRACT ------------------------------------ 7
I. INTRODUCTION 9
II. LITERATURE SURVEY
2.1 Motivation 11
2.2 Background 11
2.3 Aim 11
2.4 Requirement Analysis 12
2.4.1 Hardware Requirements 12
2.4.2 Software Requirements 12
2.5 Scope 12
2.6 Advantages 12
III. DESIGN METHODOLOGY
3.1 Hardware system design 14
3.1.1 Block level design of Smart Energy Meter 14
3.1.2 Selection of Hardware 15
3.1.3 Design consideration of Microcontroller 15
3.1.3.1 8051 15
3.1.3.2 Internal architecture of P89C51RD2FN 16
3.1.3.2.1 I/O ports 17
3.1.3.2.2 Interrupt controls 18
3.1.3.2.3 Bus controllers 19
3.1.3.2.4 Memory organization 19
3.1.3.2.5 Registers in 8051
20
3.1.3.2.6 Oscillator 22
3.1.3.3 Features 23
3.1.4 Serial communication 24
3.1.4.1 Introduction 24
3.1.4.2 Baud rate 25
3.1.5 Hardware design of LCD 25
3.1.5.1 LCD screen 26
3.1.5.2 Features 29
3.1.5.3 Pin configuration 29
3.1.5.4 Specifications 30
3.1.5.5 Functionality of LCD in project 32
3.1.6 MAX232 32
3.1.6.1 Pin configuration 33
3.1.7 RS232 (Female port) 33
3.1.7.1 Voltage levels 33
3.1.7.2 Pin configuration 34
3.1.7.3 DB9 interfacing microcontroller using MAX232 34
3.1.8 Serial port connector 35
3.1.9 Design of KEYPAD 35
3
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
IV. IMPLEMENTATION
4.1 Hardware implementation 49
4.1.1 Complete Schematic of Smart Energy Meter 50
4.1.2 Connections of P89C51RD2FN 51
4.1.3 Pin connections of LCD 52
4.1.4 Keypad connections 53
4.1.5 MAX232 and DB9 connections 53
4.1.6 IC555 timer and IR transmitter connections 54
V. SOFTWARE IMPLEMENTATION
5.1 JHD162A LCD interfacing 56
5.1.1 Initialization of LCD 56
5.1.2 Initialization sequence code 56
5.1.3 Checking the busy state of LCD 56
5.1.4 Writing the command to display 57
5.1.5 Writing data to display 57
5.1.6 Displaying the data into LCD 57
5.1.7 4*4 matrix Keypad interfacing 58
5.1.8 Sensors 58
RESULT 66
VII. BIBILOGRAPHY 67
VIII. APPENDIX
KEIL MICROVISION IDE 68
FLASH MAGIC 77
SET UP OF HYPER TERMINAL 80
COMPLETE CODE 83
5
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
ACKNOWLEDGEMENT
6
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
ABSTRACT
Saving energy is high on the agenda for consumers and businesses, but with most of
the electrical devices today, its difficult to know how much energy we are actually
using at any given point in time. Smart Energy Meter is a meter which helps the
consumers to know their day to day power consumption to better control their usage
and producers to manage production. This meter records consumption of electric
energy in intervals of hour or less. Smart meters enable two-way communication
between the meter and the central system. The proposed project comprises of
hardware design using a low-cost 8-bit P89C51RD2xx microcontroller and the
complete hardware design will be proposed .The Communication is through
SMS.They are two one is admin password and second is user. By this admin password
the cost per unit can be changed by the concerned officerThe system software driver
is also developed using embedded-C programming language in Keil Vision 4 IDE. .
Smart meters are also believed to be a less costly alternative to traditional interval or
time-of-use meters and are intended to be used on a wide scale with all customer
classes, including residential customers. The project also addresses about the various
debugging tools such as Keil Vision 4 C51 debugger and Flash magic tool 9.25
version used to test the implemented prototype.
7
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
CHAPTER-1
CHAPTER - I
8
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
INTRODUCTION
Now-a-days electricity has become a basic need to humans. The consumption
of electricity has increased a lot compared to the past years. The theft of electricity
has also become a problem these days and there is no control over the loss due to theft
of electricity. In this project we present you the smart energy meter device used to
measure the consumption of the electricity by the individual and provide security
against theft of electricity.
The term Smart meter often refers to an electricity meter, but it can
increasingly also mean a device measuring natural gas or water consumption. Smart
energy meter is software based, power efficient device that accurately tracks energy
consumption and performs computation. Meter readings can be transmitted to
distributors/utilities over wireless media; thus, eliminating the need of manual meter
reading collection process. The smart energy meter offers major benefits to both
customers and companies in terms of efficiency, reliability, and cost saving.
Imagine if you knew how much energy you were consuming at home at any
time of the day, and knew how much energy each device was using, will you stop
using those energy hog appliances? or use them at the time of the day when the
energy is cheapest? in the economy turmoil we are currently in, I believe all of us are
willing to make those small sacrifices to lower down the bill numbers at the end of the
month.
Smart energy meters are devices that will sit on your home, monitor energy
data from your electricity meter, and let you know how much energy you are using
this put more control on your hands on how you spend your energy at home.
Conventional electricity meters are normally hidden somewhere on a wall on the
basement, and the only time you realize how much energy youve been spending is
when the bill hit the door.
The new smart meters will provide Indian consumers with information
regarding energy consumption that was not previously available with a traditional
meter. This system will allow the easy disconnection of defaulted customers and
power connections from a remote site. The new smart system is also able to instantly
detect tampering with the power lines and sends signals to security personnel if
necessary. Utility employees will also have the ability to change a customers billing
method from pre paid to post paid in a matter of seconds, without having to physically
visit the meter.
9
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
CHAPTER-2
10
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
CHAPTER- II
LITERATURE SURVEY
2.1 MOTIVATION
In the present scenario, the use of advanced technologies such as
digital metering has become extremely necessary to achieve greater efficiency, theft
reduction to reduce AT & C losses and to improve revenue collection. The utilities and
planners should now focus on best use of electronic technology to develop a full
smart system, which is capable of offering long term benefits and comprehensive
solutions in addition to theft reduction. In undeveloped and under developing
countries proper distribution of power has to be done. So its the duty of us, engineers
to develop the equipments to reduce the power losses and power thefts.
2.2 BACKGROUND
An electricity meter or energy meter is a device that measures the
amount of electric energy consumed by a residence, business, or an electrically
powered device. Electricity meters are typically calibrated in billing units, the most
common one being the kilowatt hour. Periodic readings of electric meters establish
billing cycles and energy used during a cycle. In settings when energy savings during
certain periods are desired, meters may measure demand, the maximum use of power
in some interval. In some areas, the electric rates are higher during certain times of
day, to encourage reduction in use. The billing of the electricity consumption in these
present days are done with human observation, but this project deals with the
communication for the proper billing through GSM without any human involvement.
Due to theft of electricity leads to power shut down in many of the rural areas in
India.
2.3 AIM:
To design and implement the smart energy meter by using 8051 micro
controller coded in embedded c program.
11
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
2.5 SCOPE:
The scope of the project work is to introduce advanced technology in
converting dc voltage in to ac voltage and introducing smart energy metering concept.
In future this project can be used to measuring natural gas or water
consumption. These meters can be connected to GSM module and data (i.e.
consumption) can be transmitted over GSM networks and the bills can be
automatically issued to the particular customer through SMS. By making small
modifications in the program (code) we can break the connection if user does not pay
the bills in time. There is no need for the electricity officials to visit the spot to
disconnect the connections i.e., everything can be controlled over the GSM module.
The user can also sell the electricity to the government which is created in his home
using solar cells. These meters can also be used as prepaid energy meters by slightly
modifying them.
2.6 Advantages:
More accurate bills.
Lower bills.
Track of energy usage.
12
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
CHAPTER-3
13
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
CHAPTER - III
DESIGN METHODOLOGY
3.1.3.1 8051
The 8051 is an 8 bit microcontroller originally developed by Intel in 1980. It is
one of the most popular microcontrollers in the world for its high performance, rich
instruction set and low cost. This device is a Single-Chip 8-Bit Microcontroller
manufactured in an advanced CMOS process and is a derivative of the 8051
microcontroller family. The instruction set is 100% compatible with the 8051
instruction set. Three criteria in choosing the microcontrollers are as follows:
15
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
1. Meeting the computing needs of the task at hand efficiently and cost
effectively.
2. Availability of software development tools such as compliers,
assemblers, and debuggers.
3. Wide availability and reliable sources of the microcontroller.
Some of the features that have made the 8051 popular are:
4 register banks.
16
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
17
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
The 4I/O ports of 8051 are designated as port 0, port 1, port 2, and port
3. All these I/O ports have different functions and conditions while connecting to
external peripherals.
Timer 0 and timer 1 interrupts can be used in pooling method. In this method,
we have to wait until the TF is raised. The problem with this method is that the
microcontroller is tied down the controller. If the timer interrupt in the IE register is
enabled, whenever the timer rolls over, TF is raised, and the microcontroller is
interrupted in whatever it is doing, and jumps to the interrupts vector table to service
the ISR.
Reset pin is an input pin and is active high (normally low). Upon applying a
high pulse to this pin, the microcontroller will reset and terminate all activities. This is
often referred to as power-on reset. In order for RESET input to be effective, it must
have a minimum duration of two machine cycles. In other words, the high pulse must
be high for a minimum of two machine cycles before it is allowed to go low. TXD and
RXD are serial communication interrupts.
RST (Reset):
19
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
A high on this pin for two machine cycles while the oscillator is running
resets the device. An internal resistor to VSS permits a power-on reset using only an
external capacitor to VCC.
The first models of the 8051 microcontroller family did not have internal
program memory. It was added as an external separate chip. These models are
recognizable by their label beginning with 803 (for example 8031 or 8032). All later
models have a few Kbyte ROM embedded. Even though such an amount of memory
is sufficient for writing most of the programs, there are situations when it is necessary
to use additional memory as well. A typical example is so called lookup tables. They
are used in cases when equations describing some processes are too complicated or
when there is no time for solving them. In such cases all necessary estimates and
approximates are executed in advance and the final results are put in the tables
(similar to logarithmic tables).
Data Memory is used for temporarily storing data and intermediate results
created and used during the operation of the microcontroller. Besides, RAM memory
built in the 8051 family includes many registers such as hardware counters and timers,
input/output ports, serial data buffers etc. The previous models had 256 RAM
locations, while for the later models this number was incremented by additional 128
registers. However, the first 256 memory locations (addresses 0-FFh) are the heart of
memory common to all the models belonging to the 8051 family.
20
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
21
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
0 0 BANK 0 (00H-07H)
0 1 BANK 1 (08H0FH)
1 0 BANK 2 (10H-17H)
1 1 BANK 3 (18H-1FH)
Carry flag:
Carry flag is set whenever there is carry out from the MSB. This flag is
after 8bit ADD/SUB operation. It can also be set to 1 or 0 directly using SETB C or
CLR C
Auxiliary carry:
If there is a carry from D3 to D4 position during Add/Sub operation,
this bit will set. Otherwise, it is cleared. This flag is used for BCD operations.
Parity flag reflects the number of 1s in A. If A contains an odd number
of 1s, then P=1. Therefore P=0, if A has an even number of 1s.
Overflow flag:
This flag is set whenever the result of a signed number operation is too
large to be accommodated in 7 bits, causing the higher order bit to overflow into the
sign bit.
22
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
3.1.3.2.6 Oscillator:
To synchronize with timer1 (TH1) to set the baud rate as 9600 we need to set
those register value as -3 (decimal) or FD (Hexadecimal) so as to divide the baud rate
i.e.. 28800Hz should be dividing with the decimal value of TH1 to get 9600 value.
23
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
C1, C2 = 33pF.
3.1.3.3 FEATURES
80C51 Central Processing Unit
On chip Flash Program Memory with In-System Programming (ISP) and In-
Application Programming
Boot ROM contains low level Flash programming routines for downloading
via the UART
Can be programmed by the end-user application(IAP)
Supports 6-clock/12 clock mode via parallel programmer(default clock mode
after Chip Erase is 12-clock)
Speed up to 20MHz with 6-clock cycles per machine cycle
(40MHz equivalent performance), up to 33MHz with 12 clocks per machine
cycle
RAM expandable externally to 64Kbytes
Four interrupt priority levels
Seven interrupt sources
Four 8-bit I/O ports
Full-duplex enhanced UART
8-Bit ALU , with 2 registers A & B
11 bit program counter & data pointer
8-Bit program status word
8 bit stack pointer
4registers banks, each containing 8 registers
16bytes , which may be addressed at bit level
80 bytes of general purpose data
Two 16 bit timer/counter T0 & T1
Control registers TCON, TMOD, SCON, PCON and IP & IE oscillator & clock
circuits.
3.1.4.1 Introduction
In order to connect microcontroller to a modem or a pc to modem a serial port
is used. Serial is a very common protocol for device communication that is standard
on almost every PC. Most computers include two RS-232 based serial ports. Serial is
also a common communication protocol that is used by many devices for
24
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
In our project, we use a JHD162A LCD Display which has 2 rows and 16
characters. It contains internal 1 byte latch. It has a better contrast and a wider
viewing angle. To develop a protocol to interface this LCD with 89C51 first we have
to understand how they functions. These displays contain two internal byte-wide
registers, one for command and second for characters to be displayed. There are three
25
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
control signals called R/W, RS and EN. Select By making RS signal 0 you can send
different commands to display. These commands are used to initialize LCD, to display
pattern, to shift cursor or screen etc. You can see the markings right next to 1st and
16th pins. The 16by2 LCD with connections is as given below
The main control pins on JHD162A are data lines, read or write and enable.
LCD is finding wide spread use replacing LEDs (seven segment LEDs or
other multi segment LEDs) because of the following reasons:
1. The ability to display numbers, characters and graphics. This is in contrast to
LEDs, which are limited to numbers and a few characters.
2. Incorporation of a refreshing controller into the LCD, thereby relieving the
CPU of the task of refreshing the LCD. In contrast, the LED must be refreshed
by the CPU to keep displaying the data.
3. Ease of programming for characters and graphics.
26
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
4. These components are specialized for being used with the microcontrollers,
which means that they cannot be activated by standard IC circuits. They are
used for writing different messages on a miniature LCD.
The timing diagram for write and read operation of JHD162A is as follows
27
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
Write operation:
Read operation:
mode if you want to give an Instruction to the LCD. Example Clear the display,
Move cursor to home etc. You have to activate the character mode if you want to
tell the LCD to display some character. To set the LCD in Instruction mode, you set
the 4th pin of the LCD (R/S) to GND. To put it in character mode, you connect it to
Vcc.
3.1.5.2 Features
RS232 compatible serial interface (2400 & 9600 Baud Selectable)
Externally selectable serial polarities (Inverted & Non-Inverted)
Serially controllable contrast and backlight levels
8 user programmable custom characters
16 Byte serial receive buffer
D3 (Not Used in
Pin2 VCC (+5) Pin10
4bit operation)
Data/Comman
Pin4 Pin12 D5
d (R/S)
Read/Write
Pin5 Pin13 D6
(W)
D0 (Not Used
Pin7 in 4bit Pin15 VCC (LEDSV+)
operation)
D1 (Not Used
Pin8 in 4bit Pin16 Ground
operation)
3.1.5.4 SPECIFICATIONS:
29
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
Duty: 1/16
View direction: Wide viewing angle
30
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
To start with LCD the user should initialize it first which should be
programmed with its LCD commands. The LCD commands are given
31
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
32
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
To ensure data transfer between PC and microcontroller, the baud rate and
voltage levels of Microcontroller and PC should be the same. The voltage levels of
microcontroller are logic1 and logic 0 i.e., logic 1 is +5V and logic 0 is 0V. But for
PC, RS232 voltage levels are considered and they are: logic 1 is taken as -3V to -25V
and logic 0 as +3V to +25V. So, in order to equal these voltage levels, MAX232 IC is
33
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
used. Thus this IC converts RS232 voltage levels to microcontroller voltage levels
and vice versa.
34
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
The RS-232 standard defines the voltage levels that correspond to logical one
and logical zero levels for the data transmission and the control signal lines.
For data transmission lines (TxD, RxD and their secondary channel
equivalents) logic one is defined as a negative voltage, the signal condition is called
marking, and has the functional significance. Logic zero is positive and the signal
condition is termed spacing.
35
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
36
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
37
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
The photo transmitters are IR LEDs or photo diodes used to emit light.
IR LEDs are just like LEDs which emits IR rays. Since the IR rays are out of the
visible range we cannot observe the rays from the transmitter. A photodiode is a type
of photo-detector capable of converting light into either current or voltage, depending
upon the mode of operation.
Photodiodes are similar to regular semiconductor diodes except that they may
be either exposed (to detect vacuum UV or X-rays) or packaged with a window or
optical fibre connection to allow light to reach the sensitive part of the device. Many
diodes designed for use specifically as a photodiode will also use a PIN junction
rather than the typical PN junction.
39
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
1. Transistor
2. TCRT5000 IR transmitter
3. TCRT5000 IR receiver
4. 100ohms , 220ohms resistor (near transmitter)
5. 22ohms,4.7ohms resister (near receiver)
40
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
3.1.10.3 Applications:
3.1.10.4 FEATURES:
= 940 nm
Chip material =GaAs with AlGaAs window
Medium Emission Angle, 40
High Output Power
Package material and color: Clear, untinted, plastic
Ideal for remote control applications
3.1.10.5 IR Receiver:
41
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
3.1.10.6 Phototransistors:
The electrons that are generated by photons in the base-collector junction are
injected into the base, and this current is amplified by the transistor operation. Note
that although phototransistors have a higher responsiveness for light they are unable
to detect low levels of light any better than photodiodes. Phototransistors also have
slower response times.
43
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
3.1.12 Resistors:
3.1.13 Capacitors:
A capacitor (formerly known as condenser) is a device for storing electric
charge. The forms of practical capacitors vary widely, but all contain at least two
conductors separated by a non-conductor. Capacitors used as parts of electrical
systems, for example, consist of metal foils separated by a layer of insulating film.
A capacitor is a passive electronic component consisting of a pair of
conductors separated by a dielectric (insulator). When there is a potential difference
(voltage) across the conductors, a static electric field develops across the dielectric,
44
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
causing positive charge to collect on one plate and negative charge on the other plate.
Energy is stored in the electrostatic field. An ideal capacitor is characterized by a
single constant value, capacitance, measured in farads. This is the ratio of the electric
charge on each conductor to the potential difference between them.
Capacitors are widely used in electronic circuits for blocking direct current
while allowing alternating current to pass, in filter networks, for smoothing the output
of power supplies, in the resonant circuits that tune radios to particular frequencies
and for many other purposes.
The capacitor is a reasonably general model for electric fields within electric
circuits. An ideal capacitor is wholly characterized by a constant capacitance C,
defined as the ratio of charge Q on each conductor to the voltage V between them:
45
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
Quartz crystals are manufactured for frequencies from a few tens of kilohertz
to tens of megahertz. More than two billion (2109) crystals are manufactured
annually. Most are used for consumer devices such as wristwatches, clocks, radios,
computers, and cell phones. Quartz crystals are also found inside test and
measurement equipment, such as counters, signal generators, and oscilloscopes.
Before you using the LCD, the program must initialize and configure it. This
is accomplished by sending a number of initialization instructions to the LCD.
The first instruction to send is the no of data for the LCD i.e., with an 8-bit or
4-bit data bus. The other thing need to specify is display matrix; in the selected LCD
it is a 5x8 dot character font. These two options are selected by sending the command
38h to the LCD as a command. The command can give to the LCD by invoking the
pre defined function call lcdcmd with passing parameters value of 38H, the syntax for
the same can be given like lcdcmd (0x38).
46
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
47
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
48
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
Start
RS=0 RS=0
E=1
Delay
E=1
E=0
LCD Delay
Busy
P0=command
LCD
Busy
49
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
3.2.2 KEYPAD:
3.2.2.1 FLOW CHART OF KEY BOARD SCANNING ALGORITHM
50
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
51
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
CHAPTER - 4
CHAPTER 4
52
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
IMPLEMENTATION
53
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
The crystal oscillator which gives a frequency of 11.0592 MHz for the
required Baud rate of 9600Hz to the microcontroller. This crystal oscillator is
connected in between 18th (XALT 1) and 19th (XALT 2) pins of
P89C51RD2FN controller.
The 20th pin of controller is grounded.
The pins from 21st to 28th (port 2 data lines) are used for the external peripheral
connections.
The 29th pin is connected to an on-off switch so as to dump and execute the
program. Whenever the PSEN pin is connected to ground then we can execute
the last dumped program, likewise when 29th pin is connected to VCC then
code can be dumped into the controller.
Address Latch Enable pin (30th pin) of controller is connected to the ground
hence no connections need not to be given to this pin.
External Access Enable or programming supply voltage should be latched
when RST is released and any subsequent changes have no effect. This pin
also receives the programming supply voltage (VPP) during Flash
programming. Hence the pin 31st must be connected to high i.e. VCC.
Port0 (pins 32 to 39) are connected to LCD in this project. But these should be
connected to other peripherals through pull up resistors.
The 1st and 2nd pins of JHD162A LCD are connected to ground and high
voltage VCC respectively.
3rd pin of LCD is connected to the centre pin of the potentiometer or variable
resistor so as to adjust the contrast of LCD.
The 4th, 5th, 6th pins are connected to 26th (P 2.5), 27th (P 2.6), 28th (P 2.7) pins
of the microcontroller respectively.
The 7th to 14th pins are data pins and are connected to the 39th (P 0.0) to 32nd (P
0.7) pins of the microcontroller respectively.
The 15th and 16th pins are used for backlight purpose. 15th pin is connected to
VCC and 16th pin to ground.
55
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
56
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
57
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
CHAPTER - 5
58
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
CHAPTER-5
SOFTWARE IMPLEMENTATION
60
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
61
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
5.1.8 SENSORS:
62
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
CHAPTER - 6
63
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
Chapter 6
DEBUGGING TECHNIQUES
6.1.2 Features
The Keil 8051 Development Tools are designed to solve the complex problems
facing embedded software developers.
When starting a new project, simply select the microcontroller you use from the
Device Database and the vision IDE sets all compiler, assembler, linker, and
memory options for you.
Numerous example programs are included to help you get started with most
popular embedded 8051 devices.
The Keil Vision Debugger accurately simulates on-chip peripherals (CAN,
UART, SPI, Interrupts, I/O Ports, A/D Convertor, D/A convertor, and PWM
64
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
1. Install Keil Micro Vision in your PC, Then after Click on that Keil UVision icon.
After opening the window go to toolbar and select Project Tab then close previous
project.
2. Next select New Project from Project Tab.
3. Then it will open Create New Project window. Select the path where you want to
save project and edit project name.
4. Next it opens Select Device for Target window, it shows list of companies and
here you can select the device manufacturer company.
5. For an example, for your project purpose you can select the chip as 89c51rd2xx
from Philips Group. Next Click OK Button, it appears empty window here you can
observe left side a small window i.e., Project Window. Next create a new file.
6. From the Main tool bar Menu select File Tab and go to New, then it will open a
window, there you can edit the program.
7. Here you can edit the program as which language will you prefer either Assembly
or C.
8. After editing the program save the file with extension as .c or .asm, if you write
a program in Assembly Language save as .asm or if you write a program in C
Language save as .c in the selected path.
9. Then after saving the file, compile the program. For compilation go to project
window select source group and right click on that and go to Add files to
Group.
10. Here it will ask which file has to add. For an example here you can add test.c as
you saved before
11. After adding the file, again go to Project Window and right click on your c file
then select Build target for compilation. If there is any Errors or Warnings in
your program you can check in Output Window that is shown bottom of the Keil
window.
12. Here in this step you can observe the output window for errors and warnings
65
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
13. If you make any mistake in your program you can check in this slide for which
error and where the error is by clicking on that error
14. After compilation then next go to Debug Session. In Tool Bar menu go to
Debug tab and select Start/Stop Debug Session.
15. Write a program for Leds Blinking. LEDS are connected to PORT-1. you can
observe the output in that port.
16. To see the Ports and other Peripheral Features go to main toolbar menu and select
peripherals.
17. In this slide see the selected port i.e., PORT-1.
18. Start to trace the program in sequence manner i.e, step by step execution and
observe the output in port window
19. After completion of Debug Session Create an Hex file for Burning the Processor.
Here to create a Hex file goes to project window and right click on Target next
select Option for Target.
20. It appears one window; here in target tab modify the crystal frequency as you
connected to your microcontroller.
21. Next go to Output tab. In that Output tab click on Create HEX File and then
click OK.
22. Finally Once again compile your program. The Created Hex File will appear in
your path folder
6.2.1 Features
Five simple steps to erasing and programming a device and setting key options
Check which Flash blocks are blank or in use with the ability to easily erase
all blocks in use
66
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
Reprogram the Boot Vector and Status Byte with the help of confirmation
features that prevent accidentally programming incorrect values.
Display the contents of Flash in ASCII and Hexadecimal formats
Single-click access to the manual, Flash Magic home page and NXP
Microcontrollers home page
Use high-speed serial communications on devices that support it.
Control the DTR and RTS RS232 signals to place the device into Boot ROM
and Execute modes automatically (requires hardware support)
Send commands to place the device in Boot loader mode
Powerful, flexible Just In Time Code feature. Write your own JIT Modules to
generate last minute code for programming, for example serial number
generation.
Displays information about the selected Hex File, including the creation and
modification dates, flash memory used, percentage of the current device used
Read the device signature
Build your own Flash Magic based applications using the DLLs for C, C++,
Python
Build your own Flash Magic based applications using .NET languages
(Windows only)
67
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
1. From the Windows Start menu, choose All Programs, and then
choose Accessories.
2. Choose Communications, and then choose HyperTerminal.
3. In the Connection Description dialog box, in the Name box, type a name for
the connection to your SDB.
4. From the Icon list, choose an icon to represent your connection, and then
choose OK.
5. In the Connect To dialog box, in the Connect using box, choose the
communications (COM) port on the development workstation through which
you want to receive messages from the SDB.
The COM port that you choose must be the COM port on the development
workstation to which you attach the null modem cable.
6. Choose OK.
7. In the COM<Port Number> Properties dialog box, modify the settings for
your connection so that the settings are correct for your BSP.
While considering the microcontroller, the voltage level at 30th pin must be
1.6V because of the following reason
1. The voltage supply to the kit or mainly processor is 5V.
2. The duty cycle of the microcontroller is 33%
Duty Cycle = T on / (T on+T off)
Where T off = 2* T on
DC = 1/ (1+2)
DC= 0.333
Hence the voltage at 30th pin should be product of Duty Cycle and voltage
supply VCC. Therefore the voltage should be 1.6V.
3. The voltage levels at 2nd and 6th pins of MAX232 should be -10V and
+10V respectively.
CONCLUSION
68
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
RESULTS
Now the most awaited part of the program is final result which can be seen
by the following steps once the kit is ready.
Give 5V Power supply and connect the pc with serial connector to DB9
connector
Now ON the circuit.
We can see on the LCD display WELCOME RMCE SMART ENERGY
METER and press enter (E) in keypad.
The LCD asks for user id and password. Once they are correct, it shows
AUTHENTICATED.
Now main menu is displayed having options:1.Readings
2. Settings
69
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
7. BIBILOGRAPHY:
Janci Gillespie Mazidi, Muhammad Ali Mazidi, The 8051 micro controller and
embedded systems, PHI Prentice hall India, Eastern Economy Edition,
www.phindia.com.
http://en.wikipedia.org/wiki/Level_s
APPENDICES
70
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
72
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
73
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
14. Now double click on the Target1, you would get another option Source
group 1 as shown in next page.
15. Click on the file option from menu bar and select new.
74
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
16. The next screen will be as shown in next page, and just maximize it by
double clicking on its blue boarder.
75
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
19. Now right click on Source group 1 and click on Add files to Group
Source.
76
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
21. Now select as per your file extension given while saving the file
22. Click only one time on option ADD.
23. Now Press function key F7 to compile. Any error will appear if so
happen.
77
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
78
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
28. Drag the port a side and click in the program file.
29. Now keep Pressing function key F11 slowly and observe.
30. You are running your program successfully.
FLASH MAGIC:
Flash Magic is a PC tool for programming flash based microcontrollers from
NXP using a serial or Ethernet protocol while in the target hardware.
79
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
80
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
81
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
6) Then by browsing the required HEX file we can dump the code into controller by
pressing START button.
Setup of HyperTerminal
Go to
1. Start Menu>> Programs >> Accessories >> Communications >> Hyper Terminal
After that HyperTerminal window will open. If it prompt for checking of default
program as shown in fig, then say yes to it.
2. Click Yes
3. Type Connection Name as 8051 (or as per your Choice)
82
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
4. Select COM PORT (1, 2, 3 etc) whichever is available. (NOTE: Very Less USB-
TO Serial Converters as Reliable)
So use Standard Serial Port
84
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
7. Now burn the Hex File (Given) and Switch on the Circuit after Connecting
Specified Serial Port .You will see output as Follows:
If everything works fine you will see Hello World on the screen. Otherwise check
your setup.
COMPLETE CODE:
The complete source code for the project entitled as Smart Energy Meter using
Hyper Terminal is given below.
#include <reg51f.h>
sbit r0=P1^0;
sbit r1=P1^1;
sbit r2=P1^2;
sbit r3=P1^3; //rows
sbit c0=P1^4;
sbit c1=P1^5;
sbit c2=P1^6;
sbit c3=P1^7; //columns
85
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
86
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
if (Flag==1)
{
Count++;
Flag=0;
}
}
void lcdcmd (unsigned char value)
{
lcdready();
ldata=value;
rs=0;
rw=0;
en=1;
MSDelay(1);
en=0;
}
void lcddata (unsigned char value)
{
lcdready();
ldata=value;
rs=1;
rw=0;
en=1;
MSDelay(1);
en=0;
}
void lcdready(void)
{
busy=1;
87
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
rs=0;
rw=1;
while(busy==1)
{
en=0;
MSDelay(1);
en=1;
}
}
88
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
TH1=0xFD;
SCON=0x50;
TR1=1;
}
void sertx(unsigned char x)
{
SBUF=x;
while(TI==0);
TI=0;
}
void SendString(unsigned char count,unsigned char *DATA)
{
unsigned char i;
for(i=0;i<count;i++)
{
sertx(DATA[i]);
}
}
void sendintdata(unsigned int p)
{
unsigned int temp;
temp=p;
sertx(temp/1000+0x30);
temp=temp%1000;
sertx(temp/100+0x30);
temp=temp%100;
sertx(temp/10+0x30);
sertx(temp%10+0x30);
}
89
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
90
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
return '8';
else if(c2==0)
return '9';
else if(c3==0)
return 'C'; // Down Arrow
r3=0; r0=1;r1=1;r2=1;
if(c0==0)
return 'E';
else if(c1==0)
return '0';
else if(c2==0)
return 'F'; // Redail
else if(c3==0)
return 'D'; // Enter
}
}
}
// update service
void UpdateService(void)
{
unsigned int Temp;
Temp=0;
key=0;
while(1)
{
if(Temp!=Count)
{
MSDelay(50); // Intentional Delay of 0.1mSec.
Temp=Count;
91
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
LCDClear();
lcdcmd(0x80);
WriteString(11,"Total units:");
lcddata(Temp/1000+0x30);
Temp=Temp%1000;
lcddata(Temp/100+0x30);
Temp=Temp%100;
lcddata(Temp/10+0x30);
lcddata(Temp%10+0x30);
lcdcmd(0xc0);
WriteString(13,"1.send 2.exit");
do
{
key=KeyTest();
}
while(key!='1'&&key!='2');
switch(key)
{
case '1':
{
SendString(26,"\r\ncustomer no:9491327686\r\n");
SendString(10,"units are:");
sendintdata(Count);
LCDClear();
lcdcmd(0x80);
WriteString(9,"data send");
lcdcmd(0xC0);
WriteString(4,"1:ok");
do
92
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
{
key=KeyTest();
}
while(key!='1');
MainMenu();
break;
}
case '2':
{
MainMenu();
break;
}
}
}
}
}
void MainMenu(void) // Start of project
{
unsigned char key;
unsigned char mode;
// unsigned char Sensor, Data[3];
key=0;
// Sensor=0;
/*do
{
key=KeyTest();
}
while(key!='E');*/
LCDClear();
93
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
lcdcmd(0x80);
LCDClear();
WriteString(10,"1. Reading");
lcdcmd(0xC0);
WriteString(11,"2. settings");
do
{
key=KeyTest();
}
while(key!='1'&&key!='2');
switch(key)
{
case '1':
{
//Count=0;
LCDClear();
lcdcmd(0x80);
//void Init_GSM();
/* Sensor=MyData;
Data[0]=(Sensor/100)+0x30;
Sensor=Sensor%100;
Data[1]=(Sensor/10)+0x30;
Data[2]=(Sensor%10)+0x30;
if(((Data[0]+(Data[1]*10))+Data[2])<30)
WriteString(3,Data);*/
WriteString(6,"units:");
lcddata(Count/1000+0x30);
Count=Count%1000;
lcddata(Count/100+0x30);
94
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
Count=Count%100;
lcddata(Count/10+0x30);
lcddata(Count%10+0x30);
lcdcmd(0xc0);
WriteString(16,"press 2 to Exit:");
UpdateService();
MainMenu();
break;
}
case '2':
{
LCDClear();
lcdcmd(0x80);
WriteString(14,"1.Rs/Unit 2.ID");
lcdcmd(0xC0);
WriteString(13,"3.pwd 6.ph no");
do
{
key=KeyTest();
}
while(key!='1'&&key!='2'&&key!='3'&&key!='6');
mode=key;
switch(key)
{
case '1':
LCDClear();
lcdcmd(0x80);
WriteString(16,"Rs Per Unit=3.50");
lcdcmd(0xC0);
95
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
WriteString(15,"1:change 2:exit");
do
{
key=KeyTest();
}
while(key!='1'&&key!='2');
switch(key)
{
case '1':
Start();
break;
case '2':
MainMenu();
break;
};
break;
case '2':
LCDClear();
lcdcmd(0x80);
WriteString(15,"Change User ID:");
lcdcmd(0xC0);
WriteString(15,"1:change 2:exit");
do
{
key=KeyTest();
}
while(key!='1'&&key!='2');
switch(key)
{
96
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
case '1':
Start();
break;
case '2':
MainMenu();
break;
}
case '3':
LCDClear();
lcdcmd(0x80);
WriteString(11,"Pwd is 1234");
lcdcmd(0xC0);
WriteString(15,"1:change 2:exit");
do
{
key=KeyTest();
}
while(key!='1'&&key!='2');
switch(key)
{
case '1':
Start();
break;
case '2':
MainMenu();
break;
}
break;
case '6':
97
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
LCDClear();
lcdcmd(0x80);
WriteString(16,"Ph no:9491327686");
lcdcmd(0xC0);
WriteString(15,"1:change 2:exit");
do
{
key=KeyTest();
}
while(key!='1'&&key!='2');
switch(key)
{
case '1':
Start();
break;
case '2':
MainMenu();
break;
}
break;
}
}
}
}
void Start(void)
{
unsigned char key;
unsigned char uid[4],loop,pwd[4]={'0','0','0','0'};
key=0x00;
98
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
/* do
{
key=KeyTest();
}
while(key!='E'); // wait for enter. */
LCDClear();
WriteString(8,"User ID:");
loop=0;
do
{
key=KeyTest();
if(key>='0' && key<='9')
{
uid[loop]=key;
lcddata(key);
loop++;
MSDelay(100);
}
}
while(loop!=4);
lcdcmd(0xC0);
WriteString(9,"Password:");
loop=0;
key=0;
do
{
key=KeyTest();
if(key>='0' && key<='9')
{
99
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
pwd[loop]=key;
lcddata('*');
MSDelay(100);
loop++;
}
}
while(key!='E');
LCDClear();
if((pwd[0]==MY_PWD[0])&&
(pwd[1]==MY_PWD[1])&&
(pwd[2]==MY_PWD[2])&&
(pwd[3]==MY_PWD[3]))
{
WriteString(15,"Authenticated!!");
MSDelay(50);
MainMenu();
}
else
{
WriteString(16,"Access Denied!!!");
lcdcmd(0xC0);
WriteString(15,"1:change 2:exit");
do
{
key=KeyTest();
}
while(key!='1'&&key!='2');
switch(key)
{
100
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
case '1':
Start();
break;
case '2':
MainMenu();
break;
}
}
}
void LCDClear(void)
{
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);
}
void main(void)
{
IE=0x81;
sense=1;
Flag=0;
Count=0;
serialinit();
lcdcmd(0x38);
lcdcmd(0x0E);
lcdcmd(0x01);
lcdcmd(0x06);
lcdcmd(0x80);
//MyData=0xFF;
101
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)
SMART ENERGY METER
WriteString(16,"Welcome ECE@MVSR");
lcdcmd(0xC0);
WriteString(16,"SMART ENERGY Mtr");
//Start();
MSDelay(10);
MainMenu();
}
102
Raja Mahendra College Of Engineering,
Ibrahimpatnam, Ranga Reddy Dist- 501 506. (A.P.)