Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

interfacing gps and gsm using PIC18f4550

Status
Not open for further replies.

Jushoraj

Member level 1
Joined
May 22, 2012
Messages
34
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Location
Bangalore
Activity points
1,548
I need to interface gps and sim300 using PIC18F4550. Actually i need to send only the latitude and longitude to a mobile number. Can any one help me in this matter. I need the c code.





I have tried this code, but its not working






Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#define FREQ 12000000
#define baud 9600
#define spbrg_value (((FREQ/64)/baud)-1)
unsigned char rx_data();
unsigned char *gps_data;
unsigned char single_data;
unsigned int i=0;
unsigned char *at_cmd="AT";
unsigned char *sms_format="AT+CMGF=1";
unsigned char *sms_write="AT+CMGS=\"+919665479959\"";
unsigned char enter=0x0D;
unsigned char *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);
 
}
}
 
unsigned char rx_data(void)
{
while(PIR1.RCIF==0); // Wait until RCIF gets low
return RCREG; // Store data in Reception register
}
void gsm_cmd(unsigned char *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' key
while(temp!=1);
}
void tx_data(unsigned char 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;
}

 
Last edited by a moderator:

I need the code for sending latitude and longitude from the GSM which has to be received from a GPS module to a mobile number

have you try to write code for your self??
i gave you basic code which you can modify yourself according your application.
 
sending message is ok........ But how to receive and read the data that is coming from GPS to GSM.??
 

sending message is ok........ But how to receive and read the data that is coming from GPS to GSM.??

https://www.edaboard.com/threads/122935/
https://www.edaboard.com/threads/34784/
**broken link removed**

- - - Updated - - -


this code show gps data on lcd
Code:
Program to Interface GPS with PIC18F4550 Microcontroller
#define FREQ 12000000
#define baud 4800
#define spbrg_value (((FREQ/64)/baud)-1)
#define rs LATA.F0
#define rw LATA.F1
#define en LATA.F2
#define lcdport LATB
unsigned char rx_data();
void lcd_ini();
void lcdcmd(unsigned char);
void lcddata(unsigned char);

unsigned char longi_data[12];
unsigned char lati_data[12];
unsigned char data,value=0;
unsigned int i=0,pos;

void main()
{
	TRISB=0;			// Set Port B as output port
	LATB=0;
	TRISA=0;
	LATA=0;
	SPBRG=spbrg_value;		// Fill SPBRG register to set the baud rate
	RCSTA.SPEN=1;			// To activate serial port (Tx and Rx pins)                                    
	RCSTA.CREN=1;			// To enable continuous reception
	lcd_ini();
	while(1)
	{
		data=rx_data();                     // Check the string '$GPGGA,'
		if(data=='$')
		{
			data=rx_data();
			if(data=='G')
			{
				data=rx_data();
				if(data=='P');
				{
					data=rx_data();
					if(data=='G');
					{
						data=rx_data();
						if(data=='G')
						{
						data=rx_data();
						if(data=='A')
						{
						data=rx_data();
						if(data==',')
						{
						data=rx_data();
						while(data!=',')
						data=rx_data();
						for(i=0;data!='N';i++)
						data=rx_data();
						lati_data[i]=data;  // Store the Latitude data
						}
						data=rx_data();
						if(data==',')
						{
						for(i=0;data!='E';i++)
						{
						data=rx_data();
						longi_data[i]=data;  // Store the Longitude data
						}
						}
						i=0;
						lcdcmd(0x80);
						while(i<11)
						{
						lcddata(lati_data[i]);	// Print the Latitude data
						i++;
						}
						i=0;
						lcdcmd(0xC0);
						while(i<12)
						{
						lcddata(longi_data[i]);	  // Print the Longitude data
						i++;
						}
						}
						}
						}
					}
				}
			}
		}
		Delay_ms(1000);
		for(i=0;i<12;i++)
		{
			data=0;
			lati_data[i]=0;
			longi_data[i]=0;
		}
	}
}

unsigned char rx_data(void)
{
	while(PIR1.RCIF==0);		// Wait until RCIF gets low
	return RCREG;			// Store data in Reception register
}

void lcd_ini()
{
	lcdcmd(0x38);		// Configure the LCD in 8-bit mode, 2 line and 5x7 font
	lcdcmd(0x0C);		// Display On and Cursor Off
	lcdcmd(0x01);		// Clear display screen
	lcdcmd(0x06);		// Increment cursor
	lcdcmd(0x80);		// Set cursor position to 1st line, 1st column
}

void lcdcmd(unsigned char cmdout)
{
	lcdport=cmdout;		//Send command to lcdport=PORTB
	rs=0;						
	rw=0;
	en=1;
	Delay_ms(10);
	en=0;
}

void lcddata(unsigned char dataout)
{
	lcdport=dataout;	//Send data to lcdport=PORTB
	rs=1;
	rw=0;
	en=1;
	Delay_ms(10);
	en=0;
}
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top