CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Receiving SMS from GSM modem

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ratheeshbr



Joined: 26 Jan 2011
Posts: 31

View user's profile Send private message

Receiving SMS from GSM modem
PostPosted: Sun Mar 03, 2013 7:59 am     Reply with quote

In my project I have to receive SMS and control the devices. I am using PIC16F877A and CCS compilor. I successfully extracted message and number and it works fine. But Along with that I am having two sensors whose value is continuously displayed on LCD (LM35 & MQ6). But when the sensor value is displayed my SMS is not get received by the controller. I tried with Serial Interrupt but since it is quiet large I cant use Serial Interrupt. Any one can please suggest a way?
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sun Mar 03, 2013 8:51 am     Reply with quote

Hi,

My guess is that you have a faulty serial interrupt implementation. Unfortunately, my crystal ball is out for repairs, so you'll have to actually post your code if you want some help......

A clue to you problem is that your serial interrupt is "quite large".... Your interrupt needs to be "quite small", and you need to perform all other non-interrupt functions elsewhere.....

John
ratheeshbr



Joined: 26 Jan 2011
Posts: 31

View user's profile Send private message

here is my code
PostPosted: Sun Mar 03, 2013 9:11 am     Reply with quote

Code:

#define max 65534
#include<16f877a.h>
#device ADC=10
#device *=16
#include"pic1.h"
#include"lcd1.h"
#include<string.h>
#define ir rd2
#define device1 rc3
#define device2 rd1
#define device3 rd0

char num[15];
char msg[25];
char no1[15]="+919037952792";
char no2[12]="9447108108";
char no3[12]="9447108108";

char ctr[]="STATUS";
char ctr1[]="**D1ON";
char ctr2[]="**D1OF";
char ctr3[]="**D2ON";
char ctr4[]="**D2OF";
char ctr5[]="**D3ON";
char ctr6[]="**D3OF";

int dflg1,dflg2,dflg3;
msg_read(char *num,char *msg)
{

char ch;
int i,j,m;
int1 flg=0;
unsigned long time;


while(kbhit())
{
ch=getch();
if(ch=='"')
{
while(ch!= '1') ///Loop to reach to No
{

if(kbhit())
{
ch=getch();
time=0;

}
else
time++;
if(time > max)
return(0);



//Extracting NO

for(j=0;j<=12;)
{
if(kbhit())
{
num[j]=getch();
j++;
}
}

num[j]='\0';

j=0;

while(1)
{

if(kbhit())
{
ch=getch();
if(ch==10)
flg=1;
time=0;

if(flg)
{
if(j>0)
{
if(ch==10)
{ j-=2;
prints(num); msg[j]='\0';

go(64);
prints(msg);

return(1);
}
msg[j-1]=ch;
}

j++;
}
}//kbhit

}
}
}
}
}

void sms_start(char*ch)
{
printf("AT+CMGS=");
printf("\"%s\"\r",ch);
}
void sms_send(void)
{
putchar(26);
delay_ms(200);
}


void sms_123on()
{
sms_start(num);
printf("Device 1,2 & 3 is ON");
sms_send();
}
void sms_12on()
{
sms_start(num);
printf("Device 1 & 2 only is ON");
sms_send();
}
void sms_13on()
{
sms_start(num);
printf("Device 1 & 3 only is ON");
sms_send();
}
void sms_23on()
{
sms_start(num);
printf("Device 2 & 3 only is ON");
sms_send();
}

void sms_1on()
{
sms_start(num);
printf("Device 1 only is ON");
sms_send();
}
void sms_2on()
{
sms_start(num);
printf("Device 2 only is ON");
sms_send();
}
void sms_3on()
{
sms_start(num);
printf("Device 3 only is ON");
sms_send();
}
void sms_123of()
{

sms_start(num);
printf("ALL Devices are OFF");
sms_send();
}


void sms1_on()
{
sms_start(num);
printf("Device1 is ON");
sms_send();
}

void sms2_on()
{
sms_start(num);
printf("Device2 is ON");
sms_send();

}
void sms3_on()
{
sms_start(num);
printf("Device3 is ON");
sms_send();

}
void sms1_of()
{
sms_start(num);
printf("Device1 is OFF");
sms_send();
}
void sms2_of()
{
sms_start(num);
printf("Device2 is OFF");
sms_send();
}
void sms3_of()
{
sms_start(num);
printf("Device3 is OFF");
sms_send();
}
void sms2_wrong()
{
sms_start(num);
printf("You are not an authorized person");
sms_send();

}

