GSM BASED HOME AUTOMATION

Published on July 2016 | Categories: Documents | Downloads: 51 | Comments: 0 | Views: 816
of 80
Download PDF   Embed   Report

Comments

Content

INTRODUCTIONChapter-1

1

INTRODUCTIONChapter-1

CHAPTER 1 INTRODUCTION
The aim of this project is to remote monitoring of domestic energy meter using GSM. This system enables the electricity department to read the meter reading regularly without the person visiting each house through GSM network. This can be achieved by the use of microcontroller (89C51) unit. The microcontroller based system continuously observes the reading of the live meter and it sends the current reading of live meter. The microcontroller at the transmitter is provided with GSM unit.

1.1 The main features of this project are:1) Monitoring of energy meter 2) Dynamic update of meter reading

1.2 The device provides learning’s on following advancement :• • • • • GSM modem interfacing to controller Energy meter interfacing PCB design LCD interfacing Embedded C programming

2

INTRODUCTIONChapter-1

1.3 The major building blocks of this project are:• • • • Microcontroller based control unit with regulated power supply. GSM modem Energy meter LCD display with driver circuit

1.4 Simplified Block Diagram of Project

3

INTRODUCTIONChapter-1

Fig.1

4

STRUCTURAL LAYOUTChapter-2

4

STRUCTURAL LAYOUTChapter-2

CHAPTER 2 STRUCTURAL LAYOUT

Figure 2.1

As shown in above circuit diagram IC CS5460 is low cost Analog to Digital converter. So the reference voltage & current values are taken in the form of analog signal from the main source. Reference Voltage are taken on across of R1(as shown in above diagram) & Reference Current are taken on across of Rs (as shown in above diagram). The regulated power supply constantly feds supply to pin no. 14 as positive pin no. 3 as negative. Now as a clock source crystal is connected between pin no. 1 & 24. And remaining pins are connected as shown in above circuit diagram with Controller 89S52.

5

STRUCTURAL LAYOUTChapter-2

Figure 2.2

Above diagram shows detailing of connections. Here we use 5 volts DC regulated power supply. A 12 volts, 1 ampere transformer is connected with diode bride. The output of diode bridge is connected with regulate power IC (7805) to provide 5 volt regulated power supply. The two capacitors are used to filtered the DC into pure form. This power supply is supplied to the whole circuit as shown in above diagram.
6

STRUCTURAL LAYOUTChapter-2

Crystal is connected between pin no. 18 & 19. To reset the IC RC circuit is connect on pin no.9. The value acquired by controller 89S52 is stored in EPROM 24C02C every second. Pin no. 5 (SDA) of EPROM is connected on port no. P 1.0 & Pin no. 6 (SCK) is connected with port no. P 1.1 So we can get the previous data from EPROM at the time of power failure. LCD (16x2) is connected to port no. 2 of controller. And the RS pin of LCD is connected with port no. P 3.6 (WR). And the E pin of LCD is connected wiyh port no. P 3.5 (T1). Vee Pin of LCD is used for contrast setting. And 5 volt supply is given to LCD & RW is grounded. GSM MODULE SIM 300 is used to transmit & receive the data from controller. Now Rx & Tx of GSM MODULE SIM 300 are crossly connected with controller. And 12 volt supply is given to GSM module. Relay is connected with port no P 0.7 through transistor BC547. This relay can used to operate the ON & OFF function of energy meter output.

7

PROGRAMMING DESCRIPTIONChapter-3

8

PROGRAMMING DESCRIPTIONChapter-3

CHAPTER 3 PROGRAMMING DESCRIPTION 3.1 PROGRAMMING OF IC 89S52 USING uKEIL

STEP 1 Open the uKEIL application software.

9

PROGRAMMING DESCRIPTIONChapter-3

STEP 2 Crate a project as shown below

10

PROGRAMMING DESCRIPTIONChapter-3

STEP 3 Select required device from the list as given below

STEP 4
11

PROGRAMMING DESCRIPTIONChapter-3

Now right click on TARGET and ADD a new (.c format) file.

STEP 6
12

PROGRAMMING DESCRIPTIONChapter-3

Now compile the program & analysize the error. It automatically hex file in particular folder.

STEP 7
13

PROGRAMMING DESCRIPTIONChapter-3

Right click on target & click on option for target window to set parameters of particular controllers.

14

PROGRAMMING DESCRIPTIONChapter-3

3.2 Programming of IC 89S52 using C programming Language
#include<reg52.h> #include"lcd.h" #include"e2p.h" #include"spi.h" #include<string.h> long double i = 0; long int Power=0; char send=0; unsigned long int Energy = 0; unsigned long int TEnergy=0,PrevEnergy=0; char a=0,t=0; char p=0; char TeH=0,TeL=0; unsigned long int Vrms=0,count1000=0,Irms=0; char sec=0; char resp0[]="info"; char resp1[]="off9"; char resp2[]="on99"; int y=0; char v=0,b=0; char temp[10]; sbit RLY = P0^7;
15

PROGRAMMING DESCRIPTIONChapter-3

void calP(void); void timer0(void) interrupt 1 using 1 { TR0 = 0; TF0 = 0; TH0=0xfc; TL0=0x64; count1000++; if(count1000>=999) { count1000=0; sec=1; } TR0 = 1; } void putchar(char x) { SBUF = x; TR1=1; while(!TI); TF1= 0; TI = 0; }
16

