Sie sind auf Seite 1von 18

TRANSMITTER SIDE

////main.c
#include<reg51.h>
void main()
{
unsigned char count1,count2,count3;
uartinit();
lcd_init();
printlcd1("WATER IRREGATION");
printlcd2(" CONTROL SYSTEM ");
delay1();

//P0 = 0xff;

DEVICE_1=1;
DEVICE_1=0;

DEVICE_2=1;
DEVICE_2=0;

DEVICE_3=1;
DEVICE_3=0;
count1=0;
count2=0;

count3=0;

led1=0;
led2=0;
led3=0;

while(1)
{

rfid_read();

if((pass[4]=='5')&&(count1==0))
{
DEVICE_1=1;
led1=1;
count1=1;
printlcd1(" ACCESS GRANTED ");
printlcd2("

FOR M1

");

delay(500);
DEVICE_1=0;
}
else if((pass[4]=='5')&&(count1==1))
{
DEVICE_1=1;
led1=0;

count1=0;
printlcd1(" ACCESS GRANTED ");
printlcd2(" FOR M1

");

delay(500);
DEVICE_1=0;
}

else if((pass[4]=='9')&&(count2==0))
{
count2=1;
led2=1;
DEVICE_2=1;
printlcd1(" ACCESS GRANTED ");
printlcd2("

FOR M2

");

delay(50);
DEVICE_2=0;
}
else if((pass[4]=='9')&&(count2==1))
{
count2=0;
led2=0;
DEVICE_2=1;
printlcd1(" ACCESS GRANTED ");
printlcd2("
delay(500);

FOR M2

");

DEVICE_2=0;
}
else if((pass[4]=='7')&&(count3==0))
{
DEVICE_3=1;
led3=1;
count3=1;
printlcd1(" ACCESS GRANTED ");
printlcd2(" FOR M3

");

delay(500);
DEVICE_3=0;
}
else if((pass[4]=='7')&&(count3==1))
{
DEVICE_3=1;
led3=0;
count3=0;
printlcd1(" ACCESS GRANTED ");
printlcd2(" FOR
delay(500);
DEVICE_3=0;
}
else
{
DEVICE_1=0;

M3

");

DEVICE_2=0;
DEVICE_3=0;

}
}
}
void rfid_read()
{
unsigned char i;
uartinit();
while(uartdata()!= '0');
while(uartdata()!= '5');

for(i=0;i<6;i++)
{
pass[i] = uartdata();
}
pass[i]='\0';
}

///////////////////////////////lcd.c

#include<reg51.h>
sbit EN = P1^1;
sbit RS = P1^0;

sbit data0 = P1^2;


sbit data1 = P1^3;
sbit data2 = P1^4;
sbit data3 = P1^5;

unsigned int temp;


unsigned char info;

//*************LCD INITIALIZATION*************

void lcd_init(void)
{
unsigned char a[]={0x20,0x20,0x80,0x00,0xc0,0x00,0x10,0x00,0x60};
unsigned char temp;
for(temp=0;temp<5;temp++)
{
lcd_comd(a[temp]);

//*********** LCD COMMAND ****************

void lcd_comd(unsigned char w)

{
unsigned char i;
data0=0;

//clear the data pins

data1=0;
data2=0;
data3=0;
RS=0;

// write in instruction register

w = w >> 2; //w is shifted by 2 times.


LCD_PORT |= w;
EN =1;
for(i=0;i<20;i++);
EN =0;
for(i=0;i<20;i++);
}

//*********** LCD DATA *********************

void lcd_data(unsigned char info)


{
unsigned int b;
b=((info&0xf0)>>2);
P1=b;
RS=1;

EN=1;
EN=0;
b=((info&0x0f)<<2);
P1=b;
RS=1;
EN=1;
EN=0;

void delay(unsigned int it)


{
unsigned int i,j;
for(i=0;i<=it;i++);
for(j=0;i<=1275;j++);

void printlcd1(unsigned char *str)


{
unsigned char len,i;
len = strlen(str);
lcd_comd(0x80);

//sets display position in first line

lcd_comd(0x00);
for(i=0;i<len;i++)
{
lcd_data(*str); //displays the character on LCD
str++;
}
}

void printlcd2(unsigned char *str)


{
unsigned char len,i;
len = strlen(str);

lcd_comd(0xc0);

//sets display position in second line

lcd_comd(0x00);
for(i=0;i<len;i++)
{
lcd_data(*str); //displays the character on LCD
str++;
}

void delay1()
{

unsigned char i;

for(i=0;i<40;i++)
{
delay(4000000);
}
}

/////////////////////uart.c
#include <reg51.H>

void uartinit()
{
TMOD=0x20;

//20

TH1=-3; //9600 baud rate


SCON=0x50;
TR1=1;
}

unsigned char uartdata()


{
while(1)
{

unsigned char a;
while(RI==0);
RI=0;
a=SBUF;
return(a);
}
}

void uart_send(unsigned char value)


{

SBUF = value;
while(TI == 0);
TI = 0;

RECIEVER SIDE

#include<reg51.h>

sbit rf_input1=P1^0;//inputS
sbit rf_input2=P1^1;//inputS
sbit rf_input3=P1^2;//inputS

sbit data1=P3^0; //output to relay


sbit data2=P3^1;
sbit data3=P3^2;

sbit led1=P1^3;//to led


sbit led2=P1^4;
sbit led3=P1^5;

void delay(unsigned int msec);

void delay(unsigned int msec) // Time delay function


{
int i,j ;
for(i=0;i<msec;i++)

for(j=0;j<1275;j++);
}

void main()
{
unsigned char count1,count2,count3;
data1=0;
data2=0;
data3=0;

led1=0;
led2=0;
led3=0;

rf_input1=1;
rf_input1=0;

rf_input2=1;
rf_input2=0;

rf_input3=1;
rf_input3=0;

count1=0;

count2=0;
count3=0;
while(1)
{
rf_input1=0;
rf_input2=0;
rf_input3=0;

if(rf_input1==1&&count1==0)
{
data1=1;
led1=1;
count1=1;
delay(50);

}
else if(rf_input1==1&&count1==1)
{

data1=0;
led1=0;
delay(50);
count1=0;
}
else if(rf_input2==1&&count2==0)

{
data2=1;
led2=1;
count2=1;
delay(50);

}
else if(rf_input2==1&&count2==1)
{
data2=0;
led2=0;
count2=0;
delay(50);

}
else if(rf_input3==1&&count3==0)
{
data3=1;
led3=1;
count3=1;
delay(50);

}
else if(rf_input3==1&&count3==1)

{
data3=0;
led3=0;
count3=0;
delay(50);

}
else
{

}
}
}