#include<lpc214x.h>
#include "stdio.h"
#include "lcd.h"
#include "uart.h"
/* This function fetches a string from the serial port using UART_GetChar() function
** In case of GPS, the co-ordinate string starts with a character '$'
** And ends with a character '*' followed by CRC
*/
void GPS_string(unsigned char *temp)
{
unsigned int i=0;
do
{
temp[i] = uart0_receive();
}
while(temp[i++] != '*'); //while '*' character is not received, keep fetching the string
temp[i] = '\0'; //add a NULL character at the end of the string
}
/* This function takes the latitude and longitude string pointers as the input parameters
** And displays them on the LCD in a proper fashion
*/
void GPS_display(unsigned char *lat, unsigned char *lon)
{
unsigned int i;
LCD_cmd(0x84); //cursor on 1st line 5th position
for(i=0;i<2;i++)
LCD_data(*lat++); //display degrees
LCD_data('\''); //degree symbol
for(i=0;i<8;i++) //display rest of the string
LCD_data(*lat++);
LCD_cmd(0xC4); //cursor on 2nd line 5th position
for(i=0;i<3;i++)
LCD_data(*lon++); //display degrees
LCD_data('\''); //degree icon
for(i=0;i<8;i++) //display rest of the string
LCD_data(*lon++);
}
/* In the main function, we will continuously keep checking the serial port for character '$'
** If the character '$' is received, fetch all the characters between '$' and '*'
** Extract the latitude and longitude details from the string and display it on the LCD
** Eg: $GPGGA,155635,3730.4379,N,02357.4137,E,1,04,5.6,3.8,M,34.5,M,,*41
*/
int main()
{
unsigned char ch, temp[20],lat[10],lon[10];
unsigned int i=0,j=0;
PINSEL0=0x00000005;
LCD_init();
UartInit(9600);
LCD_display(1,1,"GPS Program");
delay();
LCD_cmd(0x01); //Clear Display
LCD_display(1,1,"LAT:");
LCD_display(2,1,"LON:");
while(1)
{
if((ch = uart0_receive()) == '$') //if '$' is received
{
GPS_string(temp); //fetch all characters upto '*'
if(temp[2] == 'G' && temp[3] == 'G' && temp[4] == 'A')
{
i=0;
j=0;
while(temp[i++] != ','); //$GPGGA (ignore)
while(temp[i++] != ','); //Time Stamp (ignore)
while(temp[i] != ',') //Capture Latitude
lat[j++] = temp[i++];
while(temp[i++] != ','); //North/South
lat[j++] = temp[i++];
j=0;
while(temp[i++] != ',');
while(temp[i] != ',') //Capture Longitude
lon[j++] = temp[i++];
while(temp[i++] != ','); //East/West
lon[j++] = temp[i++];
//(ignore the rest part of the string)
GPS_display(lat,lon); //display latitude and longitude on the LCD
}
}
}
return 0;
}
Tuesday, 20 March 2018
GPS-LPC2148
Subscribe to:
Post Comments (Atom)
PIC Course with IIT Bombay
Embedded Lab Course with PIC18F4550 by IIT Bombay 2017-18 Overview: Below course was conducted as an outreach initiative of Wadhwani Elect...
-
The APB divider determines the relationship between the processor clock (CCLK) and the clock used by peripheral devices (PCLK). The APB di...
-
The pin connect block allows selected pins of the microcontroller to have more than one function. Configuration registers control the mult...
-
Interrupt controller The Vectored Interrupt Controller (VIC) accepts all of the interrupt request inputs and categorizes them as Fast Inte...
No comments:
Post a Comment