char gsm_response[20];
//----------------------------------------------------------------------------------------
void _SIM900_print(unsigned const char *ptr) {
while (*ptr != 0) {
_SIM900_putch(*ptr++);
}
}
//--------------------------------------------------------------------------------------------------
//**Function to send one byte of data to UART**//
void _SIM900_putch(char bt)
{
while(!TXIF); // hold the program till TX buffer is free
TXREG = bt; //Load the transmitter buffer with the received value
}
//--------------------------------------------------------------------------------------------------
//**Function to get one byte of date from UART**//
char _SIM900_getch()
{
if(OERR) // check for Error
{
CREN = 0; //If error -> Reset
CREN = 1; //If error -> Reset
}
while(!RCIF); // hold the program till RX buffer is free
return RCREG; //receive the value and send it to main function
}
//-------------------------------------------------------------------------------------------------------
void gsm_read_line(char *buffer)
{
unsigned char rec_data;
// Read the data until Line Feed character is received.
do {
rec_data = _SIM900_getch();
*buffer++ = rec_data;
} while (rec_data != '\0');
}
//------------------------------------------------------------------------------------------------------------
void main(void)
{
//I/O Declarations//
TRISD = 0x00; //LCD pins on port D as output
Lcd_Start(); //Initialize LCD
Initialize_SIM900();//lets get our Serial ready for action
Lcd_Set_Cursor(1,1);
Lcd_Print_String("WELCOME");
/*Check if the SIM900 communication is successful*/
_SIM900_print("AT\r\n");
__delay_ms(1500);
// Read the response.
gsm_read_line(gsm_response);
// We should receive "OK" from the GSM modem. // If we don't, display "Error".
if (memcmp("OK", gsm_response, 2) != 0)
{
Lcd_Clear();
Lcd_Set_Cursor(1,1);
Lcd_Print_String("'AT' Error!!!");
while(1);
}
else if (memcmp("OK", gsm_response, 2)==0) // checking whether received string is OK and if OK then dial to ph no.
{
_SIM900_print("ATD0123456789;\r\n"); //Here we are placing a call to number 93643XXXXX
__delay_ms(1500);
Lcd_Set_Cursor(2,1);
Lcd_Print_String("Placing Call....");
__delay_ms(1500);
}
while(1);
}//main