char incchar;
char incoming[80];
char *result; // command string search result
int i = 0;
void main() {
PORTB = 0;
TRISB = 0; //RB0 input for interrupt
PORTD = 0;
TRISD = 0; //PORTD all output
ANCON0 = 0x00; // Configure PORTC pins as digital
ANCON1 = 0x00; // Configure PORTC pins as digital
ANCON2 = 0x00; // Configure PORTC pins as digital
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize
Delay_ms(2000);
UART1_Write_Text("ATE0\r\n"); // AT command for Echo OFF
Delay_ms(1000);
UART1_Write_Text("AT\r\n"); // test GSM Modem
Delay_ms(1000);
UART1_Write_Text("AT+CMGF = 1\r\n"); //convert Sim900 module to text mode
Delay_ms(1000);
UART1_Write_Text("AT+CNMI=1,2,0,0,0\r\n"); // setup receiving (now important at this stage)
Delay_ms(1000);
while (1) { // Endless loop
if (UART1_Data_Ready()) { // If data is received,
for (i= 0; i < 80; i++) {
incchar = UART1_Read(); // read the received data,
incoming[i] = incchar;
}
if (result = strstr (incoming, "ON")); // search for string "ON" in incoming and save it in result
if (memcmp("ON", result, 2) == 0)
{
PORTB.F0 = 0x01;
PORTB.F1 =0x01;
}
if (result = strstr (incoming, "OFF")); // search for string "OFF" in incoming and save it in result
if (memcmp("OFF", result, 3) == 0)
{
PORTB.F0 =0x00;
PORTB.F1 =0x00;
}
}
}
}