PROGRAMMING DESCRIPTIONChapter-3

void puts(char*a) { putchar(0x0d); putchar(0x0a); while(*a) putchar(*a++); putchar(0x0d); putchar(0x0a); } void putss(char*new) {

while(*new) putchar(*new++); } void putsn(char*str) { char i=0; for(i=0;i<=5;i++) { putchar(str[i]+48); } }
17

PROGRAMMING DESCRIPTIONChapter-3

void serial_init(void) { TMOD = 0x21; TH1 = -3; TR1 = 1; SCON = 0x50; REN = 1; TI=1; RI=0; } void serial(void) interrupt 4 using 1 { if(RI) { a++; if(a>=51 && a<=54) { temp[t]=SBUF; t++; if(t>=4) { t=0; send=1;
18

// 8-bit auto reload for timer1,timer0 16-bit mode

// 8-bit uart

PROGRAMMING DESCRIPTIONChapter-3

} } if(a>=55) { a =0; } RI=0; TI=0; TF1=0; } } void main(void)

{ char v=0; RLY=0; P1 = 0x40; P2=0x00; TH0=0xfc; TL0=0x64; TR0=1; lcd_init(); spi_init();
19

PROGRAMMING DESCRIPTIONChapter-3

TR1= 1; lcd_print(2,0,"please wait."); ms_delay(1000); serial_init(); ms_delay(100); while(v<3) { putchar('A'); putchar('T'); putchar('+'); putchar('C'); putchar('N'); putchar('M'); putchar('I'); putchar('='); putchar('1'); putchar(','); putchar('2'); putchar(','); putchar('0'); putchar(','); putchar('0'); putchar(',');
20

PROGRAMMING DESCRIPTIONChapter-3

putchar('0'); ms_delay(10); putchar(13); ms_delay(100); v++; }; i2c_start(); i2c_write(0xa0); i2c_write(0x10); i2c_start(); i2c_write(0xa1); TeH = i2c_read(0); i2c_stop(); i2c_start(); i2c_write(0xa0); i2c_write(0x11); i2c_start(); i2c_write(0xa1); TeL = i2c_read(0); i2c_stop(); PrevEnergy =(((int)TeH*100)+TeL)*1000; spi_write(8,0xa0); spi_write(32,0x4a0016e3);
21

// eeprom I2C address with R/W bit clear // data word register address

// eeprom I2C address with R/W bit clear // data word register address

PROGRAMMING DESCRIPTIONChapter-3

spi_write(8,0xe8); spi_write(8,0x18); i=adc_read(); i=(i/16777216)*250*(1.38); Vrms=(int)i; clearlcd(); CursorOff(); spi_write(8,0x16); i=adc_read(); i=(i/16777216)*5*1000; i=(int)i; IE = 0x92; while(1) { if(send==1) { if(!(strcmp(temp,resp0))) { send=0; putchar('A'); putchar('T'); putchar('+'); putchar('C');
22

PROGRAMMING DESCRIPTIONChapter-3

putchar('M'); putchar('G'); putchar('S'); putchar('='); putchar('"'); putchar('+'); putchar('9'); putchar('1'); putchar('9'); putchar('9'); putchar('2'); putchar('5'); putchar('8'); putchar('8'); putchar('7'); putchar('6'); putchar('0'); putchar('3'); putchar('"'); putchar(13); ms_delay(100); putsn(digit); ms_delay(10);
23

PROGRAMMING DESCRIPTIONChapter-3

putchar(26); } } if(!strcmp(temp,resp1)) { RLY=1; } if(!strcmp(temp,resp2)) { RLY=0; } spi_write(8,0x18); i=adc_read(); i=(i/16777216)*250*(1.38); Vrms=(int)i; spi_write(8,0x16); i=adc_read(); i=(i/16777216)*5*1000; Irms=(int)i; if(sec==1) { calP(); sec=0;
24

PROGRAMMING DESCRIPTIONChapter-3

} } } void calP(void) { Power =( Vrms * Irms * 1.41 *(0.735)); Energy = (unsigned long int)(Power); Energy=Energy/3600; TEnergy = PrevEnergy+Energy; PrevEnergy=TEnergy; TEnergy = TEnergy/1000; TeH = TEnergy/100; TeL = TEnergy%100; e2pWrite(0x10,TeH); e2pWrite(0x11,TeL); binbcd(TEnergy); lcd_print(7,0,"Wh"); lcd_print1(5,1,digit); }

25

PROGRAMMING DESCRIPTIONChapter-3

3.3 INCLUDED FILES

3.3.1 REG52.H
#ifndef __REG52_H__ #define __REG52_H__

/* BYTE Registers */ sfr P0 = 0x80; sfr P1 = 0x90; sfr P2 = 0xA0; sfr P3 = 0xB0; sfr PSW = 0xD0; sfr ACC = 0xE0; sfr B = 0xF0;

sfr SP = 0x81; sfr DPL = 0x82; sfr DPH = 0x83; sfr PCON = 0x87; sfr TCON = 0x88; sfr TMOD = 0x89; sfr TL0 = 0x8A; sfr TL1 = 0x8B;
26

PROGRAMMING DESCRIPTIONChapter-3

