+ All Categories
Home > Documents > Prepaid Electricity Billing System

Prepaid Electricity Billing System

Date post: 23-Oct-2014
Category:
Upload: eswar-ayyappa
View: 181 times
Download: 8 times
Share this document with a friend
Popular Tags:
109
ABSTRACT: The present practice of electricity billing is manual method only. With this, the total billing is a time consuming process and it requires more manpower. The collection of billing is late procedure and so many consumers may not pay in time. Disconnecting of unpaid connections is also manual. Due to all these drawbacks we cannot have proper auditing. Lack of awareness on power consumption and also the present energy meters displays only units, so the user cannot plan his usage of power. To avoid all these problems, we are introducing this system. In this system, a micro controller is interfaced with an energy metering circuit, keypad and a display, to display total units and balance amount, a contactor to make or break power line, and a buzzer indicator. At the sub-station end, a PC is connected with all energy meters using any communication channel. When the user pays money, he gets a recharge code. When he enters the code, the meter verifies the code with substation and on confirmation; it starts counting the no. of units and reduces the card amount relatively. On completion of amount, it disconnects the line automatically with an alarm prior to that. The consumption data, card status and line status are transmitted to substation for auditing. With this system, we can determine the difference between the actual powers consumed and sold power easily. With this we can easily identify the tampered areas and we can avoid power thefting. 1
Transcript
Page 1: Prepaid Electricity Billing System

ABSTRACT:

The present practice of electricity billing is manual method only. With this, the total

billing is a time consuming process and it requires more manpower. The collection of

billing is late procedure and so many consumers may not pay in time. Disconnecting of

unpaid connections is also manual. Due to all these drawbacks we cannot have proper

auditing.

Lack of awareness on power consumption and also the present energy meters

displays only units, so the user cannot plan his usage of power. To avoid all these

problems, we are introducing this system.

In this system, a micro controller is interfaced with an energy metering circuit,

keypad and a display, to display total units and balance amount, a contactor to make or

break power line, and a buzzer indicator. At the sub-station end, a PC is connected with all

energy meters using any communication channel.

When the user pays money, he gets a recharge code. When he enters the code, the

meter verifies the code with substation and on confirmation; it starts counting the no. of

units and reduces the card amount relatively. On completion of amount, it disconnects the

line automatically with an alarm prior to that. The consumption data, card status and line

status are transmitted to substation for auditing.

With this system, we can determine the difference between the actual powers

consumed and sold power easily. With this we can easily identify the tampered areas and

we can avoid power thefting.

The short message system (SMS) of a standard mobile phone can be used for much more than just

exchanging cryptic message. This application finds a humble mobile working in a remote site monitoring

and controlling external equipments. The SMS service provides by the service providers are comparatively

low cost. Hence the system is highly efficient and low cost.

1

Page 2: Prepaid Electricity Billing System

Thus the system provides an excellent hold as per industrial motion control systems. Mobile

phones have become a widespread means of communication. It becomes a part of everyday life with ever

more people enjoying the service and extra freedom they provide. It works on the basis of Global System

for Mobile Communication (GSM). A subscriber from any systems can access telecommunication services

by using a Subscriber Identity Module (SIM) card in a handset suitable for the network on the visited

system

The Short Message Service allows text messages to be sent and received to and

from mobile telephones. The text can comprise words or numbers or an alphanumeric

combination. Because Simple person - to - person messaging is such an important

component of total SMS traffic volumes, anything that simplifies message generation as

well as extended utility of the SMS being sent is an important enabler of Short Message

Service. Such extended utility of SMS fulfills certain important requirements.

Now a day’s no one is using this type of system in India, but in future in order to

save the energy and get systems automated we should use this type of intelligent system.

Wastage of power is inevitable in large industries. This is because the existing system

provides no check on the consumption and therefore there is a tendency to be careless. If

there was a system that allotted a fixed ration of power for a period then the workers would

be more careful thereby minimizing the electricity loss.

In this project, the present billing system was eliminated completely and a new

system namely prepaid billing system was introduced for embedded applications which

overcomes the drawbacks in present billing system. If this system comes in our day to day

life it will be useful for both the Government and the public.

INTERFACES USED

Embedded controller

16X2 LCD Interfacing.

GSM Modem

Serial communication

Buzzer, switches, led interfacing with micro controller Relay interfacing.

2

Page 3: Prepaid Electricity Billing System

SOFTWARES USED

A Cross compiler for compiling and linking the code written for AT89C51.

Serial communication software for downloading code to AT89C51.

Operating system: Windows XP.

BLOCK DIAGRAM:

3

POWER SUPPLYDISPLAY UNIT

BULB

MICRO CONTROLLER

DRIVER ICBUZZER

MAX232

GSM MODEM

Page 4: Prepaid Electricity Billing System

4

Page 5: Prepaid Electricity Billing System

EMBEDDED SYSTEM

INTRODUCTION TO EMBEDDED SYSTEM

Embedded systems are a system is which performs a specific or a pre-

defined task. It is the combinations of hardware and software. It is nothing but a

computer inside a product. It is a programmable hardware design nothing but an

electronic chip.

A general-purpose definition of embedded systems is that they are devices

used to control, monitor or assist the operation of equipment, machinery or plant.

“Embedded” reflects the fact that they are an integral part of the system. In many cases

their embedded ness may be such that their presence is far from obvious to the casual

observer and even the equipment for sometime before being able to conclude that an

embedded control system was involved in its functioning. At the other extreme a

general-purpose computer may be used to control the operation of a large complex

processing plant, and its presence will be obvious.

All embedded systems are or include computers or microprocessors.

Some of these computers are however very simple systems as compared with a

personal computer.

The very simplest embedded systems are capable of performing only

single functions to meet single functions to meet a single predetermined purpose. In

more complex systems an application program that enables the embedded system to be

used for a particular purpose in a specific application determines the functioning of the

embedded systems. The ability to have programs means that the same embedded

system can be used for a variety of different purpose. In some cases a microprocessor

may be designed in such way that application software for a particular purpose can be

added to the basic software in a second process, after which it is not possible to make

further changes. The applications software on such processors is sometimes referred to

as firmware.

5

Page 6: Prepaid Electricity Billing System

The simplest devices consist of a single microprocessor (often called a “chip”),

which may itself be packaged with other chips in a hybrid systems or Application Specific

Integrated Circuit (ASIC). Its input comes from a detector or sensor and its output goes

to a switch or a activator which (for example) may start or stop the operation of a

machine or, operating a value, may control the flow of fuel to an engine.

PROCESSORS:

Processors are the ones which performs some specific task or operation.

These are divided in to several types like:

1. Digital Signal Processors.

2. Application Specific Integrated Circuits.

3. Micro Processors.

4. Micro Controllers.

Digital Signal Processors:

This is a one which performs scientific and mathematical

Calculations. The output of this type of processors will be in floating point values. Hence,

we can get accurate values as outputs.

Best example of a Digital Signal Processors will be Weather Forecasting.

Applications specific Integrated Circuits:

6

Page 7: Prepaid Electricity Billing System

As the name itself specifies, this is integrated circuit designed for a specific

application. IC designed for one specific application cannot be used in other

applications.

Best Example for ASIC will be Cell phone card.

Microprocessors:

These are the ones which perform arithmetic and logical operations.

Block Diagram of Microprocessor:

Arithmetic and logical unit performs arithmetical and logical calculations. Control

unit controls all the peripheral devices connected to the microprocessors. Memory is a

one which is used to store some data or information.

Best Example for a microprocessor will be our Personal Computer.

Micro Controllers:

These are the ones which are similar to that of a microprocessor which performs

arithmetic and logical calculations. These have additional advantage to that it is having

additional inbuilt features like:

7

Page 8: Prepaid Electricity Billing System

1. Electrically Erasable Programmable Read Only Memory (EEPROM)

2. Universal Synchronous Asynchronous Receiver and Transmitter (USART).

3. Analog to Digital Converter (ADC).

4. Digital to Analog Converter (DAC).

5. Oscillators.

6. Timers.

7. Many others.

The output of a microcontroller is a always in integer format only. It cannot provide

accurate values or floating point values.

Best Example for Micro Controller will be Traffic Light Controller.

Out of all these Processors, we are using Micro Controllers.

Coming to the software point of View, we have many software languages. Out of all, we

are using Assembly Level Language to load the program in to the controller.

ALP coding is done and loaded into the microcontroller. These are different

companies that manufacture Microcontrollers like Atmel, Motorola, Intel, Philips, PIC,

etc.

We are using Atmel manufactured microcontrollers. Atmel Company manufactures

different series of microcontrollers like

8

Page 9: Prepaid Electricity Billing System

AT89C, AT90S, ATMega, ATCAN. Here we are using ATMega Microcontrollers.

Again in ATMega we are having different ATMega 8, ATMega 8515, ATMega 16,

ATMega 32,

AT Mega 162v, etc.Here, in this project we are using AT89c51 Microcontroller.

Introduction to applications of Embedded System:

Embedded Controllers may be found in many different kinds of system and are

used for many different applications. The list, which follows, is a indicative rather than

exhaustive. An item in the list may be relevant to a particular company because either

(a) It is or involves a core process or product,

(b) It is or involves an ancillary function or services performed by the company or

(c) It refers to a product or services provided by a contractor under some form of

agreement and the vulnerability of the supplier may need to be considered.

List of Applications of Embedded Systems:

(a) Manufacturing and process control:

Manufacturing plants.

Water and sewage systems.

Power stations.

Power grid systems.

Oil refineries and related storage facilities.

Bottling plants.

Automated factories.

Simulators.

Test equipment for control system development, maintenance and testing.

(b) Construction industry:

Surveying and location Equipment.

Construction Plant.

(c) Transport:

Aero planes

Trains and Buses.

