You are on page 1of 3

I am using PIC18F4550 for interfacing with GSM SIM 900.

i have cheked it via hyp


erterminal at baud rate of 9600 and the gsm work perfectly, but when now at the
controller it dosn't give the expected results. The c code written in mp lab is
given. please help me with this, why isn't it working.

#include<p18f4550.h>
#include<delays.h>
#
#
#
#
#
#

pragma
pragma
pragma
pragma
pragma
pragma

config
config
config
config
config
config

WDT=OFF
LVP=OFF
FOSC=HS
IESO=OFF
MCLRE=ON
PBADEN=OFF

unsigned char value=0;


int i=0, k=0,j=0;
unsigned
unsigned
unsigned
unsigned
unsigned
unsigned

char
char
char
char
char
char

*at_cmd="AT";
*sms_format="AT+CMGF=1";
*sms_write="AT+CMGS=\"03006464297\"";
*sms="Hello";
enter=0x0D;
*data;

#define FREQ 11059200


#define baud 9600
#define spbrg_value (((FREQ/64)/baud)-1)
unsigned char rx_data(void);
void tx_data(unsigned char serial_data)
void gsm_cmd(unsigned char *);
int check(unsigned char *);

void main()
{
TRISB=0;
LATB=0;
TRISC=0xC0;

//BAUDCONbits.WUE=1;
TXSTAbits.SYNC=0;
BAUDCONbits.BRG16=0;
SPBRG=spbrg_value;

// Fill SPBRG register to set the baud rate

INTCONbits.GIE=1;
INTCONbits.PEIE=1;

RCSTAbits.SPEN=1;

// Enable Global interrupt


// Enable Peripheral interrupt

// To activate serial port (Tx and Rx pins

)
PIE1bits.RCIE=1;
RCSTAbits.RX9=0;
RCSTAbits.CREN=1;

PIE1bits.TXIE=1;
PIE1bits.RCIE=1;
TXSTAbits.TX9=0;
TXSTAbits.TXEN=1;
RCSTAbits.RX9=1;
while (1)
{
{
PORTBbits.RB0=1;
gsm_cmd(at_cmd);
Delay10TCYx(500);
i=0;
while(i<2)
{
data[i]=rx_data();
i++;
}
if (check(data))
{
PORTBbits.RB1=1;
gsm_cmd(sms_format);
Delay10TCYx(500);
i=0;
while(i<2)
{
data[i]=rx_data();
i++;
}
if (check(data))
{
PORTBbits.RB2=1;
gsm_cmd(sms_write);
Delay10TCYx(500);
PORTBbits.RB3=1;
gsm_cmd(sms);

// Enable Reception interrupt


// Activate Reception

// Activate Transmissiom

tx_data(0x1A);
Delay10TCYx(500);

}
}
}
}
}

unsigned char rx_data(void)


{
while(PIR1bits.RCIF==0);
low
return RCREG;
ion register
}
void tx_data(unsigned char serial_data)
{
TXREG=serial_data;
while(PIR1bits.TXIF==0);
}
void gsm_cmd(unsigned char *string)
{
i=0,j=0;
while(string[i]!='\0')
{
tx_data(string[i]);
i++;
}
tx_data(enter);
}

int check(unsigned char *string)


{
int i=0;
if(string[i]=='O')
{
i++;
if(string[i]=='K')
{return 1;
}
else
return 0;
}
else
return 0;
}

// Wait until RCIF gets


// Retrieve data from recept

// Transmit data function

You might also like