sfr TH0 = 0x8C; sfr TH1 = 0x8D; sfr IE = 0xA8; sfr IP = 0xB8; sfr SCON = 0x98; sfr SBUF = 0x99;

/* 8052 Extensions */ sfr T2CON = 0xC8; sfr RCAP2L = 0xCA; sfr RCAP2H = 0xCB; sfr TL2 = 0xCC; sfr TH2 = 0xCD;

/* BIT Registers */ /* PSW */ sbit CY = PSW^7; sbit AC = PSW^6; sbit F0 = PSW^5; sbit RS1 = PSW^4; sbit RS0 = PSW^3; sbit OV = PSW^2;
27

PROGRAMMING DESCRIPTIONChapter-3

sbit P

= PSW^0; //8052 only

/* TCON */ sbit TF1 = TCON^7; sbit TR1 = TCON^6; sbit TF0 = TCON^5; sbit TR0 = TCON^4; sbit IE1 = TCON^3; sbit IT1 = TCON^2; sbit IE0 = TCON^1; sbit IT0 = TCON^0;

/* IE */ sbit EA = IE^7; sbit ET2 = IE^5; //8052 only sbit ES = IE^4; sbit ET1 = IE^3; sbit EX1 = IE^2; sbit ET0 = IE^1; sbit EX0 = IE^0;

/* IP */ sbit PT2 = IP^5;
28

PROGRAMMING DESCRIPTIONChapter-3

sbit PS = IP^4; sbit PT1 = IP^3; sbit PX1 = IP^2; sbit PT0 = IP^1; sbit PX0 = IP^0;

/* P3 */ sbit RD = P3^7; sbit WR = P3^6; sbit T1 = P3^5; sbit T0 = P3^4; sbit INT1 = P3^3; sbit INT0 = P3^2; sbit TXD = P3^1; sbit RXD = P3^0;

/* SCON */ sbit SM0 = SCON^7; sbit SM1 = SCON^6; sbit SM2 = SCON^5; sbit REN = SCON^4; sbit TB8 = SCON^3; sbit RB8 = SCON^2;
29

PROGRAMMING DESCRIPTIONChapter-3

sbit TI = SCON^1; sbit RI = SCON^0;

/* P1 */ sbit T2EX = P1^1; // 8052 only sbit T2 = P1^0; // 8052 only

/* T2CON */ sbit TF2 = T2CON^7; sbit EXF2 = T2CON^6; sbit RCLK = T2CON^5; sbit TCLK = T2CON^4; sbit EXEN2 = T2CON^3; sbit TR2 = T2CON^2; sbit C_T2 = T2CON^1; sbit CP_RL2 = T2CON^0;

#endif

3.3.2 LCD.H
sbit RS = P3^6; sbit EN = P3^5;

30

PROGRAMMING DESCRIPTIONChapter-3

static unsigned char base_y[4] = {0x80,0xc0}; void us_delay(unsigned int a) { int i; for(i=0;i<a;i++); } void ms_delay(unsigned int a) { int i,j; for(i=0;i<a;i++) for(j=0;j<i;j++); } void sendcommand(unsigned char datt) { RS=0; P2=datt; EN=1; us_delay(10); EN=0; } void senddata(unsigned char dat) { RS=1;
31

PROGRAMMING DESCRIPTIONChapter-3

P2=dat; EN=1; us_delay(10); EN=0; } void lcd_init(void) { RS= 0; EN= 0; sendcommand(0x01); us_delay(100); sendcommand(0x38); us_delay(100); sendcommand(0x38); us_delay(100); sendcommand(0x0f); us_delay(100); sendcommand(0x0f); us_delay(100); } /* void lcd_xy(char a, char b) { sendcommand(base_y[b]+a);
32

PROGRAMMING DESCRIPTIONChapter-3

} */ void lcd_print(char x, char y, char code *string) // send string of characters to LCD { int i; int c; for (i=0;string[i]!=0;i++) { c = string[i]; if (c<0) c=0; sendcommand(base_y[y]+x+i); us_delay(100); senddata(c); us_delay(100); } } // convert ASCII to LCD char address

void lcd_print1(char x, char y, char* strg) { int j; int b; for (j=0;j<=5;j++) { b = strg[j]+0x30; // convert ASCII to LCD char address
33

PROGRAMMING DESCRIPTIONChapter-3

if (b<0) b=0; sendcommand(base_y[y]+x+j); us_delay(100); senddata(b); us_delay(100); } } /*void lcd_char(char x, char y, char stg) { int j; int b; b = stg; // convert ASCII to LCD char address

if (b<0) b=0; sendcommand(base_y[y]+x+j); us_delay(100); senddata(b); us_delay(100); } */ void clearlcd(void) { sendcommand(0x01); us_delay(100); us_delay(100);
34

PROGRAMMING DESCRIPTIONChapter-3

} void CursorOn(void) { sendcommand(0x0E); us_delay(100); us_delay(100); } void CursorOff(void) { sendcommand(0x0c); us_delay(100); us_delay(100); } void CursorBlink(void) { sendcommand(0x0f); us_delay(100); us_delay(100); }

3.3.3 E2P.H sbit SCL = P1^0;
35

PROGRAMMING DESCRIPTIONChapter-3

sbit SDA = P1^1; void uss_delay(void) { int i; for(i=0;i<=200;i++); }