void sms2_me()
{
sms_start(no3);
printf("GPTC PJT IS ON");
sms_send();

}

void sms_fire()

{
sms_start(no3);
printf("Alert! Fire ");
sms_send();

}
void sms_gas()

{
sms_start(no3);
printf("Alert! Gas Leakage ");
sms_send();

}
void sms_ir()
{
sms_start(no3);
printf("Alert! Intruder Detected ");
sms_send();

}
///////////////////////////////////////////////////////////////////////////////

void sms_status(int dflg1,int dflg2,int dflg3)
{


if(dflg1&&dflg2&&dflg3)
{
sms_123on();
sms_123on();
}

if(dflg1&&dflg2==1&&(!dflg3))
{

sms_12on();
sms_12on();
}
if(dflg1&&dflg3==1&&(!dflg2))
{

sms_13on();
sms_13on();
}
if(dflg2&&dflg3==1&&(!dflg1))
{
sms_23on();
sms_23on();

}
if(dflg1==1&&(!dflg2)&&(!dflg3))
{
sms_1on();
sms_1on();
}
if(dflg2==1&&(!dflg1)&&(!dflg3))
{
sms_2on();
sms_2on();

}
if(dflg3==1&&(!dflg1)&&(!dflg2))
{
sms_3on();
sms_3on();

}
else if((!dflg3)&&(!dflg1)&&(!dflg2))
{

//sms2_me();
sms_123of();
sms_123of();

}

}
////////////////////////////////ADC///////////////////////////////////////

float gas()
{
set_adc_channel(2);
delay_us(20);

return(read_adc());
}
float temp()
{
set_adc_channel(1);
delay_us(20);
delay_ms(200);

return(read_adc()*0.48);

}




