Вы находитесь на странице: 1из 90

Real Time Energy and Monitoring

Control System


Group Members
Awais Ibrahim (09EL12)
Waqas Nasir (09EL17)
Zahoor ul Haq (09EL31)
Umar Farooq (09EL32)

Supervisor
Engr. Mahnoor
Lecturer
DEPARTMENT OF ELECTRICAL ENGINEERING
Swedish College of Engineering and Technology
(2009-2013)

Real Time Energy and Monitoring
Control System

Group Members
Awais Ibrahim (09EL12)
Waqas Nasir (09EL17)
Zahoor ul Haq (09EL31)
Umar Farooq (09EL32)
A thesis submitted in partial fulfillment of the requirements for the degree of
B.Sc. Electrical Engineering specialization in Electronics
Thesis Supervisor:
Engr. Mahnoor
Lecturer (Electronics)
External Examiner Signature: ___________________________________________
Thesis Supervisor Signature: ___________________________________________
Project Officer Signature ____________________________________________
DEPARTMENT OF ELECTRICAL ENGINEERING
Swedish College of Engineering and Technology
2009-2013
3


ABSTRACT

The goal of this project is to uproot energy loss caused by malpractices observed in energy uses in
Private or Government buildings. Keeping in mind the present energy crisis prevailing in
Pakistan, our project will be milestone to country. This project should be used in industry and any
place where energy is to be saved. Design and implement an efficient hardware to monitor real
time energy consumption. To provide the necessary controls in order to meet the energy
conservation defined in preset policies. If the electrical energy consumption is measured at run
time then optimization is possible to reduce the consumption. If the Control of electrical power is
available at some central location, then it is possible to reduce the consumption by applying time
scheduling. This project can be implemented in universities commercial and residential buildings
to save energy.


4

UNDERTAKING
Use the following undertaking as it is.
I certify that research work titled enter title of your research proposal here is my own work.
The work has not been presented elsewhere for assessment. Where material has been used from
other sources it has been properly acknowledged/referred.









Signature of Students
Waqas Nasir
Registration Numbers

5

ACKNOWLEDGEMENTS

This Project reviews the relationship between energy efficiency and demand response and
barriers to coordinating energy efficiency and demand response. While energy efficiency is an
increasingly prominent component of efforts to supply affordable, reliable, secure, and clean
electric power, demand response is becoming a valuable tool in utility and regional resource
plans. This project can provide you a fully control power supply system. Through this project
we can monitor over input and output power. According to load requirements we can adjust
the input power through the pre time schedule.











6

TABLE OF CONTENTS
Abstract .................................................................................................................... ....3
Acknowledgement ........................................................................................................................... 5
Chapter I: Introduction ................................................................................................................... 11
1.1 Objective ........................................................................................................ .......................12
1.2 Scope of the project............................12
1.3 System Block Diagram...........................13
1.4 Principal of Operation............................13
1.5 System Feature...........................14
1.6 Required Skills..........................14
1.7 Project Phases.........................14
1.8 Equipments........................14
Chapter II: Hardware Parts..............................15
2.1 Block Diagram Explanation.......................16
2.2 Micro Controller..........................16
2.3 Graphical User Interface........................17
2.4 LCD Display.........................17
2.5 Relay...........................18
2.6 Max 485........................18
2.7 CT & PT.......................19
7

Chapter III: Hardware Description...........................20
3.1 Micro Controller PIC 18F45...........................21
3.2 Features.........................21
3.3 CMOS Technolog.........................22
3.4 Programming..........................23
3.5 18F452 Pin out.........................28
3.6 Schematic of 18F452........................29
3.7 Pin Diagram of 18F452.......................30
3.8 Power Supply.....................30
3.9 Liquid Crystal Display....................33
3.10 Max 485...................35
3.11 LM 358...............37
3.12 RTC................38
3.13 Diode...............42
3.14 Current Transformer............43
3.15 Potential Transformer.............45
3.16 Max 232.............46
Chapter IV: Software Description............47
4.1 Flow Chart............48
4.2 Source Code..............49
8

Chapter V: Graphical User Interface...........54
5.1 Introduction.............55
5.2 Over View of Visual Basic............55
5.3 Visual Basic Windows............59
5.4 Visual Basic Programming...........63
5.5 Visual Basic Code..........67
Chapter VI: Conclusion & Future Direction.........70
6.1 Conclusion......71
6.2 Future Directions.....71
Appendix A: Schematic Diagrams.......72
Appendix B: PCB.....76
Appendix C: Data Sheets.....79
9

LIST OF FIGURES

Fig 1.3 System Block Diagram ............................................................ ..................13
Fig 2.2 Block Diagram .................................................................................................... .............16
Fig 2.3 LCD Display ..................................................................................................................... 18
Fig 2.4 DC Relay .......................................................................................................................... 18
Fig 2.5 MAX485. ......................................................................................................................... 19
Fig 3.1 PIC 18F452 Schematic Diagram....................................29
Fig 3.3 Stepdown Transformer..................31
Fig 3.6 LCD Pin Diagram...............33
Fig 3.8 MAX Pin and Circuit..................36
Fig 3.9 Dual Operational Amplifier..................37
Fig 3.10 LM385 Block Diagram. ..............38
Fig 3.11 DS1302 Pin Configuration...............40
Fig 3.13 Marking Diagram.............................43
Fig 3.14 RCT-35 CT................................44
Fig 3.15 Potential Transformer.............................45
10

Fig 4.1 Flow Diagram...........................48
Fig A-1 Power Supply Circuit........................72
Fig A-2 Schematic Diagram of CT & PT Interface....................73
Fig A-3 Max 232 to RS Converter Circuit....74
Fig A-4 Main Board Circuit Diagram....75
Fig B-1 Power Supply PCB......................76
Fig B-2 CT & PT Interface PCB......................77
Fig B-3 Main Board PCB....................78






















11






CHAPTER 1

I NTRODUCTI ON






















12




INTRODUCTION

All progress and development in the society is energy dependent. Societies gifted with energy
resources and those who have acquired skills for management of energy resources are better
placed in the comity of nations. Pakistan with limited resources of fossil fuels and rain dependent
hydroelectric generation is witnessing long hours of power shutdowns nationally that reflects well
on the prevailing energy crisis. The situation rings alarm as to frustrating power availability
position in the country. This would now impact on all walks of life especially the industrial and
agriculture sector in the country. This is high time we should think of alternatives such as
development of infrastructure to utilize renewable energy resources for power generation
economically and saving in the energy conservation at all levels. There are ample opportunities in
energy savings and we simply need to identify and put them in to practice. Energy wastage in
building sector is one of large possibilities where energy saving opportunities can be definitely
sought. Energy wastage in government sector building is mainly the outcome of three major
factors;
Improper infrastructure
Low quality electrical fixture and ill-planned wiring system, and
Attitude and practices of government employees towards electrical energy utilization.
The goal of this project is to uproot energy loss caused by malpractices observed in energy uses in
Private building. SCET is one of the leading public sector universities of Pakistan. The University
is located at a distance of 4 km from the city Centre. The University started functioning in 2009.




1.1 OBJECTIVES

To save the energy or power.
The automatic control of electric appliances in public gathering places.
To control the lightening system.
To design and implement an efficient hardware to monitor real time energy
consumption.
Measurement of existing load.
Defining of policies of load management according to schedule.
Identification of a person in working place (class room, lab, office) and controlling
load accordingly.
To provide the necessary controls in order to meet the energy conservation defined
in preset policies.
To use this system for security purpose.

1.2 SCOPE OF THE PROJECT

13

Keeping in mind the present energy crisis prevailing in Pakistan, our project will be milestone to
country.
This project should be used in an industry and any place where energy is to be saved.
To design and implement an efficient hardware to monitor real time energy consumption.
To provide the necessary controls in order to meet the energy conservation defined in preset
policies.
If the electrical energy consumption is measured at run time then optimization is possible to
reduce the consumption.
If the Control of electrical power is available at some central location, then it is possible to reduce
the consumption by applying time scheduling.
This project can be implemented in universities commercial and residential buildings to save
energy.
The saved energy can be profitably utilized to run the industry and feed power to agricultural
sector for better yield.
The saving so achieved can be beneficially used for other important developments to improve
efficiency and facilities for the institutions and individuals.
We can use our project for security purposes.

1.2 SYSTEM BLOCK DIAGRAM



Figure 1-3. System Block Diagram of Real Time Energy Monitoring & Control System


14

