0% found this document useful (0 votes)
46 views

Programming

This document contains code for an embedded system that controls irrigation and other processes. It defines constants and variables used for input/output pins that control devices. Functions are defined for transmitting data, receiving data, comparing strings, and delaying time. The main function initializes ports and pins, then enters a loop that checks for incoming SMS messages, compares the message to code strings, and triggers corresponding outputs to control devices like water pumps and fertilizer dispensers.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views

Programming

This document contains code for an embedded system that controls irrigation and other processes. It defines constants and variables used for input/output pins that control devices. Functions are defined for transmitting data, receiving data, comparing strings, and delaying time. The main function initializes ports and pins, then enters a loop that checks for incoming SMS messages, compares the message to code strings, and triggers corresponding outputs to control devices like water pumps and fertilizer dispensers.
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 21

APPENDIX-1

PROGRAMMING
#include<reg52.h>
#include<stdio.h>
#include<string.h>
sbit AW=P1^0;
sbit AL=P1^1;
sbit AL1=P1^2;

sbit BW=P1^3;
sbit BL=P1^4;
sbit BL1=P1^5;

sbit WATER = P2^6;


sbit L2= P2^5;
sbit L3 = P2^4;

void delay(unsigned long count);


void transmit_d(unsigned char *P);
void transmit(unsigned char *P);
void transmit1(unsigned char *P);

unsigned char data serialdata;

unsigned char code att[]={"AT"};


unsigned char code setsms[]={"AT+CSMS=0"};
unsigned char code setmem[]={"AT+CPMS=\"SM\""};
unsigned char code setmod[]={"AT+CMGF=1"};
unsigned char code mes_indicate[]={"CMTI"};//{"AT+CMGR=1"}; CMTI:
"SM",2
unsigned char code read[]={"AT+CMGR=1"};
unsigned char code delet1[]={"AT+CMGD=1"};
unsigned char code delet2[]={"AT+CMGD=2"};
unsigned char code delet3[]={"AT+CMGD=3"};

unsigned char code l1an[]={"WAAON"};


unsigned char code l1af[]={"WAAOF"};
unsigned char code l2an[]={"LA2ON"};
unsigned char code l2af[]={"LA2OF"};
unsigned char code l3an[]={"LA3ON"};
unsigned char code l3af[]={"LA3OF"};
unsigned char code coa1[]={"CONA1"};
unsigned char code coa2[]={"CONA2"};

unsigned char code l1bn[]={"WABON"};


unsigned char code l1bf[]={"WABOF"};
unsigned char code l2bn[]={"LB2ON"};
unsigned char code l2bf[]={"LB2OF"};

unsigned char code l3bn[]={"LB3ON"};


unsigned char code l3bf[]={"LB3OF"};
unsigned char code cob1[]={"CONB1"};
unsigned char code cob2[]={"CONB2"};

unsigned char code l1on[]={"WATON"};


unsigned char code l1of[]={"WATOF"};
unsigned char code l2on[]={"LT2ON"};
unsigned char code l2of[]={"LT2OF"};
unsigned char code l3on[]={"LT3ON"};
unsigned char code l3of[]={"LT3OF"};
unsigned char code con1[]={"COND1"};
unsigned char code con2[]={"COND2"};

unsigned char code wateron[]={" WATER ON "};


unsigned char code waterof[]={" WATER OFF "};
unsigned char code liq2on[]={" FERTILIZER ON "};
unsigned char code liq2of[]={" FERTILIZER OFF "};
unsigned char code liq3on[]={" pesticides ON "};
unsigned char code liq3of[]={" pesticides OFF"};

unsigned char code condition1on[]={"condition1 ON "};


unsigned char code condition1of[]={" condition1 OFF"};
unsigned char code condition2on[]={"condition2 ON "};

unsigned char code condition2of[]={" condition2 OFF"};

unsigned char code sendnum[]={"AT+CMGS=\"+919894572896\""};

unsigned char data temp[30];


bit comp_bit=0;
unsigned char bit1=0;
unsigned char bit2=0;
unsigned char bit3=0;
int i,j;
unsigned char data z;
void transmit_d(unsigned char *p)
TRANSMIT DATA

// FUNCTION TO