unsigned char i2c_read(char ack) { char i, dat=0; SDA = 1; for(i=0; i<8; i++) { dat <<= 1; do { SCL = 1; } while(SCL==0); // wait for any SCL clock stretching uss_delay(); if(SDA) dat |= 1; SCL = 0; } if(ack) SDA = 0;
36

PROGRAMMING DESCRIPTIONChapter-3

else SDA = 1; SCL = 1; uss_delay(); SCL = 0; SDA = 1; return dat; } void i2c_stop(void) { SDA = 0; uss_delay(); SCL = 1; uss_delay(); SDA = 1; uss_delay(); } void i2c_write(unsigned char DAT) { unsigned char i; for(i=0;i<8;i++) { // send (N)ACK bit

SDA=(DAT&0x80);
37

PROGRAMMING DESCRIPTIONChapter-3

DAT=DAT<<1; uss_delay(); SCL=1; uss_delay(); SCL=0; uss_delay(); }

SDA=1; uss_delay(); SCL=1; uss_delay(); SCL=0; uss_delay(); } void i2c_start(void) { SDA = 1; uss_delay(); SCL = 1; uss_delay(); SDA = 0; uss_delay(); SCL = 0;
38

PROGRAMMING DESCRIPTIONChapter-3

uss_delay(); } void e2pWrite(unsigned char address, unsigned char dat) { i2c_start(); i2c_write(0xa0); i2c_write(address); // send start sequence // eeprom I2C address with R/W bit clear // data word register address

i2c_write(dat); // data to be sent(Seconds) i2c_stop(); uss_delay();

} unsigned char e2pRead(unsigned char addr) { i2c_start(); i2c_write(0xa0); i2c_write(addr); i2c_start(); i2c_write(0xa1); return (i2c_read(1)); } // eeprom I2C address with R/W bit clear // data word register address

39

PROGRAMMING DESCRIPTIONChapter-3

3.3.4 SPI.H
#include<intrins.h> sbit sbit sbit ADC_SDI = P1^5; P1^7; P1^6;

ADC_SCLK = ADC_SDO = = P1^4; = P1^3;

sbit ADC_CS sbit ADC_RST #define TRUE 1 #define FALSE 0 char digit[6]; void u_delay(void) { int a;

for(a=0;a<100;a++); } void spi_cmd(unsigned char cmd) { char i=8; while(i>0) { ADC_SCLK=1;
40

PROGRAMMING DESCRIPTIONChapter-3

if(cmd & 0x80) ADC_SDI = 1; else ADC_SDI = 0; ADC_SCLK = 0; i--; cmd<<=1; } ADC_SDI=TRUE; }

unsigned char unithb,tenhb,hundhb,thoushb,thous10hb,lachb; void spi_write(unsigned char length, long int value) { char i; ADC_CS=FALSE; i = 32 - length; while ( i > 0) { i -= 1; value = value << 1; }
41

PROGRAMMING DESCRIPTIONChapter-3

//

ADC_CS =FALSE; while(length > 0) { if(value & 0x80000000) ADC_SDI = TRUE; else ADC_SDI = FALSE; ADC_SCLK = TRUE; u_delay(); length -= 1; value <<= 1; ADC_SCLK = FALSE; }

} long adc_read(void) { char i=24; unsigned long readed = 0x00; ADC_SDI=TRUE; while( i > 0) { ADC_SCLK = TRUE;
42

PROGRAMMING DESCRIPTIONChapter-3

u_delay(); readed <<= 1; readed = readed | (ADC_SDO); ADC_SCLK = FALSE; i-- ; } return readed; } void binbcd(unsigned long int x) {

tenhb = 0; hundhb = 0; thoushb = 0; thous10hb = 0; lachb =0; while(x >= 100000) { ++lachb; x = x - 100000; } while(x >= 10000) {
43

PROGRAMMING DESCRIPTIONChapter-3

++thous10hb; x = x - 10000; } while(x >= 1000) { ++thoushb; x = x - 1000; }

while(x >= 100) { ++hundhb; x = x - 100; }

while(x >= 10) { ++tenhb; x = x - 10; } unithb = x; digit[5]=unithb; digit[4]=tenhb;
44

PROGRAMMING DESCRIPTIONChapter-3

digit[3]=hundhb; digit[2]=thoushb; digit[1]=thous10hb; digit[0]=lachb; }

void spi_init(void) { char j=0; // ADC_CS = TRUE; ADC_RST = FALSE; u_delay(); ADC_RST = TRUE; ADC_CS = FALSE; /* for(j=0;j<4;j++) { spi_cmd(0xff);

} // // spi_cmd(0xfe); u_delay(); */ sends 3 SYNC1 (0xFF)command and 1

spi_write(32,0xFFFFFFFE); // SYNC0(0XFE)command

45

PROGRAMMING DESCRIPTIONChapter-3

