Receive SMS and turn on and off the devices


void main ()
{

clear();
lcdinit();
lcdcmd(0x80);
lcddata('K');

delay(10);
init();

SMSString("AT\r"); // AT commands to initialize gsm modem
delay(50);

SMSString( "ATe0\r"); // turn off echo
delay(50);

SMSString( "AT&W\r"); // save settings
delay(50);

SMSString( "AT+CMGF=1\r"); // select text mode for sms
delay(50);
SMSString( "AT+CNMI=2,1,0,0,0\r"); // notification of new sms
delay(10);

//New msg indication.
// +CMTI: "SM",3
while(1)
{
clear();
IE=0X90;   // Enable serial interrupt
delay(10);
read_notification(msg1);
IE=0x00;
}
}


void read_notification(unsigned char *msg)
{
unsigned char array[15],i,index_no;
i=0;
do
{
       msg++;
        i++;
}while(*msg!='+' && i!=15); // to check for first '+'.
i=0;

do
{
     array[i]=*msg++;
     i++;
}while(*msg!='\n' && i!=15);      // Check for new line.

if(strncmp(array, "+CMTI", 5) == 0)
{
        array[14] = '\0';
        IE=0x00;
        lcdcmd(0x80);
lcdstr("NEW MSG");// Just for indication.
        delay(50);
        SMSString("AT+CMGR=");
        tx0(array[12]);
        SMSString("\r");
        IE=0x90;
        delay(80);
        read_text(msg1,rec_no,time_date);
        delay(100);
}
return;
}