GSM security system using pic18f4620

Status
Not open for further replies.

ralphbanque

Newbie level 3
Joined
Mar 8, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,466
hello guys,

I am trying to make a project that sends a message to a cellphone number when a door or window is opened.
I am using pic18f4620 and sim500w GSM module.
When i run it on simulation it's ok but on the actual hardware it doesn't work, it becomes stuck at the first part of the program.
Please help and thanks in advance
 

you should provide your mcu code and hardware diagram.
that could be helpful for you
 

First of all find out that it is software problem or hardware.
1) use delays in your code.
2) use rs232 or lcd or any thing else and send current status of micro-controller on lcd or rs232.
3) connect noise filters in your micro-controller power supply and make shore that microcontroller is running on +5v.
 

Post the datasheet of SIM500w. How did you simulate GSM in proteus. Do you have GSM module in proteus or did you just check the serial communication in Proteus? Post you code so that we can see what is the first part of the program.
 

hello guys,
here are the datasheets of sim500w one is for the hardware and the other is for the software...
in simulating the GSM we used DCU-11 cable and connected it via COMPIM

here is my code :

void keypadString(int delimeter,int max,int start);
void inputPin(int delimeter,int max,int start);
char ascii(int key);
void Register();
void Sensor();
void GSM_init();
void sendSMS(char dest[15], char mess[200]);
void getData();
void check();
short newMess();
void checkGSM(short index);

short reg_num=0,reg_ans=0,arm_disarm=1;
char str[30]="", number[11]="", number2[11]="", pin1[4]="", pin2[4]="",spin[4]="",comm[3]="", *data="", *smes="";
char sender[20]=" ", mes[20]=" ";

short newMess()
{
short cnt=0,retval=0;
char *rep="",ch=' ';
while(1)
{
if(Usart_Data_Ready())
{
ch=Usart_Read();
rep[cnt]=ch;
rep[cnt+1]=0;
cnt++;
}
if(strstr(rep,"+CMTI:")!=0){retval=rep[12]; break;}
else{retval=0;break;}
}return retval;
}

void gsmON()
{
short cnt=0, OKflag=0;
char *rep="",ch=' ';
Usart_Init(57600);
while(1)
{
if(OKflag!=0) {PORTE.F1=1;break;}
else {Usart_Write('A');Usart_Write('T');Usart_Write(13);}
while(1)
{
if(Usart_Data_Ready())
{
ch=Usart_Read();
rep[cnt]=ch;
rep[cnt+1]=0;
cnt++;
}
if(strstr(rep,"OK")!=0) {OKflag=1; delay_ms(300); break;}
else {PORTE.F0=1; delay_ms(3000); PORTE.F0=0;}
}
}
}
void GSM_init()
{
short cntr=0,a,at=0,OKflag=0;
char ch=' ',ch2=' ',*rep1=" ",*rep2=" ";

gsmON();
OKflag=0;cntr=0;
while(1)
{
if(OKflag!=0) break;
else {Usart_Write('A');Usart_Write('T');Usart_Write('+');Usart_Write('C');Usart_Write('M');
Usart_Write('G');Usart_Write('F');Usart_Write('=');Usart_Write('1');Usart_Write(13);}
while(1)
{
if(Usart_Data_Ready())
{
ch=Usart_Read();
rep1[cntr]=ch;
rep1[cntr+1]=0;
cntr++;
}
if(strstr(rep1,"OK")!=0) {OKflag=1; delay_ms(300); break;}

}
}
OKflag=0;cntr=0;
while(1)
{
if(OKflag!=0) break;
else {Usart_Write('A');Usart_Write('T');Usart_Write('+');Usart_Write('C');Usart_Write('P');
Usart_Write('M');Usart_Write('S');Usart_Write('=');Usart_Write('"');Usart_Write('s');Usart_Write('m');Usart_Write('"');Usart_Write(13);}
while(1)
{
if(Usart_Data_Ready())
{
ch=Usart_Read();
rep1[cntr]=ch;
rep1[cntr+1]=0;
cntr++;
}
if(strstr(rep1,"OK")!=0) {OKflag=1; delay_ms(300); break;}

}
}

}