/*

adc_write(8,0x40); adc_write(32,0x20000000); adc_write(8,0x40); adc_write(32,0x00000000); adc_write(8,0x40); adc_write(32,0x02000000); while(1) { binbcd(85); delay1(); adc_write(8,0x0B);

// command to write configuration register // set rs bit of configureation register // command to write configuration register // set rs bit of configureation register // command to write configuration register // set VRS bit of configureation register

// command to read configuration

register i = adc_read();

binbcd(i);

//display_adcvalue(i,0); } // // adc_write(8,0x05); adc_write(32,0x00400840); adc_write(8,0x81); adc_write(8,0X82);

// displays the readed value on display

// command to write in channel set up register // define channel set up reg 1,and reg 2 // command for self offset calibration // command for self gain calibration
46

PROGRAMMING DESCRIPTIONChapter-3

*/ } long read_5460(void) { char i; char j=0; long temp; temp=0;

while(j<3) { i=7; ADC_SDI = 1;

while(i>0) { ADC_SCLK = 0; temp <<= 1; ADC_SCLK = 1; _nop_(); if(ADC_SDO == 1) temp |= 0x00000001; i--;
47

PROGRAMMING DESCRIPTIONChapter-3

}

ADC_SDI = 0; ADC_SCLK = 0; temp <<= 1; ADC_SCLK = 1; _nop_();

if(ADC_SDO == 1) temp |= 0x00000001; j++; } return(temp); }

3.3.5 STRING.H
#ifndef __STRING_H__ #define __STRING_H__

48

PROGRAMMING DESCRIPTIONChapter-3

#ifndef _SIZE_T #define _SIZE_T typedef unsigned int size_t; #endif

#ifndef NULL #define NULL ((void *) 0L) #endif #pragma SAVE #pragma REGPARMS extern char *strcat (char *s1, char *s2); extern char *strncat (char *s1, char *s2, int n);

extern char strcmp (char *s1, char *s2); extern char strncmp (char *s1, char *s2, int n);

extern char *strcpy (char *s1, char *s2); extern char *strncpy (char *s1, char *s2, int n);

extern int strlen (char *);

extern char *strchr (const char *s, char c); extern int strpos (const char *s, char c);
49

PROGRAMMING DESCRIPTIONChapter-3

extern char *strrchr (const char *s, char c); extern int strrpos (const char *s, char c); extern int strspn (char *s, char *set); extern int strcspn (char *s, char *set); extern char *strpbrk (char *s, char *set); extern char *strrpbrk (char *s, char *set); extern char *strstr (char *s, char *sub); extern char *strtok (char *str, const char *set); extern char memcmp (void *s1, void *s2, int n); extern void *memcpy (void *s1, void *s2, int n); extern void *memchr (void *s, char val, int n); extern void *memccpy (void *s1, void *s2, char val, int n); extern void *memmove (void *s1, void *s2, int n); extern void *memset (void *s, char val, int n); #pragma RESTORE #endif

50

HARDWARE DESCRIPTIONChapter-4

51

HARDWARE DESCRIPTIONChapter-4

CHAPTER 4 HARDWARE DESCRIPTION

COMPONENTS USED:1) Microcontroller 89S52 2) EPROM 24C02 3) IC CS5460 (Analog to Digital converter) 4) LCD (16x2) 5) Relay 6) Crystal (11.0592 Mhz & 6 Mhz) 7) IC 7805 8) Resistors. Capacitors, Diodes, Transistor, Connecters & Transformer.

4.1 Microcontroller 89S52
The AT89S52 is a low-power, high-performance CMOS 8-bit microcontroller with 8K bytes of in-system programmable Flash memory. The device is manufactured using Atmel’s high-density nonvolatile memory technology and is compatible with the industry-standard 80C51 instruction set and pinout. The on-chip Flash allows the program memory to be reprogrammed in-system or by a conventional nonvolatile memory programmer.

52

HARDWARE DESCRIPTIONChapter-4

By combining a versatile 8-bit CPU with in-system programmable Flash on a monolithic chip, the Atmel AT89S52 is a powerful microcontroller which provides a highly-flexible and cost-effective solution to many embedded control applications.

The AT89S52 provides the following standard features: 8K bytes of Flash, 256 bytes of RAM, 32 I/O lines, timers, two data pointers, three 16-bit timer/counters, a six-vector two-level interrupt architecture, a full duplex serial port, on-chip oscillator, and clock circuitry. In addition, the AT89S52 is designed with static logic for operation down to zero frequency and supports two software selectable power saving modes. The Idle Mode stops the CPU while allowing the RAM, timer/counters, serial port, and interrupt system to continue functioning.

53

HARDWARE DESCRIPTIONChapter-4

The Power-down mode saves the RAM contents but freezes the oscillator, disabling all other chip functions until the next interrupt or hardware reset.

Why we are using 89s52?
Microcontroller 89s51 89s52 ROM(Code Memory) 4,000 Bytes(4 kB) 8,000 Bytes(8 kB) RAM 128 B 256 B Table-4.1 Timer 2 3 Ext.-Int. Sources 6 8

Difference between S-type and C-type
Type Power Consumption C-type S-type Less More Less More Speed Crystal Frequency 0-24 MHz 0-33 MHz Table-4.2 10 mA 10 mA 10 mA Very weak Sink Source

Features
54

HARDWARE DESCRIPTIONChapter-4



Compatible with MCS®-51 Products 8K Bytes of In-System Programmable (ISP) Flash Memory Endurance: 10,000 Write/Erase Cycles 4.0V to 5.5V Operating Range Fully Static Operation: 0 Hz to 33 MHz Three-level Program Memory Lock 256 x 8-bit Internal RAM 32 Programmable I/O Lines Three 16-bit Timer/Counters Eight Interrupt Sources Full Duplex UART Serial Channel Low-power Idle and Power-down Modes Interrupt Recovery from Power-down Mode Watchdog Timer Dual Data Pointer Power-off Flag Fast Programming Time Flexible ISP Programming (Byte and Page Mode) Green (Pb/Halide-free) Packaging Option

