Code:
this is the logic
[code]
/* Header file declaration */
#include<pins.h>
#include<string.h>
/* variable declarations */
extern unsigned char pass[15];
void main()
{
unsigned char code gsm_cmd5[]="AT+CMGD=4";
uart_gps(); //To initalise the uart
gsm_init(); //To initalise the GSM
gsmcmdsend(gsm_cmd5); //clear the SIM memory
while(Rx_data()!='O');
while(Rx_data()!='K'); //waiting for the modem response
lcd_cmdwrt(0x01); //clear the LCD
lcd_datawrt("MSG DELETED..");//To print message on lcd
}
}
/************************************************************************************
Function Name : enter()
Return value : None
Purpose of this function: To send carrage return and line feed to modem
************************************************************************************/
void enter(void)
{
SBUF=0x0A;//line feed
while(TI==0);
TI=0;
SBUF=0x0D;//carriage return
while(TI==0);
TI=0;
}
/************************************************************************************
Function Name : gsmcmdsend()
Arguments : cmd to be transmit to modem
Return value : None
Purpose of this function: To transmit the cmd to modem
/************************************************************************************/
void gsmcmdsend(unsigned char *cmd)
{
unsigned char i;
for(i=0;*cmd!='\0';i++)
{
SBUF=*cmd;
while(TI==0); //COMMENTED WHILE
TI=0;
cmd++;
}
delay(1);
enter();
}
/************************************************************************************
Function Name : gsm_init()
Return value : None
Purpose of this function: To initialising the modem
/************************************************************************************/
void gsm_init(void)
{
unsigned char code gsm_cmd1[]="AT";
unsigned char code gsm_cmd2[]="ATE0";
unsigned char code gsm_cmd3[]="AT+CMGF=1";
unsigned char code gsm_cmd4[]="AT+IPR=4800";
unsigned char code gsm_cmd5[]="AT&W";
unsigned char code gsm_cmd6[]="AT+CNMI=2,2,0,0,0";
//checking for AT commands
gsmcmdsend(gsm_cmd1);
while(Rx_data()!='O');
while(Rx_data()!='K');//Waiting for modem response
lcd_datawrt(" command 1 OK");
delay(20);
lcd_cmdwrt(0x01);
//removing echo char
gsmcmdsend(gsm_cmd2);
while(Rx_data()=='O');
while(Rx_data()=='K');//Waiting for modem response
lcd_datawrt(" command 1 OK");
delay(20);
lcd_cmdwrt(0x01);
//setting the text command
gsmcmdsend(gsm_cmd3);
while(Rx_data()!='O');
while(Rx_data()!='K'); //Waiting for modem response
lcd_datawrt(" command 1 OK");
delay(1);
lcd_cmdwrt(0x01);
//setting the Baudrate command
gsmcmdsend(gsm_cmd4);
while(Rx_data()!='O');
while(Rx_data()!='K');//Waiting for modem response
lcd_datawrt(" command 1 OK");
delay(1);
lcd_cmdwrt(0x01);
//setting the save to modem EEPROM command
gsmcmdsend(gsm_cmd5);
while(Rx_data()!='O');
while(Rx_data()!='K');//Waiting for modem response
lcd_datawrt(" command 1 OK");
delay(1);
lcd_cmdwrt(0x01);
//to enable the sms strchr (buf, 't')
gsmcmdsend(gsm_cmd6);
while(Rx_data()!='O');
while(Rx_data()!='K');//Waiting for modem response
lcd_datawrt("command 1 OK");
delay(1);
lcd_cmdwrt(0x01);
}
/************************************************************************************
Function Name : Recv_frm_mob()
Return value : None
Purpose of this function: To read phone number and message from modem
************************************************************************************/
void Recv_frm_mob()
{
unsigned char count;
while((Rx_data())!=':');
while((Rx_data())!='+'); //wait till " receive
for(count=0;count<12;count++) // then store 12 digit phone number including
{
phone[count]=Rx_data();
}
phone[count]='\0';
while(Rx_data()!='\n'); //wait till next line
for(count=0;count<3;count++) // store message
{
pass[count]=Rx_data();
}
pass[count]='\0'; //Add null char to string to indicate end of string
lcd_cmdwrt(0xc0);
lcd_datawrt("MSG REC ...");
delay(2);
lcd_cmdwrt(0x01);
}
[/code]