Wednesday, 25 July 2012
Example coding to know the response from GSM Modem.
#include <pic.h>
#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;
}
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment