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.

8051 Gps Serial Data - Acquiring Latitude and Longitude

Status
Not open for further replies.

meetvivekthangam

Newbie level 3
Newbie level 3
Joined
Apr 5, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Visit site
Activity points
1,333
I am Vivek,
I am doing my final year Project.
The objective of my project is to control my boat using a GPS unit. (Automatic Navigation)
I have a GPS Unit that transmits data something similar to
$GPGGA,114948.000,2836.6518,N,07722.0835,E,1,5,3.58,195.9,M,-35.9,M,,*7B
$GPGSA,A,3,14,32,01,12,11,,,,,,,,3.70,3.58,0.92*05
$GPGSV,3,1,10,31,65,191,,22,55,094,,14,47,028,38,11,29,287,27*7B
$GPGSV,3,2,10,01,24,312,39,32,23,313,39,25,20,085,,12,07,053,17*73
$GPGSV,3,3,10,19,07,243,14,30,07,175,20*72
$GPRMC,114948.000,A,2836.6518,N,07722.0835,E,0.28,92.31,020113,,,A*56

From a previous post in this forum i have learnd GPGGA has the latitude and longitude positions. I need only to acquire those two values and ignore all else. I am using a 8051 microprocessor. Please Help me

Thanks in advance
 

#include<reg51.h> //Define 8051 Registers

void serial(void); //Serial Communication Register
void DelayMs(unsigned int); //Delay Function

unsigned int i,j;
unsigned char l[25],m[25],ch;

//---------------------------
// Main Program
//---------------------------
void main()
{
EA=1; //Enable All Interrupt
ES=1; //Enable Serial Port Interrupt
serial(); //Serial Communication
while(1); //Loop Forever
}

//-------------------------------------------
// Serial Communication Register Initialisation
//--------------------------------------------
void serial(void)
{
TMOD=0X20; //Timer1, Mode2
SCON=0X50; //Serial Mode1, Receive Enable
TH1=0XFD; //Baud Rate 9600bps
TR1=1; //Timer1 ON
}





//-----------------------------------------
// Serial Interrupt Function
//-----------------------------------------
void serin (void) interrupt 4 //Serial Port Interrupt
{
if(RI==1) //Receive Interrupt Gets Enabled
{ //after Stop Bit get Received
ch=SBUF; //Serial Buffer value moved to a variable
while(1)
while(1)
{
while(RI==0);
ch=SBUF;
RI=0;
if(ch=='G') //g
{

ch=0;
while(RI==0);
ch=SBUF;
RI=0;
if(ch=='P') //p
{
ch=0;
while(RI==0);
ch=SBUF;
RI=0;
if(ch=='G') //g
{

ch=0;
while(RI==0);
ch=SBUF;
RI=0;
if(ch=='G') //g
{

ch=0;
while(RI==0);
ch=SBUF;
RI=0; //a
if(ch=='A')
{

ch=0;

for(i=0;i<12;i++) //receiving the time(we have skipped it)
{
while(RI==0);
ch=SBUF;
RI=0;
}
for(i=0;i<9;i++) //receiving the latitude
{
while(RI==0);
l=SBUF;

RI=0;
}
l[10]='\0';
for(i=0;i<3;i++) //receiving the indicator(we have skipped it)
{
while(RI==0);
RI=0;
}
for(i=0;i<10;i++) //receiving the longitute
{
while(RI==0);
m=SBUF;
RI=0;
}
}

}

}

}

}
DelayMs(2500); //Delay Function
j++;

}
SCON=0X50;
P2 = l[0]; //Initialising Receive and Transmit Interrupt
}
}

//---------------------------------
// Delay Function
//---------------------------------
void DelayMs(unsigned int k)
{
unsigned int i;
for(i=0;i<=k;i++);
}

This is the program i have written in keil refering some sources in net.
My objective is to obtain the latitude and longitude data in the array l,m
 

You code is totally wrong. I think you need serial receive code right? Do you have to issue any commands to GPRS system?

A sample program to receive data. It doesn't display the result. How do you want to display the result? On LCD?


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
#include<at89x52.h>
#include<string.h>
 
#define FREQ 11.0592 MHZ
 
 
void USART_Init();
void USART_Send(unsigned char *data2send);
void USART_Receive();
 
unsigned char data2rcv[80];
unsigned int idx = 0;
 
//USART Interrupt Routine
 
void receive() interrupt 4
{
    while(RI == 0);
    data2rcv[idx++] = SBUF;
    RI = 0;
}
 
