#include <REGX52.H>
#include <string.h>
#include <ctype.h>
#include "lcd.c"
#include "serial.c"
#define MAX_DELAY() delay(65000)
sbit Device=P0^0;
bit Dev_Stat=0;
unsigned char SE_INTR_ST = 0;
unsigned char re_str[6], number[14];
unsigned char dummy[6];
void intro()
{
lcd_init();
lcd_str(" Applaince Ctrl ",0x80);
lcd_str("Using GSM - 8051",0xc0);
MAX_DELAY();MAX_DELAY();
MAX_DELAY();MAX_DELAY();
lcd_clr();
}
void serial0() interrupt 4
{
char z;
if(RI==1)
{
z=SBUF;RI=0;
if(z=='+')
SE_INTR_ST = 1;
}
}
void temp_receive(unsigned char r)
{
unsigned char ten;
do
{
ten=se_rx();
}while(ten!=r);
}
void gsmread(const unsigned char *str,char limit,unsigned char *dummy_str)
{
unsigned char i,temp,lmt_chk = 0;
lcd_clr();
while(*str!='\0')
{
se_tx(*str);
str++;
}
se_tx('\r');//se_tx(0x0a);
if(limit==1)
{
for(i=0;i<2;i++)
temp_receive('"');temp_receive('1');
i=0;
do
{
temp=se_rx();
if(isdigit(temp))
{
number[i]=temp; i++;
}
}while(temp!='"');
temp_receive(0x0d);
number[i]='\0';
}
// if(RI == 1)
// do
// {
// temp=se_rx();
// }
// while(isalnum(temp) || (temp == '=') || (temp == '+'));
if(limit!=1)
temp_receive('O');
i=0;lmt_chk = 0;
do
{
temp=se_rx();
if(isalnum(temp))
{
lmt_chk = 1;
dummy_str[i]=toupper(temp); i++;
}
}while(((temp!=0x0d) || (lmt_chk == 0)) && (i < 10));
dummy_str[i]='\0';
if(limit==1)
{
temp_receive(0x0d);
temp_receive(0x0d);
temp=se_rx();
lcd_clr();
}
delay(5000);
}
void msgdelete()
{
gsmread("AT",0,dummy);
lcd_str(dummy,0xc0);delay(50000);
gsmread("AT+CMGF=1",0,dummy);
lcd_str(dummy,0xc0);delay(50000);
gsmread("AT+CMGD=1",0,dummy);
lcd_str(dummy,0xc0);delay(50000);
}
void main()
{
unsigned char i=0;
Device = 0;
intro();
se_init();
delay(35000);//se_gsm("Testing Testing");while(1);
msgdelete();
lcd_clr();
delay(50000);
TI = 0; RI = 0;
delay(5000);
EA=1; //Enabling Global interrupt
ES=1; //Enabling Serial interrupt
while(1)
{
if(SE_INTR_ST == 1)
{
IE=0x00;
SE_INTR_ST = 0;
lcd_clr();
lcd_str("Msg Received",0x80);
delay(65000);delay(65000);
TI = 0; RI = 0;
delay(65000);
gsmread("AT",0,dummy); //lcd_str(dummy,0xc0);delay(50000);
gsmread("AT+CMGF=1",0, dummy); //lcd_str(dummy,0xc0);delay(50000);
gsmread("AT+CMGR=1",1, re_str); //lcd_str(re_str,0xc0);delay(50000);
gsmread("AT+CMGD=1",0, dummy); //lcd_str(dummy,0xc0);delay(50000);
lcd_clr();
lcd_str(re_str,0x80);
// lcd_str(number,0xc0);
MAX_DELAY();MAX_DELAY();
// MAX_DELAY();MAX_DELAY();
lcd_clr();
if(!strcmp(re_str,"DONN"))
{
lcd_str("Device turned On",0x80);
Device = 1;Dev_Stat = 1;
}
else if(!strcmp(re_str,"DOFF"))
{
lcd_str("Device turnd Off",0x80);
Device = 0;Dev_Stat = 0;
}
else
{
lcd_str(" Wrong Format ",0x80);
}
MAX_DELAY();MAX_DELAY(); MAX_DELAY();
IE=0x90;
}
else
{
lcd_clr();
lcd_str("No Msg Received",0x80);
if(Dev_Stat == 1)
{
lcd_str("Device turned On",0xc0);
}
else
{
lcd_str("Device turnd Off",0xc0);
}
while(SE_INTR_ST == 0);
}
}
}
#include <string.h>
#include <ctype.h>
#include "lcd.c"
#include "serial.c"
#define MAX_DELAY() delay(65000)
sbit Device=P0^0;
bit Dev_Stat=0;
unsigned char SE_INTR_ST = 0;
unsigned char re_str[6], number[14];
unsigned char dummy[6];
void intro()
{
lcd_init();
lcd_str(" Applaince Ctrl ",0x80);
lcd_str("Using GSM - 8051",0xc0);
MAX_DELAY();MAX_DELAY();
MAX_DELAY();MAX_DELAY();
lcd_clr();
}
void serial0() interrupt 4
{
char z;
if(RI==1)
{
z=SBUF;RI=0;
if(z=='+')
SE_INTR_ST = 1;
}
}
void temp_receive(unsigned char r)
{
unsigned char ten;
do
{
ten=se_rx();
}while(ten!=r);
}
void gsmread(const unsigned char *str,char limit,unsigned char *dummy_str)
{
unsigned char i,temp,lmt_chk = 0;
lcd_clr();
while(*str!='\0')
{
se_tx(*str);
str++;
}
se_tx('\r');//se_tx(0x0a);
if(limit==1)
{
for(i=0;i<2;i++)
temp_receive('"');temp_receive('1');
i=0;
do
{
temp=se_rx();
if(isdigit(temp))
{
number[i]=temp; i++;
}
}while(temp!='"');
temp_receive(0x0d);
number[i]='\0';
}
// if(RI == 1)
// do
// {
// temp=se_rx();
// }
// while(isalnum(temp) || (temp == '=') || (temp == '+'));
if(limit!=1)
temp_receive('O');
i=0;lmt_chk = 0;
do
{
temp=se_rx();
if(isalnum(temp))
{
lmt_chk = 1;
dummy_str[i]=toupper(temp); i++;
}
}while(((temp!=0x0d) || (lmt_chk == 0)) && (i < 10));
dummy_str[i]='\0';
if(limit==1)
{
temp_receive(0x0d);
temp_receive(0x0d);
temp=se_rx();
lcd_clr();
}
delay(5000);
}
void msgdelete()
{
gsmread("AT",0,dummy);
lcd_str(dummy,0xc0);delay(50000);
gsmread("AT+CMGF=1",0,dummy);
lcd_str(dummy,0xc0);delay(50000);
gsmread("AT+CMGD=1",0,dummy);
lcd_str(dummy,0xc0);delay(50000);
}
void main()
{
unsigned char i=0;
Device = 0;
intro();
se_init();
delay(35000);//se_gsm("Testing Testing");while(1);
msgdelete();
lcd_clr();
delay(50000);
TI = 0; RI = 0;
delay(5000);
EA=1; //Enabling Global interrupt
ES=1; //Enabling Serial interrupt
while(1)
{
if(SE_INTR_ST == 1)
{
IE=0x00;
SE_INTR_ST = 0;
lcd_clr();
lcd_str("Msg Received",0x80);
delay(65000);delay(65000);
TI = 0; RI = 0;
delay(65000);
gsmread("AT",0,dummy); //lcd_str(dummy,0xc0);delay(50000);
gsmread("AT+CMGF=1",0, dummy); //lcd_str(dummy,0xc0);delay(50000);
gsmread("AT+CMGR=1",1, re_str); //lcd_str(re_str,0xc0);delay(50000);
gsmread("AT+CMGD=1",0, dummy); //lcd_str(dummy,0xc0);delay(50000);
lcd_clr();
lcd_str(re_str,0x80);
// lcd_str(number,0xc0);
MAX_DELAY();MAX_DELAY();
// MAX_DELAY();MAX_DELAY();
lcd_clr();
if(!strcmp(re_str,"DONN"))
{
lcd_str("Device turned On",0x80);
Device = 1;Dev_Stat = 1;
}
else if(!strcmp(re_str,"DOFF"))
{
lcd_str("Device turnd Off",0x80);
Device = 0;Dev_Stat = 0;
}
else
{
lcd_str(" Wrong Format ",0x80);
}
MAX_DELAY();MAX_DELAY(); MAX_DELAY();
IE=0x90;
}
else
{
lcd_clr();
lcd_str("No Msg Received",0x80);
if(Dev_Stat == 1)
{
lcd_str("Device turned On",0xc0);
}
else
{
lcd_str("Device turnd Off",0xc0);
}
while(SE_INTR_ST == 0);
}
}
}
Comments
Post a Comment