// Variables
volatile unsigned char i=0,j=0, yesgot=0, message[100];
volatile unsigned int storedloc=0,gotit;
// STEP.1-- CHECK REGISTER
unsigned char rx_incoming()
{
while(PIR1.RCIF==0); // if data not read stay here
return RCREG; // Data is present in this regester
} // Return means take
void main()
{
delay_ms(40);
UART1_Init(9600);
RCSTA.SPEN=1;RCSTA.CREN=1; // To set usart pins as Transmitter
delay_ms(50);
UART1_Write_Text("ATE0"); // Echo Off
UART1_Write(0xd);
delay_ms(40);
UART1_Write_Text("AT+CMGF=1");
UART1_Write(0xd);
//STEP2. -----Save Memory Slot
while(storedloc==0)
{
gotit= rx_incoming();
if(gotit=='+')
{
gotit= rx_incoming();
if(gotit=='C')
{ gotit=rx_incoming();
if(gotit=='M')
{
gotit=rx_incoming();
if(gotit=='T')
{
gotit=rx_incoming();
if(gotit=='I')
{
gotit=rx_incoming();
if(gotit==':')
{
gotit=rx_incoming();
while(gotit!=',')gotit=rx_incoming();
storedloc=rx_incoming();
}
}
}
}
}
} // Memory slot saved
}
// STEP.3 ----- Use command
delay_ms(100); //
UART1_Write_Text("AT+CMGR="); // Read SMS
UART1_Write(storedloc); //
UART1_Write(0xd);
// STEP.4------Extracting SMS CMGR+ :
while(yesgot==0)
{
gotit=rx_incoming();
if(gotit=='+')
{
gotit=rx_incoming();
if(gotit=='C')
{
gotit=rx_incoming();
if(gotit=='M')
{
gotit=rx_incoming();
if(gotit=='G')
{
gotit=rx_incoming();
if(gotit=='R')
{
gotit=rx_incoming();
if(gotit==':')
{ // Save in Array
gotit=rx_incoming();
while(gotit!=0xa){gotit=rx_incoming();}
//STEP.5---- save in array
for(i=0;gotit!=0xd;i++){gotit=message[i]=rx_incoming();}
UART1_Write_Text("AT+CMGD="); // Delete
UART1_Write(storedloc);
UART1_Write(0xd);
Lcd_Out(1,1,message); // LCD Display
yesgot=1;
}
}
}
}
}
}
}
// Fahad Wasti