1.4 PRINCIPLE OF OPERATION
Measurement of existing load of different section of department and prevailing practice to control
the load effectively to optimal efficiency.
Categorization of different types and duration of working of the class room, lab and offices load.
Defining of policies of load management as per time table and the university timing and day light
hours.



1.5 SYSTEM FEATURES

Easy operation
Convenient
Affordable

1.6 REQUIRED SKILLS

Understanding of Micro controller
Embedded C Programming
Understanding Interfacing Techniques
Knowledge on Sensors
Designing of PCBs

1.7 PROJECT PHASES

Schematic design and making PCBs
Design and Interfacing Circuits for Micro controller
Assembling and Testing of Interfacing Circuits
Code for the Application
Debugging and Testing
Project Report

1.8 EQUIPMENTS

Micro controller PIC 18F452
5V,-5V, 12V Dc Power supply
LCD 2 line by 20 characters
Lamps
RTC 1302
MAX 485, PC, CT& PT, Relay




15










CHAPTER 2

Hardware Parts







16



Hardware Parts

2.1 BLOCK DIAGRAM EXPLANATION


Figure 2-1. Block Diagram of Real Time Energy Monitoring & Control System

2.2 MICRO CONTROLLER

We have used PIC18F452 Microcontroller. We have preferred PIC Microcontroller because of
following reasons.
It is built in A/D coveters.
It is easily programmable.
Is has reduced set of instruction set.
It is easily available in Market.

17





2.3 GRAPHICAL USER INTERFACE (GUI)

GUI is user friendly environment in which user can easily interact with the software. In our
project for GUI we used Microsoft Visual Basic software for creating time schedule and
necessary control elements for the energy conservation. This Visual Basic is a powerful and
sophisticated tool for creating business-critical and mission-critical applications.

2.4 LCD DISPLAY

A liquid crystal is a material (normally organic for LCDs) that will flow like a liquid but whos
molecular structure has some properties normally associated with solids. The in the order of
microwatts for the LCD. However, an LCD requires an external or internal light source.






18


Figure 2-3. Green LCD Display

2.5 RELAYS

A relay is an electrically operated switch. Many relays use an electromagnet to operate a
switching mechanism. Relays are used where it is necessary to control a circuit by a low-power
signal. In our system we have used JQC-3FC (T73) relay. It works on 12v DC voltage. Its
switching voltage is 250v AC and 7 ampere. In our projects we have used three relays on 21, 22,
23 pin of microcontroller.


Figure 2-4. DC 12V Relay



2.6 MAX 485

The MAX485, MAX487, MAX491, and MAX1487 are low-power transceivers for RS-485 and
RS-422 communication, each device has a drive and a receiver, MAX483, MAX487, MAX488,
and MAX489 are slew rate drive to reduce EMI and reduce reflections caused match by
19

improperly terminated cables, to achieve error -free data transmission up to 250kbps. The
MAX481, MAX485, MAX490, MAX491, and MAX1487 are the drive slew rate without
restriction, you can realize up to 2.5Mbps transfer rate. These transceivers disabled drivers
unloaded or fully loaded state draw a supply current of 120A and 500A.


Figure 2-5. MAX485- RS485 Transceiver


2.7 CT&PT

