#include <pic.h>
#device adc=8
#use delay (clock=20000000)
#fuses hs,nolvp,nowdt,noprotect,nobrownout
#use rs232(baud=9600, bits=8, xmit=pin_C6, rcv=pin_C7, parity=n, stream=GSM)
#byte porta=5
#byte portb=6
#byte portc=7
#include "flex_lcd.c"
volatile int counter_search=0; //counter to traverse the array
volatile int counter_read=0; //counter to fill the array
volatile Char Recieve_String[70]; //buffer for incoming data
int GET_OK(int Stop_Search); // Just searches for an OK.
int TEST_AT();
void main()
{
SET_TRIS_A( 0x00 ); // to avoid floating pins
SET_TRIS_B( 0x00 );
OUTPUT_B(0X00);
SET_TRIS_C( 0x80 );
enable_interrupts(INT_RDA); // enable RDA interrupts
enable_interrupts(GLOBAL); // enable global ints
delay_ms(500);
lcd_init();
lcd_gotoxy(3,1);
lcd_putc("GET RESPONSE");
delay_ms(1000);
delay_ms(1000);
TEST_AT();
}
int TEST_AT()
{
counter_read=0;
lcd_gotoxy(8,2);
lcd_putc("AT");
printf("AT\n\r"); //send command
While(counter_read<=8) //"A T \R \R \N O K \R \N" characters returned by modem
{
}
counter_read=0;
Delay_ms(500);
if(GET_OK(0X0A))
{ lcd_gotoxy(8,2);
lcd_putc("OK");
Return(1); }
else return(0);
}
int GET_OK(Stop_Search)
{
counter_search=0;
while((Recieve_String[counter_search]!='O')&&(counter_search<Stop_Search))
{
counter_search++; //obvious
}
if((Recieve_String[counter_search]=='O')&&(Recieve_String[counter_search+1]=='K'))
{
counter_search=0;
Return(1);
}
Return(0);
counter_search=0;
}
#int_RDA
void RDA_isr()
{
Recieve_String[counter_read]=getchar(GSM);
counter_read++;
if(counter_read==69)counter_read=0;
}
This program code have some problem, where the #int_RDA can't work properly. The interrupts can be recall and the response get stuck.