Marine craft (known cases include: radar mapping; ballast monitoring; cargo

loading; ship main control system)

9

Page 10: Prepaid Electricity Billing System

Automobiles

Fuel services.

Air Traffic Control Systems.

Signaling system.

Radar Systems.

Traffic Lights.

Ticketing systems and Machines.

Car Parking and other meters.

(d) Buildings and premises:

Electrically supply- supply, measurement, control, protection.

Backing lighting and generators.

Fire control systems.

Heating and ventilating systems.

Lifts Elevators, escalators.

Security Systems.

Security Cameras.

Door locks.

(e) Domestic service:

Catering.

Cleaning.

(f) Communications:

Telephone.

Cable systems.

Telephone switches.

Satellites.

(g) Office systems and mobile management:

Telephone systems

Faxes and Copier.

Time recording systems.

Mobile telephones

Still and Video Cameras.

(h) Banking, Finance and Commercial:

Automated teller systems.

Credit card Systems.

10

Page 11: Prepaid Electricity Billing System

Point of scale systems including scanner / cash systems.

11

Page 12: Prepaid Electricity Billing System

CHAPTER – 2

OVER VIEW OF THE PROJECT

12

Page 13: Prepaid Electricity Billing System

CHAPTER 3

HARDWARE DETAILS OF THE PROJECT

The basic circuit diagram of the project as shown in the Fig2 describes

the necessary connections that are to be made while designing the hardware module of

the project.

There are different hardware modules in this project. They are:

1. 8051 Microcontroller (AT89c51)

2. Transformer

3. Power supply board

4. Serial communication

5. GSM MODEM

6. 16X2 LCD DISPLAY

7. OBCTACLE SENSOR

8. GAS SENSOR

9. FIRE SENSOR

MICROCONTROLLER

13

Page 14: Prepaid Electricity Billing System

a. MICROCONTROLLER:

A microcontroller is an integrated chip with minimum required devices. The

microcontroller includes a CPU: ALU, PC,SP and registers, RAM, ROM, I/O ports, and

timers like a standard computer, but because they are designed to execute only a single

specific task to control a single system, they are much smaller and simplified so that they

can include all the functions required on a single chip.

Fig 2.1: Microcontroller Block Diagram.

Most microcontrollers will also combine other devices such as:

A Timer module to allow the microcontroller to perform tasks for certain time

periods.

A serial I/O port to allow data to flow between the microcontroller and other

devices such as a PC or another microcontroller.

An ADC to allow the microcontroller to accept analogue input data for

processing.

14

Page 15: Prepaid Electricity Billing System

Fig 2.2: Functional Block Diagram of Microcontroller.

2. MICROCONTROLLER Vs MICROPROCESSOR:

1. A microcontroller is meant to be more self-contained and independent, and functions

as a tiny, dedicated computer than microprocessor.

2. The microcontroller may function as a computer with addition of external digital parts;

the microprocessor must have many additional parts to be operational.

3. Most microprocessors have many operational codes (opcodes) for moving data from

external memory to the CPU; microcontrollers may have one or two.

ALU

ACCUMULATOR

REGISTERS

STACK POINTER

TIMER/COUNTER

INTERNAL

ROM

PROGRAM COUNTER

I/O

PORTS

I/O

PORTS

INTERNAL

CIRCUITS

CLOCK CIRCUIT

INTERNAL

RAM

15

A BLOCK DIAGRAM OF MICROCONTROLLER (EXPANDED)

Page 16: Prepaid Electricity Billing System

4. Microcontrollers are designed by using CMOS (complementary metal oxide

semiconductor) technology, an efficient fabrication technique that uses less power and is

more immune to power spikes than other techniques.

3. ADVANTAGES OF MICROCONTROLLERS:

Their powerful, cleverly chosen electronics is able to control a variety of

processes and devices (industrial automatics, voltage, temperature, engines, etc)

independently or by means of I/O instruments such as switches, buttons, sensors, LCD

screens, relays etc.

4. TYPES OF 8051 MICROCONTROLLER:

The 8051 has the widest range of variants of any embedded controller on the

market. The smallest device is the Atmel 89c1051, a 20 Pin FLASH variant with 2

timers, UART, 20mA. The fastest parts are from Dallas, with performance close to 10

MIPS! The most powerful chip is the Intel Technologies 80C517A, with 32 Bit ALU, 2

UARTS, 2K RAM, PLCC84 package, 8 x 16 Bit PWMs, and other features.

Among the MAJOR manufacturers are:

AMD - Enhanced 8051 parts (no longer producing 80x51 parts)

Atmel - FLASH and semi-custom parts

Cygnal - Fastest 8051 with Flash with 12-bit 1LSB A/D. 20MHz

internal clock

Dallas -Fast variant. Also battery backed

Intel -8051 through 80C51GB / 80C51Sl. They invented the 8051

ISSI -IS80C51/31 runs up to 40MHz

Matra - 80C154, low voltage static variants

OKI -80C154, mask parts

16

Page 17: Prepaid Electricity Billing System

Philips -87C748 thru 89c588, mostly old legacy 8051 parts from

Signetics.

Infineon -80C501 through 80C517A, and a wide variety of CAN devices.

SMC - COM20051 with ARCNET token bus network engine

SSI - 80x52, 2 x HDLC variant for MODEM use

Microcontroller Architectural Block Diagram:

17

Page 18: Prepaid Electricity Billing System

Atmel At89c51 Pin out and Description:

18

Page 19: Prepaid Electricity Billing System

The smallest current device is the ATMEL 89c51, a 40 Pin FLASH variant with 2 timers,

UART, 500mA. ATMEL was the first with standard FLASH, and with more program

cycles than other custom FLASH. These parts compete with OTP and MASK product on

price, but eliminate inventory problems and the hidden costs of OTP development.

Why we go for AT89C51?

The AT89C51 is a low power, high performance CMOS 8-bit microcontroller with

4Kbytes of Flash programmable and erasable read only memory (PEROM). This device

is compatible with the industry standard 8051 instruction set and pinout. The on-chip

Flash allows the program memory to be quickly reprogrammed using a nonvolatile

memory programmer such as the PG302 (with the ADT87 adapter). By combining an

industry standard 8-bit CPU with Flash on a monolithic chip, the 8951 is a powerful

microcomputer which provides a highly flexible and cost effective solution to many

embedded control applications.

Features of AT89C51:

1. It is a 8-bit microcontroller.

2. It has a flash memory of 4KB for storing the program.

3. It has RAM of 128 bytes.

4. It has 32 I/O ports .

-Port 0 (pin 39 to pin 32).

-Port 1 (pin 1 to pin 8).

-Port 2 (pin 21 to pin 28).

-Port 3 (pin 10 to pin 17).

5. It has four register banks.

6. It has two 16-bit timers.

- Timer 0

- Timer 1

7. It has full duplex asynchronous serial port.

19

Page 20: Prepaid Electricity Billing System

8. It can support up to 64KB of external memory with the help of PC and DPTR.

9. It has 16-bit address bus.

10. Six interrupts with two priority levels

-2 general purpose interrupts (INT0, INT1).

-4 preprogrammed interrupt ( Timer0,Timer1,Serial interrupt, Reset interrupt).

11. Wide range of frequency of operation (0 to 24 MHz).

12. It will operate on 5V dc supply.

13. It can support maximum of 500mA of current.

In addition, the 8951 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 hardware reset.

PINOUT DIAGRAM:

20

Page 21: Prepaid Electricity Billing System

Fig : Microcontroller Pin Diagram.

.1–8: Port 1: Each of these pins can be used as either input or output. Also, pins 1 and 2

(P1.0 and P1.1) have special functions associated with Timer 2.

.9: Reset Signal: High logical state on this input halts the MCU and clears all the

registers. Bringing this pin back to logical state zero starts the program anew as if the

power had just been turned on. In another words, positive voltage impulse on this pin

resets the MCU. Depending on the device's purpose and environs, this pin is usually

connected to the push-button, reset-upon-start circuit or a brown out reset circuit. The

image shows one simple circuit for safe reset upon starting the controller. It is utilized in

situations when power fails to reach its optimal voltage.

21

Page 22: Prepaid Electricity Billing System

Fig : Reset Circuit

.10-17: Port 3: As with Port 1, each of these pins can be used as universal input or

output. However, each pin of Port 3 has an alternative function:

.Pin 10: RXD - Serial input for asynchronous communication or serial output for

synchronous communication.

Pin 11: TXD - Serial output for asynchronous communication or clock output for

synchronous communication

Pin 12: INT0 - Input for interrupt 0

Pin 13: INT1 - Input for interrupt 1

Pin 14: T0 - Clock input of counter 0

Pin 15: T1 - Clock input of counter 1

Pin 16: WR - Signal for writing to external (add-on) RAM memory

Pin 17: RD - Signal for reading from external RAM memory

18-19: X2 and X1: Input and output of internal oscillator. Quartz crystal controlling the

frequency commonly connects to these pins. Capacitances within the oscillator

mechanism (see the image) are not critical and are normally about 30pF. New MCUs

work at frequencies from 0Hz to 50MHz+.

22

Page 23: Prepaid Electricity Billing System

Fig : Clock Circuit.

.20: GND: Ground

21- 28: Port 2: If external memory is not present, pins of Port 2 act as universal

input/output. If external memory is present, then these pins serve as the location of the

higher address byte, i.e. addresses A8 – A15. It is important to note that in cases when

not all the 8 bits are used for addressing the memory (i.e. memory is smaller than

64kB), the rest of the unused bits are not available as input/output.

29: PSEN: MCU activates this bit (brings to low state) upon each reading of byte

(instruction) from program memory. If external ROM is used for storing the program,

PSEN is directly connected to its control pins.

30: ALE: Before each reading of the external memory, MCU sends the lower byte of