char ascii(int key) {

switch(key) {
case 0: break;
case 1: return '1'; break;
case 2: return '2'; break;
case 3: return '3'; break;
case 5: return '4'; break;
case 6: return '5'; break;
case 7: return '6'; break;
case 9: return '7'; break;
case 10: return '8'; break;
case 11: return '9'; break;
case 13: break;
case 14: return '0'; break;
case 15: break;
}
}

void inputPin(int delimeter,int max,int start)
{
int key=0,cntr=0,S=start,i,j;
char ch=' ';
lcd_custom_out(1,1,"Input pin: ") ;
Lcd_Custom_Cmd(LCD_SECOND_ROW);
while(key != delimeter) {

key = keypad_released();
if(key!=0 && key!=delimeter && key!=13 && cntr<max)
{
ch = ascii(key);
// str = ch;
Eeprom_Write(S,ch); delay_ms(100);
Lcd_Custom_chr_cp(Eeprom_Read(S));
cntr++; S++;
}

if(key==13)
{
LCD_Custom_Cmd(LCD_MOVE_CURSOR_LEFT);
Lcd_Custom_chr_cp(' ');
LCD_Custom_Cmd(LCD_MOVE_CURSOR_LEFT);
cntr--; S--;
}

if(key==delimeter)
{
if(cntr==max)
{
if(start==0x0b)
{
for(i=0,j=start;i<max;i++,j++)
pin1 = Eeprom_Read(j);
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "PinRegistered:");
Lcd_Custom_Out(2, 1, pin1);
delay_ms(1000);
}
else if(start==0x1b)
{
for(i=0,j=start;i<max;i++,j++)
pin2 = Eeprom_Read(j);
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "PinRegistered::");
Lcd_Custom_Out(2, 1, pin2);
delay_ms(1000);
}
}
else
{ Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "Invalid Input");
cntr=0; key=0; S=start; delay_ms(1000);
Lcd_Custom_Cmd(Lcd_Clear);
lcd_custom_out(1,1,"Input Pin: ") ;
Lcd_Custom_Cmd(LCD_SECOND_ROW);
}
}
}
}

void keypadString(int delimeter,int max,int start) {

int key=0,cntr=0,S=start,i,j;
char ch=' ';
lcd_custom_out(1,1,"Input Number: ") ;
Lcd_Custom_Cmd(LCD_SECOND_ROW);
while(key != delimeter) {

key = keypad_released();
if(key!=0 && key!=delimeter && key!=13 && cntr<max)
{
ch = ascii(key);
// str = ch;
Eeprom_Write(S,ch); delay_ms(100);
Lcd_Custom_chr_cp(Eeprom_Read(S));
cntr++; S++;
}

if(key==13)
{
LCD_Custom_Cmd(LCD_MOVE_CURSOR_LEFT);
Lcd_Custom_chr_cp(' ');
LCD_Custom_Cmd(LCD_MOVE_CURSOR_LEFT);
cntr--; S--;
}

if(key==delimeter)
{
if(cntr==max)
{
if(start==0x00)
{
for(i=0,j=start;i<max;i++,j++)
number = Eeprom_Read(j);
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "NumberRegistered:");
Lcd_Custom_Out(2, 1, number);
delay_ms(1000);
}
else if(start==0x10)
{
for(i=0,j=start;i<max;i++,j++)
number2 = Eeprom_Read(j);
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "NumberRegistered:");
Lcd_Custom_Out(2, 1, number2);
delay_ms(1000);
}
Lcd_Custom_Cmd(Lcd_Clear);
inputPin(15,4,start+0x0b);
}
else
{ Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "Invalid Input");
cntr=0; key=0; S=start; delay_ms(1000);
Lcd_Custom_Cmd(Lcd_Clear);
lcd_custom_out(1,1,"Input Pin: ") ;
Lcd_Custom_Cmd(LCD_SECOND_ROW);
}
}
}
}