• • • • • • • • • • • • • • • • • •

Pin configuration
55

HARDWARE DESCRIPTIONChapter-4

Fig 4.1

4.2 EPROM 24C02
56

HARDWARE DESCRIPTIONChapter-4

Features
• Low-Voltage and Standard-Voltage Operation – – – – • • • • • • • • • • • 5.0 (VCC = 4.5V to 5.5V) 2.7 (VCC = 2.7V to 5.5V) 2.5 (VCC = 2.5V to 5.5V) 1.8 (VCC = 1.8V to 5.5V)

Internally Organized 128 x 8 (1K), 256 x 8 (2K), 512 x 8 (4K), 1024 x 8 (8K) or 2048 x 8 (16K) 2-Wire Serial Interface Schmitt Trigger, Filtered Inputs for Noise Suppression Bidirectional Data Transfer Protocol 100 kHz (1.8V, 2.5V, 2.7V) and 400 kHz (5V) Compatibility Write Protect Pin for Hardware Data Protection 8-Byte Page (1K, 2K), 16-Byte Page (4K, 8K, 16K) Write Modes Partial Page Writes Are Allowed Self-Timed Write Cycle (10 ms max) High Reliability – – – Endurance: 1 Million Write Cycles Data Retention: 100 Years ESD Protection: >3000V

• •

Automotive Grade and Extended Temperature Devices Available 8-Pin and 14-Pin JEDEC SOIC, 8-Pin PDIP, 8-Pin MSOP, and 8-Pin TSSOP Packages

Description
57

HARDWARE DESCRIPTIONChapter-4

The AT24C01A/02/04/08/16 provides 1024/2048/4096/8192/16384 bits of serial electrically erasable and programmable read only memory (EEPROM) organized as 128/256/512/1024/2048 words of 8 bits each. The device is optimized for use in many industrial and commercial applications where low power and low voltage operation are essential. The AT24C01A/02/04/08/16 is available in space saving 8-pin PDIP, (AT24C01A/02/04/08/16) , 8-Pin MSOP (AT24001A/02), 8-Pin TSSOP (AT24C01A/02/04/08/16), and 8-Pin and 14-Pin JEDEC SOIC (AT24C01A/02/04/08/16) packages and is accessed via a 2-wire serial interface. In addition, the entire family is available in 5.0V (4.5V to 5.5V), 2.7V (2.7V to 5.5V), 2.5V (2.5V to 5.5V) and 1.8V (1.8V to 5.5V) versions.

PIN CONFIGURATION

Fig 4.2

58

HARDWARE DESCRIPTIONChapter-4

4.3 IC CS5460 (Analog to Digital converter)

CS5460 Features
CS5460 is a single chip containing two one Σ analog-digital converter (ADC), highspeed power calculation functions and a serial interface of highly integrated analog Σ a digital converter. He can accurately measure the instantaneous voltage, instantaneous current, instantaneous power, etc.; He also has two-way communication with the microcontroller serial port. The CS5460 can be initialized after power and can perform all functions, including procedures under the control of the user system calibration.
59

HARDWARE DESCRIPTIONChapter-4

Structure
CS5460 structure shown in Figure 1. Ten of them IN, IN A analog current input channels; VIN +, VIN an output an analog voltage input channels; and different order and magnitude of the input voltage matches the current channel also features a programmable gain amplifier (PGA), the input signal full-scale range selectable; 2 △ Σ analog-digital converter samples the signal on the system model of a digital conversion; two digital highspeed filter to (MCLK / K) / 1024 output rate of output data word; 2 high-pass filter can be calculated in the energy before the DC component of the input signal filter; calibration unit to achieve the calibration of the analog input channels;-power computing unit used to calculate the instantaneous power and voltage and current RMS and so on. Serial Interface (Serial Interface) unit provides a CS5460 with external data communication interface.

Works
CS5460 energy calculation is a monolithic CMOS cited Hajime power measurement chip. Voltage analog signal from the VIN +, VIN A △ Σ after the analog input of a digital converter to convert the converted signal by the high-speed filter and high-pass filter given away after the power calculator. Current analog signal from the VIN +, VIN A △ Σ after the input of a digital analog converter to convert the converted signal by the high-speed filter and high-pass filter given away after the power calculator. Power calculator for processing the two signals output measured after the operation voltage, current, power and so on. All of these data by the serial interface and microcontroller for data exchange.

Analog input
Measure the instantaneous sampling circuit is to achieve voltage, instantaneous current, instantaneous power basis. The resistors and capacitors not only high precision, but its role is not the same. Circuit RPl inrush current for the current channel when the input pin for current limit protection; in VlN + feet do not need to protect the resistance because of the introduction of the resistive divider as sensors, resistive voltage divider resistors in series have been be directed to the VIN + pin, if the voltage input channel CS5460 negative
60

HARDWARE DESCRIPTIONChapter-4