the address register (addresses A0 – A7) to port P0 and activates the output ALE.

External register (74HCT373 or 74HCT375 circuits are common), memorizes the state

of port P0 upon receiving a signal from ALE pin, and uses it as part of the address for

memory chip. During the second part of the mechanical MCU cycle, signal on ALE is

off, and port P0 is used as Data Bus. In this way, by adding only one cheap integrated

circuit, data from port can be multiplexed and the port simultaneously used for

transferring both addresses and data.

31: EA: Bringing this pin to the logical state zero designates the ports P2 and P3 for

transferring addresses regardless of the presence of the internal memory. This means

that even if there is a program loaded in the MCU it will not be executed, but the one

from the external ROM will be used instead. Conversely, bringing the pin to the high

logical state causes the controller to use both memories, first the internal, and then the

external (if present).

23

Page 24: Prepaid Electricity Billing System

32-39: Port 0: Similar to Port 2, pins of Port 0 can be used as universal input/output, if

external memory is not used. If external memory is used, P0 behaves as address

output (A0 – A7) when ALE pin is at high logical level, or as data output (Data Bus)

when ALE pin is at low logical level.

40: VCC: Power +5V

INPUT – OUTPUT (I/O) PORTS:

Every MCU from 8051 family has 4 I/O ports of 8 bits each. This provides the user with

32 I/O lines for connecting MCU to the environs.

Port 0:

Port 0 has two fold role: if external memory is used, it contains the lower address

byte (A0-A7), otherwise all bits of the port are either input or output. Another feature of

this port comes to play when it has been designated as output. Port 0 lacks the "pull up"

resistor (resistor with +5V on one end). Therefore, to get one (5V) on the output, external

"pull up" resistor needs to be added for connecting the pin to the positive pole.

Port 1:

This is "true" I/O port, devoid of dual function characteristic for Port 0. Having the

"pull up" resistor, Port 1 is fully compatible with TTL circuits.

Port 2:

When using external memory, this port contains the higher address byte (addresses A8–

A15). Otherwise, it can be used as universal I/O port.

Port 3:

Beside its role as universal I/O port, each pin of Port 3 has an alternate function.

In order to use one of these functions, the pin in question has to be designated as input,

i.e. the appropriate bit of register P3 needs to be set. From a hardware standpoint, Port

3 is similar to Port 0.

Memory in 8051 Microcontroller:

The 8051 has three very general types of memory. The memory types are

illustrated in the following figure: On-Chip Memory, External Code Memory, and External

RAM.

24

Page 25: Prepaid Electricity Billing System

Fig : Memory Block Diagram.

On-Chip Memory refers to any memory (Code, RAM, or other) that physically

exists on the microcontroller itself. External Code Memory is code (or program) memory

that resides off-chip. This is often in the form of an external EPROM. External RAM is

RAM memory that resides off-chip. This is often in the form of standard static RAM or

flash RAM.

During the runtime, microcontroller uses two different types of memory: one for

holding the program being executed (ROM memory), and the other for temporary

storage of data and auxiliary variables (RAM memory).

ROM memory:

In this MCU contain 4 kilobytes of the flash memory on the chip. It is of

EEPROM. We can use 12v to program MCU. This option is cost-effective only for large

series. The main purpose of ROM is to store the programs to be executed.

RAM memory:

RAM is used for storing temporary data and auxiliary results generated during

the runtime. Apart from that, RAM comprises a number of registers: hardware counters

and timers, I/O ports, buffer for serial connection, etc. With older versions, RAM spanned

256 locations, while new models feature additional 128 registers. First 256 memory

locations form the basis of RAM (addresses 0 – FFh) of every 8051 MCU. Locations that

25

Page 26: Prepaid Electricity Billing System

are available to the user span addresses from 0 to 7Fh, i.e. first 128 registers, and this

part of RAM is split into several blocks as can be seen in the following figure.

Fig: Ram Memory.

The main purpose of RAM is to provide synchronization between ROM and CPU so as

to increase the speed of microcontroller.

Bit Memory:

The 8051, being a communications-oriented microcontroller, gives the user the

ability to access a number of bit variables. These variables may be either 1 or 0. There

are 128 bit variables available to the user, numbered 00h through 7Fh.

Special Function Register (SFR) Memory:

Special Function Registers (SFRs) are areas of memory that control specific

functionality of the 8051 processor. It may appear that SFR is part of Internal Memory.

26

Page 27: Prepaid Electricity Billing System

However, when using this method of memory access (its called direct address), any

instruction that has an address of 00h through 7Fh refers to an Internal RAM memory

address; any instruction with an address of 80h through FFh refers to an SFR control

register.

Register Banks:

General Purpose registers:

The 8051 uses 8 "R" registers which are used in many of its instructions. These

"R" registers are numbered from 0 through 7 (R0, R1, R2, R3, R4, R5, R6, and R7).

These registers are generally used to assist in manipulating values and moving data

from one memory location to another.

SFR Registers (Special Function Registers):

SFR registers can be seen as a sort of control panel for managing and

monitoring the microcontroller.

27

Page 28: Prepaid Electricity Billing System

Fig : Special Function Registers.

TIMERS:

The 8051 comes equipped with two timers, both of which may be controlled, set,

read, and configured individually. The 8051 timers have three general functions:

1) Keeping time and/or calculating the amount of time between events,

2) Counting the events themselves, or

3) Generating baud rates for the serial port.

28

Page 29: Prepaid Electricity Billing System

USING TIMERS TO MEASURE TIME:

Obviously, one of the primary uses of timers is to measure time. When a timer is

used to measure time it is also called an "interval timer" since it is measuring the time of

the interval between two events. .

Timer SFRs:

The 8051 has two timers which each function essentially the same way. One

timer is TIMER0 and the other is TIMER1. The two timers share two SFRs (TMOD and

TCON) which control the timers, and each timer also has two SFRs dedicated solely to

itself (TH0/TL0 and TH1/TL1).

An SFR has a numeric address. It is often useful to know the numeric address

that corresponds to an SFR name. When you enter the name of an SFR into an

assembler, it internally converts it to a number.

THE TMOD SFR (Timer Mode):

The TMOD SFR is used to control the mode of operation of both timers. Each bit

of the SFR gives the microcontroller specific information concerning how to run a timer.

The high four bits (bits 4 through 7) relate to Timer 1 whereas the low four bits (bits 0

through 3) perform the exact same functions, but for timer 0.

The individual bits of TMOD have the following functions:

Bit Name Explanation of Function Timer

7 GATE1

When this bit is set the timer will only run when

INT1 (P3.3) is high. When this bit is clear the timer

will run regardless of the state of INT1.

1

6 C/T1 When this bit is set the timer will count events on T1

(P3.5). When this bit is clear the timer will be

1

29

Page 30: Prepaid Electricity Billing System

incremented every machine cycle.

5 T1M1 Timer mode bit (see below) 1

4 T1M0 Timer mode bit (see below) 1

3 GATE0

When this bit is set the timer will only run when

INT0 (P3.2) is high. When this bit is clear the timer

will run regardless of the state of INT0.

0

2 C/T0

When this bit is set the timer will count events on T0

(P3.4). When this bit is clear the timer will be

incremented every machine cycle.

0

1 T0M1 Timer mode bit (see below) 0

0 T0M0 Timer mode bit (see below) 0

The Four bits (two for each timer) are used to specify a mode of operation. modes of operation

are:

TxM1 TxM0 Timer Mode Description of Mode

0 0 0 13-bit Timer.

0 1 1 16-bit Timer

1 0 2 8-bit auto-reload

1 1 3 Split timer mode

30

Page 31: Prepaid Electricity Billing System

.

The TCON SFR:

There is one more SFR that controls the two timers and provides valuable

information about them. The TCON SFR has the following structure:

TCON (88h) SFR:

Bit NameBit

AddressExplanation of Function Timer

7 TF1 8FhTimer 1 Overflow. This bit is set by the

microcontroller when Timer 1 overflows.1

6 TR1 8EhTimer 1 Run. When this bit is set Timer 1 is turned

on. When this bit is clear Timer 1 is off. 1

5 TF0 8DhTimer 0 Overflow. This bit is set by the

microcontroller when Timer 0 overflows.0

31

Page 32: Prepaid Electricity Billing System

4 TR0 8ChTimer 0 Run. When this bit is set Timer 0 is turned

on. When this bit is clear Timer 0 is off. 0

Only four bits of SFR are used for timers, the remaining four are used for interrupts.

SCHEMATIC REPRESTATION OF PROJECT WITH INTERFACING

32

Page 33: Prepaid Electricity Billing System

POWER SUPPLY

b. Power supply:

Any invention of latest technology cannot be activated without the source of

power. So in this fast moving world we deliberately need a proper power source which

will be apt for a particular requirement. All the electronic components starting from diode

to is only work with a DC supply ranging from 5V to 12V.We are utilizing for the same,

the cheapest and commonly available energy source of 230V-50Hz and stepping down,

rectifying, filtering and regulating the voltage.

33

Page 34: Prepaid Electricity Billing System

Transformer:

A bridge rectifier coupled with a step down transformer is used for our design.

The voltage rating of transformer used is 0-12V and the current rating is 500mA. When

AC voltage of 230V is applied across the primary winding an output AC voltage of 12V is

obtained. One alteration of input causes the top of transformer to be positive and the

bottom negative. The next alteration will temporarily cause the reverse.

Rectifier:

In the power supply unit, rectification is normally achieved using a solid state

diode. Diode has the property that will let the electron flow easily at one direction at

proper biasing condition. Bridge rectifiers of 4 diodes are used to achieve Bridge wave

rectification. Two diodes will conduct during the negative cycle and the other two will

conduct during the positive half cycle.

Filtering unit:

100

uf

12v

230V/12

AC step-down transformer

7812 7805