void Register()
{
int key=0,no1=0,ovr=0;
if(reg_num==0)
{
keypadString(15,11,0x00);
reg_num++;
delay_ms(1000);
}
else if(reg_num==1)
{
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "Add new number?");
Lcd_Custom_Out(2, 1, "(*=yes/#=no)");
delay_ms(500);
while(key!=13 && no1!=1)
{
key= keypad_released();
if(key==13)
{
key=0;
Lcd_Custom_Cmd(Lcd_Clear);
keypadString(15,11,0x10);
reg_num++;
delay_ms(1000);

}
else if(key==15)
{no1=1;reg_ans=1;}

}
}
else if(reg_num==2)
{
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "Overwrite a number?");
Lcd_Custom_Out(2, 1, "(*=yes/#=no)");
delay_ms(500);
while(key!=13 && no1!=1)
{
key= keypad_released();
if(key==13)
{
key=0;
Lcd_Custom_Cmd(Lcd_Clear);Lcd_Custom_Out(1, 1, number);Lcd_Custom_Out(2, 1,number2);
delay_ms(3000);
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "Choose number");Lcd_Custom_Out(2, 1,"(*=1st/#=2nd)");
key=keypad_released();
while(ovr!=1)
{
if(key==13)
{
keypadString(15,11,0x00);
reg_num++;ovr=1;
delay_ms(1000);
}
else if(key==15)
{
keypadString(15,11,0x0f);
reg_num++;ovr=1;
delay_ms(1000);
}
}
}
else if(key==15)
{no1=1;reg_ans=1;}

}
}

}

void Sensor()
{
if(arm_disarm==1)
{
Lcd_Custom_Cmd(Lcd_Clear);
lcd_custom_out(1,1,"System Armed") ;
if(PORTB.F0==1)
{
sendSMS(number,"Sensor 1 is Tripped");delay_ms(2000);
if(reg_num==2)
sendSMS(number2,"Sensor 1 is Tripped");delay_ms(50);
}
if(PORTB.F1==1)
{
sendSMS(number,"Sensor 2 is Tripped");delay_ms(2000);
if(reg_num==2)
sendSMS(number2,"Sensor 2 is Tripped");delay_ms(50);
}
if(PORTB.F2==1)
{
sendSMS(number,"Sensor 3 is Tripped");delay_ms(2000);
if(reg_num==2)
sendSMS(number2,"Sensor 3 is Tripped");delay_ms(50);
}
if(PORTB.F3==1)
{
sendSMS(number,"Sensor 4 is Tripped");delay_ms(2000);
if(reg_num==2)
sendSMS(number2,"Sensor 4 is Tripped");delay_ms(50);
}
if(PORTB.F4==1)
{
sendSMS(number,"Sensor 5 is Tripped");delay_ms(2000);
if(reg_num==2)
sendSMS(number2,"Sensor 5 is Tripped");delay_ms(50);
}
}
else
lcd_custom_out(1,1,"System Disarmed") ;
delay_ms(500);
}

void checkGSM(short index)
{
char data[15] = " ";
int aCntr=0,cntr=0, a=0, start=0, end=0, b=0, cmgr=0;
int cQntr=0,cQntr2=0, num_start=0,num_end=0,mes_start=0,mes_end=0;
char ch = ' ', gprmc[100]=" ";char gsmData[50]=" ";

// char sender[20]=" ", mes[20]=" ";
TRISB=0x00;
ADCON1=0x0F;
PORTB=0x01;
delay_ms(100);

Usart_Write('A');Usart_Write('T');Usart_Write('+');Usart_Write('C');Usart_Write('M');Usart_Write('G');Usart_Write('R');Usart_Write('=');Usart_Write(index+48);Usart_Write(13);
while(1)
{
if(Usart_Data_Ready())
{
if(aCntr==8){break;}
else{
ch = Usart_Read();
gsmData[cntr] = ch;
gsmData[cntr+1] = 0;
}cntr++;
if(ch=='"') { aCntr++; }
}
}

if(strstr(gsmData,number)!=0)
{
if(strstr(gsmData,pin1)!=0)
{
if(strstr(gsmData,"arm")!=0)
{
if(arm_disarm==1)
{sendSMS(number,"Already Armed");}
else {sendSMS(number,"System Armed");arm_disarm=1;}
}
else if(strstr(gsmData,"dis")!=0)
{
if(arm_disarm==0)
{sendSMS(number,"Already Disarmed");}
else {sendSMS(number,"System Armed");arm_disarm=0;}
}
}
else
{sendSMS(number,"Wrong PIN");}
}
else if(strstr(gsmData,number2)!=0)
{
if(strstr(gsmData,pin2)!=0)
{
if(arm_disarm==1)
{sendSMS(number2,"Already Armed");}
else {sendSMS(number2,"System Armed");arm_disarm=1;}
}
else if(strstr(gsmData,"dis")!=0)
{
if(arm_disarm==0)
{sendSMS(number2,"Already Disarmed");}
else {sendSMS(number2,"System Armed");arm_disarm=0;}
}
}
else
{sendSMS(number2,"Wrong PIN");}

}


