truth_seeker
Member level 1
at commands in c
Hello all ,
my graduation project has a part where PIC microcontroller should be connected to a mobile phone , which will use the GPRS service to send the received data from the microcontroller
here is a code to send the needed AT Commands to the mobile phone to open the GPRS connection..it has no errors ..but still no response from the mobile , and the G sign which indicates that GPRS is activated doesn't appear on the mobile screen.
I use PIC 18F4550 , nokia 6610i mobile phone , and I used a zener diode instead of max232 between the microcontroller and the mobile phone.
Please tell me if there is anything wrong with this code...
is this the right way to send the AT Commands using C language , or there is another way???
note: on hyper terminal ..the command ..AT+CGDCONT=1,IP,INTERNET ..is written ..AT+CGDCONT=1,"IP","INTERNET"..but the compiler gives an error when I write it this way using C language..why?? is it maybe the problem??
Thanks a lot :|
[/code]
Hello all ,
my graduation project has a part where PIC microcontroller should be connected to a mobile phone , which will use the GPRS service to send the received data from the microcontroller
here is a code to send the needed AT Commands to the mobile phone to open the GPRS connection..it has no errors ..but still no response from the mobile , and the G sign which indicates that GPRS is activated doesn't appear on the mobile screen.
I use PIC 18F4550 , nokia 6610i mobile phone , and I used a zener diode instead of max232 between the microcontroller and the mobile phone.
Code:
#include <string.h>
#include <p18f4550.h>
#include<portb.h>
#include<usart.h>
#include<delays.h>
#define false 0
#define true 1
#define maxsize 10
int i;
char COMMAND[5] = {"AT","AT+CGATT=1","AT+CGDCONT=1,IP,INTERNET", "AT+CGACT=1,1","ATD*99#"};
char RESPONSES[5] = {"OK","OK","OK","OK","CONNECT"};
char tmpdata; // Used in receive function
int READY = false ;
int FLAG = true ;
void receive(int j);
void send(int k);
void initialize (void) ;
void main(void)
{
TRISD=0;
TRISCbits.TRISC6 =0;
TRISCbits.TRISC7 =1;
TRISAbits.TRISA4 =0;
//configures Usart with boud rate 9600 ? (4*9600)/ 2400000 -1=624
OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF & USART_SYNCH_MODE & USART_EIGHT_BIT & USART_CONT_RX & USART_BRGH_LOW,624);
PORTAbits.RA4= 1;
for (i=0;i<=4;++i)
{
send (i);
if(i==4) receive(7);
else receive(2);
while(FLAG)
{
if (strcmp(tmpdata,RESPONSES[i]))
{
if (i==0)PORTDbits.RD0= 1; // ok
if (i==1)PORTDbits.RD1= 1;
if (i==2)PORTDbits.RD2= 1;
if (i==3)PORTDbits.RD3= 1;
if (i==4)PORTDbits.RD4= 1;
Delay10TCYx( 5 );
READY = 1;
FLAG = false;
}
else
{
if (i==0)PORTDbits.RD0= 0; //error
if (i==1)PORTDbits.RD1= 0;
if (i==2)PORTDbits.RD2= 0;
if (i==3)PORTDbits.RD3= 0;
if (i==4)PORTDbits.RD4= 0;
Delay10TCYx( 5 );
send(i);
if(i==4) receive(7);
else receive(2);
}
}
if (READY == 1)
{
FLAG = true;
}
}
}
void receive( int j)
{
if( DataRdyUSART( ))
getsUSART(tmpdata,j); //read data ;
}
void send ( int k)
{
putsUSART(COMMAND[i]);
while(BusyUSART());
}
Please tell me if there is anything wrong with this code...
is this the right way to send the AT Commands using C language , or there is another way???
note: on hyper terminal ..the command ..AT+CGDCONT=1,IP,INTERNET ..is written ..AT+CGDCONT=1,"IP","INTERNET"..but the compiler gives an error when I write it this way using C language..why?? is it maybe the problem??
Thanks a lot :|
[/code]