Current transformers (CT's) provide a simple, inexpensive and yet accurate means of sensing
current flow in power conductors. CT's used with watt transducers enable the owner to control
demand as well as monitor building and tenant power consumption.
A current transformer appears to be the simplest of electrical devices. For example, the bushing
type current transformer is simply a winding on an insulated core which becomes a transformer
only when placed over the primary conductor. The opening paragraph of Moreton's classic paper
states that the art of calculating current transformer characteristics from excitation curve data has
been known for some time. Moreton wrote this paper in 1943 and referred to papers written two
years earlier.
A potential transformer is a conventional transformer having primary and secondary windings.
The primary winding is connected directly to the power circuit either between two phases or
between one phase and ground, depending on the rating of the transformer and on the
requirements of the application. A capacitance potential device is a voltage- transforming
equipment using a capacitance voltage divider connected between phase and ground of a power
circuit.












20





CHAPTER 3

HARDWARE DESCRI PTI ON
























21

HARDWARE DESCRIPTION


3.1 MICROCONTROLLER PIC 18F452
This series of microcontroller is important for current measurements. It has some very useful
features, which make it unique in applications. Its features and specifications are given below.

High-Performance RISC CPU:

Source code compatible with the PIC16 and PIC17 instruction sets
Linear program memory addressing to 32 Kbytes
DC - 40 MHz osc./clock input
16-bit wide instructions 8-bitwide data path
Priority levels for interrupts
8 x 8 Single Cycle Hardware Multiplier.


Table 3-1. Device Features


3.2 FEATURES

Peripheral Features

High current sink/source 25 mA/25 mA
Three external interrupt pins
Two 16-bit timer/counter (TMR1, TMR3)
One 8-bit/16-bit timer/counter with prescaler
One 8-bit timer/counter with 8-bit period register
Capture 16-bit, max. Resolution 6.25 ns (TCY/16)
Compare 16-bit, max.Resolution100 ns.
3-wire SPI (supports all 4 SPI modes)
22

I C Master and Slave mode
Supports RS-485 and RS-232
Parallel Slave Port (PSP) module

Analog Features:
Compatible 10-bit Analog-to-Digital Converter module (A/D)
Programmable Low Voltage Detection (PLVD)
Programmable Brown-out Reset (BOR)

Special Microcontrollers Features:

Power-On Reset
Power-up Timer (PWRT) and Oscillator Start-Up Timer (OST)
Power-On Reset
100,000 erase/write cycle Enhanced FLASH program memory typical
1,000,000 erase/write cycle Data EEPROM memory
Self-reprogrammable under software control
Watchdog Timer (WDT) with its own On-Chip RC oscillator
Programmable code protection
Power saving SLEEP mode
4X Phase Lock Loop (of primary oscillator)
Secondary Oscillator (32kHz) clock input
Single supply 5V In-circuit Serial Programming via two pins
In-Circuit Debug (ICD)

3.3 CMOS TECHNOLOGY

Low power, high speed FLSH/EEPROM technology
Fully static design
Wide operating voltage range (2.0V to 5.5V)
Industrial and Extended temperatur e ranges
1.6 mA typical @ 5V, 4 MHz

Detail Description

Here is the detail of the module, which is the basic reason for using this microcontroller in our
project.
A PIC microcontroller is a processor with built in memory and RAM and you can use it to control
your projects (or build projects around it). So it saves you building a circuit that has separate
external RAM, ROM and peripheral chips.
What this really means for you is that you have a very powerful device that has many useful built
in modules e.g.

EEPROM
23

Timers
Analogue comparators
UART
Even with just these four modules (note these are just example modules - there are more) you can
make up many projects e.g.:
* Frequency counter- using the internal timers and reporting through UART (RS232) or output
to LCD.
* Capacitance meter- analogue comparator oscillator.
* Event timer - using internal timers.
* Event data logger-capturing analogue data using an internal ADC and using the internal
EEPROM for storing data (using an external I2C for high data storage capacity.
* Servo controller (Control through UART) - using the internal PWM module or using a
software created PWM.
The PIC Micro is one of the most popular microcontrollers and in case you were wondering the
difference between a microprocessor and a microcontroller is that a microcontroller has an
internal bus within built memory and peripherals.
In fact the 8 pin (DIL) version of the 12F675 has an amazing number of internal peripherals.
These are:
Two timers.
One 10bit ADC with 4 selectable inputs.
An internal oscillator (or you can use an external crystal).
An analogue comparator.
1024 words of program memory.
1536 Bytes of RAM.
256 Bytes of EEPROM memory.
External interrupt (as well as interrupts from internal peripherals).
External crystal can go up to 20MHz.
ICSP: PIC standard programming interface.

And all of these work from within a 40 pin DIL package.


3.4 PROGRAMMING

One of the most useful features of a PIC microcontroller is that you can re-program them as they
use flash memory (if you choose a part with an F in the part number e.g. 12F675 not 12C509).
You can also use the ICSP serial interface built into each PIC Microcontroller for programming
and even do programming while it's still plugged into the circuit. You can either program a PIC
microcontroller using assembler or a high level language and I recommend using a high level
language such as C as it is much easier to use (after an initial learning curve). Once you have
learned the high level language you are not forced to use the same processor e.g. you could go to
an AVR or Dallas microcontroller and still use the same high level language.

24


Table 3-2. PIC Microcontroller Feature Description Table

Input / Output - I/O

A PIC Microcontroller can control outputs and react to inputs e.g. you could drive a relay or read
input buttons. With the larger devices it's possible to drive LCDs or seven segment displays with
very few control lines as all the work is done inside the PIC Micro.

So using those saves prototype design effort as you can use built in peripherals to take care of lots
of the circuit operation. Many now have a built in ADC so you can read analogue signal levels so
you don't need to add an external devices e.g. you can read an LM35 temperature sensor directly
with no interface logic.

Peripherals

The PIC microcontroller has many built in peripherals and this can make using them quite
daunting at first which is why I have made this introductory page with a summary of each major
peripheral block.
The best way to start is to learn about the main features of a chip and then begin to use each

25

Flash memory

This is the program storage area and gives you the most important benefit for using a PIC
microcontroller - You program the device many times. Since when does anyone get a program
right first time? Devices used in projects on this site can be re-programmed up to 100,000 times
(probably more) as they use Flash memory - these have the letter F in the part name. You can get
cheaper (OTP) devices but these are One-Time-Programmable; once programmed you can't
program it again.

ICSP

In Circuit Serial Programming (ICSP) is the next most important benefit. Instead of transferring
your chip from the programmer to the development board you just leave it in the board. By
arranging the programming connections to your circuit correctly you won't need to remove the
chip. You can re-program the device while it's still in the circuit so once your programmer is
setup you can leave it on the bench and test your programs without moving the chip around and
it makes the whole process much easier.

I/O Ports

Input / Output ports let you communicate with the outside world so you can control leads, LCDs
or just about anything with the right interface. You can also set them as inputs to gather
information.

Pin Direction

Most PIC microcontroller pins can be set as an input or and output and this can be done on the
fly e.g. for a Dallas 1 wire system a pin can be written to generate data and read at a later stage.
The TRIS register controls the I/O direction and setting a bit in this register to zero sets the pin
as output while setting it as one sets the pin as input. This allows you to use a pin for multiple
operations e.g. the Real Time clock project uses
RA0, the first pin of PORTA, to output data to a seven segment display and at a later point in the
program read the analogue value as an input.

Current

The PIC I/O ports are high current ports capable of directly driving LEDs (up to 25ma output
current) - the total current allowed usually ~200mA this is often for the whole chip (or specified
for several ports combined together).

Timer / Counters

Each PIC microcontroller has up to three timers that you can either use as a timer or a counter
(Timer 1 & 2) or a baud clock (Timer 2).
Timer 0

26

The original timer: Timer 0 was the first timer developed and you can find it in all the earliest
devices e.g. 16F84 up to the most current e,g, 16F877A. It is an 8 bit timer with an 8 bit
prescaler that can be driven from an internal (Fosc/4) or external clock. It generates an interrupt
on overflow when the count goes from 255 to zero.

Timer 1

This is a 16 bit timer that generates an overflow interrupt when it goes from 65535 to zero. It has
an 8 bit programmable prescaler and you can drive it from the internal clock (Fosc/4) or an
external pin. To eliminate false triggering it also has an optional input synchronizer for external
pin input.

Timer 2

This is an 8 bit timer with an 8 bit pre scaler and an 8 bit post scaler. It takes its input only from
the internal oscillator (Fosc/4). This timer is used for the time base of a PWM when PWM is
active and it can be software selected by the SSP module as a baud clock. It also has a period
register that allows easy control of the period. When timer 2 reaches the PR2 register value then
it resets. This saves having to check the timer value in software and then reset the timer and since
it is done in hardware the operation is much faster - so you can generate fast clocks with periods
that are multiples of the main clocks.

USART

The USART is a useful module and saves having to code up a software version so it saves
valuable program memory. You can find more information on RS232 here and how to make it
work. Look here for pin outs. All you need to interface it to a PC serial port is a MAX232 chip
(or equivalent).













27

Special Features



WDT

If your software goes haywire then this timer resets the processor. To stop the reset the well
behaved software must periodically issue the CLRWDT instruction to stop a reset. The WDT
runs using its own oscillator. It runs during sleep and shares Timer 0 presaler.

POR

Power on Reset starts PIC microcontroller initialization when it detects a rising edge on MCLR.

PWRT

If you enable this then 72ms after a POR the PIC microcontroller is started.

OST

Oscillator Startup Timer delays for 1024 oscillator cycles after PWRT (if PWRT is enabled)
ensuring that the oscillator has started and is stable. It is automatic and only used for crystal
oscillator modes and is active after POR or wake from sleep.
28


SLEEP

Sleep mode (or low power consumption mode) is entered by executing the 'SLEEP' command.
The device can wake from sleep caused by an external reset, Watch Dog Timer timeout, INT pin
RB port change or peripheral interrupt.

3.5 18F452 PIN OUT

The 18F452 is the largest chip used (40 pins) in the projects on this site functions are much more
spread out. This makes it the easiest chip to use for designs as you can put separate circuits on
separate ports without having to think too much if you are going to need a different function later
on.





























29

3.6 SCHEMATIC OF 18F452


Figure 3-1.PIC18F452 Schematic Diagram







30

3.7 PIN DIAGRAM OF 18F452



Figure 3-2.PIC18F452 Pin Diagram

3.8 POWER SUPPLY

Power supply block consists of following units:
Step down transformer.
Bridge rectifier circuit.
Input filter.
Voltage regulators.
Output filter.
Indicator unit.

Step Down Transformer

The step-down transformer is used to step down the supply voltage of 230v ac from mains to
lower values, as the various ICs used in this project require reduced voltages. The transformer
consists of primary and secondary coils.
31

To reduce or step down the voltage, the transformer is designed to contain less number of turns
in its secondary core. The outputs from the secondary coil which is center tapped are the ac
values of 0v, 15v and 15v. The conversion of these ac values to dc values to dc values is done
using the full wave rectifier unit.


Figure 3-3.Stepdown Transformer
Rectifier Unit

A diode bridge is an arrangement of four diodes connected in a bridge circuit. That provides the
polarity of output voltage of any polarity of the input voltage. When used in its most common
application, for conversion of alternating current (A.C) input into direct current (D.C) output, it
is known as a bridge rectifier. The diagram describes a diode-bridge design known as a full wave
rectifier. This design can be used to rectify single phase A.C. when no transformer center tap is
available. A bridge rectifier makes use of four diodes in a bridge arrangement to achieve full
wave rectification. This is a widely used configuration, both with individual diodes wired as
shown and with single component bridges where the diode bridge is wired internally.
For both positive and negative swings of the transformer, there is a forward path through the
diode bridge. Both conduction paths cause current to flow in the same direction through the load
resister, accomplishing full-wave rectification. While one set of diodes is forward biased, the
other set is reversing biased and effectively eliminated from the circuit.

Input Filter

Capacitors are used as filters. The ripples from the dc voltages are removed and pure dc voltage
is obtained. The primary action performed by capacitor is charging and discharging.
It charges in positive half cycle of the ac voltage and it will discharge in negative half cycle. So it
allows only ac voltage and does not allow the dc voltage. This filter is fixed before the regulator.
32

Capacitors used here are of the value 1000uF



Regulator unit

Regulator regulates the output voltage to a specific value. The output voltage is maintained
irrespective of the fluctuations in the input dc voltage. Whenever there are any ac voltage
fluctuations, the dc voltage also changes, and to avoid this regulators are used.
Regulators can be classified as: -
1. Positive regulator, which regulates the positive voltage (7805, 7812)


Figure 3-4.Fixed-Output Regulator

1. input pin
2. ground pin
3. output pin
2. Negative regulator, which regulates the negative voltage (7905).

1. ground pin
2. input pin
3. output pin Regulators used in this application are: -

7805 which provides 5v dc
7812 which provides 12v dc
7905 which provides -5v dc

Output Filter

This filter is fixed after the Regulator circuit to filter any of the possibly found ripples in the
output received finally. Capacitors used here are of value 10F.

33

3.9 LIQUID CRYSTAL DISPLAY (LCD)

LCD is a type of display used in digital watches and many portable computers. LCD displays
utilize to sheets of polarizing material with a liquid crystal solution between them. An electric
current passed through the liquid causes the crystals to align so that light cannot pass through
them. LCD technology has advanced very rapidly since its initial inception over a decade ago for
use in lap top computers. Technical achievements has resulted in brighter displace, higher
resolutions, reduce response times and cheaper manufacturing process.
Other advances have allowed LCDs to greatly reduce liquid crystal cell response times.
Response time is basically the amount of time it takes for a pixel to change colors, in reality
response time is the amount of time it takes a liquid crystal cell to go from being active to
inactive.
This is due to following reasons:
The declining prices of LCDs.
The ability to display numbers, characters and graphics. This is in contrast to LEDs,
which are limited to numbers and a few characters.

An intelligent LCD display of two lines, 20 characters per line that is interfaced to the
PIC18F452 microcontroller. Incorporation of a refreshing controller into the LCD, thereby
relieving the CPU to keep displaying the data. Ease of programming for characters and graphics.
Most of the LCD modules conform to a standard interface specification. A 14-pin access is
provided having eight data lines, three control lines and three power lines. The connections are
laid out in one of the two common configurations, either two rows of seven pins, or a single row
of 14 pins.
One of these pins is numbered on the LCDs printed circuit board (PCB), but if not, it is quite
easy to locate pin1. Since this pin is connected to ground, it often has a thicker PCB track,
connected to it, and it is generally connected to metal work at same point.



















34

Pin Diagram of LCD


Figure 3-6.LCD PIN Diagram



Pin Description

Vcc, Vss and VEE

While Vcc and Vss provide +5V and ground respectively, Vee is used for controlling LCD
contrast.

RS Register Select

There are two very important registers inside the LCD. The RS pin is used for their selection as
follows. If RS=0, the instruction command code register is selected, allowing the user to send a
command such as clear display, cursor at home, etc. If RS=1, the data register is selected,
allowing the user to send data to be displayed on the LCD.

R/W, read/write

R/W input allows the user to write information to the LCD or read information from it.
R/W = 1 for reading.
R/W= 0 for writing.


35

EN, enable

The LCD to latch information presented to its data pins uses the enable pin. When data is
supplied to data pins, a highto-low pulse must be applied to this pin in order for the LCD to
latch in the data present at the data pins. This pulse must be a minimum of 450 ns wide.

D0 D7

The 8bit data pins, DO D7, are used to send information to the LCD or read the contents of
the LCDs internal registers.
To display letters and numbers, we send ASCII codes for the letters AZ, a-z numbers 0-9 to
these pins while making RS=1.
There are also instruction command codes that can be sent to the LCD to clear the display or
force the cursor to home position or blink the instruction command codes.
We also use RS = 0 to check the busy flag bit to see if the LCD is ready to receive information.
The busy flag is D7 and can be read when R/W=1 and RS=0, as follows: if R/W = 1, RS = 0.
When D7= 1 (busy flag = 1), the LCD is busy taking care of internal operations and will not
accept any information.








3.10 MAX 485

The MAX485 is a type of chip interface the MAX485 interface chip is a Maxim's RS-485 chip.

Figure 3-7. RS-485 Chip.

The MAX481, MAX485, MAX490, MAX491, and MAX1487 are the drive slew rate without
restriction, you can realize up to 2.5Mbps transfer rate. These transceivers disabled drivers
unloaded or fully loaded state draw a supply current of 120A and 500A it has completed the
TTL level is converted to RS-485 level functionality. the structure of the MAX485 chip and pin
are very simple, the interior includes a driver and receiver side of RO and DI, respectively for the
36

input of the receiver output and drive with a microcontroller connected simply respectively
connected to the RXD and TXD of microcontroller can, / RE and DE side were enabled to
receive and send side, when / RE to logic 0, the device in the receiving state, when the DE is
logic 1, the device in the sending state, because the MAX485 work in half-duplex state control
these two pins can just use a pin of the microcontroller, the A side and B side, respectively, for
the differential signal terminal for receiving and sending, when the pin A level higher than that
of B, on behalf of the data sent 1, when A's level lower than that of B-side, on behalf of the data
sent. Wiring in connection with a microcontroller is very simple. Only need a signal to control
the MAX485 to receive and send can at the same time between the A and B side plus matching
resistor, generally optional 100 resistor.


Figure 3-8. MAX (Pin) and Working Circuit


Basic Parameters

Half-duplex
Rate: 2.5 Mbps
The slew rate: NO, low current shutdown mode: NO, the receiver allows control: YES
The quiescent current of 300
Load number: 32
Pin number: 8

Role

The MAX485 is a low-power transceivers for RS-485 and RS-422 communication driver slew
rates of the MAX485 is not restricted, can achieve a transfer rate of up to 2.5Mbps. State of
These transceivers is unloaded or fully loaded with disabled drivers supply current draw between
120A and 500A. All devices work in a single 5V supply. Drive short-circuit current limit and
thermal shutdown circuitry places the driver outputs to high impedance state. Receiver input has
a fail-safe characteristic, when the inputs are open, you can ensure that a logic high output with
high anti-jamming performance. The MAX485 is available in the market the most common
RS422 chip is also the largest amount of RS422 chip, cost, quality, supply stability is most of the
manufacturers it is the main reason.



37

3.11 LM 358

The LM358 series consists of two independent high gain, internally frequency compensated
operational amplifiers. It can be operated from a single power supply and also split power
supplies. The LM358 is available in SOP-8, DIP-8, and TSSOP-8 and MSOP-8 packages.
These devices consist of two independent, high-gain, frequency-compensated operational
amplifiers designed to operate from a single supply over a wide range of voltages. Operation
from split supplies also is possible if the difference between the two supplies is 3 V to 30 V (3 V
to 26 V for the LM2904 and LM2904Q), and VCC is at least 1.5 V more positive than the input
common-mode voltage. The low supply-current drain is independent of the magnitude of the
supply voltage. Applications include transducer amplifiers, dc amplification blocks, and all the
conventional operational amplifier circuits that now can be more easily implemented in single-
supply-voltage systems. For example,
These devices can be operated directly from the standard 5-V supply used in digital systems and
easily provides the required interface electronics without additional 5-V supplies. The LM2904Q
is manufactured to demanding automotive requirements. The LM158 and LM158A are
characterized for operation over the full military temperature range of 55Co to125Co. The
LM258 and LM258A are characterized for operation from 25Co to 85Co, the LM358 and
LM358Afrom 0Co to 70Co, and the LM2904 and LM2904Q from 40Co to 125Co.


Figure 3-9.Dual Operational Amplifiers-LM358

Features

Internally frequency compensated for unity gain
Wide power supply range 3V - 32 V
Input common-mode voltage range include ground
Large DC voltage gain: 100dB Typical RoHS Compliance
Wide Range of Supply Voltages: 3 V to 32 V(LM2904: 3 V to 26 V) or Dual Supplies
Low Supply Current Drain Independent of Supply Voltage : 0.8 mA
Common-Mode Range Extends to Negative Supply
Low Input Bias and Offset Current
Differential Input Voltage Range Equal to Maximum-Rated Supply Voltage :32 V(26
V for LM2904)
Single And Split Supply Operation
Internal Frequency Compensation




38

Internal block diagram

Figure 3-10.LM358 Internal Block Diagram

Table 3-3.LM358 Pin Configuration

3.12 RTC

The DS1302 trickle-charge timekeeping chip contains a real-time clock/calendar and 31 bytes of
static RAM. It communicates with a microprocessor via a simple serial interface. The real-time
clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The
end of the month date is automatically adjusted for months with fewer than 31 days, including
corrections for leap year. The clock operates in either the 24-hour or 12-hour format with an
39

AM/PM indicator.
Interfacing the DS1302 with a microprocessor is simplified by using synchronous serial
communication. Only three wires are required to communicate with the clock/RAM: CE, I/O
(data line), and SCLK (serial clock). Data can be transferred to and from the clock/RAM 1 byte
at a time or in a burst of up to 31 bytes. The DS1302 is designed to operate on very low power
and retain data and clock information on less than 1W.
The DS1302 is the successor to the DS1202. In addition to the basic timekeeping functions of the
DS1202, the DS1302 has the additional features of dual power pins for primary and backup
power supplies, programmable trickle charger for VCC1, and seven additional bytes of
scratchpad memory.


Figure 3-11.DS1302 Timekeeping Chip
Features
Real-Time Clock Counts Seconds, Minutes, Hours, Date of the Month, Month, Day of
the Week, and Year with Leap-Year Compensation Valid Up to 2100
31 x 8 Battery-Backed General-Purpose RAM
Serial I/O for Minimum Pin Count
2.0V to 5.5V Full Operation
Optional Industrial Temperature Range: -40C to +85C
DS1202 Compatible

Pin description

Figure 1 shows the main elements of the serial timekeeper: shift register, control logic, oscillator,
real-time clock, and RAM.

40


Figure 3-12.DS1302 Pin Configuration (Top view)




PIN Description Table

PIN DESCRIPTION
PIN

NAME

FUNCTION

1 VCC2

Primary Power-Supply Pin in Dual Supply
Configuration. VCC1 is connected to a
backup source to maintain the time and date
in the absence of primary power. The
DS1302 operates from the larger of VCC1 or
VCC2. When VCC2 is greater than VCC1 +
0.2V, VCC2 powers the DS1302. When
VCC2 is less than VCC1, VCC1 powers the
DS1302.
41


2 X1 Connections for Standard 32.768kHz Quartz
Crystal. The internal oscillator is designed
for operation with a crystal having a
specified load capacitance of 6pF. For more
information on crystal selection and crystal
layout considerations, refer to Application
Note 58: Crystal Considerations for Dallas
Real-Time Clocks. The DS1302 can also be
driven by an external 32.768kHz oscillator.
In this configuration, the X1 pin is connected
to the external oscillator signal and the X2
pin is floated.

3 X2 Same as X1
4 GND Ground

5 CE Input. CE signal must be asserted high during
a read or a write. This pin has an internal
40k (type) pull down resistor to ground.
Note: Previous data sheet revisions referred
to CE as RST. The functionality of the pin
has not changed.

6 I/O Input/Push-Pull Output. The I/O pin is the
bidirectional data pin for the 3-wire interface.
This pin has an internal 40k (type) pull
down resistor to ground.

7 SCLK Input. SCLK is used to synchronize data
movement on the serial interface. This pin
has an internal 40k (type) pull down
resistor to ground.

8 VCC1 Low-Power Operation in Single Supply and
Battery-Operated Systems and Low-Power
Battery Backup. In systems using the trickle
charger, the rechargeable energy source is
connected to this pin. UL recognized to
ensure against reverse charging current when
used with a lithium
Table 3-4. DS1302 Trickle-Charge Timekeeping Chip Pin Description

Oscillator Circuit

The DS1302 uses an external 32.768 kHz crystal. The oscillator circuit does not require any
external resistors or capacitors to operate. The following Table specifies several crystal
42

parameters for the external crystal. If using a crystal with the specified characteristics, the startup
time is usually less than one second.


Table 3-5.Crystal Parameters for External Crystal


3.13 DIODE

Features
Low forward voltage drop
Low leakage current
High forward surge capability
Solder dip 275 C max. 10 s, per JESD 22-B106
Compliant to RoHS Directive 2002/95/EC and in accordancetoWEEE2002/96/EC
Shipped in plastic bags, 1000 per bag
Available Tape and Reeled, 5000 per reel, by adding a RL suffix to the part number
Available in FanFold Packaging, 3000 per box, by adding a FF suffix to the part
number
PbFree Packages are Available

Mechanical Characteristics
Case: Epoxy, Molded
Weight: 0.4 gram (approximately)
Finish: All External Surfaces Corrosion Resistant and Terminal Leads are Readily Solder
able
Lead and Mounting Surface Temperature for Soldering Purposes: 260C Max. For 10
Seconds, 1/16 in. from case
Polarity: Cathode Indicated by Polarity Band


43



Figure 3-13.Marking Diagram

The 1N4001 series or 1N4000 series is a family of popular 1.0 amp general purpose silicon
rectifier diodes commonly used in AC adapters for common household appliances. Blocking
voltage varies from 50 to 1000 volts. This diode is made in an axial-lead DO-41 plastic package.
The 1N5400 series is a similarly popular series for higher current applications, up to 3 A. These
diodes come in the larger DO-201 axial package. These are fairly low-speed rectifier diodes,
being inefficient for square waves of more than 15 kHz. The series was second sourced by many
manufacturers. The 1N4000 series were in the Motorola Silicon Rectifier Handbook. These
devices are widely used.

3.14 CURRENT TRANSFORMER

In electrical engineering, a current transformer (CT) is used for measurement of electric currents.
Current transformers, together with voltage transformers (VT) (potential transformers (PT)), are
known as instrument transformers. When current in a circuit is too high to directly apply to
measuring instruments, a current transformer produces a reduced current accurately proportional
to the current in the circuit, which can be conveniently connected to measuring and recording
instruments. A current transformer also isolates the measuring instruments from what may be
very high voltage in the monitored circuit. Current transformers are commonly used in metering
and protective relays in the electrical power industry.
44



Figure 3-14. RCT-35 CT

Current transformers used in metering equipment for three-phase 400 ampere electricity supply.
Like any other transformer, a current transformer has a primary winding, a magnetic core, and a
secondary winding. The alternating current flowing in the primary produces a magnetic field in
the core, which then induces a current in the secondary winding circuit. A primary objective of
current transformer design is to ensure that the primary and secondary circuits are efficiently
coupled, so that the secondary current bears an accurate relationship to the primary current.
The most common design of CT consists of a length of wire wrapped many times around a
silicon steel ring passed over the circuit being measured. The CT's primary circuit therefore
consists of a single 'turn' of conductor, with a secondary of many tens or hundreds of turns. The
primary winding may be a permanent part of the current transformer, with a heavy copper bar to
carry current through the magnetic core. Window-type current transformers are also common,
which can have circuit cables run through the middle of an opening in the core to provide a
single-turn primary winding. When conductors passing through a CT are not centered in the
circular (or oval) opening, slight inaccuracies may occur.

Usage

Many digital clamp meters utilize a current transformer for measuring ac current. Current
transformers are used extensively for measuring current and monitoring the operation of the
power grid. Along with voltage leads, revenue-grade CTs drive the electrical utility's watt-hour
meter on virtually every building with three-phase service and single-phase services greater than
200 amps.
The CT is typically described by its current ratio from primary to secondary. Often, multiple CTs
are installed as a "stack" for various uses. For example, protection devices and revenue metering
may use separate CTs to provide isolation between metering and protection circuits, and allows
current transformers with different characteristics (accuracy, overload performance) to be used
for the devices.

Safety Precautions

Care must be taken that the secondary of a current transformer is not disconnected from its load
while current is flowing in the primary, as the transformer secondary will attempt to continue
45

driving current across the effectively infinite impedance. This will produce a high voltage across
the open secondary (into the range of several kilovolts in some cases), which may cause arc. The
high voltage produced will compromise operator and equipment safety and permanently affect
the accuracy of the transformer.

3.15 POTENTIAL TRANSFORMER

Features
Frequency...50Hz.
Standard Secondary Voltage .220VAC
Insulation Class 15.5kV, BIL 110KV Full Wave
UL Recognized
FOR INDOOR USE ONLY


Figure 3-15.Potential Transformer

Voltage transformers connected line-to-ground cannot be considered to be grounding
transformers and must not be operated with the secondary in closed delta because excessive
currents may flow in the delta.
Two fuse transformers should not be used for Y connections. It is preferred practice to connect
one lead from each voltage transformer directly to the neutral terminal, using a fuse in the line
side of the primary only. By this connection a transformer can never be "alive" from the line side
by reason of a blown fuse in the neutral side. For continuous operation, the transformer primary
voltage should not exceed 110% of rated value. Use one fuse, one bushing models for Y
applications. Use two fuses, two bushing models for delta applications.
A potential transformer is a conventional transformer having primary and secondary windings.
The primary winding is connected directly to the power circuit either between two phases or
between one phase and ground, depending on the rating of the transformer and on the
requirements of the application. A capacitance potential device is voltage-transforming
equipment using a capacitance voltage divider connected between phase and ground of a power
circuit


46

3.16 MAX 232

MAX 232 is a16 pin IC. The MAX232 is an integrated circuit that converts signals from an RS-
232 serial port to signals suitable for use in TTL compatible digital logic circuits.
When communicating with various microprocessors one needs to convert the RS232 levels down
to lower levels, typically 3.3 or 5.0 Volts. Here is a cheap and simple way to do that.
Serial RS-232 (V.24) communication works with voltages -15V to +15V for high and low. On
the other hand, TTL logic operates between 0V and +5V. Modern low power consumption logic
operates in the range of 0V and +3.3V or even lower. It is connected to microcontroller at pin no
25.




































47








Chapter 4

Software Description























48

Software Description

4.1 FLOW CHART




Figure 4-1.Flow Diagram







49

4.2 SOURCE CODE

#include "main.h"
#include <DS1302.C>
#include "lcd.c"
#define DevicId 1
#define rt Pin_C5
#define led1 Pin_C0
#define led2 Pin_C1
#define led3 Pin_C2
#define relay1 Pin_D2
#define relay2 Pin_D3
#define relay3 Pin_C4
#define MinSw pin_E1
#define HrSw pin_E2
#define counterAd 0
#define aAd 10
#define unitAd 20
int8 c,id,charcount,lenth;
int16 t1,t2,t3,t4;
int8 m[12];
int1 flag1,flag2,flag3;
#ZERO_RAM
#int_RDA
void RDA_isr(void)
{
c=getch();
if(c<4){id=c;}
if(c==10){Flag1=1;}
if(c==11){Flag1=0;}
if(c==12){Flag2=1;}
if(c==13){Flag2=0;}
if(c==14){Flag3=1;}
if(c==15){Flag3=0;}
if(c>19)
{
if(c!= 20)
{
m[charcount]=c;
CharCount++;
if(charcount>10) charcount=0;
}
else
{
lenth=charcount;
if(id==DevicId)
{t1=m[0]-48;
t2=(m[1]-48)*10;
t3=t3+(m[4]-48);
t4=(m[5]-48)*10;
t4=t4+(m[6]-48);}
charcount=0;
}
}
}
50

void main()
{
unsigned int16 i,TotalMin,temp;
unsigned int8 hr,min,sec;
unsigned int16 volt,amps;
setup_adc_ports(AN0_AN1_AN3);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_spi(SPI_SS_DISABLED);
setup_wdt(WDT_OFF);
enable_interrupts(GLOBAL);
set_tris_a(15);
set_tris_e(0);
set_tris_b(0);
set_tris_d(3);
set_tris_c(128);
set_tris_e(6);
lcd_init();
rtc_init();
flag1=0;
clrscr();
lcd_gotoxy(1,1);
sprintf(line,"*Bismillah Hirahman*");printlcd();
lcd_gotoxy(2,1);
sprintf(line,"* i_Raheem *");printlcd();
for(i=1;i<=2;i++)
{
output_high(led1);
output_high(led2);
Delay_ms(500);
output_low(led1);
output_low(led2);
Delay_ms(500);
}
clrscr();
lcd_gotoxy(1,1);
sprintf(line," REAL TIME ENERGY ");printlcd();
lcd_gotoxy(2,1);
sprintf(line,"MONITORING & CONTROL");printlcd()
for(i=1;i<=2;i++)
{
output_high(led1);
output_high(led2);
Delay_ms(500);
output_low(led1);
output_low(led2);
Delay_ms(500);
}
clrscr();
lcd_gotoxy(1,1);
sprintf(line," UMAIR ALTAF ");printlcd();
lcd_gotoxy(2,1);
sprintf(line,"* 2K8-EE-44 *");printlcd();
for(i=1;i<=2;i++)
{
output_high(led1);
51

output_high(led2);
Delay_ms(500);
output_low(led1);
output_low(led2);
Delay_ms(500);
}
clrscr();
lcd_gotoxy(1,1);
sprintf(line,"* MUHAMMAD KAMRAN *");printlcd();
lcd_gotoxy(2,1);
sprintf(line,"* 2K8-EE-27 *");printlcd();
for(i=1;i<=2;i++)
{
output_high(led1);
output_high(led2);
Delay_ms(500);
output_low(led1);
output_low(led2);
Delay_ms(500);
}
clrscr();
lcd_gotoxy(1,1);
sprintf(line," ASIA SUMER *");printlcd();
lcd_gotoxy(2,1);
sprintf(line,"* 2K8-EE-42 *");printlcd();
for(i=1;i<=2;i++)
{
output_high(led1);
output_high(led2);
Delay_ms(500);
output_low(led1);
output_low(led2);
Delay_ms(500);
}
clrscr();
lcd_gotoxy(1,1);
sprintf(line,"*Under Supervision *");printlcd();
lcd_gotoxy(2,1);
sprintf(line,"SIR TOHEED-UR-REHMAN");printlcd();
for(i=1;i<=2;i++)
{
output_high(led1);
output_high(led2);
Delay_ms(500);
output_low(led1);
output_low(led2);
Delay_ms(500);
}
clrscr();
lcd_gotoxy(1,1);
sprintf(line,"LAB 1");printlcd();
//if(input(sw)==0){save(counterAd,0);save(aAd,99);save(unitAd,2350);}
//counter=read(counterAd);
//a=read(aAd);
//unit=read(unitAd);
// OverLoadTime=6;
52

//rtc_set_datetime(BYTE day, BYTE mth, BYTE year, BYTE dow, BYTE hr, BYTE min);
//
lenth=0;
while(true)
{
//================================
set_adc_channel( 0 );
delay_us(100);
volt = read_adc();
set_adc_channel( 1 );
delay_us(100);
amps = read_adc();
if(amps>2)amps+=25;
amps/=5;
display(volt,amps);
//---------- time set ----------------------------
if(input(HrSw)==1)
{
hr++;
if(hr>24)hr=0;
rtc_set_datetime(23,7, 12, 3, hr,min);
delay_ms(100);
rtc_get_time(hr,min,sec);
lcd_gotoxy(1,12);
print_time(hr,min,sec);
delay_ms(400);
while(input(HrSw)==1);
}
if(input(MinSw)==1)
{
min++;
if(min>59)min=0;
rtc_set_datetime(23,7, 12, 3, hr,min);
delay_ms(100);
rtc_get_time(hr,min,sec);
lcd_gotoxy(1,12);
print_time(hr,min,sec);
delay_ms(400);
while(input(MinSw)==1);
}
//-----------------------------------------
rtc_get_time(hr,min,sec);temp=hr;TotalMin=(temp*60)+min;
lcd_gotoxy(1,12);
print_time(hr,min,sec);
delay_ms(200);
//-------- action ----------
if(volt<250 && volt>160)
{
if(id==DevicId)
{
if((TotalMin>=(t1*60) && TotalMin<=(t2*60)) || (TotalMin>=(t3*60) && TotalMin<=(t4*60)))
{
if(Flag1==1)output_high(relay1); else output_low(relay1);
if(Flag2==1)output_high(relay2); else output_low(relay2);
if(Flag3==1)output_high(relay3); else output_low(relay3);
}
53

}
}
else { output_low(relay1); output_low(relay2); output_low(relay3);}
}
}
















54





CHAPTER 5

GRAPHICAL USER I NTERFACE
(GUI )





















55

GRAPHICAL USER INTERFACE (GUI)

5.1 INTRODUCTION

Visual Studio .NET is Microsofts Integrated Development Environment (IDE) for creating,
running and debugging programs (also called applications) written in a variety of .NET
programming languages. This IDE is a powerful and sophisticated tool for creating business-
critical and mission-critical applications. In this chapter, we provide an overview of the Visual
Studio .NET IDE and demonstrate how to create a simple Visual Basic program by dragging and
dropping predefined building blocks into placethis technique is called visual programming.

5.2 OVER VIEW OF VISUAL BASIC

When Visual Studio .NET begins execution, the Start Page1 displays (Figure 5-1).The left hand
side of the Start Page contains a list of helpful links, such as Get Started. Clicking a link displays
its contents. We refer to single-clicking with the left mouse button as selecting, or clicking,
whereas we refer to double-clicking with the left mouse button as double-clicking. When
clicked, Get Started loads a page that contains a table listing the names of recent projects (such
as A Simple Program in Figure 5-1), along with the dates on which these projects were last
modified. A project is a group of related files, such as the Visual Basic code and images that
make up a program. When you load Visual Studio .NET for the first time, the list of recent
projects is empty. There are two buttons on the pageOpen Project and New Project, which are
used to open an existing project (such as the ones in the table of recent projects) and to create a
new project, respectively. We discuss the process of creating new projects momentarily.
Other links on the Start Page offer information and resources related to Visual Studio .NET.
Clicking whats New displays a page that lists new features and updates for Visual Studio .NET,
including downloads for code samples and programming tools. Online Community links to
online resources for contacting other software developers through news groups (organized
message boards on the Internet) and Web sites.


56


Figure 5-1. Start Page in Visual Studio .NET

Programmers can browse the Web from the IDE using Internet Explorer (also called internal
Web browser in Visual Studio .NET). To request a Web page, type its address into the location
bar (Figure 5-1) and press the Enter key. [Note: The computer must be connected to the Internet.]
Several other windows appear in the IDE besides the Start Page; we discuss them in subsequent
sections.
To create a new Visual Basic program, click the New Project button (Figure 5-1), which
Displays the New Project dialog (Figure 5-2). Dialogs are windows that facilitate user computer
communication. The Visual Studio .NET IDE organizes programs into projects and solutions,
which contain one or more projects. Multiple-project solutions are used to create large-scale
applications in which each project performs a single, well-defined task.
The Visual Studio .NET IDE provides project types for a variety of programming languages.
This book focuses on Visual Basic, so we select the Visual Basic Projects folder from the Project
Types window (Figure 5-2). We use some of the other project types in later chapters. A
57

Windows Application is a program that executes inside the Windows OS (e.g., Windows 2000 or
Windows XP). Windows applications include customized software that programmers create, as
well as software products like Microsoft Word, Internet Explorer and Visual Studio .NET.
By default, the Visual Studio .NET IDE assigns the name WindowsApplication1 to new project
and solution (Figure 5-2). The Visual Studio Projects folder in the My Documents folder is the
default folder referenced when Visual Studio .NET is executed for the first time. Programmers
can change both the name of the project and the location where it is created. After selecting a
projects name and location, click OK to display the IDE in design view (Figure 5-3), which
contains all the features necessary to begin creating programs.


Figure 5-2. New Project Dialog

58


Figure 5-3.Design View of Visual Studio

The gray rectangle (called a form) titled Form1 represents the Windows application that
The programmer is creating. Later in this chapter, we discuss how to customize this form by
adding controls (i.e., reusable components, such as buttons). Collectively, the form and controls
constitute the programs Graphical User Interface (GUI), which is the visual part of the program
with which the user interacts. Users enter data (inputs) into the program by typing at the
keyboard, by clicking the mouse buttons and in a variety of other ways. Programs display
instructions and other information (outputs) for users to read in the GUI. For example, the
New Project dialog in Figure 5-2 presents a GUI where the user clicks with the mouse button to
select a project type and then inputs a project name and location from the keyboard. The name of
each open document is listed on a tab. In our case, the documents are the Start Page and
Form1.vb [Design] (Figure 5-3). To view a document, click its tab. Tabs save space and facilitate
easy access to multiple documents. The active tab (the tab of the document currently displayed in
the IDE) is displayed in bold text (e.g., Form1.vb [Design]) and is positioned in front of all the
other tabs.


59

5.3 VISUAL BASIC Windows

The IDE provides windows for accessing project files and customizing controls. In this section,
we introduce several windows that are essential in the development of Visual Basic applications.
These windows can be accessed via the toolbar icons or by selecting the name of the desired
window in the View menu.
Visual Studio .NET provides a space-saving feature called auto-hide (Figure 5-5). When
Auto-hide is enabled; a toolbar appears along one of the edges of the IDE. This toolbar contains
one or more icons, each of which identifies a hidden window. Placing the mouse
Pointer over one of these icons displays that window, but the window is hidden once the
Mouse pointer is moved outside the windows area. To pin down a window (i.e., to disable
auto-hide and keep the window open), click the pin icon. Notice that, when a window is pinned
down, the pin icon has a vertical orientation, whereas, when auto-hide is enabled, the pin icon
has a horizontal orientation (Figure 5-5).


Figure 5-4.Tool Tip Demonstration
60


Figure 5-5. Auto-Hide Feature Demonstration

Solution Explorer

The Solution Explorer window (Figure 5-6) provides access to all the files in the solution. When
the Visual Studio .NET IDE is first loaded, the Solution Explorer is empty; there are no files to
display. Once a solution is open, the Solution Explorer displays that solutions contents. The
solutions startup project is the project that runs when the program executes and appears in bold
text in the Solution Explorer. For our single-project solution, the startup project is the only
project (WindowsApplication1). The Visual Basic file, which corresponds to the form shown in
Figure 5-3, is named Form1.vb. (Visual Basic files use the vb filename extension, which is short
for Visual Basic.) The other files and folders are discussed later in the book. [Note: We use
fonts to distinguish between IDE features (such as menu names and menu items) and other
elements that appear in the IDE. Our convention is to emphasize IDE features in a sans-serif bold
Helvetica font and to emphasize other elements, such as File names (e.g., Form1.vb) and
property names, in a serif Bold courier font.] The plus and minus boxes to the left of the project
name and the References folder expand and collapse the tree, respectively. Click a plus box to
display items grouped under the heading to the right of the plus box; click the minus box to
collapse a tree already in its expanded state. Other Visual Studio windows also use this plus-
box/minus-box convention.


61


Figure 5-6.Solution Explorer with an Open Solution.

Properties Window

The Properties window (Figure 5-8) displays the properties for a form or control. Properties
specify information such as size, color and position. Each form or control has its own set of
properties; a propertys description is displayed at the bottom of the Properties window
whenever that property is selected. If the Properties window is not visible, selecting
View > Properties Window, displays the Properties window
62


Figure 5-7. Toolbox window


63



Figure 5-8.Properties Window


5.4 VISUAL BASIC PROGRAMMING

Now that we have presented our first console application, we provide a step-by-step explanation
of how to create and run it using the features of the Visual Studio .NET IDE.
1. Create the console application. Select File > New > Project... to display the New Project
dialog (Figure 5-9). In the left pane, select Visual Basic Projects, and, in the right pane, select
Console Application. In the dialogs Name field, type Welcome1. The location in which project
files will be created is specified in the Location field. By default, projects are saved in the folder
64

Visual Studio Projects inside the My Documents folder (on the Windows desktop). Click OK to
create the project. The IDE now contains the open console application, as shown in Figure 5-10.
Notice that the editor window contains four lines of code provided by the IDE. The
coloring scheme used by the IDE is called syntax-color highlighting and helps
programmers visually differentiate programming elements. Keywords appear in blue, whereas
text is black. When present, comments are colored green. In Step 4, we discuss how to use the
editor window to write code.
2. Change the name of the program file. For programs in this book, we change the name of the
program file (i.e., Module1.vb) to a more descriptive name. To rename the file, click Module1.vb
in the Solution Explorer window, this step will display the program files properties in the
Properties window (Figure 5-11). Change the File Name property to Welcome1.vb.


Figure 5-9. Creating a Console Application with the New Project Dialog


65


Figure 5-10. IDE with an Open Console Application


Figure 5-11. Renaming the program file in the Properties window


66


3. Change the name of the module. Notice that changing the name of the program file does not
affect the module name in the program code. Module names must be modified in the editor
window. To do so, replace the identifier Module1 with mod First Welcome by deleting the old
name and typing the new name after the keyword Module.

4. Writing code. After the programmer types the class name and the dot operator (i.e., Console.),
a window containing a scrollbar is displayed. This Visual Studio .NET IDE feature, called
IntelliSense, lists a classs members, which include method names. As the programmer types
characters, the first member that matches all the characters typed is highlighted, and a tool tip
containing a description of that member is displayed. The programmer can type the complete
member name (e.g., Write Line), double-click the member name in the list or press the Tab key
to complete the name. Once the complete name is provided, the IntelliSense window closes.
When the programmer types the open parenthesis character, (, after Console.Write Line, two
additional windows are displayed. These are the Parameter Info and Parameter List windows.
The Parameter Info window displays information about a methods arguments. This window
indicates how many versions of the selected method are available and provides up and down
arrows for scrolling through the different versions. For example, there are 18 versions of the
Write Line method used in our example. The Parameter List window lists possible arguments for
the method shown in the Parameter Info window. These windows are part of the many features
provided by the IDE to aid program development. You will learn more about information
displayed in these windows over the next several chapters. In this case, because we know that we
want to use the version of Write Line that takes a string argument, we can close these windows
by pressing the Escape key twice (i.e., once for each of the windows).
Testing and Debugging Tip 3.2 Visual Basic provides a large number of classes and methods.
The Parameter Info and Parameter List windows help ensure that a method is being used
correctly. 3.2

5. Run the program. We are now ready to compile and execute our program.
To compile the program, select Build > Build Solution. This creates a new file, named
Welcome1.exe, in the projects directory that contains the Microsoft Intermediate Language
(MSIL) code for our program. The .exe file extension denotes that the file is executable (i.e.,
contains instructions that can be executed by another program, such as the Common Language
Runtime). To run this console application
(i.e., Welcome1.exe), select Debug > Start without Debugging.











67

5.5 VISUAL BASIC CODE

Private Sub Com_OnComm()
Select Case Com.CommEvent
Case comEvReceive
tmrCom.Enabled = True
TimeOut = 0
End Select
End Sub
Private Sub Combo1_Change()
On Error Resume Next
Data1.Recordset.FindFirst "serno='" & Combo1 & "'"
Text12.Text = Data1.Recordset.Fields(1)
End Sub
Private Sub Combo1_Click()
On Error Resume Next
Data1.Recordset.FindFirst "serno='" & Combo1 & "'"
Text12.Text = Data1.Recordset.Fields(1)
End Sub
Private Sub Command1_Click()
Com.Output = Chr$(1)
Com.Output = Chr$(10)
'Com.Output = Chr$(1) & Text21.Text & Chr$(20)
End Sub
Private Sub Command10_Click()
Com.Output = Chr$(1)
Text23.Text = Text1.Text + Text2.Text + Text10.Text + Text9.Text
Com.Output = Text23.Text + Chr$(20)
End Sub
Private Sub Command11_Click()
Com.Output = Chr$(2)
Text23.Text = Text4.Text + Text3.Text + Text11.Text + Text13.Text
Com.Output = Text23.Text + Chr$(20)
End Sub
Private Sub Command12_Click()
Com.Output = Chr$(3)
Text23.Text = Text6.Text + Text5.Text + Text16.Text + Text17.Text
Com.Output = Text23.Text + Chr$(20)
End Sub
Private Sub Command13_Click()
Form2.Show
End Sub
Private Sub Command16_Click()
Dim i As Integer
Dim j As Integer
Text3.Text = Text1.Text
68

Text4.Text = Time
Text5.Text = Date
Com.RTSEnable = False
For i = 1 To 2000 Step 2
Next i
If Val(Text1.Text) = 50 Then
Com.Output = Chr$(10)
'Label3.Caption = "aaa"
End If
If Val(Text1.Text) = 51 Then
Com.Output = Chr$(20)
'Label3.Caption = "bbb"
End If
For i = 1 To 30000 Step 1
For j = 1 To 50 Step 1
Next j
Next i
'Com.RTSEnable = True
End Sub
Private Sub Command17_Click()
Com.Output = Chr$(1)
Com.Output = Chr$(11)
End Sub
Private Sub Command18_Click()
Com.Output = Chr$(1)
Com.Output = Chr$(13)
End Sub
Private Sub Command19_Click()
Com.Output = Chr$(1)
Com.Output = Chr$(15)
Private Sub Command2_Click()
Com.Output = Chr$(1)
Com.Output = Chr$(12)
End Sub
Private Sub Command20_Click()
Com.Output = Chr$(2)
Com.Output = Chr$(11)
End Sub
Private Sub Command21_Click()
Com.Output = Chr$(2)
Com.Output = Chr$(13)
End Sub
Private Sub Command22_Click()
Com.Output = Chr$(2)
Com.Output = Chr$(15)
End Sub
69

Private Sub Command23_Click()
Com.Output = Chr$(3)
Com.Output = Chr$(11)
End Sub
Private Sub Command24_Click()
Com.Output = Chr$(3)
Com.Output = Chr$(13)
End Sub
Private Sub Command25_Click()
Com.Output = Chr$(3)
Com.Output = Chr$(15)
End Sub
Private Sub Command3_Click()
Com.Output = Chr$(1)
Com.Output = Chr$(14)
End Sub
Private Sub Command4_Click()
Com.Output = Chr$(2)
Com.Output = Chr$(14)
End Sub
Private Sub Command5_Click()
Com.Output = Chr$(2)
Com.Output = Chr$(12)
End Sub
Private Sub Command6_Click()
Com.Output = Chr$(2)
Com.Output = Chr$(10)
End Sub
Private Sub Command7_Click()
Com.Output = Chr$(3)
Com.Output = Chr$(14)
End Sub
Private Sub Command8_Click()
Com.Output = Chr$(3)
Com.Output = Chr$(12)
End Sub
Private Sub Command9_Click()
Com.Output = Chr$(3)
Com.Output = Chr$(10)
End Sub






70





CHAPTER 6

CONCLUSI ON & FUTURE
DI RECTI ONS
























71

CONCLUSION & FUTURE DIRECTIONS

6.1 CONCLUSION

Real Time energy Monitoring and Control System is not limited for any particular application, it
can be used anywhere in a process industries with little modifications in software coding
according to the requirements. This concept not only ensures that our work will be usable in the
future but also provides the flexibility to adapt and extend, as needs change.
In this project work we have studied and implemented a complete working model using a PIC
microcontroller. The programming and interfering of PIC microcontroller has been mastered
during the implementation. This work includes the study of energy saving system in many
applications.

6.2 FUTURE DIRECTIONS:

We expect that our next generation will develop this monitoring and control system with large
scale application such as implementation of this project to whole Engineering College.
In our project we developed a GUI for inter department Labs. This can be developed with all
Labs of all departments and can be provided a central control in the principal office. For this
purpose a Database need to developed in the same manner as we did for the time schedule of
Labs of Electrical Department























72

Appendix A

Schematic Diagrams

A-1 Power Supply Circuit Diagram


Figure A-1.Power Supply Circuit Diagram










73





A-2 CT & PT INTERFACE


Figure A-2.Schematic Diagram of CT & PT Interface
















74





A-3 MAX 232 to RS 485 Converter Circuit Diagram


Figure A-3.MAX 232 to RS 485 Converter Circuit Diagram


















75

A-4 Main Board Circuit Diagram


Figure A-4 Main Board Circuit Diagram










76

APPENDIX B
PCBs

B-1 Power Supply PCB.


Figure B-1.Power Supply















77

B-2 CT& PT Interface PCB

Figure B-2 CT & PT Interface






















78


B-3 MAIN BOARD PCB


Figure B-3.Main Board











79


Appendex C
Data Sheets

C-1 CURRENT TRANSFORMER











80


81


82

C-2 DS 1302






83



84

C-3 LM 7905



85















86

C-4 MAX 485


87








88




89

BIBLIOGRAPHY
BOOKS REFERRED

1) Adler, R. B., A. C. Smith, and R. L. Longani: Introduction to Semiconductor Physics, vol.
1, p. 78, Semiconductor Electronics Education Comitee, John Wiley & Sons, Inc., New York
,1964.

2) Schade, O. H.: Analysis of Rectifier Operation, proc. IRE, vol.31, pp. 341-361, July, 1943.

3) Stout, M. B.: Analysis of Rectifier Circuits, Elec. Eng., vol. 54, September, 1935.