void sendSMS(char dest[15], char mess[200])
{
int a=0;

Usart_Write('A');
Usart_Write('T');
Usart_Write('+');
Usart_Write('C');
Usart_Write('M');
Usart_Write('G');
Usart_Write('S');
Usart_Write('=');
Usart_Write('"');

for(a=0;a<11;a++) { delay_ms(100); Usart_Write(dest[a]); }

Usart_Write('"');
Usart_Write(13);delay_ms(10);

for(a=0;a<strlen(mess);a++) { delay_ms(100); Usart_Write(mess[a]); }

delay_ms(1000);
Usart_Write(26);Usart_Write(13);
delay_ms(15000);
}

void main() {
ADCON1=0x0F;
TRISB=0xff;
PORTB=0x00;
Lcd_Custom_Config(&PORTA,3,2,1,0,&PORTE,1,0,2);
Lcd_Custom_Cmd(Lcd_CURSOR_OFF);
delay_ms(1000);
Lcd_Custom_Out(1, 4, "GSM-Based"); Lcd_Custom_Out(2, 1, "Security System");
delay_ms(3000);Lcd_Custom_Cmd(Lcd_Clear);
Keypad_Init(&PORTD);
Lcd_Custom_Out(1, 4, "Initializing");
GSM_init();//GSM_init();
Lcd_Custom_Cmd(Lcd_Clear);

while(reg_ans==0)
{Register();}

while(1)
{
//if("new message")
Sensor();
if(newMess())
checkGSM(newMess());
//checkGSM();
//else

Lcd_Custom_Cmd(Lcd_Clear);
delay_ms(10);
}

}

- - - Updated - - -

hello guys,
here are the datasheets of sim500w one is for the hardware and the other is for the software...
in simulating the GSM we used DCU-11 cable and connected it via COMPIM

here is my code :

void keypadString(int delimeter,int max,int start);
void inputPin(int delimeter,int max,int start);
char ascii(int key);
void Register();
void Sensor();
void GSM_init();
void sendSMS(char dest[15], char mess[200]);
void getData();
void check();
short newMess();
void checkGSM(short index);

short reg_num=0,reg_ans=0,arm_disarm=1;
char str[30]="", number[11]="", number2[11]="", pin1[4]="", pin2[4]="",spin[4]="",comm[3]="", *data="", *smes="";
char sender[20]=" ", mes[20]=" ";

short newMess()
{
short cnt=0,retval=0;
char *rep="",ch=' ';
while(1)
{
if(Usart_Data_Ready())
{
ch=Usart_Read();
rep[cnt]=ch;
rep[cnt+1]=0;
cnt++;
}
if(strstr(rep,"+CMTI:")!=0){retval=rep[12]; break;}
else{retval=0;break;}
}return retval;
}