side is not earthed (VIN + and VIN connected as a differential input mode) plus the input signal is necessary to protect the resistance. CPl and CP2 is the role of absorption coupled to the input line of high-frequency noise. The resistance and capacitance, the voltage channel should be the ultimate guarantee of full scale input signal amplitude is 150mV, the current channel input signal amplitude of 30mV full scale or 150mV selectable (programmable gain amplifier by the program through implementation).

Calibration
Calibration of the input channels, there are several software shown in Figure 3, the calibration process. Channel all of the calibration samples were calibrated by computer software, should be the order from left to right in Figure 3 in order calibration. After calibration by the calibration equipment used to do a higher level than the right, to ensure the accuracy of the measurement data.

Computing
Voltage and current channel input signal is calibrated to the power calculation unit, the measured voltage and current to calculate power. Also from the measured instantaneous voltage and current to calculate the instantaneous voltage and current RMS.

Hardware Design
CS5460 implementation of the system by the instantaneous voltage, instantaneous current, instantaneous power measurement, energy measurement achieved by the microcontroller μPD75P3116 and other features, interface circuit shown in Figure 4 instructions. CS5460s serial interface consists of four control lines that: CS, SDI, SDO, and SCLK. CS is chip select signal, is allows access to the serial port of the control line, active low, high, high-impedance state when the SDO client; SDI as serial data input, used to transfer data from the microcontroller to the CS5460; SDO is serial data output, used to
61

HARDWARE DESCRIPTIONChapter-4

output data to the microcontroller; SCLK is to control the data input or output serial bit clock, SCLK port level conversion can be identified before the CS must be set to logic low. MCU is through the four control lines to achieve the data exchange with the CS5460. Microcontroller to read from the CS5460 the instantaneous voltage, instantaneous current and instantaneous power exists and other data in memory after treatment, after power microcontroller read the data from memory to memory. All of these data can be an external communication interface from the host computer read out by the LCD display can easily query. Order to ensure safe and reliable system operation in the system by adding "watchdog" circuit. HCF4060 CMOS components and parts from the discrete components of the "watchdog" circuit, its low cost, simple to use, stable and reliable. When the program runs into infinite loop error or when the system can ensure quick and safe and reliable reset.

System software design
Program starts, first start the watchdog circuit, and then test the memory. If the test is not successful then the re-testing, if successful, read CS5460. After the reading of the data processing, the instantaneous voltage, instantaneous current, instantaneous power, total power and voltage and current RMS displayed on the LCD display.

Conclusion
The CS5460 and t ~ PD75P3116 used to achieve power and energy measurement approach to simple, easy to use, high cost performance characteristics by the majority of design and development departments of all ages, a very good market prospects. At present, our company has developed under this approach the single-phase electronic meter, three phase and single-phase multi-site electronic form calibrator and other products, has been widely used in the power sector.

Pin Configuration
62

HARDWARE DESCRIPTIONChapter-4

Fig 4.3

4.4 LCD (16x2)

63

HARDWARE DESCRIPTIONChapter-4

Description.
This is the first interfacing example for the Parallel Port. We will start with something simple. This example doesn't use the Bi-directional feature found on newer ports, thus it should work with most, if no all Parallel Ports. It however doesn't show the use of the Status Port as an input. So what are we interfacing? A 16 Character x 2 Line LCD Module to the Parallel Port. These LCD Modules are very common these days, and are quite simple to work with, as all the logic required to run them is on board.

Schematic
64

HARDWARE DESCRIPTIONChapter-4

Fig4.4

Above is the quite simple schematic. The LCD panel's Enable and Register Select is connected to the Control Port. The Control Port is an open collector / open drain output. While most Parallel Ports have internal pull-up resistors, there are a few which don't. Therefore by incorporating the two 10K external pull up resistors, the circuit is more portable for a wider range of computers, some of which may have no internal pull up resistors. We make no effort to place the Data bus into reverse direction. Therefore we hard wire the R/W line of the LCD panel, into write mode. This will cause no bus conflicts on the data lines. As a result we cannot read back the LCD's internal Busy Flag which tells us if the LCD has accepted and finished processing the last instruction. This problem is overcome by inserting known delays into our program.

65

HARDWARE DESCRIPTIONChapter-4

The 10k Potentiometer controls the contrast of the LCD panel. Nothing fancy here. As with all the examples, I've left the power supply out. You can use a bench power supply set to 5v or use a onboard +5 regulator. Remember a few de-coupling capacitors, especially if you have trouble with the circuit working properly.

The 2 line x 16 character LCD modules are available from a wide range of manufacturers and should all be compatible with the HD44780. The one I used to test this circuit was a Powertip PC-1602F and an old Philips LTN211F-10 which was extracted from a Poker Machine! The diagram to the right, shows the pin numbers for these devices. When viewed from the front, the left pin is pin 14 and the right pin is pin 1.

66

GSMChapter-5

67

GSMChapter-5

CHAPTER 5 GSM
This GSM wireless data module is the ready a solution for remote wireless applications, machine to machine or user to machine and remote data communications in all vertical market applications.

5.1 SIM300 AT Command Set
In application, controlling device controls the GSM engine by sending AT Command via its serial interface. The controlling device at the other end of the serial line is referred to as following term: 1) TE (Terminal Equipment); 2) DTE (Data Terminal Equipment)

