#include<pic.h>
void serial_init();
void serial_char(unsigned char);
void serial_string(unsigned char *);
void serial_get(unsigned char);
void gsm_init();
void delay(unsigned int);
unsigned char msg[40],j=0,start=0,got=0,rec;
void delay(unsigned int del)
{
while(del--);
}
void serial_init()
{
TXSTA=0X24;
RCSTA=0X90;
SPBRG=25;
}
void serial_char(unsigned char val)
{
TXREG=val;
while(!TXIF);
TXIF=0;
}
void serial_string(unsigned char *string)
{
while(*string)
{
serial_char(*string++);
}
}
void gsm_init()
{
serial_string("AT");
serial_char(0x0d);
serial_char(0x0a);
delay(65000);
delay(65000);
serial_string("ATE0");
serial_char(0x0d);
serial_char(0x0a);
delay(65000);
delay(65000);
serial_string("AT+CLIP=1");
serial_char(0x0d);
serial_char(0x0a);
delay(65000);
delay(65000);
// serial_string("AT+CMGF=1");
// serial_char(0x0d);
// serial_char(0x0a);
// delay(65000);
// delay(65000);
// serial_string("AT+CNMI=2,2,0,0,0");
// serial_char(0x0d);
// serial_char(0x0a);
// delay(65000);
// delay(65000);
// serial_string("AT+CLIP=1");
// serial_char(0x0d);
// serial_char(0x0a);
// delay(65000);
// delay(65000);
}
void interrupt external()
{
if(RCIF)
{
rec=RCREG;
if(start==1)
{
msg[j]=rec;
j++;
if(rec==0X0D)
{
got=1;
}
}
if(start==0)
{
if(rec==0X0A)
{
start=1;
}
}
RCIF=0;
}
}
void main()
{
unsigned char del;
TRISD=0X00;
PORTD=0X00;
RD0=1;
RD1=1;
GIE=1;
PEIE=1;
INTE=1;
RCIE=1;
RCIF=0;
INTEDG=1;
serial_init();
delay(65000);
delay(65000);
gsm_init();
while(1)
{
if(got==1)
{
got=0;
j=0;
start=0;
if(msg[0]=='R'&&msg[1]=='I'&&msg[2]=='N'&&msg[3]=='G'&&msg[4]=='+'&&msg[5]=='C'&&msg[6]=='L'&&msg[7]=='I'&&msg[8]=='P'&&msg[9]==':'&&msg[10]==' '&&msg[11]=='"'&&msg[12]=='+'&&msg[13]=='9'&&msg[14]=='1'&&msg[15]=='9'&&msg[16]=='7'&&msg[17]=='8'&&msg[18]=='9'&&msg[19]=='3'&&msg[20]=='9'&&msg[21]=='3'&&msg[22]=='7'&&msg[23]=='2'&&msg[24]=='4'&&msg[25]=='"'&&msg[26]==','&&msg[27]=='1'&&msg[28]=='4'&&msg[29]=='5'&&msg[30]==','&&msg[31]=='"'&&msg[32]=='"'&&msg[33]==','&&msg[34]==','&&msg[35]=='"'&&msg[36]=='"'&&msg[37]==','&&msg[38]=='0')
{
RD0=0;
RD1=0;
for(del=0;del<30;del++)
{
delay(60000);
}
RD0=1;
RD1=1;
}
}
}
}