void gsmON()
{
short cnt=0, OKflag=0;
char *rep="",ch=' ';
Usart_Init(57600);
while(1)
{
if(OKflag!=0) {PORTE.F1=1;break;}
else {Usart_Write('A');Usart_Write('T');Usart_Write(13);}
while(1)
{
if(Usart_Data_Ready())
{
ch=Usart_Read();
rep[cnt]=ch;
rep[cnt+1]=0;
cnt++;
}
if(strstr(rep,"OK")!=0) {OKflag=1; delay_ms(300); break;}
else {PORTE.F0=1; delay_ms(3000); PORTE.F0=0;}
}
}
}
void GSM_init()
{
short cntr=0,a,at=0,OKflag=0;
char ch=' ',ch2=' ',*rep1=" ",*rep2=" ";

gsmON();
OKflag=0;cntr=0;
while(1)
{
if(OKflag!=0) break;
else {Usart_Write('A');Usart_Write('T');Usart_Write('+');Usart_Write('C');Usart_Write('M');
Usart_Write('G');Usart_Write('F');Usart_Write('=');Usart_Write('1');Usart_Write(13);}
while(1)
{
if(Usart_Data_Ready())
{
ch=Usart_Read();
rep1[cntr]=ch;
rep1[cntr+1]=0;
cntr++;
}
if(strstr(rep1,"OK")!=0) {OKflag=1; delay_ms(300); break;}

}
}
OKflag=0;cntr=0;
while(1)
{
if(OKflag!=0) break;
else {Usart_Write('A');Usart_Write('T');Usart_Write('+');Usart_Write('C');Usart_Write('P');
Usart_Write('M');Usart_Write('S');Usart_Write('=');Usart_Write('"');Usart_Write('s');Usart_Write('m');Usart_Write('"');Usart_Write(13);}
while(1)
{
if(Usart_Data_Ready())
{
ch=Usart_Read();
rep1[cntr]=ch;
rep1[cntr+1]=0;
cntr++;
}
if(strstr(rep1,"OK")!=0) {OKflag=1; delay_ms(300); break;}

}
}

}

char ascii(int key) {

switch(key) {
case 0: break;
case 1: return '1'; break;
case 2: return '2'; break;
case 3: return '3'; break;
case 5: return '4'; break;
case 6: return '5'; break;
case 7: return '6'; break;
case 9: return '7'; break;
case 10: return '8'; break;
case 11: return '9'; break;
case 13: break;
case 14: return '0'; break;
case 15: break;
}
}

void inputPin(int delimeter,int max,int start)
{
int key=0,cntr=0,S=start,i,j;
char ch=' ';
lcd_custom_out(1,1,"Input pin: ") ;
Lcd_Custom_Cmd(LCD_SECOND_ROW);
while(key != delimeter) {

key = keypad_released();
if(key!=0 && key!=delimeter && key!=13 && cntr<max)
{
ch = ascii(key);
// str = ch;
Eeprom_Write(S,ch); delay_ms(100);
Lcd_Custom_chr_cp(Eeprom_Read(S));
cntr++; S++;
}

if(key==13)
{
LCD_Custom_Cmd(LCD_MOVE_CURSOR_LEFT);
Lcd_Custom_chr_cp(' ');
LCD_Custom_Cmd(LCD_MOVE_CURSOR_LEFT);
cntr--; S--;
}

if(key==delimeter)
{
if(cntr==max)
{
if(start==0x0b)
{
for(i=0,j=start;i<max;i++,j++)
pin1 = Eeprom_Read(j);
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "PinRegistered:");
Lcd_Custom_Out(2, 1, pin1);
delay_ms(1000);
}
else if(start==0x1b)
{
for(i=0,j=start;i<max;i++,j++)
pin2 = Eeprom_Read(j);
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "PinRegistered::");
Lcd_Custom_Out(2, 1, pin2);
delay_ms(1000);
}
}
else
{ Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "Invalid Input");
cntr=0; key=0; S=start; delay_ms(1000);
Lcd_Custom_Cmd(Lcd_Clear);
lcd_custom_out(1,1,"Input Pin: ") ;
Lcd_Custom_Cmd(LCD_SECOND_ROW);
}
}
}
}