4) Jacob Millman Christos C. Halkias.: Electronic Devices And Circuits, Tata McGraw-Hill
Publishing Company Ltd. Sep, 2003.

5) Fair, Z. E.: Piezoelectric Crystals in Oscillator Circuits, Bell System Tech. J., vol.24, April,
1945.

6) Hakim, S. s.:Open and Closed Loop Response of Feedback Amplifiers, Electron. Eng.,
October, 1962

7) Bode, H. W.: Negative Feedback in Current Amplifier Design, D. Van Nostrand Company,
Inc., Princeton, N.J., 1945.

8) Sawhney, A.K.: Electrical and Electronic Measurements and Instruments, Dhanpat Rai &
Co. 2003.

9) Yang, E.S: Fundamentals of Semiconductor Devices, chap. 1 McGraw Hill Book Company,
New York, 1978.

10) Shive, J.N.: Semiconductor Devices, chaps 8&9, D.Van Nostrand Inc. Princeton, N.J.,
1959.

11) Millman, J.: Microelectronics: Digital and Analog Circuits and Systems, McGraw Hill
Book Company, New York, 1979.

12) Roger L Stevens : Serial Communications, Dontrics, 1997

13) Robert Terusalim: Programming in Luo 2-nd edition, D. Van Nostrand Company, Inc.,
Princeton, N.J., 1987.