Types of AT commands and responses
Test command AT+<x>=? The mobile equipment returns the list of parameters and value ranges set with the corresponding Write command or by internal processes. This command returns the currently set value of the parameter or parameters. This command sets the user-definable parameter values. The execution command reads non-variable parameters affected by internal processes in the GSM engine

Read command Write command Execution command

AT+<x>? AT+<x>=<…> AT+<x> Table 5.1

68

GSMChapter-5

5.2 Product concept
Designed for global market, SIM300 is a Tri-band GSM/GPRS engine that works on frequencies EGSM 900 MHz, DCS 1800 MHz and PCS 1900 MHz. SIM300 features GPRS multi-slot class 10/ class 8 (optional) and supports the GPRS coding schemes CS-1, CS-2, CS-3 and CS-4.

69

MERITS & DEMERITSChapter-6

70

MERITS & DEMERITSChapter-6

CHAPTER 6 MERITS & DEMERITS
6.1 MERITS • • • • • • Different Tariffs can be implemented. Power thefts can be caught. Power can be cut-off in case of non payement of bill. For ON & OFF purpose security feature is provided. Quick reponse. It can Give every second update of energy meter value by SMS.

6.2 DEMERITS •


The energy meter is of only 5 ampere current rating only (Domestic Use). Maximum rating of meter is 10 KWh but it can be extended upto 10 MWh. Costing of GSM is higher for regular use. GSM module can be operated only proper network coverage is available. It has to rely on particular SIM or service provider. Accuracy of energy meter is only in watt hour. The relay used has switching rating of 6 ampere so we can perform upto that only. The SIM card must have a balance in order to send message.

• • • • • •

71

FUTURE DEVELOPMENTChapter-7

72

FUTURE DEVELOPMENTChapter-7

CHAPTER 7 FUTURE DEVELOPMENT

• • • • •

Power theft can be caught using this device. This device can perform as reminder for bills or tariffs. Using this device new tariffs can be implemented. Prepaid tariffs can also be available using this device. Electric consumption can be improved if once gets regular update of its energy consumption.



Any fault in power system can be detected using this device. The capacity of energy meter can be increased upto 10 MWh.



73

CONCLUSIONChapter-8

74

CONCLUSIONChapter-8

CHAPTER 8 CONCLUSION
While preparing this project we learn the operating of microcontroller 89S52. And also understand the performance of IC CS5460. We learn interfacing of LCD (16x2), EPROM 24C02C with microcontroller 89S52.And also learn programming of 89S52 to operate remaining components. Along with controller this device provide learning about GSM module and also interfacing GSM module with controller. We also learn about the usage of AT Command & how it can used to send SMS. Finally by preparing this device we can understand how the device can be useful in present as well as future.

75

REFERENCES

REFERENCES

[1] Electric Power Distribution By A. S. Pabla [2] A Textbook of Electrical Technology By R.K. Rajput [3] Principles and Applications of GSM By Garg [4] Exploring C for microcontrollers: a hands on approach By Jivan S. Parab, Vinod

G. Shelake, Rajanish K. Kamat
[5] Microprocessors & Microcontroller Systems By D.A.Godse A.P.Godse [6] http://www.keil.com/dd/docs/datashts/atmel/at89s52_ds.pdf [7] http://www.atmel.com/dyn/resources/prod_documents/doc1919.pdf [8] http://www.alldatasheet.com/datasheet-pdf/pdf/230848/CIRRUS/CS5460.html [9] http://www.datasheetcatalog.org/datasheet/Cirrus_Logic/mXxtrxu.pdf

[10] http://catalog.gaw.ru/project/download.php?id=2834 [11] http://www.datasheetcatalog.com/datasheets_pdf/2/4/C/0/24C02.shtml [12]http://microchip.ua/simcom/GSM-GPRS-GPS/AppNotes%20-%20doc/_ %20FAQ-2.pdf
[13] http://wm.sim.com/Sim/FrontShow_en/default.aspx Module

[14] http://www.datasheetcatalog.org/datasheet/philips/BC546_547_3.pdf
[15] http://www.datasheetcatalog.com/datasheets_pdf/B/C/5/4/BC547.shtml [16] http://www.autoshop101.com/forms/hweb2.pdf [17] http://electronics.howstuffworks.com/relay.htm [18] http://www.engineersgarage.com/sites/default/files/LCD%2016x2.pdf

[19]http://www.bioenabletech.com/technical_introduction_to_gsm_modem_technology.htm [20] http://www.sourcecodester.com/visual-basic/sending-sms-using-commands-gsmmodemgsm-phone-receiving-sms-updated.html

[21] http://myrobobazaar.com/store/images/lcd16x2.jpg
76

REFERENCES

[22] http://www.byvac.com/bv3/image/data/Displays/LCD/LCD16x2_physical.gif [23] http://microcontrollerkits.com/Spare%20Parts/IC%2089C51.jpg
[24] http://www.dongfangic.com/UploadFiles/14/39b1d12b21aae80d88898f2bbfdfb448.jpg [25] http://www.crodnet.co.uk/images/24c02.jpg

77

APPENDIX

78

APPENDIX

APPENDIX A Cost Of Project

79

Sponsor Documents

Or use your account on DocShare.tips

Hide

Forgot your password?

Or register your new account on DocShare.tips

Hide

Lost your password? Please enter your email address. You will receive a link to create a new password.

Back to log-in

Close