//Function Definitions
//Delay Function
 
void Delay(unsigned int msec)   
{
    int i,j;
    for(i=0;i<msec;i++)
        for(j=0;j<1275;j++);
}
 
//USART Functions
 
void USART_Init()
{
    EA=1;
    TMOD=0x20;
    TH1=0xfd;    //9600 (baud rate)  
    SCON=0x50;   //timer1 mode2
    TR1=1;
    
}
 
void USART_Send(unsigned char *data2send)
{
    while(*data2send){
        SBUF = data2send++;
        while(TI == 0);
        TI = 0;     
    }
}
 
void USART_Receive()
{   
    while(RI == 0);
    data2rcv[idx++] = SBUF;
    RI = 0;
}
 
 
void main()
{
    P1 = 0x00;
    P2 = 0X00;
    P3 = 0x00;             
        
    USART_Init();    
    
    while(1)
    {
        data2rcv[idx] = '\0';
                
 
    }
    
}

 
Last edited:
Sir,
Thank your for your reply. I need to get the lattidude and longitude data and store them in a array sir. My objective is to use them to compare to preset values and then use for automatic navigation sir



You code is totally wrong. I think you need serial receive code right? Do you have to issue any commands to GPRS system?

A sample program to receive data. It doesn't display the result. How do you want to display the result? On LCD?


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
#include<at89x52.h>
#include<string.h>
 
#define FREQ 11.0592 MHZ
 
 
void USART_Init();
void USART_Send(unsigned char *data2send);
void USART_Receive();
 
unsigned char data2rcv[80];
unsigned int idx = 0;
 
//USART Interrupt Routine
 
void receive() interrupt 4
{
    while(RI == 0);
    data2rcv[idx++] = SBUF;
    RI = 0;
}
 
//Function Definitions
//Delay Function
 
void Delay(unsigned int msec)   
{
    int i,j;
    for(i=0;i<msec;i++)
        for(j=0;j<1275;j++);
}
 
//USART Functions
 
void USART_Init()
{
    EA=1;
    TMOD=0x20;
    TH1=0xfd;    //9600 (baud rate)  
    SCON=0x50;   //timer1 mode2
    TR1=1;
    
}
 
void USART_Send(unsigned char *data2send)
{
    while(*data2send){
        SBUF = data2send++;
        while(TI == 0);
        TI = 0;     
    }
}
 
void USART_Receive()
{   
    while(RI == 0);
    data2rcv[idx++] = SBUF;
    RI = 0;
}
 
 
void main()
{
    P1 = 0x00;
    P2 = 0X00;
    P3 = 0x00;             
        
    USART_Init();    
    
    while(1)
    {
        data2rcv[idx] = '\0';
                
 
    }
    
}


- - - Updated - - -

I have used AT89C51 microprocessor sir.
I wrote the below mentioned code and connected GPS to the Micro processor and then MP to LED board sir.
I seem to get some binary values sir.....
I assumed they should be ASCII Values of the data sent by the GPS.
However, they do not resemble the data sent by the GPS as the ASCII values corresponding to data i receive do not have any values of the NMEA FORMAT like G,G,P,G,A etc....


#include<reg51.h> //Define 8051 Registers

void serial(void); //Serial Communication Register
void DelayMs(unsigned int); //Delay Function

unsigned int i,j;
unsigned char b[25],d;

//---------------------------
// Main Program
//---------------------------
void main()
{
EA=1; //Enable All Interrupt
ES=1; //Enable Serial Port Interrupt
serial(); //Serial Communication
while(1); //Loop Forever
}

//-------------------------------------------
// Serial Communication Register Initialisation
//--------------------------------------------
void serial(void)
{
TMOD=0X20; //Timer1, Mode2
SCON=0X50; //Serial Mode1, Receive Enable
TH1=0XFD; //Baud Rate 9600bps
TR1=1; //Timer1 ON
}





//-----------------------------------------
// Serial Interrupt Function
//-----------------------------------------
void serin (void) interrupt 4 //Serial Port Interrupt
{
if(RI==1) //Receive Interrupt Gets Enabled
{ //after Stop Bit get Received
d=SBUF; //Serial Buffer value moved to a variable

P2=d;
DelayMs(30000); //Delay Function
j++;

}
SCON=0X50; //Initialising Receive and Transmit Interrupt
}



//---------------------------------
// Delay Function
//---------------------------------
void DelayMs(unsigned int k)
{
unsigned int i;
for(i=0;i<=k;i++);
}
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top