Professional Documents
Culture Documents
INTRODUCTION
1.1 OVERVIEW
From the early days till today meter reading for electricity consumption and billing is
done by human operators from houses to houses. This therefore requires a very large number of
human operators and long working hours to acquire complete data reading and billing in a
particular area. However, there may be cases where human operators miss to bill few houses in
an area or restricted and slowed down by bad weather condition, transportation problems, etc.
Moreover human operators are very much likely to make mistake while billing or reading a
meter and sometimes the houses electric power meter may be placed in a location where it is not
easily accessible. Again printed billing has the tendency of being lost in the mail box or being
never delivered. Day by day due to the increasing number of residential housings and
commercial buildings, more human operators and longer working hours is needed to complete
the meter reading task which eventually increases the energy provider operation costs for meter
reading.
To achieve efficient meter reading, reduce billing error and operation costs, an Automatic
Electric Meter reading system can be introduced with every energy meter in an area. It is an
effective means of data collection that allow substantial saving through the reduction of meter re
read, greater data accuracy, frequent reading, improved billing and customer service, more
energy profiles and consumption trends updates and better deployment of human resource.
"Electricity meter reading using GSM" implements the emerging applications of the
GSM technology. GSM is a Global system for mobile communication (GSM) and is a wide area
wireless communications system that uses digital radio transmission to provide voice, data, and
multimedia communication services. A GSM system coordinates the communication between
mobile telephones (mobile stations), base stations (cell sites), and switching systems. Each GSM
radio channel is 200 KHz wide channels that are further divided into frames that hold 8 time
slots. The GSM system includes mobile telephones (mobile stations), radio towers (base
stations), and interconnection switching systems. We have selected a particular GSM modem
1
SIM300 for our project. The message are sent from the mobile set that contain commands in
written form which are then processed accordingly to perform the required task. The proposed
approach for designing this system is to implement microcontroller based control module that
receives its instructions and command from a cellular phone over the GSM network. The
microcontroller then will carry out the issued commands and then communicate the status of a
given appliance or device back to the cellular phone. First, the sent SMS is stored and polled
from the receiver mobile station and then the required control signal is generated and sent to the
intermediate hardware that we have designed according to the command received in form of the
sent message.
Many companies came up with automatic meter reading system with GSM and few
companies came up with smart home technologies which involve control of home appliances.
Here control of home appliances includes ON and OFF of electrical and electronic home
appliances. Our project involves both automatic meter reading system and load control system.
Therefore our project provides billing information to the user as well as also helps the user to
control the load (home appliance).
billed. The system was implemented using Visual Basic and database in order to perform the
prototype and the system works successfully in sending SMS to user for notification.
CHAPTER 2
HARDWARE DEVELOPMENT
2.1 BLOCK DIAGRAM
Figure 2.1 Block diagram of GSM based electricity system with load control
BLOCKS
Transformer
Rectifier
Voltage Regulator
Micro Controller
Energy Meter
Comparator
GSM Modem
Crystal Oscillator
Relay Driver
Relay
Load
LCD Display
COMPONENT USED
Step down transformer
Bridge rectifier
LM7805
AT89S52
Electro-mechanical type
LM358
SIM 300
11.0592 MHz
ULN2003A
SPDT Relay
Any electrical appliance
162 LCD Display
Mains Transformer
Rectifier
Filter
Regulator
Here 5V D.C. output is used as power supply to AT89S52 Microcontroller, RF
Transmitter & Receiver pair and LCD display etc and 12 Volt D.C. power supply is mainly used
for relays.
Filter circuit which is usually a capacitor acts as a surge arrester always follows the
rectifier unit. This capacitor is also called as a decoupling capacitor or a bypass capacitor, is used
not only to short the ripple with frequency to ground but also leave the frequency of the DC to
appear at the output.
2.2.1.4 Voltage Regulators
The voltage regulators play an important role in any power supply unit. The
primary purpose of a regulator is to aid the rectifier and filter circuit in providing a constant DC
voltage to the device. Power supplies without regulators have an inherent problem of changing
DC voltage values due to variations in the load or due to fluctuations in the AC line voltage.
With a regulator connected to DC output, the voltage can be maintained within a close tolerant
region of the desired output.
11
Port 0: Port 0 is an 8-bit open drain bidirectional I/O port. As an output port, each pin can sink
eight TTL inputs. When 1s are written to port 0 pins, the pins can be used as high-impedance
inputs. Port 0 can also be configured to be the multiplexed low-order address/data bus during
accesses to external program and data memory. In this mode, P0 has internal pull-ups. Port 0 also
receives the code bytes during Flash programming and outputs the code bytes during program
verification. External pull-ups are required during program verification.
Port 1: Port 1 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 1 output buffers
can sink/source four TTL inputs. When 1s are written to Port 1 pins, they are pulled high by the
internal pull-ups and can be used as inputs. As inputs, Port 1 pins that are externally being pulled
low will source current (IIL) because of the internal pull-ups. In addition, 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, as shown in the following table. Port 1 also receives the
low-order address bytes during Flash programming and verification.
Port Pin
Alternate Functions
P1.0
P1.1
P1.5
P1.6
P1.7
Port 2: Port 2 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 2 output buffers
can sink/source four TTL inputs. When 1s are written to Port 2 pins, they are pulled high by the
internal pull-ups and can be used as inputs. As inputs, Port 2 pins that are externally being pulled
low will source current (IIL) because of the internal pull-ups. Port 2 emits the high-order address
byte during fetches from external program memory and during accesses to external data memory
that uses 16-bit addresses (MOVX @ DPTR). In this application, Port 2 uses strong internal pullups when emitting 1s. During accesses to external data memory that uses 8-bit addresses
(MOVX @ RI), Port 2 emits the contents of the P2 Special Function Register. Port 2 also
receives the high-order address bits and some control signals during Flash programming and
verification.
12
Port 3: Port 3 is an 8-bit bidirectional I/O port with internal pull-ups. The Port 3 output buffers
can sink/source four TTL inputs. When 1s are written to Port 3 pins, they are pulled high by the
internal pull-ups and can be used as inputs. As inputs, Port 3 pins that are externally being pulled
low will source current (IIL) because of the pull-ups. Port 3 receives some control signals for
Flash programming and verification. Port 3 also serves the functions of various special features
of the AT89S52, as shown in the following table.
Port Pin
Alternate Functions
P3.0
P3.1
P3.2
0 (external interrupt 0)
P3.3
(external interrupt 1)
P3.4
P3.5
P3.6
WR
(external data memory write strobe)
P3.7
RD
(external data memory read strobe)
Table 2.3 Alternate Functions of Port 3
RST: Reset input. A high on this pin for two machine cycles while the oscillator is running resets
the device. This pin drives high for 98 oscillator periods after the Watchdog times out. The
DISRTO bit in SFR AUXR (address 8EH) can be used to disable this feature. In the default state
of bit DISRTO, the RESET HIGH out feature is enabled.
ALE/PROG: Address Latch Enable (ALE) 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. Note, however,
that one ALE pulse is skipped during each access to external data memory. If desired, ALE
operation can be disabled by setting bit 0 of SFR location 8EH. With the bit set, ALE is active
only during a MOVX or MOVC instruction. Otherwise, the pin is weakly pulled high. Setting the
ALE-disable bit has no effect if the microcontroller is in external execution mode.
13
PSEN: Program Store Enable (PSEN) is the read strobe to external program memory. When the
AT89S52 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.
XTAL1: Input to the inverting oscillator amplifier and input to the internal clock operating
circuit.
XTAL2: Output from the inverting oscillator amplifier.
Memory Organization: MCS-51 devices have a separate address space for Program and Data
Memory. Up to 64K bytes each of external Program and Data Memory can be addressed.
Program Memory: If the EA pin is connected to GND, all program fetches are directed to
external memory. On the AT89S52, if EA is connected to VCC, program fetches to addresses
0000H through 1FFFH are directed to internal memory and fetches to addresses 2000H through
FFFFH are to external memory.
Data Memory: The AT89S52 implements 256 bytes of on-chip RAM. The upper 128 bytes
occupy a parallel address space to the Special Function Registers. This means that the upper 128
bytes have the same addresses as the SFR space but are physically separate from SFR space.
When an instruction accesses an internal location above address 7FH, the address mode used in
the instruction specifies whether the CPU accesses the upper 128 bytes of RAM or the SFR
space. Instructions which use direct addressing access the SFR space. For example, the following
direct addressing instruction accesses the SFR at location 0A0H (which is P2). MOV 0A0H,
#data instructions that use indirect addressing access the upper 128 bytes of RAM. For example,
the following indirect addressing instruction, where R0 contains 0A0H, accesses the data byte at
address 0A0H, rather than P2 (whose address is 0A0H). MOV @R0, #data Note that stack
14
operations are examples of indirect addressing, so the upper 128 bytes of data RAM are available
as stack space.
Oscillator Characteristics
XTAL1 and XTAL2 are the input and output, respectively, of an inverting amplifier
that can be configured for use as an on-chip oscillator, as shown in Figure 16-1. Either a quartz
crystal or ceramic resonator may be used. To drive the device from an external clock source,
XTAL2 should be left unconnected while XTAL1 is driven, as shown in Figure 16-2. There are
no requirements on the duty cycle of the external clock signal, since the input to the internal
clocking circuitry is through a divide-by-two flip-flop, but minimum and maximum voltage high
and low time specifications must be observed.
15
functions registers remain unchanged during this mode. The idle mode can be terminated by any
enabled interrupt or by a hardware reset. Note that when idle mode is terminated by a hardware
reset, the device normally resumes pro-gram execution from where it left off, up to two machine
cycles before the internal reset algorithm takes control. On-chip hardware inhibits access to
internal RAM in this event, but access to the port pins is not inhibited. To eliminate the
possibility of an unexpected write to a port pin when idle mode is terminated by a reset, the
instruction following the one that invokes idle mode should not write to a port pin or to external
memory.
2.3.5.2 Power-Down Mode
In the Power-down mode, the oscillator is stopped, and the instruction that invokes
Power-down is the last instruction executed. The on-chip RAM and Special Function Registers
retain their values until the Power-down mode is terminated. Exit from Power-down mode can be
initiated either by a hardware reset or by an enabled external interrupt. Reset redefines the SFRs
but does not change the on-chip RAM. The reset should not be activated before VCC is restored
to its normal operating level and must be held active long enough to allow the oscillator to restart
and stabilize.
Mode
Program
ALE
Idle
Idle
Power-Down
Power-Down
Memory
Internal
External
Internal
External
1
1
0
0
Port 0
PSEN
1
1
0
0
Data
Float
Data
Float
Port 1
Port 2
Port 3
Data
Data
Data
Data
Data
Address
Data
Data
Data
Data
Data
Data
Table 2.4 Status of External Pins During Idle and Power-Down Mode
all the conventional op-amp circuits, which can now be more easily implemented in single
power supply systems. For example, these circuits can be directly supplied with the standard
+5 V, which is used in logic systems and will easily provide the required interface electronics
with no additional power supply.
Very low supply current per operator essentially independent of supply voltage
18
2.4.1.2 Specification
stabilize frequencies for radio transmitters and receivers. The most common type of piezoelectric
resonator used is the quartz crystal, so oscillator circuits incorporating them became known as
crystal oscillators, but other piezoelectric materials including polycrystalline ceramics are used in
similar circuits.
Quartz crystals are manufactured for frequencies from a few tens of kilohertz to hundreds
of megahertz. More than two billion 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.
drivers, and logic buffers. The ULN2003 has a 2.7k series base resistor for each darlington pair
for operation directly with TTL or 5V CMOS devices.
21
22
23
2.6.2 RESISTORS
A resistor is a passive two-terminal electrical component that implements electrical resistance as
a circuit element. Resistors act to reduce current flow, and, at the same time, act to lower voltage
levels within circuits. In electronic circuits resistors are used to limit current flow, to adjust
signal levels, bias active elements, terminate transmission lines among other uses. High-power
resistors that can dissipate many watts of electrical power as heat may be used as part of motor
controls, in power distribution systems, or as test loads for generators. Fixed resistors have
resistances that only change slightly with temperature, time or operating voltage. Variable
resistors can be used to adjust circuit elements (such as a volume control or a lamp dimmer), or
as sensing devices for heat, light, humidity, force, or chemical activity.
The resistors used in the project are mainly 1K and 10K.
24
Shape
Size
Gender
Connection mechanism
Function
2.6.3.1 Jumpers
Jumpers are small blocks on a circuit board with two or more pins emerging from them. Plastic
plugs containing a wire fit down over the pins. The wire connects the pins and creates a circuit.
To change a jumper setting, pull the plug off its pin(s) and carefully fit it down onto the pin(s)
indicated. A jumper is referred to as open or unjumpered when the plug is pushed down over
only one pin or if there is no plug at all. When the plug is pushed down over two pins, the jumper
is referred to as jumpered. The jumper setting is often shown in text as two numbers, such as 1-2.
The number 1 is printed on the circuit board so that you can identify each pin number based on
the location of pin 1. There are two types of jumper connectors:
1. Male jumper connector
25
26
Base Station Subsystem the base stations and their controllers explained
Network and Switching Subsystem the part of the network most similar to a fixed
network, sometimes just
GPRS Core Network the optional part which allows packet-based Internet connections
27
28
GSM is a cellular network, which means that cell phones connect to it by searching for cells in
the immediate vicinity. There are five different cell sizes in a GSM network
macro, micro, pico, femto, and umbrella cells. The coverage area of each cell varies according to
the implementation environment. Macro cells can be regarded as cells where the base
station antenna is installed on a mast or a building above average rooftop level. Micro cells are
cells whose antenna height is under average rooftop level; they are typically used in urban areas.
Picocells are small cells whose coverage diameter is a few dozen metres; they are mainly used
indoors. Femtocells are cells designed for use in residential or small business environments and
shopping centers or airports. However, this is not a prerequisite, since indoor coverage is also
provided by in-building penetration of the radio signals from any nearby cell.
2.7.2 GSM CARRIER FREQUENCIES
GSM networks operate in a number of different carrier frequency ranges (separated into GSM
frequency ranges for 2G and UMTS frequency bands for 3G), with most 2G GSM networks
operating in the 900 MHz or 1800 MHz bands. Where these bands were already allocated, the
850 MHz and 1900 MHz bands were used instead (for example in Canada and the United
States). In rare cases the 400 and 450 MHz frequency bands are assigned in some countries
because they were previously used for first-generation systems.
Most 3G networks in Europe operate in the 2100 MHz frequency band. For more information on
worldwide GSM frequency usage, see GSM frequency bands.
Regardless of the frequency selected by an operator, it is divided into timeslots for individual
phones. This allows eight full-rate or sixteen half-rate speech channels per radio frequency.
These eight radio timeslots (or burst periods) are grouped into a TDMA frame. Half-rate
channels use alternate frames in the same timeslot. The channel data rate for all 8
channels is 270.833 kbit/s, and the frame duration is 4.615 ms.
The transmission power in the handset is limited to a maximum of 2 watts in GSM
850/900 and 1 watt in GSM 1800/1900.
2.7.3 SUBSCRIBER IDENTITY MODULE (SIM)
One of the key features of GSM is the Subscriber Identity Module, commonly known as a SIM
card. The SIM is a detachable smart card containing the user's subscription information and
phone book. This allows the user to retain his or her information after switching handsets.
Alternatively, the user can also change operators while retaining the handset simply by changing
the SIM. Some operators will block this by allowing the phone to use only a single SIM, or only
a SIM issued by them; this practice is known as SIM locking.
30
with USIM to prevent connections to fake base stations and downgrade attacks, users will be
protected in the medium term, though migration to 128-bit GEA/4 is still recommended.
32
The most common unit of measurement on the electricity meter is the kilowatt hour [kWh],
which is equal to the amount of energy used by a load of one kilowatt over a period of one hour,
or 3,600,000 joules. Some electricity companies use the SI megajoule instead. There are two
types of energy meters. They are:
2.8.1 ELECTROMECHANICAL METERS
The most common type of electricity meter is the electromechanical induction watt-hour meter.
The electromechanical induction meter operates by counting the revolutions of a non-magnetic,
but electrically conductive, metal disc which is made to rotate at a speed proportional to the
power passing through the meter. The number of revolutions is thus proportional to the energy
usage. The voltage coil consumes a small and relatively constant amount of power, typically
around 2 watts which is not registered on the meter. The current coil similarly consumes a small
amount of power in proportion to the square of the current flowing through it, typically up to a
couple of watts at full load, which is registered on the meter.
The disc is acted upon by two sets of coils, which form, in effect, a two phase induction motor.
One coil is connected in such a way that it produces a magnetic flux in proportion to
the voltage and the other produces a magnetic flux in proportion to the current. The field of the
voltage coil is delayed by 90 degrees, due to the coil's inductive nature, and calibrated using a lag
coil. This produces eddy currents in the disc and the effect is such that a force is exerted on the
disc in proportion to the product of the instantaneous current, voltage and phase angle (power
factor) between them. A permanent magnet exerts an opposing force proportional to the speed of
rotation of the disc. The equilibrium between these two opposing forces results in the disc
rotating at a speed proportional to the power or rate of energy usage. The disc drives a register
mechanism which counts revolutions, much like the odometer in a car, in order to render a
measurement of the total energy used.
33
34
of
displaying
special
&
even custom
characters (unlike
in
seven
36
Pin
No
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Function
Name
Ground (0V)
Ground
Supply voltage; 5V (4.7V 5.3V)
Vcc
Contrast adjustment; through a variable resistor
VEE
Selects command register when low; and data register when
Register Select
high
Low to write to the register; High to read from the register
Read/write
Sends data to data pins when a high to low pulse is given
Enable
DB0
DB1
DB2
DB3
8-bit data pins
DB4
DB5
DB6
DB7
Backlight VCC (5V)
Led+
Backlight Ground (0V)
Led-
37
CHAPTER 3
IMPLEMENTATION AND WORKING
Implementation part includes bringing together all the hardware components used in the project
and interfacing them to the microcontroller which is the heart of the project. We need to interface
GSM modem, LCD display and energy meter to the microcontroller.
38
Serial communication takes place between GSM module and microcontroller. This serial
communication is achieved by RS232 serial protocol.
3.1.1 RS-232 SERIAL PROTOCOL
One of the most common serial interfaces is based on the RS-232 standard. This standard was
developed to allow individuals to use remote computer systems over dialup telephone lines with remote
terminals. The standard includes provisions for a remote terminal that is connected to a modem that
places a telephone call, a modem that answers the telephone call, and a computer that is connected to
that modem. The terminal can be connected directly to the computer, eliminating the need for two
modems, through the use of a special device called a null modem adapter. Sometimes this device is built
directly into a cable, in which case the cable is called a null modem cable.
3.1.2 AT COMMANDS
GSM modem communicates with the microcontroller in the form of AT commands. Here AT
refers to attention.
39
information required and the result code. This information is received by the microcontroller and
it displays the result in the LCD display.
Overview of AT Commands
AT+CMGD
AT+CMGF
AT+CMGL
AT+CMGR
AT+CMGS
AT+CMGW
AT+CMSS
AT+CMGC
AT+CNMI
AT+CPMS
AT+CRES
AT+CSAS
AT+CSCA
AT+CSCB
AT+CSDH
AT+CSMP
AT+CSMS
Description
DELETE SMS MESSAGE
SELECT
SMS
MESSAGE
FORMAT
LIST SMS MESSAGES FROM
PREFERRED STORE
READ SMS MESSAGE
SEND SMS MESSAGE
WRITE SMS MESSAGE TO
MEMORY
SEND SMS MESSAGE FROM
STORAGE
SEND SMS COMMAND
NEW
SMS
MESSAGE
INDICATIONS
PREFERRED SMS MESSAGE
STORAGE
RESTORE SMS SETTINGS
SAVE SMS SETTINGS
SMS
SERVICE
CENTER
ADDRESS
SELECT CELL BROADCAST SMS
MESSAGES
SHOW SMS
TEXT MODE
PARAMETERS
SET
SMS
TEXT
MODE
PARAMETERS
SELECT MESSAGE SERVICE
40
microcontroller, then microcontroller sends logic 1 or 0 as per the received symbol, to relay
driver this switches the relay 1 to ON 0 to OFF and hence load is controlled.
CHAPTER 4
RESULTS
At first when initializing the Electricity Meter Reading using GSM system, the
microcontroller sends command to operate the GSM modem. The GSM modem will now
PROJECT OUTLOOK
43
Firstly an initial message is displayed on the LCD. It indicates that we need to send a message to
the stored mobile number in the GSM module.
In the first step we need to send a message which may contain any symbol to stored number in
GSM module. Then an acknowledgment is received to the mobile which acknowledges us that
the mobile number has been registered.
44
In order to ON the load we need to send symbol * as a message to the GSM modem. The GSM
modem sends the symbol to microcontroller. Then the loads are switched ON.
45
The loads are switched OFF by sending the symbol #. The acknowledgement is displayed on
the LCD display.
To get the meter reading we have to send @ symbol as text message and the meter reading is
displayed on the LCD display as well as an SMS is sent to the mobile also.
46
CONCLUSION
There is a lot of wastage of power due to inefficient consumption of electricity by
consumers. The distribution company, most of the time, has to receive huge amounts due to
pending bills which results in substantial revenue losses and also causes hurdles to
modernization because of lack of funds. The consumer, on the other hand, is facing problems like
receiving due bills for bills that have already been paid and poor reliability of electricity supply.
The remedy for all these problems is to keep track of the consumers load on a
timely basis, which will help assure accurate billing, track maximum demand, and detect online
theft. These are all the features to be taken into account for designing an efficient energy billing
system. The present project incorporates these features to address the problems faced by both the
consumers and the distribution companies.
47
REFERENCES
1. Dr.T. Vigneswaran, M. Srikarthik and S. Altamash, Modern Electricity Billing System
Using GSM, International Conference on Computing and Control Engineering (ICCCE),
Vol 40, pp. 315-317,12 and 13April, 2012
2. M.A. Mazidi and Janice G. Mazidi And Rolin D. Mckinlay, The 8051 Microcontroller
and Embedded
3. Systems Using Assembly and C Prentice Hall, pp. 300-330.
4. Frederic P. Miller, Agnes F. Vandome, GSM: Cellular Network, Subscriber Identity
Module 2004.
5. The ATMEL AT89S52 8-Bit Microcontroller, 8KB ISP Flash
6. http://www.atmel.com/devices/AT89S52.aspx
7. Prepaid
electricity
billing
system
using
GSM
mobile
http://www.seminarprojects.com/Threadprepaid-energy-meter-using-gsmmobile#
ixzz1BUylZEck
8. http://probots.co.in/Manuals/SIM300.pdf
9. http://www.engineersgarage.com/tutorials/at-commands
10. Ramakant A. Gayakwad, Op-Amps and Linear Integrated Circuit PHI Learning, 4th
edition, pp. 315-317
APPENDIX
48
Program code:
#include<reg51.h>
#include<string.h>
#include"serial.h"
#define lcd_data P2
sbit lcd_rs = P2^0;
sbit lcd_en = P2^1;
sbit relay1 = P1^0;
sbit relay2= P1^1;
sbit mtr = P1^2;
int energy_val,relay_val;
int amt;
unsigned char rcv;
unsigned char rcg,pastnumber[11],i,count;
void lcdcmd(unsigned char value)
// LCD COMMAND
{
lcd_data=value&(0xf0); //send msb 4 bits
lcd_rs=0; //select command register
lcd_en=1; //enable the lcd to execute command
delay(3);
lcd_en=0;
lcd_data=((value<<4)&(0xf0)); //send lsb 4 bits
lcd_rs=0; //select command register
lcd_en=1; //enable the lcd to execute command
delay(3);
lcd_en=0;
}
void lcd_init(void)
{
lcdcmd(0x02);
lcdcmd(0x02);
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
lcdcmd(0x28); //intialise the lcd in 4 bit mode*/
lcdcmd(0x0e);
lcdcmd(0x06);
lcdcmd(0x01);
//cursor blinking
//move the cursor to right side
//clear the lcd
}
void lcddata(unsigned char value)
{
lcd_data=value&(0xf0); //send msb 4 bits
lcd_rs=1; //select data register
49
50
lcddata(a);
lcddata(c);
lcddata(d);
return 1;
}
unsigned convert(unsigned int value)
{
unsigned char a,b,c,d;
a=value/100;
b=value%100;
c=b/10;
d=b%10;
a=a|0x30;
c=c|0x30;
d=d|0x30;
sertx(a);
sertx(c);
sertx(d);
return 1;
}
void main()
{
unsigned int pulse_val=0;
relay1=0;
relay2=0;
mtr=1;
51
lcd_init();
lcdcmd(0x01);
lcdcmd(0x80);
msgdisplay("ENERGY METER BASED DEVICE");
delay(100);
serinit();
sertxs("AT\r\n");
sertxs("AT+CMGF=1\r\n");
sertxs("AT+CNMI=1,2,0,0\r\n");
lcdcmd(0x01);
msgdisplay("SEND MESSAGE TO STR MOBL NUM");
do
{
rcg=receive();
}while(rcg != '+');
for(count=0;count<9;count++)
{
rcg=receive();
}
for(count=0;count<10;count++)
{
pastnumber[count]=receive();
}
sertxs("AT+CMGS=\"");
sertxs(pastnumber);
sertxs("\"\r\n");
sertxs("Mobile no. registered\r\n");
sertx(0x1A);
lcdcmd(0x01);
msgdisplay("MOBILE NUMBER IS REGISTERED");
delay(200);
lcdcmd(0x01);
sie();
delay(10);
msgdisplay("ENERGY METER BAS");
while(1)
{
if(relay_val==1)
{ relay_val=3;
relay1=1;
52
relay2=1;
lcdcmd(0x01);
msgdisplay("LIGHTS ON");
}
else if(relay_val==2)
{
relay_val=3;
relay1=0;
relay2=0;
lcdcmd(0x01);
msgdisplay("LIGHTS OFF");
}
if(energy_val==1)
{ sid();
energy_val=0;
sertxs("AT+CMGS=\"");
sertxs(pastnumber);
sertxs("\"\r\n");
sertxs("READING:");
sertxs("\"\r\n");
convert(pulse_val);
sertxs("\r\n");
sertx(0x1A);
sie();
}
if(mtr==0)
{
pulse_val++;
lcdcmd(0xc0);
msgdisplay("PULSE:");
convert1(pulse_val);
while(mtr == 0);
}
}
}
void serial_int (void) interrupt 4
{
if (RI == 1)
{
53
//
rcv = SBUF;
/* read the character into our local buffer */
RI = 0;
/* clear the received interrupt flag */
}
//
lcdcmd(0x01);
msgdisplay("* rcvd");
if(rcv=='*')
{
relay_val=1;
}
else if(rcv=='#')
{
relay_val=2;
}
else if(rcv=='@')
{
energy_val=1;
rcv=0; } }
}
SOFTWARE DESCRIPTION
This project is implemented using following software:
Embedded Keil C language
54
A project manager
A make facility
Tool configuration
Editor
A powerful debugger
BUILDING AN APPLICATION
To build (compile, assemble, and link) an application in uVision2, you must:
.
Select Project - Rebuild all target files or Build target. UVision2 compiles, assembles,
Select Project - Select Device and select an 8051, 251, or C16x/ST10 device from the
Device
Database
Select Project - Targets, Groups, and Files. Add/Files, select Source Group1, and add the
source files to the project.
Select Project - Options and set the tool options. Note when you select the target device
from the Device Database all-special options are set automatically. You only need to
configure the memory map of your target hardware. Default memory model settings are
optimal for most.
APPLICATIONS:
.
Use the Step toolbar buttons to single-step through your program. You may enter G, main
in the Output Window to execute to the main C function.
Open the Serial Window using the Serial #1 button on the toolbar.
Debug your program using standard options like Step, Go, Break, and so on.
PERIPHERAL SIMULATION
The Keil debugger provides complete simulation for the CPU and on chip peripherals of
most embedded devices. To discover which peripherals of a device are supported, in u vision2.
Select the Simulated Peripherals item from the Help menu. You may also use the web-based
56
device database. We are constantly adding new devices and simulation support for on-chip
peripherals so be sure to check Device Database often.
2.
3.
4.
57
5.
Save the Project by typing suitable project name with no extension in u r own folder
sited in either C:\ or D:\
6.
7.
8.
9.
59
10.
Then Click on OK
11.
12.
13.
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
60
16.
The next screen will be as shown in next page, and just maximize it by double
clicking on its blue boarder.
17.
18.
For a program written in Assembly, then save it with extension . asm and for C
based program save it with extension .C
61
19.
Now right click on Source group 1 and click on Add files to Group Source
20.
Now you will get another window, on which by default C files will appear.
62
21.
Now select as per your file extension given while saving the file
22.
23.
Now Press function key F7 to compile. Any error will appear if so happen.
24.
25.
63
26.
Then Click OK
27.
Now Click on the Peripherals from menu bar, and check your required port as shown
in fig below
28.
64
29.
30.
65