Академический Документы
Профессиональный Документы
Культура Документы
A PROJECT REPORT
Submitted by
ANANDASUNDARARAMAN. S 12005105005
BARNABAS. M. S 12005105011
KUMARAN. R 12005105029
PRASANNA. V 12005105328
BONAFIDE CERTIFICATE
SIGNATURE SIGNATURE
i
CERTIFICATE OF EVALUATION
The Report of the Project work submitted by the above students in partial
fulfillment for the award of Bachelor of Engineering degree in ELECTRICAL
AND ELECTRONICS ENGINEERING of Anna University was evaluated
and confirmed to be report of the work done by the above students and then
evaluated.
ii
ACKNOWLEDGEMENT
iii
ABSTRACT
Electronic prepaid energy meter is the emerging technology in the field of
electricity all over the world. It mainly ensures the accuracy of energy consumed
and eliminates the errors which usually occur in mechanical energy meters. In
addition to this, we use RF signals instead of using expensive smart card system.
This project uses the advantages of ADE 7758 – Energy Meter Chip and AT Mega
128 as the main host controller of the entire process. By using the toroidal current
transformer, voltage and current values are stepped down to a suit the functions of
electronic chips. The voltage and current values are multiplied using multiplier to
calculate the instantaneous power utilized by the consumer. Instantly the phase
difference between the voltage and current is noted by phase detector to calculate
the power factor. The Power utilized will be displayed on the LCD display in units,
along with the balance amount. These measured and noted power and current
values are transferred to AT Mega 128 host micro controller by means of SPI
status and data registers. These values are gathered at nearest EB office by means
stage of exhausting, buzzer and light emitting diode will pre inform to the utilities
about the minimum balance of power at the consumer premises. Then the utilities
will TOP UP power values by means of paying the money. RF signals are tamper
1. INTRODUCTION 1
1.1 ENERGY METER 1
1.2 TYPES OF ENERGY METERS 2
1.2.1 Mechanical Energy Meters 2
1.2.2 Multiple Tariff Meters 3
1.2.3 Electronic Energy Meters 3
1.2.3.1 Advantages of Static Meter 4
v
4. BASIC CIRCUIT DESIGN 10
4.1 PCB FABRICATION 10
5. DESIGN SPECIFICATIONS 12
5.1 POWER SUPPPLY AND OTHER MAIN
ACCESSORIES 12
5.1.1 Current Transformers 13
5.1.2 Specifications 13
5.1.3 Switched Mode Power Supply (SMPS) 13
5.1.4 Light Emitting Diode (LED) 14
5.1.5 Three Phase Contactor 15
5.1.6 Relay 15
5.1.7 Latch 15
5.1.8 Buzzer 16
5.1.9 Oscillator 16
5.2 RS 232 Driver 17
5.2.1 Features 17
5.2.2 Pin Diagram of RS 232 Driver 17
5.2.3 Description 17
5.2.4 Applications 18
5.3 ADE 7758 MICROCONTROLLER 18
5.3.1 Pin Diagram 18
5.3.2 Pin Description 18
5.4 ATmeg 128 Microcontroller 22
5.4.1 Pin Diagram and Block Diagram 22
5.4.2 Pin Description 23
vi
5.5 CC 2520 MICROCONTROLLER 26
5.5.1 Pin Diagram 26
5.5.2 Block Diagram of CC 2520 27
5.5.3 Pin Function Description 27
5.5.3.1 General Purpose I/O 28
5.5.3.2 Miscellaneous 28
5.5.3.3 Analog 28
5.5.4.4 Power / Ground Pins 29
5.6 HD 44780 LCD MICROCONTROLLER 30
5.6.1 Pin Diagram 30
5.6.2 Pin function Description 31
6. OPERATION 33
6.1 BASIC BLOCK DIAGRAM 33
6.2 GENERAL OPERATIONAL BLOCK DIAGRAM 34
6.3 OPERATIONAL DESCRIPTION 35
7. PROGRAMMING OF MICROCONTROLLER 38
8. CONCLUSION 63
vii
LIST OF FIGURES
viii
LIST OF ABBREVIATIONS
µC - Micro Controller
µF - Micro Farad
A - Ampere
ABS - Absolute
AC - Alternating Current
APCF - Active Power Calibration Frequency
CMOS - Complementary Metal Oxide
Semiconductor
CS - Chip Select
DOUT - Data Output for serial interface
EB - Electricity Board
GND - Ground
Hz - Hertz
I rms - Root Mean Square Current
IRO - Interrupt Request Output
kbps - Kilo bits per second
LCD - Liquid Crystal Display
LED - Light Emitting Diode
LFO - Low Frequency Oscillator
MHz - Mega Hertz
nF - Nano Farad
PC - Personal Computer
PCB - Printed Circuit Board
ix
PCE - Power Company Employee
ppm - Parts per Million
PSU - Power Supply Unit
RF - Radio Frequency
RS 232 - IEEE Recommended Standard 232
SBM - Spot Billing Machine
SCLK - Serial Clock Input for serial interface
SMPS - Switched Mode Power Supply
SPI - Serial Programming Interface
TTL - Transistor – Transistor Logic
V - Volt
VARCF - Reactive Power Calibration Frequency
Logic Output
VCC - Digital Supply Voltage
V rms - Root Mean Square Voltage
x
1. INTRODUCTION
1
1.2 TYPES OF ENERGY METERS
The electrical energy meters are classified as
• Electromechanical energy meter (Ferraris type)
• Multiple Tariff Meters
• Electronic energy meter (Static type)
2
The drawbacks of this type of Energy meters are as follows.
Due to the effect of temperature on the resistance of eddy current paths,
they are subjected to serious errors, which increases the losses and result
in poor working. These errors lead to development of electronic type
energy meter, which has better working than mechanical type energy
meters.
3
1.2.3.1 Advantages of Static Meters
The Static watt-hour meter has overcome the disadvantages of the
Ferraris Meter. It has more advantages like good measuring accuracy and
wide ranges of scale, low power consumption, wide operating
temperature, equipped with fault indication etc.
4
2. METERING AND BILLING
5
The proposed digital meter has been designed fully keeping in mind the
above shortcomings in the existing systems.
iv) The manual logging process also introduces a wide range of errors
such as data transpose errors, reproduction errors etc. In transpose errors
the order of numeric representation is mistaken changed. For example, 21
is represented as 12. This type of errors can be significant and create
customer dissatisfaction.
6
2.3.1 Smart Card System
The Smart Card System for Electric Power Metering operates on
the following basis.
• The meters are installed at the user’s end
• The meter reader visits the place at specific intervals ( once in a
month) and notes down the meter reading
• The present meter reading is fed into the computer at the Electricity
board
• The software is designed to compute the number of units consumed
in the month = present reading - previous reading.
• Based on the number of units consumed during the month the bill
is generated at applicable slab rate
• The bill is sent to the consumer
• The consumer pays the amount at the electricity board office
• The details of payment is entered
• The overdue position of bills is generated
• Power supply is disconnected
8
3.2 TOOLS USED IN THE PROJECT
a. Code Vision AVR – PCB Printing
b. OrCAD 9 – For Programming of Chips
c. Hercules – Virtual Simulation for the Project (Only for testing
circuits)
9
4. BASIC CIRCUIT DESIGN
10
Figure 4.2 PCB Fabrication
11
5. DESIGN SPECIFICATIONS
12
5.1.1 Current Transformers
Current Transformers are instrument transformers designed for
measuring electrical current. Toroidal Current Transformers are smaller
and lighter than most other types of current transformers. They have no
air-gaps, no magnetic stray field, and are very quiet .Toroidal Current
Transformers with an accuracy of better than 1%, which can be used to
monitor, protect, and control electrical systems for the following
applications:
• Energy (watt-hour, electricity) meter, Energy management.
• Circuit breakers, electricity protection systems.
5.1.2 Specifications
• Primary current: 5 A – 8,000 A.
• Secondary Current: 0.1 A – 5 A.
• Frequency: 50 Hz – 400 Hz.
• Accuracy: 1% .
• Construction: Tape insulated.
13
Switching power supply in automotive products often have
universal inputs, meaning that they can accept power from most mains
supplies throughout the world, with frequencies from 50 Hz to 60 Hz and
voltages from 100 V to 240 V (although a manual voltage "range" switch
may be required).
The features of the SMPS are as listed below
1) AC input range selected by switch.
2) Protections: Short circuit/Over load.
3) Cooling by free air convection.
4) 100% full load burn-in.
5) High reliability.
14
5.1.5 Three Phase Contactor
ITC-LC1-D type A.C. Contactors is suitable for frequency 50/60
Hz, rated insulation voltage up to 1000v, rated operation current 9330A
under AC-3 duty. It is mainly used for making/breaking electric circuits
at a long distance & for frequent starting/stopping & controlling A.C.
Motors. It is used in combination with thermal relay to compose a
magnetic motor starter.
5.1.6 Relay
A relay is an electrical switch that opens and closes under the
control of another electrical circuit. In the original form, the switch is
operated by an electromagnet to open or close one or many sets of
contacts. Because a relay is able to control an output circuit of higher
power than the input circuit, it can be considered to be, in a broad sense, a
form of an electrical amplifier.
5.1.7 Latch
These 8-bit registers feature totem-pole 3-STATE outputs designed
specifically for driving highly-capacitive or relatively low-impedance
loads.
15
The output control does not affect the internal operation of the
latches or flip-flops. That is, the old data can be retained or new data can
be entered even while the outputs are OFF.
5.1.8 Buzzer
A buzzer or beeper is a signaling device, usually electronic,
typically used in automobiles, household appliances such as a microwave
oven, or game shows. It most commonly consists of a number of switches
or sensors connected to a control unit that determines ‘if’ and ‘which’
button was pushed or a preset time has lapsed, and usually illuminates a
light on the appropriate button or control panel, and sounds a warning in
the form of a continuous or intermittent buzzing or beeping sound.
Nowadays, it is more popular to use a ceramic-based piezoelectric
sounder which makes a high-pitched tone. Usually these were hooked up
to "driver" circuits which varied the pitch of the sound for on and off.
5.1.9 Oscillator
An electronic oscillator is an electronic circuit that produces a
repetitive electronic signal, often a sine wave or a square wave.
16
5.2 RS 232 DRIVER
5.2.1 Features
• Operates with single 5V power supply.
• Operates Up to 12 kbps.
• Two drivers and two receivers.
• ± 30V Input levels.
• 2000V Human Body model.
5.2.3 Description
The MAX233 is a dual driver/ receiver that include a capacitive
voltage generator to supply. TIA/ EIA -232-F voltages levels from a
single 5V supply. Each receiver converts TIA/ EIA -232-F inputs to 5V
TTL/ CMOS levels.
17
These receivers have a typical threshold of 1.3 V, a typical hysteresis of
0.5 V, and can accept ±30V inputs. Each driver converts TTL/CMOS
input levels into TIA/ EIA -232-F levels.
5.2.4 Applications
• Battery- powered systems.
• Terminals.
• Modems and computers.
18
PIN 2: DGND-This provides the ground reference for the digital
circuitry in the ADE7758, that is, the multiplier, filters, and digital-to-
frequency converter. Because the digital return currents in the ADE7758
are small, it is acceptable to connect this pin to the analog ground plane
of the whole system.
PIN 4: AVDD- Analog Power Supply. This pin provides the supply
voltage for the analog circuitry in the ADE7758. The supply should be
maintained at 5 V ± 5% for specified operation. Every effort should be
made to minimize power supply ripple and noise at this pin by the use of
proper decoupling.
19
PIN 9, 10: ICP, ICN as similar as PIN 5.
PIN 11: AGND-This pin provides the ground reference for the analog
circuitry in the ADE7758, that is, ADCs, temperature sensor, and
reference. This pin should be tied to the analog ground plane or the
quietest ground reference in the system. To keep ground noise around the
ADE7758 to a minimum, the quiet ground plane should be connected to
the digital ground plane at only one point.
PIN 12: REF IN/OUT : This pin provides access to the on-chip voltage
reference. The on-chip reference has a nominal value of 2.4 V ± 8% and a
typical temperature coefficient of 30 ppm/°C. An external reference
source can also be connected at this pin.
PIN 13, 14: VN, VCP-Analog Inputs for the Voltage Channel. This
channel is used with the voltage transducer. It has the same description
has IAP AND IAN i.e. pin 5, 6. Instead of current rating, voltage ratings
are used here.
20
PIN 18: IRO -Interrupt Request Output. This is an active low open-drain
logic output. Maskable interrupts include: an active energy register at half
level, an apparent energy register at half level, and waveform sampling
up to 26 kBPS
PIN 19: CLKIN-Master Clock for ADCs and Digital Signal Processing.
An external clock can be provided at this logic input. Alternatively, a
parallel resonant AT crystal can be connected across CLKIN and
CLKOUT to provide a clock source for the ADE7758. The clock
frequency for specified operation is 10 MHz.
PIN 20: CLKOUT-A crystal can be connected across this pin and
CLKIN as previously described to provide a clock source for the
ADE7758. The CLKOUT pin can drive one CMOS load when either an
external clock is supplied at CLKIN or a crystal is being used.
PIN 21: CS - Chip Select. Part of the 4-wire serial interface. This active
low logic input allows the ADE7758 to share the serial bus with several
other devices.
PIN 22: DIN- Data Input for the Serial Interface. Data is shifted in at this
pin on the falling edge of SCLK.
PIN 23: SCLK - Serial Clock Input for the Synchronous Serial Interface.
All serial data transfers are synchronized to this clock. The SCLK has a
Schmidt-trigger input for use with a clock source that has a slow edge
transition time, for example, opto-isolator outputs.
21
PIN 24: DOUT - Data Output for the Serial Interface. Data is shifted out
at this pin on the rising edge of SCLK. This logic output is normally in a
high impedance state; unless it is driving data onto the serial data bus.
22
Figure 5.4 Block Diagram of ATmeg 128
23
As inputs, Port A pins that are externally pulled low will source current if
the pull-up resistors are activated. The Port A pins are tri-stated when a
reset condition becomes active, even if the clock is not running. The Port
A has an alternate function as the address low byte and data lines for the
External Memory Interface.
24
Port F (PF7, PF0): Port F serves as the analog inputs to the A/D
Converter. Port F also serves as an 8-bit bi-directional I/O port, if the A/D
Converter is not used. Port pins can provide internal pull-up resistors
(selected for each bit). Refer port A for explanation. If the JTAG interface
is enabled, the pull-up resistors on pins PF7 (TDI), PF5 (TMS), and PF4
(TCK) will be activated even if a Reset occurs. The TDO pin is tri-stated
unless TAP states that shift out data are entered. Port F also serves the
functions of the JTAG interface.
XTAL1:
Input to the inverting Oscillator amplifier and input to the internal
clock operating circuit.
XTAL2:
Output from the inverting Oscillator amplifier.
25
AVCC:
AVCC is the supply voltage pin for Port F and the A/D Converter.
It should be externally connected to VCC, even if the ADC is not used. If
the ADC is used, it should be connected to VCC through a low-pass
filter.
AREF:
AREF is the analog reference pin for the A/D Converter.
PEN:
PEN is a programming enable pin for the SPI Serial Programming
mode, and is internally pulled high. By holding this pin low during a
Power-on Reset, the device will enter the SPI Serial Programming mode.
26
5.5.2 Block Diagram of CC 2520
27
5.5.3.1 General Purpose I/O
PIN 4: GPIO5 - General purpose digital I/O.
PIN 5: GPIO4 - General purpose digital I/O.
PIN 6: GPIO3 - General purpose digital I/O.
PIN 7: GPIO2 - General purpose digital I/O.
PIN 9: GPIO1 - General purpose digital I/O.
PIN 10: GPIO0 - General purpose digital I/O.
5.5.3.2 Miscellaneous
PIN 25: RESETn - External reset pin, active low.
PIN 26: VREG_EN - When high, digital voltage regulator is active.
PIN 15, 18, and 21: NC – Not Connected.
5.5.3.3 Analog
PIN 23: RBIAS - External precision bias resistor for reference current.
56 kΩ, ±1%.
PIN 19: RF_N - Negative RF input signal to LNA in receive mode.
Negative RF output signal from PA in transmit mode.
PIN 17: RF_P - Positive RF input signal to LNA in receive mode.
Positive RF output signal from PA in transmit mode.
PIN 13: XOSC32M_Q1 - Crystal oscillator pin 1.
PIN 12: XOSC32M_Q2 - Crystal oscillator pin 2.
28
5.5.2.4 Power / Ground Pins
PIN 11, 14, 16, 20, and 22: AVDD - 1.8 V to 3.8 V analog power supply
connections. AVDD_GUARD - Power supply connection for digital
noise isolation and digital voltage regulator.
PIN 27: DCOUPL - 1.6 V to 2.0 V digital power supply output for
decoupling.
PIN 8: DVDD - 1.8 V to 3.8 V digital power supply for digital pads.
29
5.6 HD44780 LCD MICROCONTROLLER
5.6.1 Pin Diagram
30
5.6.2 Pin Function Description
DB4 to DB7: Four high order bidirectional tri state data bus pins. Used
for data transfer and receive between the MPU and the HD44780U. DB7
can be used as a busy flag.
DB0 to DB3: Four low order bidirectional tri state data bus pins. Used for
data transfer and receive between the MPU and the HD44780U.These
pins are not used during 4-bit operation.
M: Switch signal for converting the liquid crystal drive waveform to AC.
31
D: Character pattern data corresponding to each segment signal.
COM1 to COM16: Common signals that are not used are changed to
non-selection waveforms. COM9 to COM16 are non-selection
waveforms at 1/8 duty factor and COM12 to COM16 are non-selection
waveforms at 1/11 duty factor.
32
6. OPERATION
33
6.2 GENERAL OPERATIONAL BLOCK DIAGRAM
Sending End
SPI RS 232
ADE 7758 ATmeg 128 µC
Antenna
Antenna
CC 2520
RS 232
PC Interface
µC
Receiving End
34
6.2 OPERATIONAL DESCRIPTION
Generally, three phase power supplies from the electricity board
are logging into our houses for utilization. Three phase lines are passed
through the toroidal current transformer for stepping down the value
suitable for the working of the electronic chips. Similarly, these three
phase lines are soldered to the energy meter chip ADE 7758, for voltage
measuring purpose. Here the oscillator range of ADE 7758 chip is
10MHZ. Then current and voltage terminals are connected to
corresponding pins of ADE 7758 chip. In that chip, there is an 16 bit,
second order sigma – delta ADC with an over sampling rate of 833KHz,
which converts the analog current and voltage signals to digitalized
signals.
35
At the same time, phase detectors are used to detect the phase
difference between current and voltage of each phase. Finally we
calculate VI cosφ which is the real power and VI sinφ which is reactive
power. Then these are integrated with respect to time to measure the
energy utilized by the consumer.
36
Then the LED display values are also viewed at the nearest
electricity board office by means of RF transceiver. It is used to send and
receive the information from EB office and also receive from the
customer end. As soon as the energy consumed by the customer reaches
the amount just below 10 rupees, a buzzer starts its buzzing sound along
with the glow of LED which also indicates to customer about his lack of
balance and also indicates at the EB office terminal. At that time,
customer has to inform to the EB office to top up the money by means of
toll free telephone numbers or by means of internet. Once the account is
recharged the customer gets uninterrupted power supply. This process is
repeated for reliable power supply.
37
7. PROGRAMMING OF MICROCONTROLLER
//Declarations
#include <mega128.h>
#include <spi.h>
#include <math.h>
#define LCD_COMMAND_B 0x99
#define RED 1
#define GREEN 2
#define ORANGE 3
#define BREAKER_CNT 8000
#define LED_PIN PORTC.0
#define AP_V 16
#define VA_V 16
#define IA_V 16
#define A_WATTHR 0x01
#define B_VARHR 0x05
# #define C_VAHR 0X09
#define A_IRMS 0x0A
#define A_VRMS 0x0D
#define VPEAK 0x21
#define IPEAK 0x22
#define ADE_CS PORTB.5
#define LOW 0
#define HIGH 1
38
// USART1 Receiver buffer
#define RX_BUFFER_SIZE1 50
char rx_buffer1[RX_BUFFER_SIZE1];
unsigned char rx_wr_index1,rx_rd_index1,rx_counter1;
39
"****WELCOMES YOU****"//3
};
flash char *UDE[4]={
//0123456789ABCDEF6789
"UN = DCS ",//0
"SN = 12345 ",//1
"CN = 044-43551421 ",//2
"ML = 1000watts "//3
};
flash char *AP[4]={
//0123456789ABCDEF6789
" V I AP ",//0
"A ",//1
"B ",//2
"C "//3
};
flash char *AC[4]={
//0123456789ABCDEF6789
" V I AC ",//0
"A ",//1
"B ",//2
"C "//3
};
flash char *RP[4]={
//0123456789ABCDEF6789
" V I RP ",//0
"A ",//1
40
"B ",//2
"C "//3
};
flash char *VI[4]={
//0123456789ABCDEF6789
" V I ",//0
"PEK ",//1
"NOR ",//2
"LOW "//3
};
flash char *UR[4]={
//0123456789ABCDEF6789
" U R ",//0
"Ra/Hr ",//1
"AVI ",//2
" DT= hrs "//3
};
flash char *END_MSG[4]={
" CONTACT TNEB @ ",//0
" 044-26200261 ",//1
"E_M:QUERIES@TNEB.COM",//2
"*****THANK YOU******"//3
};
41
//RF Communication
Flash unsigned char
IMR[]="***PEM0904M0;IMREADY;===@@@@@@@@@@@@@
@@@@@@@@@@@@@";
flash unsigned char UD[]="***PEM0904M1;JKPROJECT TEAM
2009;SN:12345678;===";
flash unsigned char
CN[]="***PEM0904M1;CONTACTNUMBER=044-
43551421;===@@@@@@@";
flash unsigned char
AMST[]="***PEM0904M3;A|P=123456;R/U=12;PDU=123;DT=123;==
=@";
flash unsigned char
VOLT[]="***PEM0904M4;VA=123;VB=123;VC=123;===@@@@@
@@@@@@@@";
flash unsigned char
CUR[]="***PEM0904M5;IA=123;IB=123;IC=123;===@@@@@@@
@@@@@@";
flash unsigned char
PHI[]="***PEM0904M6;PIA=123;PIB=123;PIC=123;===@@@@@@
@@@@";
flash unsigned char
FT[]="***PEM0904M7;FA=12.3;FB=12.3;FC=12.3;T=12.3;===@@@
@";
42
//Getting details from ADE 7758
union{
signed char uc8_data[4];
signed int ui16_data[2];
signed long int uli32_data;
}u, v;
//Read Functions
signed int Fun_Read_A_WATT(void) {
unsigned char junk = 0;
u.uli32_data = 0; //clears the union
ADE_CS = LOW;
SPDR = A_WATTHR; //loads the register valve.
while(!(SPSR & 0x80));
junk = SPDR;
delay_ms(1);
SPDR = 0x00;
while(!(SPSR & 0x80));
u.uc8_data[1] = SPDR; //sends the MSB (15-8).
delay_ms(1);
SPDR = 0x00;
while(!(SPSR & 0x80));
u.uc8_data[0] = SPDR; //sends the LSB (7-0).
delay_ms(1);
ADE_CS=HIGH;
43
return(u.ui16_data[0]); //retrns the 16 bit value.
}
ADE_CS=LOW;
SPDR=TEMP; //loads the register valve.
while(!(SPSR & 0x80));
junk=SPDR;
SPDR=0x00;
while(!(SPSR & 0x80));
junk = SPDR; //sends the LSB (7-0).
ADE_CS=HIGH;
ADE_CS = LOW;
SPDR = AVRMSGAIN; //loads the register valve.
while(!(SPSR & 0x80));
junk = SPDR;
44
SPDR = 0x00;
while(!(SPSR & 0x80));
u.uc8_data[1] = SPDR; //sends the MSB (xxxx11-8).
SPDR = 0x00;
while(!(SPSR & 0x80));
u.uc8_data[0] = SPDR; //sends the LSB (7-0).
ADE_CS = HIGH;
ADE_CS = LOW;
SPDR = AVARG; //loads the register valve.
while(!(SPSR & 0x80));
junk = SPDR;
SPDR = 0x00;
while(!(SPSR & 0x80));
u.uc8_data[1] = SPDR; //sends the MSB (xxxx11-8).
SPDR = 0x00;
while(!(SPSR & 0x80));
45
u.uc8_data[0] = SPDR; //sends the LSB (7-0).
ADE_CS = HIGH;
ADE_CS = LOW;
SPDR = AWATTOS; //loads the register valve.
while(!(SPSR & 0x80));
junk = SPDR;
SPDR = 0x00;
while(!(SPSR & 0x80));
u.uc8_data[1] = SPDR; //sends the MSB (xxxx11-8).
SPDR = 0x00;
while(!(SPSR & 0x80));
u.uc8_data[0] = SPDR; //sends the LSB (7-0).
ADE_CS = HIGH;
46
void Fun_Write_APHCAL(unsigned char write_data) {
unsigned char junk = 0;
ADE_CS = LOW;
SPDR = (APHCAL | 0x80);
while(!(SPSR & 0x80));
junk = SPDR;
SPDR = write_data;
while(!(SPSR & 0x80));
junk = SPDR; //sends the LSB (7-0).
ADE_CS = HIGH;
}
unsigned char Fun_Read_VARDIV(void) {
unsigned char junk = 0;
ADE_CS = LOW;
SPDR = VARDIV; //loads the register valve.
while(!(SPSR & 0x80));
junk = SPDR;
SPDR = 0x00;
while(!(SPSR & 0x80));
junk = SPDR; //sends the LSB (7-0).
ADE_CS = HIGH;
47
}
unsigned char Fun_Read_VADIV(void) {
unsigned char junk = 0;
ADE_CS = LOW;
SPDR = VADIV; //loads the register valve.
while(!(SPSR & 0x80));
junk = SPDR;
SPDR = 0x00;
while(!(SPSR & 0x80));
junk = SPDR; //sends the LSB (7-0).
ADE_CS = HIGH;
ADE_CS = LOW;
SPDR = (APCFNUM | 0x80);
while(!(SPSR & 0x80));
junk = SPDR;
SPDR = u.uc8_data[1];
48
while(!(SPSR & 0x80));
junk = SPDR; //sends the MSB (xxxx11-8).
SPDR = u.uc8_data[0];
while(!(SPSR & 0x80));
junk = SPDR; //sends the LSB (7-0).
ADE_CS = HIGH;
}
ADE_CS = LOW;
SPDR = (APCFDEN | 0x80);
while(!(SPSR & 0x80));
junk = SPDR;
SPDR = u.uc8_data[1];
while(!(SPSR & 0x80));
junk = SPDR; //sends the MSB (xxxx11-8).
SPDR = u.uc8_data[0];
while(!(SPSR & 0x80));
junk = SPDR; //sends the LSB (7-0).
ADE_CS = HIGH;
}
void Fun_Write_VARCFDEN (unsigned int write_data) {
49
unsigned char junk = 0;
u.uli32_data = write_data; //clears the union
ADE_CS = LOW;
SPDR = (VARCFDEN | 0x80);
while(!(SPSR & 0x80));
junk = SPDR;
SPDR = u.uc8_data[1];
while(!(SPSR & 0x80));
junk = SPDR; //sends the MSB (xxxx11-8).
SPDR = u.uc8_data[0];
while(!(SPSR & 0x80));
junk = SPDR; //sends the LSB (7-0).
ADE_CS = HIGH;
}
unsigned char Fun_Read_VERSION(void) {
unsigned char junk = 0;
ADE_CS = LOW;
SPDR = VERSION; //loads the register valve.
while(!(SPSR & 0x80));
junk = SPDR;
SPDR = 0x00;
while(!(SPSR & 0x80));
50
junk = SPDR; //sends the LSB (7-0).
ADE_CS = HIGH;
// LCD Functions
// Timer 0 overflow interrupt service routine
interrupt [TIM0_OVF] void timer0_ovf_isr(void)
{
TCNT0=6;
if(++timecount == 200)
{
g++;
timecount = 0;
}
}
void TIME(void)
{
switch(2)
{
case 0:
Load_FBuf(STRTUP_MSG[0]);
Lcd_Dispmessage(1);
Load_FBuf(STRTUP_MSG[1]);
Lcd_Dispmessage(2);
Load_FBuf(STRTUP_MSG[2]);
51
Lcd_Dispmessage(3);
Load_FBuf(STRTUP_MSG[3]);
Lcd_Dispmessage(4);
break;
case 1:
Load_FBuf(UDE[0]);
Lcd_Dispmessage(1);
Load_FBuf(UDE[1]);
Lcd_Dispmessage(2);
Load_FBuf(UDE[2]);
Lcd_Dispmessage(3);
Load_FBuf(UDE[3]);
Lcd_Dispmessage(4);
break;
}
}
void V_I(void)
{
/*q=uli32_V/100;
r=uli32_V%100;
LCD_Buff[VI_V]=q+48;
q=r/10;
LCD_Buff[VI_V+1]=q+48;
q=r%10;
LCD_Buff[VI_V+2]=q+48;*/
q=uli32_I/100;
52
r=uli32_I%100;
LCD_Buff[VI_I]=q+48;
q=r/10;
LCD_Buff[VI_I+1]=q+48;
q=r%10;
LCD_Buff[VI_I+2]=q+48;
}
//write led function latched the data in the databus to the 74ls574 during
the rising edge of the clock pin.
void Write_4_LED()
{
DATA_DIRC=OUTPUT; //OUTPUT
DATA_PORT=LED_R;
DATA_DIRC=OUTPUT; //OUTPUT
DATA_PORT=LED_R;
LED_PIN=CLEAR;
delay_us(2);
LED_PIN=SET;
DATA_PORT=LED_R;
DATA_DIRC=INPUT;
}
//Reading Logic
unsigned char Fun_M0_IMREADY(void){
strcpyf(Ud_Tx_buff,IMR);
for(i=0;i<50;i++){
putchar1(Ud_Tx_buff[i]);
53
}
}
54
}*/
void Fun_M2_ENERGYSTATUS(void){
strcpyf(Ud_Tx_buff,ES);
q=U_DATA_0/100000;
r=U_DATA_0%100000;
Ud_Tx_buff[AP_V]=q+48;
q=r/10000;
r1=r%10000;
Ud_Tx_buff[AP_V+1]=q+48;
q=r1/1000;
r=r1%1000;
Ud_Tx_buff[AP_V+2]=q+48;
q=r/100;
r1=r%100;
Ud_Tx_buff[AP_V+3]=q+48;
q=r1/10;
Ud_Tx_buff[AP_V+4]=q+48;
q=r1%10;
Ud_Tx_buff[AP_V+5]=q+48;
q=U_DATA_1/100000;
r=U_DATA_1%100000;
Ud_Tx_buff[RP_V]=q+48;
q=r/10000;
r1=r%10000;
Ud_Tx_buff[RP_V+1]=q+48;
55
q=r1/1000;
r=r1%1000;
Ud_Tx_buff[RP_V+2]=q+48;
q=r/100;
r1=r%100;
Ud_Tx_buff[RP_V+3]=q+48;
q=r1/10;
Ud_Tx_buff[RP_V+4]=q+48;
q=r1%10;
Ud_Tx_buff[RP_V+5]=q+48;
q=U_DATA_2/100000;
r=U_DATA_2%100000;
Ud_Tx_buff[AC_V]=q+48;
q=r/10000;
r1=r%10000;
Ud_Tx_buff[AC_V+1]=q+48;
q=r1/1000;
r=r1%1000;
Ud_Tx_buff[AC_V+2]=q+48;
q=r/100;
r1=r%100;
Ud_Tx_buff[AC_V+3]=q+48;
q=r1/10;
Ud_Tx_buff[AC_V+4]=q+48;
q=r1%10;
Ud_Tx_buff[AC_V+5]=q+48;
56
for(i=0;i<50;i++){
putchar1(Ud_Tx_buff[i]);
}
}
unsigned char Fun_M3_AMOUNTSTATUS(void){
strcpyf(Ud_Tx_buff,AMST);
q=U_DATA_3/100000;
r=U_DATA_3%100000;
Ud_Tx_buff[AMPD_V]=q+48;
q=r/10000;
r1=r%10000;
Ud_Tx_buff[AMPD_V+1]=q+48;
q=r1/1000;
r=r1%1000;
Ud_Tx_buff[AMPD_V+2]=q+48;
q=r/100;
r1=r%100;
Ud_Tx_buff[AMPD_V+3]=q+48;
q=r1/10;
Ud_Tx_buff[AMPD_V+4]=q+48;
q=r1%10;
Ud_Tx_buff[AMPD_V+5]=q+48;
q=U_DATA_4/10;
Ud_Tx_buff[RPU_V]=q+48;
q=U_DATA_4%10;
57
Ud_Tx_buff[RPU_V+1]=q+48;
q=U_DATA_5/100;
r1=U_DATA_5%100;
Ud_Tx_buff[PDU_V]=q+48;
q=r1/10;
Ud_Tx_buff[PDU_V+1]=q+48;
q=r1%10;
Ud_Tx_buff[PDU_V+2]=q+48;
q=U_DATA_6/100;
r1=U_DATA_6%100;
Ud_Tx_buff[DT_V]=q+48;
q=r1/10;
Ud_Tx_buff[DT_V+1]=q+48;
q=r1%10;
Ud_Tx_buff[DT_V+2]=q+48;
for(i=0;i<50;i++){
putchar1(Ud_Tx_buff[i]);
}
}
/*unsigned char Fun_M3_AMOUNTPAID(void){
strcpy(Ud_Tx_buff,AMPA);
for(i=0;i<50;i++){
putchar1(Ud_Tx_buff[i]);
}
58
}
unsigned char Fun_M3_RUPEESPERUNIT(void){
strcpy(Ud_Tx_buff,RPU);
for(i=0;i<50;i++){
putchar1(Ud_Tx_buff[i]);
}
}
unsigned char Fun_M8_TEMPERATURE(void){
strcpyf(Ud_Tx_buff,TEM);
for(i=0;i<50;i++){
putchar1(Ud_Tx_buff[i]);
}
} */
// Display Logic
unsigned char Fun_MODE(void){
MODE=Fun_CHK_4_MX();
switch(MODE)
{
case '0':
for(i=z;i<y;i++){
if(rx_buffer1[i+3]=='R' && rx_buffer1[i+4]=='U' &&
rx_buffer1[i+5]=='R'
&& rx_buffer1[i+6]=='E' && rx_buffer1[i+7]=='A'
&& rx_buffer1[i+8]=='D'
&& rx_buffer1[i+9]=='Y'){
Fun_M0_IMREADY();
59
}
}
break;
case '1':
for(i=z;i<y;i++){
if(rx_buffer1[i+3]=='U' && rx_buffer1[i+4]=='S' &&
rx_buffer1[i+5]=='E'
&& rx_buffer1[i+6]=='R' && rx_buffer1[i+7]=='D'
&& rx_buffer1[i+8]=='E'
&& rx_buffer1[i+9]=='T' && rx_buffer1[i+10]=='A'
&& rx_buffer1[i+11]=='I'
&& rx_buffer1[i+12]=='L' &&
rx_buffer1[i+13]=='S'){
Fun_M1_USERDETAILS();
Fun_M1_CONTACTNUMBER();
}
/*else if(rx_buffer1[i+3]=='U' &&
rx_buffer1[i+4]=='S' && rx_buffer1[i+5]=='E'
&& rx_buffer1[i+6]=='R' && rx_buffer1[i+7]=='N'
&& rx_buffer1[i+8]=='A'
&& rx_buffer1[i+9]=='M' && rx_buffer1[i+10]=='E'){
Fun_M1_USERNAME();
}
else if(rx_buffer1[i+3]=='S' && rx_buffer1[i+4]=='E'
&& rx_buffer1[i+5]=='R'
&& rx_buffer1[i+6]=='I' && rx_buffer1[i+7]=='A' &&
rx_buffer1[i+8]=='L'
60
&& rx_buffer1[i+9]=='N' && rx_buffer1[i+10]=='U'
&& rx_buffer1[i+11]=='M'
&& rx_buffer1[i+12]=='B' && rx_buffer1[i+13]=='E'
&& rx_buffer1[i+14]=='R'){
Fun_M1_SERIALNUMBER();
}*/
}
break;
case '2':
for(i=z;i<y;i++){
if(rx_buffer1[i+3]=='E' && rx_buffer1[i+4]=='N' &&
rx_buffer1[i+5]=='E'
&& rx_buffer1[i+6]=='R' && rx_buffer1[i+7]=='G'
&& rx_buffer1[i+8]=='Y'
&& rx_buffer1[i+9]=='S' && rx_buffer1[i+10]=='T'
&& rx_buffer1[i+11]=='A'
&& rx_buffer1[i+12]=='T' && rx_buffer1[i+13]=='U'
&& rx_buffer1[i+14]=='S'){
Fun_M2_ENERGYSTATUS();
}
/*else if(rx_buffer1[i+3]=='A' &&
rx_buffer1[i+4]=='C'){
Fun_M2_AC();
}
else if(rx_buffer1[i+3]=='R' &&
rx_buffer1[i+4]=='P'){
Fun_M2_RP();
}
61
else if(rx_buffer1[i+3]=='A' &&
rx_buffer1[i+4]=='P'){
Fun_M2_AP();
}*/
}
break;
}
}
void main(void)
{
PORTG=0x18;
SPSR=0x00;
#asm("sei")
INIT_LCD();
Lcd_Write_Cmd(BLINK_OFF);
for(uc_j=0; uc_j<5; uc_j++)
{ for(uc_i=1; uc_i<4; uc_i++)
{ ON_LED(uc_i,uc_j);
Write_4_LED();
delay_ms(100);
}
}
62
8. CONCLUSION
63
APPENDIX 1
Chennai: Suburban police officials are on the lookout for the proprietors
of a plastic manufacturing firm, who reportedly stole electricity from
overhead TNEB wires, to the tune of Rs 59.43 lakhs over a period of a
year. Based on a complaint filed by Jagadish Kumar, assistant engineer of
TNEB’s Manali unit, police have launched a search for Isakkimuthu and
Hanuman Patel, proprietors of Swastik Plastic Company, Thiruvotriyur.
According to suburban police officials, the two had connected a metal
hook to the electric wires running over their factory and during the night,
he had been stealing electricity through this. During the day though, the
hooks were removed and all signs of the theft would be covered up.
Despite the meters recording the excessive electricity being used, TNEB
officials realised that such large quantities were being stolen only after
many consumers lodged complaints of being over-billed. The officials
then launched an enquiry into the issue a few weeks back and through
field investigation, they narrowed down on the spot where the electricity
was stolen. Police officials are on the lookout for the two proprietors,
who are absconding.
64
APPENDIX 2
65
66
67
68
69
70
71
72
REFERENCES
73