1000uf

1 2

3

1 2

3

330

uf

5vBridge

Rectifier

34

Page 35: Prepaid Electricity Billing System

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.

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. IC 7805 and 7812

regulators are used in this project for providing a DC voltage of +5V and +12V

respectively.

SERIAL COMMUNICATION

INTRODUCTION:

All IBM PC and compatible computers are typically equipped with two serial ports

35

Page 36: Prepaid Electricity Billing System

and one parallel port. Although these two types of ports are used for communicating with

external devices, they work in different ways.

BI- DIRECTIONAL COMMUNICATIONS:

The serial port on PC is a full-duplex device meaning that it can send and receive

data at the same time. In order to be able to do this, it uses separate lines for

transmitting and receiving data. Some types of serial devices support only one-way

communications and therefore use only two wires in the cable - the transmit line and the

signal ground.

COMMUNICATION BY BITS:

Once the start bit has been sent, the transmitter sends the actual data bits. There

may either be 5, 6, 7, or 8 data bits, depending on the number selected. Both receiver

and the transmitter must agree on the number of data bits, as well as the baud rate.

Almost all devices transmit data using either 7 or 8 data bits.

SYNCHRONOUS AND ASYNCHRONOUS COMMUNICATIONS:

There are two basic types of serial communications, synchronous and

asynchronous. With synchronous communications, the two devices initially synchronize

themselves to each other, and then continually send characters to stay in sync. Even

when data is not really being sent, a constant flow of bits allows each device to know

where the other is at any given time. That is, each character that is sent is either actual

data or an idle character. Synchronous communications allows faster data transfer rates

than asynchronous methods, because additional bits to mark the beginning and end of

each data byte are not required.

Asynchronous means "no synchronization", and thus does not require sending and receiving

idle characters. However, the beginning and end of each byte of data must be identified by start

and stop bits. The start bit indicates when the data byte is about to begin and the stop bit

signals when it ends. The requirement to send these additional two bits causes asynchronous

communication to be slightly slower than synchronous however it has the advantage that the

processor does not have to deal with the additional idle characters.

36

Page 37: Prepaid Electricity Billing System

  9 Pin Connector on a DTE device (PC connection)

Male RS232

DB9

Pin Number Direction of signal:

1 Carrier Detect (CD) (from DCE) Incoming signal from a modem

2 Received Data (RD) Incoming Data from a DCE

3 Transmitted Data (TD) Outgoing Data to a DCE

4 Data Terminal Ready (DTR) Outgoing handshaking signal

5 Signal Ground Common reference voltage

6 Data Set Ready (DSR) Incoming handshaking signal

7 Request To Send (RTS) Outgoing flow control signal

8 Clear To Send (CTS) Incoming flow control signal

9 Ring Indicator (RI) (from DCE) Incoming signal from a modem

The TD (transmit data) wire is the one through which data from a DTE device is

transmitted to a DCE device. The TD line is kept in a mark condition by the DTE device

when it is idle. The RD (receive data) wire is the one on which data is received by a DTE

device, and the DCE device keeps this line in a mark condition when idle .RTS stands

for Request To Send. This line and the CTS line are used when "hardware flow control"

is enabled in both the DTE and DCE devices. The DTE device puts this line in a mark

condition to tell the remote device that it is ready and able to receive data. If the DTE

device is not able to receive data (typically because its receive buffer is almost full), it will

put this line in the space condition as a signal to the DCE to stop sending data. The

complement of the RTS wire is CTS, which stands for Clear To Send. The DCE device

puts this line in a mark condition to tell the DTE device that it is ready to receive the

data. Likewise, if the DCE device is unable to receive data, it will place this line in the

space condition. Together, these two lines make up what is called RTS/CTS or

"hardware" flow control.

37

Page 38: Prepaid Electricity Billing System

DTR stands for Data Terminal Ready. Its intended function is very similar to the

RTS line. DSR (Data Set Ready) is the companion to DTR in the same way that CTS is

to RTS. Some serial devices use DTR and DSR as signals to simply confirm that a

device is connected and is turned on.

CD stands for Carrier Detect. Carrier Detect is used by a modem to signal that it has a

made a connection with another modem, or has detected a carrier tone.

RI or Ring Indicator. A modem toggles the state of this line when an incoming call rings

your phone. The Carrier Detect (CD) and the Ring Indicator (RI) lines are only available

in connections to a modem

DRIVER FOR SERIAL COMMUNCATION:

INTRODUCTION:

Serial RS-232 communication works with voltages (-15V ... -3V for high) and +3V

... +15V for lo]) which are not compatible with normal computer logic voltages. On the

other hand, microcontroller operates between 0V ... +5V. Therefore, to receive serial

data from an RS-232 interface the voltage has to be reduced

RS-232 µC Logic

-----------------------------------------------

-15V ... -3V <-> 0V <-> low

+3V ... +15V <-> 5V <-> high

RS 232:

RS-232 stands for Recommend Standard number 232 . The full RS-232C

standard specifies a 25-pin "D" connector of which 22 pins are used. Most of these pins

are not needed for normal PC communications, and indeed, most new PCs are

equipped with male D type connectors having only 9 pins.

RS-232 Level Converters:

38

Page 39: Prepaid Electricity Billing System

Almost all digital devices required either TTL or CMOS logic levels. Therefore the first

step to connecting a device to the RS-232 port is to transform the RS-232 levels back

into 0 and 5 Volts, this is done by RS-232 Level Converters.

Fig : Pin Diagram of MAX232

MAX-232:

It includes a Charge Pump, which generates +10V and -10V from a single 5v

supply. This I.C. also includes two receivers and two transmitters in the same package.

This is handy in many cases when you only want to use the Transmit and Receive data

Lines. You don't need to use two chips, one for the receive line and one for the transmit.

However all this convenience comes at a price, but compared with the price of designing

a new power supply it is very cheap.

39

Page 40: Prepaid Electricity Billing System

Fig 7.2: Typical MAX-232 Circuit.

40

Page 41: Prepaid Electricity Billing System

BUZZER:

Buzzer is a transducer, which produces sound signal to the corresponding electric

signal. The switching operation of the buzzer is controlled by using microcontroller. the

buzzer draws more current while it is operating so by using 2N2222 fast switching

transistor we directly operate the buzzer by using microcontroller. The connection of the

buzzer is as shown below,

Fig Buzzer Circuit.

When output pin of the microcontroller is high, then 2N2222 goes to saturation, then

buzzer gets operated. Whenever output pin of the microcontroller is low the buzzer stops

operating.

OVERVIEW OF GSM

1.1 HISTORY OF GSM

During the early 1980s, analog cellular telephone systems were experiencing rapid

growth in Europe, particularly in Scandinavia and the United Kingdom, but also in France

and Germany. Each country developed its own system, which was incompatible with

41

Page 42: Prepaid Electricity Billing System

everyone else's in equipment and operation. This was an undesirable situation, because

not only was the mobile equipment limited to operation within national boundaries, which

in a unified Europe were increasingly unimportant, but there was also a very limited

market for each type of equipment, so economies of scale and the subsequent savings

could not be realized.

The Europeans realized this early on, and in 1982 the Conference of European Posts

and Telegraphs (CEPT) formed a study group called the Groupe Spécial Mobile (GSM)

to study and develop a pan-European public land mobile system. The proposed system

had to meet certain criteria:

Good subjective speech quality

Low terminal and service cost

Support for international roaming

Ability to support handheld terminals

Support for range of new services and facilities

Spectral efficiency

ISDN compatibility

And interaction with the Integrated service digital network (ISDN) which offers the

capability to extend the single-subscriber –line system with the various to a

multiservice system.

The first commercial GSM system, called D2, was implemented in Germany in 1982.

This valuable channel of communication can equip us with a powerful tool for

controlling desired device or process parameter from distant location, through

electromagnetic waves.

With a little effort logic can be setup to even receive a feedback on the status of the

device or the process being controlled.

42

Page 43: Prepaid Electricity Billing System

1.2 SERVICES PROVIDED BY GSM

From the beginning, the planners of GSM wanted ISDN compatibility in terms of the

services offered and the control signalling used. However, radio transmission limitations,

in terms of bandwidth and cost, do not allow the standard ISDN B-channel bit rate of 64

kbps to be practically achieved.

Using the ITU-T definitions, telecommunication services can be divided into bearer

services, teleservices, and supplementary services. The most basic teleservice

supported by GSM is telephony. As with all other communications, speech is digitally

encoded and transmitted through the GSM network as a digital stream. There is also an

emergency service, where the nearest emergency-service provider is notified by dialing

three digits.

A variety of data services is offered. GSM users can send and receive data, at rates up

to 9600 bps, to users on POTS (Plain Old Telephone Service), ISDN, Packet Switched

Public Data Networks, and Circuit Switched Public Data Networks using a variety of

access methods and protocols, such as X.25 or X.32. Since GSM is a digital network, a

modem is not required between the user and GSM network, although an audio modem

is required inside the GSM network to interwork with POTS.

Other data services include Group 3 facsimile, as described in ITU-T recommendation

T.30, which is supported by use of an appropriate fax adaptor. A unique feature of GSM,

not found in older analog systems, is the Short Message Service (SMS). SMS is a

bidirectional service for short alphanumeric (up to 160 bytes) messages. Messages are

transported in a store-and-forward fashion. For point-to-point SMS, a message can be

sent to another subscriber to the service, and an acknowledgement of receipt is provided

to the sender. SMS can also be used in a cell-broadcast mode, for sending messages

such as traffic updates or news updates. Messages can also be stored in the SIM card

for later retrieval .

Supplementary services are provided on top of teleservices or bearer services. In the

current (Phase I) specifications, they include several forms of call forward (such as call

forwarding when the mobile subscriber is unreachable by the network), and call barring