void main()
{
float i,t;
int flg=0;
int smsflg=0,sms_fflg=0,sms_gflg=0,sms_iflg=0,g;
int dflg1,dflg2,dflg3;
int fflgset=0;int gflgset=0;
trisb=0x00;
trisd7=trisd1=trisd0=0;
trisc3=0;
trisd2=1;


dflg1=dflg2=dflg3=0;
device1=device2=device3=0;
delay_ms(500);
sms2_me();
lcdinit();
go(5);
printc("GPTC");
delay_ms(500);
delay_ms(500);
clrscr();
setup_adc(ADC_CLOCK_INTERNAL);
setup_adc_ports(ALL_ANALOG);
//device3=device1=device2=1;
while(1)
{
loop: if(msg_read(num,msg)==1)
{
if(!strcmp(num,no1))
{


if(!strcmp(ctr,msg))
{
delay_ms(800);
clrscr();
delay_ms(1000);

sms_status(dflg1,dflg2,dflg3);
delay_ms(5000);

delay_ms(8000);
clrscr();
}

if(!strcmp(ctr1,msg))
{
device1=1;
dflg1=1;
delay_ms(800);
clrscr();
delay_ms(1000);
sms1_on();

}
if(!strcmp(ctr2,msg))
{
device1=0;
dflg1=0;
delay_ms(800);
clrscr();
delay_ms(1000);
sms1_of();
}
if(!strcmp(ctr3,msg))
{
device2=1;
dflg2=1;
delay_ms(800);
clrscr();
delay_ms(1000);
sms2_on();
}
if(!strcmp(ctr4,msg))
{
device2=0;
dflg2=0;
delay_ms(800);
clrscr();
delay_ms(1000);
sms2_of();
}
if(!strcmp(ctr5,msg))
{
device3=1;
dflg3=1;
delay_ms(800);
clrscr();
delay_ms(1000);
sms3_on();
}
if(!strcmp(ctr6,msg))
{
device3=0;
dflg3=0;
delay_ms(800);
clrscr();
delay_ms(1000);
sms3_of();
}
}
else
{
printc("Unauthorized");
if(smsflg<2)
{
sms2_wrong();
sms2_wrong();
delay_ms(500);
smsflg++;
}
delay_ms(800);
clrscr();
delay_ms(1000);
clrscr();

}



}
else{

t=temp();
g=gas();
if(msg_read(num,msg)==1)
goto loop;
if(!fflgset)
sms_fflg=0;
if(!gflgset)
sms_gflg=0;
if(!rd2)
sms_iflg=0;
if(msg_read(num,msg)==1)
goto loop;
go(0);
printc("Temp=");
print(t);
if(msg_read(num,msg)==1)
goto loop;
go(10);
printc(" ");
go(11);
if(msg_read(num,msg)==1)
goto loop;
printc("G=");
print(g);
delay_ms(500);
if(msg_read(num,msg)==1)
goto loop;
if(t>45)
{
if(msg_read(num,msg)==1)
goto loop;
if(sms_fflg<2)
{
sms_fire();
delay_ms(500);
sms_fflg++;
}
if(msg_read(num,msg)==1)
goto loop;
go(64);
printc("Alert! Fire");
delay_ms(500);
go(64);
printc(" ");
// delay_ms(5000);
fflgset=1;
}
if(msg_read(num,msg)==1)
goto loop;
else
{
fflgset=0;
}
if(msg_read(num,msg)==1)
goto loop;
if(g>300)
{
if(sms_gflg<2)
{

sms_gas();
delay_ms(500);
sms_gflg++;
}
if(msg_read(num,msg)==1)
goto loop;
go(64);
printc("Alert!GasLeakage");
delay_ms(500);
go(64);
printc(" ");
// delay_ms(5000);
gflgset=1;
}
else
{
gflgset=0;
}
if(msg_read(num,msg)==1)
goto loop;
if(rd2)
{
if(sms_iflg<2)
{
sms_ir();
delay_ms(500);
sms_iflg++;
}
go(64);
printc("Alert!Intruder");
delay_ms(200);
go(64);
printc(" ");
// delay_ms(2000);

}


if(msg_read(num,msg)==1)
{
if(!strcmp(num,no1))
{


if(!strcmp(ctr,msg))
{
delay_ms(800);
clrscr();
delay_ms(1000);

sms_status(dflg1,dflg2,dflg3);
delay_ms(5000);

delay_ms(8000);
clrscr();
}

if(!strcmp(ctr1,msg))
{
device1=1;
dflg1=1;
delay_ms(800);
clrscr();
delay_ms(1000);
sms1_on();

}
if(!strcmp(ctr2,msg))
{
device1=0;
dflg1=0;
delay_ms(800);
clrscr();
delay_ms(1000);
sms1_of();
}
if(!strcmp(ctr3,msg))
{
device2=1;
dflg2=1;
delay_ms(800);
clrscr();
delay_ms(1000);
sms2_on();
}
if(!strcmp(ctr4,msg))
{
device2=0;
dflg2=0;
delay_ms(800);
clrscr();
delay_ms(1000);
sms2_of();
}
if(!strcmp(ctr5,msg))
{
device3=1;
dflg3=1;
delay_ms(800);
clrscr();
delay_ms(1000);
sms3_on();
}
if(!strcmp(ctr6,msg))
{
device3=0;
dflg3=0;
delay_ms(800);
clrscr();
delay_ms(1000);
sms3_of();
}
}
else
{
printc("Unauthorized");
if(smsflg<2)
{
sms2_wrong();
sms2_wrong();
delay_ms(500);
smsflg++;
}
delay_ms(800);
clrscr();
delay_ms(1000);
clrscr();

}



}
}


}
}

Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

Indentation
PostPosted: Sun Mar 03, 2013 9:45 am     Reply with quote

I'm not even going to try to read your code without indentation.

The idea (for me) is, each closing } should align exactly below its opening {

Code:

main()
{
  some code
  {
    more code
    at next level
    .......
    .......
  }
  code at same level as some code
  .........
}


At the end of your code you've got FIVE }'s

So your code must be at least five levels deep

I simply can't cope, I've got better things to do.

Mike
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Sun Mar 03, 2013 3:32 pm     Reply with quote

Hi,

I was hoping you'd show us your interrupt version of the code. An interrupt driven serial receive implementation will make your life easier, but you've got to do it correctly. Forum user Gabriel has a program that he's posted that does more-or-less what you want. You should do a search, and have a look....

John
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Sun Mar 03, 2013 8:39 pm     Reply with quote

there is a LETHAL number of app killing DELAY_MS( ) funcs in this code
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group