{
unsigned char i;
TR1=1;

// TIMER1 RUN

for(i=0;*p!='\0';i++)
{
SBUF=*p;
*p++;
while(TI==0)
{}
TI=0;
}

// SEND THE ARRAY 'TEMP'

SBUF=0X0D;

// INDICATE END OF

COMMAND
while(TI==0)
{}
TI=0;
TR1=0;

void transmit1(unsigned char *p)


TRANSMIT DATA

// FUNCTION TO

{
unsigned char i;
TR1=1;

// TIMER1 RUN

for(i=0;*p!='\0';i++)
{
SBUF=*p;

// SEND THE ARRAY 'TEMP'

*p++;
while(TI==0)
{}
TI=0;
}
SBUF=0X1A;
MESSAGE 'ctrl+z'

// INDICATE END OF

while(TI==0)
{}
TI=0;
TR1=0;

void sendsms(void)
{
transmit_d(setsms);
transmit_d(setmod);
transmit_d(sendnum);

void delay(unsigned long count)


{
unsigned long int i;
for(i=0;i<count;i++);

}
void receive()

TR1=1;
while(RI==0) {}

serialdata=SBUF; // COPY TO 'serialdata'


RI=0; TR1=0;

void receive1(unsigned char n)

unsigned char i;
TR1=1;
for(i=0;i<n;i++) {
while(RI==0) {}
temp[i]=SBUF;

// COPY TO 'temp'

RI=0;

TR1=0;
temp[i]='\0';

void str_cpy(unsigned char *p,unsigned char *p1) {


while(*p1!='\0')

*p=*p1;
*p++;*p1++;

p='\0';}

str_comp(unsigned char *p,unsigned char *p1)


comp_bit=0;
while(*p1!='\0')

if(*p==*p1)comp_bit=1;
else

comp_bit=0;
break;

*p++;*p1++;

return (comp_bit); }

//char temp[25]= "LCD TEST PROGRAM SUCCESS";

void main()
{

P1=0x00;
P2=0x00;
P0=0x00;
TMOD=0x20;
TH1=0xFD;
SCON=0x50;
TR1=1;

AW=AL=AL1=0;

transmit_d(att);transmit_d(att);
transmit_d(att);delay(500);
transmit_d(delet1);delay(1000);
transmit_d(delet2);delay(1000);

while(1)
{
transmit_d(att);
transmit_d(att);
transmit_d(delet1);delay(1000);
transmit_d(delet2);delay(1000);
receive();
while(serialdata!='+') receive();
receive1(5);

str_comp(temp,mes_indicate);delay(4000);
if(comp_bit==1)
{
delay(10000);
transmit_d(read);
receive();
while(serialdata!=0x0A) receive();receive();
while(serialdata!=0x0A) receive();
receive1(5);
delay(5000); transmit_d(temp);

str_comp(temp,l1an);
if(comp_bit==1)

{
AW=1;
sendsms(); transmit1(wateron); delay(100);
//sendsms1(); transmit1(light1on); delay(5000);

}
else
{
str_comp(temp,l1af);
if(comp_bit==1)
{
AW=0;

sendsms(); transmit1(waterof); delay(100);


//sendsms1(); transmit1(light1of); delay(10000);
}

else
{
str_comp(temp,l2an);
if(comp_bit==1)
{
AL=1;

sendsms(); transmit1(liq2on); delay(100);


//sendsms1(); transmit1(light2on); delay(10000);
}
else
{
str_comp(temp,l2af);
if(comp_bit==1)
{
AL=0;
sendsms(); transmit1(liq2of); delay(100);
//sendsms1(); transmit1(light2of); delay(10000);
}

else
{
str_comp(temp,l3an);
if(comp_bit==1)
{AL1=1;delay(500);

sendsms(); transmit1(liq3on); delay(100);


//

sendsms1(); transmit1(slow); delay(10000);


}

else
{

str_comp(temp,l3af);
if(comp_bit==1)
{AL1=0;delay(500);

sendsms(); transmit1(liq3of); delay(100);


//sendsms1(); transmit1(medium); delay(10000);
}
else
{
str_comp(temp,coa1);
if(comp_bit==1)
{
sendsms(); transmit1(condition1on); delay(100);
AW=1;AL1=1;delay(300000);AL1=0;AL=1;delay(20000);AL=0;
AW=0;

sendsms(); transmit1(condition1of); delay(100);

}
else
{
str_comp(temp,coa2);
if(comp_bit==1)
{

sendsms(); transmit1(condition2on); delay(100);


AW=1;AL1=0;AL=1;delay(400000);AL=0;
AW=0;

sendsms(); transmit1(condition2of); delay(100);

else
{

str_comp(temp,l1bn);
if(comp_bit==1)
{
BW=1;
sendsms(); transmit1(wateron); delay(100);
//sendsms1(); transmit1(light1on); delay(5000);

}
else
{
str_comp(temp,l1bf);
if(comp_bit==1)

{
BW=0;

sendsms(); transmit1(waterof); delay(100);


//sendsms1(); transmit1(light1of); delay(10000);
}

else
{
str_comp(temp,l2bn);
if(comp_bit==1)
{
BL=1;

//

sendsms(); transmit1(liq2on); delay(100);

//sendsms1(); transmit1(light2on); delay(10000);


}
else
{
str_comp(temp,l2bf);
if(comp_bit==1)
{
BL=0;
//sendsms(); transmit1(liq2of); delay(100);

//sendsms1(); transmit1(light2of); delay(10000);


}

else
{
str_comp(temp,l3bn);
if(comp_bit==1)
{BL1=1;delay(500);

sendsms(); transmit1(liq3on); delay(100);


//

sendsms1(); transmit1(slow); delay(10000);


}

else
{
str_comp(temp,l3bf);
if(comp_bit==1)
{BL1=0;delay(500);

sendsms(); transmit1(liq3of); delay(100);


//sendsms1(); transmit1(medium); delay(10000);
}
else
{
str_comp(temp,cob1);

if(comp_bit==1)
{
sendsms(); transmit1(condition1on); delay(100);
BW=1;BL1=1;delay(300000);BL1=0;BL=1;delay(200000);BL=0;
BW=0;

sendsms(); transmit1(condition1of); delay(100);

}
else
{
str_comp(temp,cob2);
if(comp_bit==1)
{
sendsms(); transmit1(condition2on); delay(100);
BW=1;BL1=0;BL=1;delay(400000);BL=0;
BW=0;

sendsms(); transmit1(condition2of); delay(100);

}
else{
str_comp(temp,l1on);

if(comp_bit==1)
{
WATER=1;
sendsms(); transmit1(wateron); delay(100);
//sendsms1(); transmit1(light1on); delay(5000);

}
else
{
str_comp(temp,l1of);
if(comp_bit==1)
{
WATER=0;

sendsms(); transmit1(waterof); delay(100);


//sendsms1(); transmit1(light1of); delay(10000);
}

else
{
str_comp(temp,l2on);
if(comp_bit==1)
{
L2=1;

sendsms(); transmit1(liq2on); delay(100);


//sendsms1(); transmit1(light2on); delay(10000);
}
else
{
str_comp(temp,l2of);
if(comp_bit==1)
{
L2=0;
sendsms(); transmit1(liq2of); delay(100);
//sendsms1(); transmit1(light2of); delay(10000);
}

else
{
str_comp(temp,l3on);
if(comp_bit==1)
{L3=1;delay(500);

sendsms(); transmit1(liq3on); delay(100);


//

sendsms1(); transmit1(slow); delay(10000);


}

else

{
str_comp(temp,l3of);
if(comp_bit==1)
{L3=0;delay(500);

sendsms(); transmit1(liq3of); delay(100);


//sendsms1(); transmit1(medium); delay(10000);
}
else
{
str_comp(temp,con1);
if(comp_bit==1)
{
sendsms(); transmit1(condition1on); delay(100);
WATER=1;L3=1;delay(300000);L3=0;L2=1;delay(200000);L2=0;
WATER=0;

sendsms(); transmit1(condition1of); delay(100);

}
else
{
str_comp(temp,con2);
if(comp_bit==1)

{
sendsms(); transmit1(condition2on); delay(100);

WATER=1;L3=0;L2=1;delay(400000);L2=0;
WATER=0;

sendsms(); transmit1(condition2of); delay(100);

}}}}}}}

}}}}}}}}
}}}}}}}}

delay(100);
transmit_d(delet1);delay(1000);
transmit_d(delet2);delay(1000);
transmit_d(delet3);delay(1000);
}

else
{
transmit_d(delet1);delay(1000);

transmit_d(delet2);delay(1000);
transmit_d(delet3);delay(1000);

}
}

You might also like