of outgoing or incoming calls, for example when roaming in another country. Many

43

Page 44: Prepaid Electricity Billing System

additional supplementary services will be provided in the Phase 2 specifications, such as

caller identification, call waiting, multi-party conversations.

1.3 ARCHITECTURE OF THE GSM NETWORK

A GSM network is composed of several functional entities, whose functions and

interfaces are specified. Figure 1.1 shows the layout of a generic GSM network. The

GSM network can be divided into three broad parts. The Mobile Station is carried by the

subscriber. The Base Station Subsystem controls the radio link with the Mobile Station.

The Network Subsystem, the main part of which is the Mobile services Switching Center

(MSC), performs the switching of calls between the mobile users, and between mobile

and fixed network users. The MSC also handles the mobility management operations.

Not shown is the Operations and Maintenance Center, which oversees the proper

operation and setup of the network. The Mobile Station and the Base Station Subsystem

communicate across the Um interface, also known as the air interface or radio link. The

Base Station Subsystem communicates with the Mobile services Switching Center

across the A interface.

Figure 1.1 General Architecture of a GSM Network

1.3.1 Mobile Station

The mobile station (MS) consists of the mobile equipment (the terminal) and a smart

card called the Subscriber Identity Module (SIM). The SIM provides personal mobility, so

44

Page 45: Prepaid Electricity Billing System

that the user can have access to subscribed services irrespective of a specific terminal.

By inserting the SIM card into another GSM terminal, the user is able to receive calls at

that terminal, make calls from that terminal, and receive other subscribed services.

The mobile equipment is uniquely identified by the International Mobile Equipment

Identity (IMEI). The SIM card contains the International Mobile Subscriber Identity (IMSI)

used to identify the subscriber to the system, a secret key for authentication, and other

information. The IMEI and the IMSI are independent, thereby allowing personal mobility.

The SIM card may be protected against unauthorized use by a password or personal

identity number.

1.3.2 Base Station Subsystem

The Base Station Subsystem is composed of two parts, the Base Transceiver Station

(BTS) and the Base Station Controller (BSC). These communicate across the

standardized Abis interface, allowing (as in the rest of the system) operation between

components made by different suppliers.

The Base Transceiver Station houses the radio transceivers that define a cell and

handles the radio-link protocols with the Mobile Station. In a large urban area, there will

potentially be a large number of BTSs deployed, thus the requirements for a BTS are

ruggedness, reliability, portability, and minimum cost.

The Base Station Controller manages the radio resources for one or more BTSs. It

handles radio-channel setup, frequency hopping, and handovers, as described below.

The BSC is the connection between the mobile station and the Mobile service Switching

Center (MSC).

1.3.3 Network Subsystem

The central component of the Network Subsystem is the Mobile services Switching

Center (MSC). It acts like a normal switching node of the PSTN or ISDN, and

additionally provides all the functionality needed to handle a mobile subscriber, such as

registration, authentication, location updating, handovers, and call routing to a roaming

subscriber. These services are provided in conjuction with several functional entities,

45

Page 46: Prepaid Electricity Billing System

which together form the Network Subsystem. The MSC provides the connection to the

fixed networks (such as the PSTN or ISDN). Signalling between functional entities in the

Network Subsystem uses Signalling System Number 7 (SS7), used for trunk signalling in

ISDN and widely used in current public networks.

The Home Location Register (HLR) and Visitor Location Register (VLR), together with

the MSC, provide the call-routing and roaming capabilities of GSM. The HLR contains all

the administrative information of each subscriber registered in the corresponding GSM

network, along with the current location of the mobile. The location of the mobile is

typically in the form of the signalling address of the VLR associated with the mobile

station. The actual routing procedure will be described later. There is logically one HLR

per GSM network, although it may be implemented as a distributed database.

The Visitor Location Register (VLR) contains selected administrative information from

the HLR, necessary for call control and provision of the subscribed services, for each

mobile currently located in the geographical area controlled by the VLR. Although each

functional entity can be implemented as an independent unit, all manufacturers of

switching equipment to date implement the VLR together with the MSC, so that the

geographical area controlled by the MSC corresponds to that controlled by the VLR, thus

simplifying the signalling required. Note that the MSC contains no information about

particular mobile stations --- this information is stored in the location registers.

The other two registers are used for authentication and security purposes. The

Equipment Identity Register (EIR) is a database that contains a list of all valid mobile

equipment on the network, where each mobile station is identified by its International

Mobile Equipment Identity (IMEI). An IMEI is marked as invalid if it has been reported

stolen or is not type approved. The Authentication Center (AuC) is a protected database

that stores a copy of the secret key stored in each subscriber's SIM card, which is used

for authentication and encryption over the radio channel.

1.4 GSM MODEM

GSM Modem Product, from Sparr Electronics limited (SEL), provides full functional

capability to Serial devices to send SMS and Data over GSM Network. The product is

46

Page 47: Prepaid Electricity Billing System

available as Board Level or enclosed in Metal Box. The Board Level product can be

integrated in to Various Serial devices in providing them SMS and Data capability and

the unit housed in a Metal Enclosure can be kept outside to provide serial port

connection. The GSM Modem supports popular "AT" command set so that users can

develop applications quickly. The product has SIM Card holder to which activated SIM

card is inserted for normal use. The power to this unit can be given from UPS to provide

uninterrupted operation. This product provides great feasibility for Devices in remote

location to stay connected which otherwise would not have been possible where

telephone lines do not exist

1.5 APPLICATION AREAS

Mobile Transport vehicles.

LAN based SMS servers

Alarm notification of critical events including Servers

Network Monitoring and SMS reporting

Data Transfer applications from remote locations

Monitor and control of Serial services through GSM Network

Integration to custom software for Warehouse, Stock, Production, Dispatch

notification through SMS.

AMR- Automatic Meter Reading

And many more…

1.6 CONNECTION DIAGRAM

47

Page 48: Prepaid Electricity Billing System

Figure 1.2 Connection Diagram

1.7 PINOUTS AND DETAILS

Figure1.3 Pinout and Details

1.7.1 Serial Pin out (D-9 Connector)

48

Page 49: Prepaid Electricity Billing System

Serial Port D-Type 9 pin connector which is male on the back of the GSM modem, thus

you will require a female connector on your device. Below is a table of pin connections

for the 9 pin D-Type connector.

Pin No. Abbreviation Full Name

Pin 3 TD Transmit Data

Pin 2 RD Receive Data

Pin 7 RTS Request To Send

Pin 8 CTS Clear To Send

Pin 6 DSR Data Set Ready

Pin 5 SG Signal Ground

Pin 1 CD Carrier Detect

Pin 4 DTR Data Terminal Ready

Pin 9 RI Ring Indicator

1.7.2 Pin Functions

  Abbreviation Full Name Function

    TD Transmit

DataSerial Data Output (TXD)

     RD Receive Data Serial Data Input (RXD)

     CTS Clear to Send This line indicates that the Modem is ready to

49

Page 50: Prepaid Electricity Billing System

exchange data.

    

DCD Data Carrier

Detect

When the modem detects a "Carrier" from the

modem at the other end of the phone line, this Line

becomes active.

    DSR Data Set

Ready

This tells the UART that the modem is ready to

establish a link.

    

DTR Data

Terminal

Ready

This is the opposite to DSR. This tells the Modem

that the UART is ready to link.

    RTS Request To

Send

This line informs the Modem that the UART is

ready to exchange data.

    RI Ring Indicator Goes active when modem detects a ringing signal

from the PSTN.

1.8 NULL MODEMS

A Null Modem is used to connect two DTE's together. This is commonly used as a cheap

way to network games or to transfer files between computers using Zmodem Protocol,

Xmodem Protocol etc. This can also be used with many Microprocessor Development

Systems.

50

Page 51: Prepaid Electricity Billing System

Figure 1.4: Null Modem Wiring Diagram

Above is my preferred method of wiring a Null Modem. It only requires 3 wires (TD, RD

& SG) to be wired straight through thus is more cost effective to use with long cable

runs. The theory of operation is reasonably easy. The aim is to make to computer think it

is talking to a modem rather than another computer. Any data transmitted from the first

computer must be received by the second thus TD is connected to RD. The second

computer must have the same set-up thus RD is connected to TD. Signal Ground (SG)

must also be connected so both grounds are common to each computer.

The Data Terminal Ready is looped back to Data Set Ready and Carrier Detect on both

computers. When the Data Terminal Ready is asserted active, then the Data Set Ready

and Carrier Detect immediately become active. At this point the computer thinks the

Virtual Modem to which it is connected is ready and has detected the carrier of the other

modem.

All left to worry about now is the Request to Send and Clear To Send. As both

computers communicate together at the same speed, flow control is not needed thus

these two lines are also linked together on each computer. When the computer wishes

to send data, it asserts the Request to Send high and as it's hooked together with the

Clear to Send, It immediately gets a reply that it is ok to send and does so.

1.9 SHORT MESSAGE COMMANDS

1.9.1 Parameters Definition

<da> Destination Address, coded like GSM 03.40 TP-DA

51

Page 52: Prepaid Electricity Billing System

<dcs> Data Coding Scheme, coded like in document [5].

<dt> Discharge Time in string format :

“yy/MM/dd,hh :mm :sszz”(Year [00-99], Month [01-12], Day [01-31],

Hour,

Minute, Second and Time Zone [quarters of an hour] )

<fo> First Octet, coded like SMS-SUBMIT first octet in document [4], default

value is

17 for SMS-SUBMIT

<index> Place of storage in memory.

<length> Text mode (+CMGF=1): number of characters PDU mode (+CMGF=0):

length of

the TP data unit in octets

<mem1> Memory used to list, read and delete messages (+CMGL, +CMGR and

+CMGD).

<mem2> Memory used to write and send messages (+CMGW, +CMSS).

