EXP.6: GPS Module Interfacing with LPC2148 Development Board.
CODE
#include <lpc214x.h>
// Define Clock settings
#define PCLK 15000000
#define BAUDRATE 9600 // Set Baud Rate here
void delay(unsigned int time)
{
unsigned int i, j;
for (j = 0; j < time; j++)
{
for (i = 0; i < 8000; i++);
}
}
void InitUART(void)
{
unsigned int Baud16;
U0LCR = 0x83;
Baud16 = (PCLK / (16 * BAUDRATE));
U0DLM = Baud16 >> 8;
U0DLL = Baud16;
U0LCR = 0x03;
}
// Function to Transmit a character
void SendByte(unsigned char data)
{
U0THR = data;
while ((U0LSR & 0x40) == 0);
}
// Function to Receive a character
unsigned char ReceivedByte()
{
while ((U0LSR & 0x01) == 0);
return U0RBR;
}
// Function to Transmit a string
void SendString(const unsigned char *str)
{
while (*str != '\0')
{
SendByte(*str++);
}
}
int main(void)
{
unsigned char string1[] = "GPGGA";
unsigned char i, flag = 0;
unsigned char cmd_data[5], time_data[15], latitude[15], longitude[15];
PINSEL0 = 0x00000005; // Enable UART0 Rx and Tx pins
InitUART();
delay(1000);
while (1)
{
if (ReceivedByte() == '$') // Start of GPS Sentence
{
for (i = 0; i < 5; i++)
{
flag = 0;
cmd_data[i] = ReceivedByte(); // Receive GPS sentence type
if (cmd_data[i] != string1[i]) // Verify GPS sentence with GPGGA
{
flag = 1;
break;
}
}
if (flag == 0)
{
for (i = 0; i < 12; i++)
{
time_data[i] = ReceivedByte(); // Receive the Time
}
time_data[12] = '\0';
for (i = 0; i < 12; i++)
{
latitude[i] = ReceivedByte(); // Receive the Latitude
}
latitude[11] = '\0';
for (i = 0; i < 12; i++)
{
longitude[i] = ReceivedByte(); // Receive the Longitude
}
longitude[12] = '\0';
}
}
}
return 0;
}

Comments
Post a Comment