void keypadString(int delimeter,int max,int start) {

int key=0,cntr=0,S=start,i,j;
char ch=' ';
lcd_custom_out(1,1,"Input Number: ") ;
Lcd_Custom_Cmd(LCD_SECOND_ROW);
while(key != delimeter) {

key = keypad_released();
if(key!=0 && key!=delimeter && key!=13 && cntr<max)
{
ch = ascii(key);
// str = ch;
Eeprom_Write(S,ch); delay_ms(100);
Lcd_Custom_chr_cp(Eeprom_Read(S));
cntr++; S++;
}

if(key==13)
{
LCD_Custom_Cmd(LCD_MOVE_CURSOR_LEFT);
Lcd_Custom_chr_cp(' ');
LCD_Custom_Cmd(LCD_MOVE_CURSOR_LEFT);
cntr--; S--;
}

if(key==delimeter)
{
if(cntr==max)
{
if(start==0x00)
{
for(i=0,j=start;i<max;i++,j++)
number = Eeprom_Read(j);
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "NumberRegistered:");
Lcd_Custom_Out(2, 1, number);
delay_ms(1000);
}
else if(start==0x10)
{
for(i=0,j=start;i<max;i++,j++)
number2 = Eeprom_Read(j);
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "NumberRegistered:");
Lcd_Custom_Out(2, 1, number2);
delay_ms(1000);
}
Lcd_Custom_Cmd(Lcd_Clear);
inputPin(15,4,start+0x0b);
}
else
{ Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "Invalid Input");
cntr=0; key=0; S=start; delay_ms(1000);
Lcd_Custom_Cmd(Lcd_Clear);
lcd_custom_out(1,1,"Input Pin: ") ;
Lcd_Custom_Cmd(LCD_SECOND_ROW);
}
}
}
}




void Register()
{
int key=0,no1=0,ovr=0;
if(reg_num==0)
{
keypadString(15,11,0x00);
reg_num++;
delay_ms(1000);
}
else if(reg_num==1)
{
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "Add new number?");
Lcd_Custom_Out(2, 1, "(*=yes/#=no)");
delay_ms(500);
while(key!=13 && no1!=1)
{
key= keypad_released();
if(key==13)
{
key=0;
Lcd_Custom_Cmd(Lcd_Clear);
keypadString(15,11,0x10);
reg_num++;
delay_ms(1000);

}
else if(key==15)
{no1=1;reg_ans=1;}

}
}
else if(reg_num==2)
{
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "Overwrite a number?");
Lcd_Custom_Out(2, 1, "(*=yes/#=no)");
delay_ms(500);
while(key!=13 && no1!=1)
{
key= keypad_released();
if(key==13)
{
key=0;
Lcd_Custom_Cmd(Lcd_Clear);Lcd_Custom_Out(1, 1, number);Lcd_Custom_Out(2, 1,number2);
delay_ms(3000);
Lcd_Custom_Cmd(Lcd_Clear);
Lcd_Custom_Out(1, 1, "Choose number");Lcd_Custom_Out(2, 1,"(*=1st/#=2nd)");
key=keypad_released();
while(ovr!=1)
{
if(key==13)
{
keypadString(15,11,0x00);
reg_num++;ovr=1;
delay_ms(1000);
}
else if(key==15)
{
keypadString(15,11,0x0f);
reg_num++;ovr=1;
delay_ms(1000);
}
}
}
else if(key==15)
{no1=1;reg_ans=1;}

}
}

}

void Sensor()
{
if(arm_disarm==1)
{
Lcd_Custom_Cmd(Lcd_Clear);
lcd_custom_out(1,1,"System Armed") ;
if(PORTB.F0==1)
{
sendSMS(number,"Sensor 1 is Tripped");delay_ms(2000);
if(reg_num==2)
sendSMS(number2,"Sensor 1 is Tripped");delay_ms(50);
}
if(PORTB.F1==1)
{
sendSMS(number,"Sensor 2 is Tripped");delay_ms(2000);
if(reg_num==2)
sendSMS(number2,"Sensor 2 is Tripped");delay_ms(50);
}
if(PORTB.F2==1)
{
sendSMS(number,"Sensor 3 is Tripped");delay_ms(2000);
if(reg_num==2)
sendSMS(number2,"Sensor 3 is Tripped");delay_ms(50);
}
if(PORTB.F3==1)
{
sendSMS(number,"Sensor 4 is Tripped");delay_ms(2000);
if(reg_num==2)
sendSMS(number2,"Sensor 4 is Tripped");delay_ms(50);
}
if(PORTB.F4==1)
{
sendSMS(number,"Sensor 5 is Tripped");delay_ms(2000);
if(reg_num==2)
sendSMS(number2,"Sensor 5 is Tripped");delay_ms(50);
}
}
else
lcd_custom_out(1,1,"System Disarmed") ;
delay_ms(500);
}