<mid> CBM Message Identifier.

<mr> Message Reference.

<oa> Originator Address.

<pid> Protocol Identifier.

<pdu> For SMS : GSM 04.11 SC address followed by GSM 03.40 TPDU

in hexadecimal

format, coded as specified in doc [4] For CBS : GSM 03.41 TPDU in

hexadecimal

format

<ra> Recipient Address.

52

Page 53: Prepaid Electricity Billing System

<sca> Service Center Address

<scts> Service Center Time Stamp in string format :

“yy/MM/dd,hh :mm :ss zz”

(Year/Month/Day, Hour: Min: Seconds Time Zone)

<sn> CBM Serial Number

<st> Status of a SMS-STATUS-REPORT

<stat> Status of message in memory.

<tooa> Type-of-Address of <oa>.

<tora> Type-of-Address of <ra>.

<tosca> Type-of-Address of <sca>.

<total1> Number of message locations in <mem1>.

<total2> Number of messages locations in <mem2.

<used1> Total number of messages locations in <mem1>.

<used2> Total number of messages locations in <mem2.

<vp> Validity Period of the short message, default value is 167

1.10 READ MESSAGE +CMGR

1.10.1 Description :

This command allows the application to read stored messages. The messages are read

from the memory selected by +CPMS command.

1.10.2 Syntax :

53

Page 54: Prepaid Electricity Billing System

Command syntax : AT+CMGR=<index>

Response syntax for text mode:

+CMGR :<stat>,<oa>,[<alpha>,] <scts> [,<tooa>,<fo>,

<pid>,<dcs>,<sca>,<tosca>,<length>] <CR><LF> <data> (for SMS MS MS-DELIVER

only)

+CMGR : <stat>,<da>,[<alpha>,] [,<toda>,<fo>,<pid>,<dcs>, [<vp>], <sca>,

<tosca>,<length>]<CR><LF> <data> (for SMS-SUBMIT only)

+CMGR : <stat>,<fo>,<mr>,[<ra>],[<tora>],<scts>,<dt>,<st> (for SMS SMS-

STATUS-

REPORT only)

Response syntax for PDU mode :

+CMGR: <stat>, [<alpha>] ,<length> <CR><LF> <pdu>

A message read with status “REC UNREAD” will be updated in memory with the status

“REC READ”.

Note :

the <stat> parameter for SMS Status Reports is always “READ”.

54

Page 55: Prepaid Electricity Billing System

Table 1.1 :Example for CMGR commands

COMMAND POSSIBLE RESPONSE

AT+CMTI:”SM”,1

Note: New message received

AT+CMGR=1

Note: read the message

+CMGR :”REC UNREAD”,”0146290800”,

“98/10/01;18:22:11+00”,<CR><LF>

ABcdefGH

Ok

AT+CMGR=1

Note: read the message again

+CMGR:”REC UNREAD”,”0146290800”,

“98/10/01,18:22:11+00”,<CR><LF>

ABCdefGHI

OK

Note: message is read now

AT+CMGR=2

Note :Read at a wrong index

+CMS ERROR:321

Note : Error : invalid index

AT+CMGF=0 : +CMGR=1

Note :In PDU mode

+CMGR: 2,<Length><CR><LF><pde>

OK

Note :Message is stored but unsent, no

<alpha>field

AT+CMGF=1;+CPMS+”SR”;+CNMI=…2

Reset to text mode ,set read memory to

“SR”,and allow storage of further SMS

Status Report into”SR”memory

OK

55

Page 56: Prepaid Electricity Billing System

AT+CMSS=3

Send an SMS previously stored

+CMSS :160

OK

+CDSI :”SR”,1

New SMS Status Report Stored in “SR”

Memory at index 1

AT+CMGR=1

Read the SMS Status Report

+CMGR :’READ’,6,160,

“+33612345678’,129,”01/05/31,15:15:09

+00’,’01/05/31,15:15:09+00”,0

OK

.

1.11 SEND MESSAGE +CMGS

1.11.1 Description :

The <address> field is the address of the terminal to which the message is sent. To send

the message, simply type, <ctrl-Z> character (ASCII 26). The text can contain all existing

characters except <ctrl-Z> and <ESC> (ASCII 27). This command can be aborted using

the <ESC> character when entering text. In PDU mode, only hexadecimal characters

are used (‘0’…’9’,’A’…’F’).

1.11.2 Syntax :

Command syntax in text mode:

AT+CMGS= <da> [ ,<toda> ] <CR>

text is entered <ctrl-Z / ESC >

56

Page 57: Prepaid Electricity Billing System

Command syntax in PDU mode :

AT+CMGS= <length> <CR>

PDU is entered <ctrl-Z / ESC >

Command Possible response

AT+CMGS=”+33146290800”<CR>

Please call me soon, fred. <ctrl.z>

Note: send a message in text mode.

+CMGS;<mr>

Ok

Note:successful

transmission

AT+CMGS+<length><CR><pdu><ctrlz>

Note: Send a message in pdu mode.

+CMGS;<mr>

Ok

Note:Sucessful transmission.

Table 1.2 :Examples for CMGS commands

The message reference, <mr>, which is returned to the application is allocated by the

product. This number begins with 0 and is incremented by one for each outgoing

message (successful and failure cases); it is cyclic on one byte (0 follows 255).

Note:

this number is not a storage number – outgoing messages are not stored.

1.12 COMPARISON WITH OTHER NETWORKS

57

Page 58: Prepaid Electricity Billing System

Comparing this project with other methods i.e.PSTN lines, where number is fixed and

cannot control our unit from different locations due to fixed phone line.

LIQUID CRYSTAL DISPLAY UNIT (LCD)

58

Page 59: Prepaid Electricity Billing System

2.7.1 Introduction: -

Liquid Crystal Displays are created by sandwiching a thin (10-12 micro mm) layer of a

liquid crystal fluid between two glass plates. A transparent, electrically conductive film or

back plane is put up on the rear glass sheet. The transparent sections of the conductive

film in the shape of the desired characters are coated on the front glass plate. When a

voltage is applied between a segment and the back plane, an electric field is created in

the region under the segment. This electric field changes the transmission of light

through the region under the segment film.

2.7.2 Liquid Crystal Display Description: -

In this project, JHD 162A Liquid Crystal Display (16x2), which is shown in Figure 3.9, is

interfaced with the CPU.

Figure 2.10 JHD 162A Liquid Crystal Display

The features of JHD 162A LCD is as follows: -

16 Characters x 2 Lines5x7DotswithCursor

Built-in controller +5v Power Supply

1/16 Duty Circle.The pin description of the JHD 162A LCD without backlight is as shown

in Table 2.13. If the LCD is having Backlight, then it will have two more pins with pin

numbers 15 & 16 connected to VCC and GND respectively.

59

Page 60: Prepaid Electricity Billing System

Pin

numberSymbol  Level   I/O Function

1 Vss - - Power supply (GND)

2 Vcc - - Power supply (+5V)

3 Vee - - Contrast adjust

4 RS 0/1 I0= Instruction input

1 = Data input

5 R/W 0/1 I0 = Write to LCD module

1 = Read from LCD module

6 E 1, 1->0 I Enable signal

7 DB0 0/1 I/O Data bus line 0 (LSB)

8 DB1 0/1 I/O Data bus line 1

9 DB2 0/1 I/O Data bus line 2

10 DB3 0/1 I/O Data bus line 3

11 DB4 0/1 I/O Data bus line 4

12 DB5 0/1 I/O Data bus line 5

13 DB6 0/1 I/O Data bus line 6

14 DB7 0/1 I/O Data bus line 7 (MSB)

Table 2.12. Pin assignment for <= 80 character displaysAn LCD allows an

application to output a very specific message (or prompt) to the user, making the

application much more user friendly and impressive. LCD's are invaluable for displaying

status messages and information during application debug. ASCII-input LCDs even

60

Page 61: Prepaid Electricity Billing System

though they have these advantages, they have a reputation of being difficult to hook up

and get to work. Most alphanumeric LCD's use a common controller chip and a common

connector interface. Both of these actions have resulted in alphanumeric LCDs that

range in size from 8 characters to 80 (arranged as 40 b 2 or 20 b 4) and are

interchangeable, without requiring hardware or software changes.The ASCII code to be

displayed is 8 bits long and is sent to the LCD either 4 or 8 bits at time. If the 4-bit mode

is used, two nibbles of data (sent high 4 bits then low 4 bits with an E clock pulse with

each nibble) are sent to make up a full 8-bit transfer. The "E" clock is used to initiate the

data transfer within the LCD. In the LCD there is a cursor,This specifies where the next

data character is to be written. This cursor can be moved or be made invisible to blink.

The blinking function is very rarely used because it is pretty obnoxious. Sending

parallel data either as 4 or 8 bits are the two primary modes of operation. While there are

secondary considerations and modes deciding how to send the data to the LCD is more

critical decision to be made for an LCD interface application. 4-bit mode is best used

when the speed required in an application and at least 10 I/O pins are available. 4-bit

mode requires minimum 6 bits. To wire a Microcontroller to an LCD 4-bit mode, just the

top 4-bits (DB4-7) are written as shown in the Figure 2.11 below:

Figure

2.11 Data Transfer using a 4-Bit InterfaceUsing a shift register so that a minimum of

three I/O pins is required can further reduce this. 8-bit mode could be used with a shift

register, but a ninth bit (which will be used as R/S) will be required.The display contains

two internal byte-wide registers, one for command (RS=0) and the second for the

61

Page 62: Prepaid Electricity Billing System

characters to be displayed (RS=1). The R/S bit is used to select whether data or an

instruction is being transferred between the Microcontroller and the LCD. If the bit is set,

the byte at the current LCD cursor position can be read or written.When the bit is reset,

either an instruction is being sent to the LCD or the execution status of the last