14) Jan Axelson: Parallel Port Complete, McGraw Hill Book Company, New York, 1989.

15) Peter H.Anderson, PIC C Routines copyright, Baltimore, MD, Nov,99

16) Bahadur, B.: Liquid Crystals- Applications and Uses, Litton Systems Canada, 1992.

90

17) Myke Predko: Programming and Customizing PIC Microcontrollers, Amazon, 1998.

18) Myke Predko: Handbook of Microcontrollers, Amazon, 1887.

19) Muhammad Ali Mazidi PIC Microcontrollers and Embedded System , Amazon, 2011.


Journals Referred
1) Innovation: Magazine of Research & Technology,2000

2) International Journal of Reliability, Quality and Safety Engineering(IJRQSE)

Editor-in-chief
Hoang Pham
Dept. of Industrial Eng

3) Journal of Electronics Manufacturing (JEM)

Editor-in-Chief
Paul P. Conway
Wolfson School of Mechanical & Manufacturing Engineering

4) Foundations and Trends in Electronic Design Automation (FTEDA)

Editor in-chief
Sharad Malik,
Dept.of Electrical Eng.,
Princeton University.
5) Printed Circuit Design Online (Magazine).

6) Design Magazine.

7) Journal of Instrumentation (JNIST).

8) Microcontroller solutions.

Вам также может понравиться