void checkGSM(short index)
{
char data[15] = " ";
int aCntr=0,cntr=0, a=0, start=0, end=0, b=0, cmgr=0;
int cQntr=0,cQntr2=0, num_start=0,num_end=0,mes_start=0,mes_end=0;
char ch = ' ', gprmc[100]=" ";char gsmData[50]=" ";

// char sender[20]=" ", mes[20]=" ";
TRISB=0x00;
ADCON1=0x0F;
PORTB=0x01;
delay_ms(100);

Usart_Write('A');Usart_Write('T');Usart_Write('+');Usart_Write('C');Usart_Write('M');Usart_Write('G');Usart_Write('R');Usart_Write('=');Usart_Write(index+48);Usart_Write(13);
while(1)
{
if(Usart_Data_Ready())
{
if(aCntr==8){break;}
else{
ch = Usart_Read();
gsmData[cntr] = ch;
gsmData[cntr+1] = 0;
}cntr++;
if(ch=='"') { aCntr++; }
}
}

if(strstr(gsmData,number)!=0)
{
if(strstr(gsmData,pin1)!=0)
{
if(strstr(gsmData,"arm")!=0)
{
if(arm_disarm==1)
{sendSMS(number,"Already Armed");}
else {sendSMS(number,"System Armed");arm_disarm=1;}
}
else if(strstr(gsmData,"dis")!=0)
{
if(arm_disarm==0)
{sendSMS(number,"Already Disarmed");}
else {sendSMS(number,"System Armed");arm_disarm=0;}
}
}
else
{sendSMS(number,"Wrong PIN");}
}
else if(strstr(gsmData,number2)!=0)
{
if(strstr(gsmData,pin2)!=0)
{
if(arm_disarm==1)
{sendSMS(number2,"Already Armed");}
else {sendSMS(number2,"System Armed");arm_disarm=1;}
}
else if(strstr(gsmData,"dis")!=0)
{
if(arm_disarm==0)
{sendSMS(number2,"Already Disarmed");}
else {sendSMS(number2,"System Armed");arm_disarm=0;}
}
}
else
{sendSMS(number2,"Wrong PIN");}

}


void sendSMS(char dest[15], char mess[200])
{
int a=0;

Usart_Write('A');
Usart_Write('T');
Usart_Write('+');
Usart_Write('C');
Usart_Write('M');
Usart_Write('G');
Usart_Write('S');
Usart_Write('=');
Usart_Write('"');

for(a=0;a<11;a++) { delay_ms(100); Usart_Write(dest[a]); }

Usart_Write('"');
Usart_Write(13);delay_ms(10);

for(a=0;a<strlen(mess);a++) { delay_ms(100); Usart_Write(mess[a]); }

delay_ms(1000);
Usart_Write(26);Usart_Write(13);
delay_ms(15000);
}

void main() {
ADCON1=0x0F;
TRISB=0xff;
PORTB=0x00;
Lcd_Custom_Config(&PORTA,3,2,1,0,&PORTE,1,0,2);
Lcd_Custom_Cmd(Lcd_CURSOR_OFF);
delay_ms(1000);
Lcd_Custom_Out(1, 4, "GSM-Based"); Lcd_Custom_Out(2, 1, "Security System");
delay_ms(3000);Lcd_Custom_Cmd(Lcd_Clear);
Keypad_Init(&PORTD);
Lcd_Custom_Out(1, 4, "Initializing");
GSM_init();//GSM_init();
Lcd_Custom_Cmd(Lcd_Clear);

while(reg_ans==0)
{Register();}

while(1)
{
//if("new message")
Sensor();
if(newMess())
checkGSM(newMess());
//checkGSM();
//else

Lcd_Custom_Cmd(Lcd_Clear);
delay_ms(10);
}

}
 

Attachments

  • SIM500W&SIM540W_HD_V1.01.pdf
    1.9 MB · Views: 91
  • SIM500W_ATC_V1.00.pdf
    1.1 MB · Views: 61
  • Schematic.BMP
    6.6 MB · Views: 66

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…