instruction is read back (whether it has completed or not).The display contains two

internal byte-wide registers, one for command (RS=0) and the second for characters to

be displayed (RS=1). It also contains a user programmed RAM area (the character

RAM) that can be programmed to generate a desired character that can be formed using

a dot matrix. To distinguish between these two data areas, the hex command byte 80

will be used to signify that the display RAM address 00h is chosen.Port 1 is used to

furnish the commands or data byte and ports 3.2 to 3.4 furnish register select and

read/write levels. The display takes varying amounts of time to accomplish the functions.

LCD bit 7 is monitored for a long high (bus) to ensure the display is not over written. A

slightly more complicated LCD display (4 lines* 40 characters) is currently being used in

medical diagnostic systems to run a very familiar program.2.7.3 Getting The LCD To

Display Text: -After successfully initializing the LCD and turning the display ON, one

can begin to display messages on the LCD by sending the correct instructions to it.

Getting the LCD to display text is a two-step process. First, the LCD's cursor must be

moved to the LCD address where the character is to be displayed. This is done with the

"DDRAM Address Set" command. Second, the actual character must be written to the

cursor in order to store it in the DDRAM at the cursor's location. This is performed with

the "CGRAM/DDRAM Data Write" command.2.7.4 LCD Busy Flag Polling: -The LCD

will not accept new commands while it is busy with some internal operation. This

condition must be tested before sending a new command to the LCD. The "Busy

Flag/Address Read" instruction should be used for this purpose. The BF bit in this

instruction is the busy flag. When this bit is 1, LCD controller is busy. When BF is 0, LCD

is ready for the next command. In addition to busy flag polling, this instruction is used to

determine where the address of the LCD cursor is. Examples for Busy Flag testing using

both 4-bit and 8-bit interfaces are shown in figures 2.12 and 2.13 respectively.

62

Page 63: Prepaid Electricity Billing System

Fi

gure 2.12 Example of busy flag testing using a 4-bit interface.

Figure 2.13 Example of busy flag testing using an 8-bit interface.

Defining LCD Custom Characters: -One of the nice features of the LCD is that it

allows for the creation and use of up to eight unique, user-defined characters. Character

Generator RAM (CGRAM) has been added to the LCD for this purpose. Before a custom

character can be used it must be created. Each character that can be displayed by the

LCD is composed of a 5 x 8 grid of pixels or dots. Each of these dots can be turned

either ON or OFF when a character is being displayed. Therefore, in order for the LCD

controller to display a character, it must have a definition of which of the character dots

need to be turned ON.2.7.5 Interfacing of LCD with 89s52 Microcontroller: -In this

project, the JHD 162A LCD is interfaced with the 89s52 Microcontroller. Port1 pins of

89s52 are used to read and write the data from LCD by interfacing P0.0 - P0.7 lines to

D0-D7 lines of LCD. Similarly Port3 pins (P3.2-P3.4) are connected to control pins of

LCD i.e. E, R/W and RS pins respectively.SOFTWARE DESCRIPTION AND CODING3.1

Introduction: -The software coding required to perform the control operations of

AT89s52 micro controller developed was coded with the help of Keil Cx51 Complier

package. Keil Cx51 Complier compiles the program written and checks for errors in the

63

Page 64: Prepaid Electricity Billing System

program. Then, the compiler generates a filename.hex file that can be burnt in EPROM

of 89S52 Microcontroller. Finally the error free compiled filename.hex file was burnt into

the CPU memory with the help of Keil Programmer.3.2 SOFTWARE USED:

Embedded C or Assembly Language.3.3 TOOLS USED: Keil uv2 IDE.3.4

Definition of Embedded SystemAny sort of device which includes a programmable

computer, but itself is not intended to be a general-purpose computer”Wayne Wolf

3.4.1 Why Embedded Systems?

Embedded Device Technology is a transformational technology – a technology

that is revolutionizing the way we function. Embedded Systems can be seen everywhere

from Wrist Watches, Washing Machines, Microwave Ovens and Mobile Telephones to

Automobiles, Aircrafts and Nuclear Power Plants. Embedded Systems are the brains

behind 90% of all electronic devices worldwide. The explosion of Embedded System

Technology is expected to happen across product categories like office products,

consumer products, industrial automation products, automobiles, medical

instrumentation, vending machines, vehicles, communications infrastructure, etc.

An Embedded System is a combination of hardware and software designed to control

the additional hardware attached to the system. The software system is completely

encapsulated by the hardware that it controls. Embedded system means the processor

is embedded into that application or it is meant for that specific application. Thus printer,

keyboard, and video game player etc. are all examples of devices performing specific

application. In an Embedded System, there is only one application software that is

typically burned into ROM. An Embedded System is time-constrained and often

resource-constrained. The brain of an Embedded System is the processor. It may be a

general-purpose microprocessor like Intel x86 family or a microcontroller like 8051

family. An embedded product uses a microprocessor or microcontroller to do one

specific task only.

A microcontroller is a specific kind of microprocessor whose primary job is to control the

hardware it is attached to. A microcontroller has more pins dedicated to carrying I/O

signals as compared to microprocessor. A

64

Page 65: Prepaid Electricity Billing System

Microcontroller has built-in memory and peripherals (single-chip computer). Whereas a

microprocessor has memory and supporting peripherals externally connected.

3.5 Introduction to Keil Cx51 Complier: -

The Cx51 Complier package may be used on all 8051 family processors and is

executable under the Windows 32-bit command line prompt. The C programming

language is a general-purpose programming language that provides code efficiency,

elements of structured programming and a rich set of operators. C is not a big language

and is not designed for a particular area of application. It is generally combined with its

absence of restrictions, makes C a convenient and effective programming solution for a

wide variety of software tasks. Many applications can be solved more easily and

efficiently with C than with any other specialized languages.

The Cx51 optimising C complier is a complete implementation of the American National

Standards Institutes (ANSI) standard for the C language. Cx51 is not a universal C

complier adapted for the 8051 target. It is a ground-up implementation dedicated to

generating extremely fast and compact code for the 8051 microcontroller. Cx51 provides

the flexibility of programming in C and the code efficiency and speed of assembly

language.

The C language on its own is not capable of performing operations (such as input and

output) that would normally require intervention from the operating systems. Because

these functions are separate from the language itself, C is specially suited for producing

code and portable across a wide number of platforms. Since Cx51 is a cross complier

Some code of the C programming language and standard libraries are altered or

enhanced as the peculiarities of an embedded processor.

65

Page 66: Prepaid Electricity Billing System

3.5.1 Support for all 8051 Variants: -

8051 family is one of the fastest growing Microcontroller Architectures. More than one

device variants from various Silicon vendors are today available. New extended 8051

devices like the Philips 80C51MX architecture are dedicated for large application with

several Mbytes code and data space. For optimum support of these different 8051

variants, Keil provides the several development tools that are listed in the Table 1 below.

A new output file format (OFM2) allows direct support of upto 16MB code and data

space. The cx51 complier is a variant of the C51 complier that is designed for the new

Philips 80C51MX architecture. The Cx51 complier is available in different packages. The

table 1 below refers to the entire line of the 8051 development tools.

Table 3.1 Development tools in Keil Software

3.5.2 Compiling with the Cx51 Compiler: -

The directives below allow compiling of the Cx51 compiler. Control directives can be

divided into three groups: Source controls, Object controls and Listing controls.

Source controls define macros on the command line and determine the name of the file

to be complied.

66

Page 67: Prepaid Electricity Billing System

Object controls affect the form and content of the generated object module (*.obj). These

directives allow specifying the optimising level or including debugging formation in the

object file.

Listing controls govern various aspects of the listing file (*.LST), in particular its format

and specific content.

3.5.3 Running Cx51 from the Command Prompt: -

To invoke the C51 or Cx51 compiler, enter C51 or Cx51 at the command prompt. On the

command line, the name of the C source file to be compiled as well as other necessary

control directives required to compile the source file must be included. The format for the

Cx51 command line is:

C51 sourcefile_directives..._

Cx51 sourcefile_directives.... _

OR

C51 @commandfile

Cx51 @commandfile

Where:

Source file is the name of the source program you want to compile.

Directives are the directives we want to use to control the function of the command.

Commandfile is the name of a command input file that may contain source file and

directives. A commandfile is used, when the Cx51 invocation line gets complex and

exceeds the limits of the windows command prompt.

The Cx51 complier displays the following information upon successful compilation:

C51 COMPLIER V6.10

C51 COMPILATION COMPLETE 0 WARNING (S), 0 ERROR (S)

67

Page 68: Prepaid Electricity Billing System

0 ERROR LEVEL

After the compilation, the number of errors and warnings detected is the output to the

screen. The Cx51 complier then sets the ERRORLEVEL to indicate the status of

compilation. As shown below:

ERRORLEVEL MEANING

0 No errors or warnings

1 Warnings only

2 Errors and possible warnings

3 Fatal errors

3.5.4 Cx51 Output Files: -

The Cx51 complier generates a number of output files during compilation. By default

each of these output files shares the same filename as the source file. However, each

has a different file extension. The following lists the files and gives a brief description of

each: File

filename.LST : -

Files with this extension are listing files that contain the formatted source text along with

any errors detected by the compiler. Listing files may optionally contain the symbols

used and the assembly code generated.

filename.OBJ: -

Files with this extension are object modules that contain relocatable object code. The

Lx51 Linker/Locator may link object modules to an absolute object module.

filename.I: -

Files with this extension contain the source text as expanded by the preprocessor. All

macros are expanded and all comments are deleted in this listing.

68

Page 69: Prepaid Electricity Billing System

filename.SRC: -

Files with this extension are assembly source files generated from your C source code.

These files can be assembled with the A51 assembler.

3.5.5 Debugging: -

