I am working on tracking project. I want C code for PIC18F4550 which is interfaced with GPS and GSM module.
This PIC has to read data from GPS and send this data to GSM with AT commands for sending SMS.
Please help.
#define FREQ 12000000#define baud 9600#define spbrg_value (((FREQ/64)/baud)-1)unsignedchar rx_data();unsignedchar*gps_data;unsignedchar single_data;unsignedint i=0;unsignedchar*at_cmd="AT";unsignedchar*sms_format="AT+CMGF=1";unsignedchar*sms_write="AT+CMGS=\"+919665479959\"";unsignedchar enter=0x0D;unsignedchar*data;void main(){
TRISB=0;// Set Port B as output port
LATB=0;
TRISA=0;
LATA=0;
SPBRG=spbrg_value;// Fill SPBRG reg to set the baud rate
RCSTA.SPEN=1;// To activate serial port (Tx and Rx pins)
RCSTA.CREN=1;// To enable continuous reception
TXSTA.TXEN=1;// Activate Transmissiom
PIE1.RCIE=1;// Enable Reception interrupt
INTCON.GIE=1;// Enable Global interrupt
INTCON.PEIE=1;// Enable Peripheral interrupt
gsm_cmd(at_cmd);while(1){
single_data=rx_data();// Check the string '$GPGGA,'if(data=='$'){
single_data=rx_data();for(i=0;single_data!='$';i++){
single_data=rx_data();
gps_data[i]=single_data;// Store the data}
gsm_cmd(sms_format);
Delay_ms(1000);
gsm_cmd(sms_write);
Delay_ms(1000);
gsm_cmd(gps_data);
tx_data(0x1A);
Delay_ms(1000);}}unsignedchar rx_data(void){while(PIR1.RCIF==0);// Wait until RCIF gets lowreturn RCREG;// Store data in Reception register}void gsm_cmd(unsignedchar*string){
i=0;j=0;while(string[i]!='\0'){
temp=0;if(string[i]==0x5C)// Not to send '\' cahracter
i++;
tx_data(string[i]);// Send by serial comm.
i++;while(temp!=1);}
temp=0;
tx_data(enter);// Send ASCII code for 'Enter' keywhile(temp!=1);}void tx_data(unsignedchar serial_data)// Transmit data function{
TXREG=serial_data;while(PIR1.TXIF==0);}void interrupt(){
data[j]=RCREG;// Store the data into array when Reception
value=RCREG; interrupt occurs.
j++;
temp=1;}