When micro-Vision2 IDH and the micro-Vision2 Debugger is being used,

complete debug information is obtained when Options for Target - Output - Debug

information is obtained. For command line tools the following rules apply. By default, the

C51 complier uses the Intel Object Format (OFM2) for object files and generates

complete symbol information. All Intel compatible emulators may be used for program

debugging. The DEBG directive embeds debugging information in the object file. In

addition, the OBJECTEXTEND directive embeds additional variable type information in

the object file that allows type specific display of variables and structures when using

certain emulators. The Cx51 complier uses the OFM2 object file format. The Cx51

complier also uses the OFM2 format when the directive OFM2 is active. The OFM2

format requires the extended Lx51 linker/locator and cannot be used with the BL51

linker/locator.

3.5.6 Complier Limits: -

The Cx51 complier embodies some known limitations that are listed below. For the most

part, there are no limits with respect to components of the C language. If there is enough

address space, several thousand symbols could be defined.

A maximum of 19 levels of indirection (access modifiers) to any standard data type are

supported. This includes array descriptors, indirection operators and function

descriptors.

69

Page 70: Prepaid Electricity Billing System

Names may be up to 256 characters long. The C language provides for case sensitivity

in regard to function and variable names. However, for compatibility reasons all names

in the object file appear in capital letters. It is therefore irrelevant if an external object

name within the source program is written in capital or small letters.

The maximum number of case statements in a switch block is not fixed. Limits are

imposed only by the available memory size and the maximum size of the individual

functions.

The maximum number of nested calls in an invocation parameter list is 10. This value is

independent of pre-processor files or whether not an object file is to be generated.

The maximum depth of directives for conditional compilation is 20. This is a pre-

processor limitation.

Instruction blocks ({...}) may be nested up to 15 levels deep.

Macros may be nested up to 8 levels deep. A maximum of 32 parameters may be

passed into a macro or function call. The maximum length of a line or a macro definition

is 2000 characters. Even after a macro expansion the result may not exceed 2000

characters.

70

Page 71: Prepaid Electricity Billing System

71

Page 72: Prepaid Electricity Billing System

72

Page 73: Prepaid Electricity Billing System

SOURCE CODE

#include<reg52.h>

#include<string.h>

#define LCD P0

bit flag=0;

sbit power=P2^0;

#define ON 1

#define OFF 0

bit recharge;

char balance=0;

bit t_flag = 0;

bit r_flag = 0;

bit sucess = 0;

int i=0,z;

char idata buff[150];

void init_lcd(void);

void cmd_lcd(unsigned char);

void data_lcd(unsigned char);

void display_lcd(unsigned char *);

void delay_ms(int);

void integer_lcd(int n);

void SEND_CHR(unsigned char);

73

Page 74: Prepaid Electricity Billing System

void external0() interrupt 0

{

flag=1;

balance=balance--;

delay_ms(10);

}

void print(char *str0)

{

while(*str0)

{

t_flag = 0;

SBUF = *str0++;

while(t_flag == 0);

}

}

void main()

{

int l;

power = OFF;

TMOD = 0x20;

74

Page 75: Prepaid Electricity Billing System

SCON = 0x50;

TH1 = 0xFD;

TR1 = 1;

init_lcd();

display_lcd("GSM TESTING");

delay_ms(500);

cmd_lcd(0x01);

display_lcd("INITIALIZING");

i = 0;

print("AT+CMGF=1\r\n");

delay_ms(100);

balance=0;

sucess = 0;

do{

strcpy(buff," ");

r_flag = 0;

i = 0;

print("AT+CMGD=1,4\r\n");

while(i < 16);

delay_ms(100);

display_lcd(buff);

delay_ms(1000);

75

Page 76: Prepaid Electricity Billing System

l = 0;

while(buff[l] != '\0')

{

if(buff[l++] == 'E')

sucess = 1;

}

delay_ms(1000);

}while(sucess != 1);

cmd_lcd(0x01);

display_lcd("MESSAGES DELETED");

delay_ms(500);

while(1)

{

sucess = 0;

cmd_lcd(0x01);

display_lcd("INBOX EMPTY");

delay_ms(100);

do

{

i = 0;

strcpy(buff,"");

r_flag = 0;

76

Page 77: Prepaid Electricity Billing System

while(r_flag == 0)

{

recharge=0;

cmd_lcd(0x01);

cmd_lcd(0x80);

display_lcd("Amount Used");

cmd_lcd(0xc0);

integer_lcd(balance);

if(balance>0)

{

power=ON;

for(z=0;z<balance;z++)

{

cmd_lcd(0xc0);

integer_lcd(z);

delay_ms(1000);

if(z==balance)

power=OFF;

}

balance=0;

77

Page 78: Prepaid Electricity Billing System

}

else if(balance<=0)

{

power = OFF;

} else{;}

cmd_lcd(0xc0);

integer_lcd(balance);

if(balance<=0)

{

flag = 0;

if(!balance)

//if(P1^0==0)

{

power = OFF;

cmd_lcd(0x01);

cmd_lcd(0x80);

display_lcd(" NO BALANCE");

delay_ms(100);

recharge=0;

cmd_lcd(0x01);

display_lcd("SENDING SMS....");

print("AT+CMGS=");

78

Page 79: Prepaid Electricity Billing System

SEND_CHR('"');

print("918885283676");

SEND_CHR('"');

print("\r\n");

print("NO BALANCE PLEASE RECHARGE ENERGY METER\r\n");

print("\r\n");

delay_ms(500);

cmd_lcd(0x01);

display_lcd("Message sent");

delay_ms(50);

cmd_lcd(0x01);

sucess=0;

while(sucess != 1);

cmd_lcd(0x01);

display_lcd("MESSAGE DELETED : ");

delay_ms(500);

sucess=0;

cmd_lcd(0x01);

display_lcd("INBOX EMPTY");

delay_ms(100);

}

79

Page 80: Prepaid Electricity Billing System

}

}

cmd_lcd(0x80);

display_lcd(" NO BALANCE ");

cmd_lcd(0xc0);

display_lcd("PLEASE RECHARGE");

i = 0;

strcpy(buff,"");

r_flag = 0;

while(r_flag == 0);

delay_ms(100);

if(buff[2] == '+')

sucess = 1;

}while(sucess != 1);

cmd_lcd(0x01);

display_lcd("MESSAGE RECEIVED");

delay_ms(1000);

i = 0;

strcpy(buff,"");

print("AT+CMGR=1\r\n");

delay_ms(1000);

l=0;

80

Page 81: Prepaid Electricity Billing System

while(buff[l++] != ',');

cmd_lcd(0x01);

display_lcd("CELL NO : ");

cmd_lcd(0xC0);

cmd_lcd(0x01);

display_lcd("MESSAGE : ");

cmd_lcd(0xC0);

data_lcd(buff[l]);

delay_ms(2000);

sucess = 0;

while(sucess != 1);

cmd_lcd(0x01);

display_lcd("MESSAGE DELETED : ");

delay_ms(1000);

}

}

void integer_lcd(int n)

{

unsigned char c[6];

unsigned int t=0;

if(n<0)

81

Page 82: Prepaid Electricity Billing System

{

data_lcd('_');

n=-n;

}

if(n==0)

data_lcd('0');

while(n>0)

{

c[t++] =(n%10)+48;

n/=10;

}

while(t-- >= 1)

data_lcd(c[t]);

data_lcd(' ');

}

void init_lcd(void)

{

cmd_lcd(0x38);

cmd_lcd(0x0C);

cmd_lcd(0x06);

cmd_lcd(0x01);

82

Page 83: Prepaid Electricity Billing System

}

void cmd_lcd(unsigned char var)

{

LCD = ((var & 0xF0) | 0x08);

LCD = 0;

LCD = ((var << 4) | 0x08);

LCD = 0;

delay_ms(2);

}

void data_lcd(unsigned char var)

{

LCD = ((var & 0xF0) | 0x0a);

LCD = 0;

LCD = ((var << 4) | 0x0a);

LCD = 0;

delay_ms(2);

}

void display_lcd(char *str)

{

while(*str)

data_lcd(*str++);

}

83

Page 84: Prepaid Electricity Billing System

void delay_ms(int cnt)

{

int i;

while(cnt--)

for(i=0;i<500;i++);

}

void SEND_CHR(unsigned char c)

{

t_flag = 0;

SBUF = c;

while(t_flag == 0);

}

CONCLUSION

84

Page 85: Prepaid Electricity Billing System

ADVANTAGES

GSM providers are available almost in many countries

It can also used in industries, colleges, police people, fire stations, hospitals.

We can control the home appliances by sending a SMS to programmed home

automation kit with coded instructions by the authenticated programmer

simultaneously we will get a feedback and the status of the device. Since we have

an option of Roaming Service provided by the GSM service providers hence we can

get SMS at any place on the earth.

We can Switch ON/OFF the devices by sending a SMS from any place in the world.

It is cheaper when compared to the other type of automation system.

It is more effective when compared to the other type of automation system.

It is easy to change the system’s action according to change in situation.

DISADVANTAGES

It requires a continuous electrical power supply for its proper working

We have to continuously recharge the GSM SIMCARD.

Maintenance cost is high i.e. service charges are more per SMS.

If the SIM gets damaged we need to reprogram with other number for security

purposes because the cost depends on the service provider.

BIBLIOGRAPHY

The 8051 microcontroller Architecture, programming& Applications

85

Page 86: Prepaid Electricity Billing System

Author “Kenneth J.Ayala”

The 8051 “Microcontroller & Embedded Systems”

Author “Muhammad Ali Mazidi “&

“Janice Gillispi Mazidi”

ATMEL Datasheet

WEBSITES

www.nicrochip.com

www.microelect.com

www.kpsec.freeuk.com

www.atmel.com

www.electrofriends.com

86


Recommended