//Memory Card Chip Select Connection
sfr sbit Mmc_Chip_Select at RC2_bit;
sfr sbit Mmc_Chip_Select_Direction at TRISC2_bit;
// LCD module connections
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;
sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;
// End LCD module connections
char txt5[] = "GPS with PIC877A";
char txt6[] = "F.M.S.";
// "$xxxxx,xxxxxxxxx,xxxx.xxx,x,xxxxx.xxx,x,x,xx,x.x,xxx.x,x,xx.x,x,,*xx"; GPGGA
int i = 0;
int received = 0;
char DataType[] = "GPXXX";
char NMEA[] = "$xxxxx,xxxxxx.xx,x,xxxx.xx,x,xxxxx,x,x.x,x.x,xxxxxx,x.x,x*xx";
char receive;
unsigned char filename[] = "Temp.TXT";
unsigned char error;
void main()
{
while(1)
{
TRISD = 0x00;
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,txt5); // Write text in first row
Lcd_Out(2,6,txt6); //displays txt5
Delay_ms(1000); //displays txt6
Lcd_Cmd(_LCD_CLEAR); // Clear display
Delay_ms(250);
UART1_Init(9600); // Initialize UART for GPS board connectivity
SPI1_Init();
SPI1_Init_Advanced(_SPI_MASTER_OSC_DIV64, _SPI_DATA_SAMPLE_MIDDLE, _SPI_CLK_IDLE_LOW, _SPI_LOW_2_HIGH);
Delay_us(10);
Delay_mS(100);
Lcd_Cmd(_LCD_CLEAR);
while(1)
{
if (UART1_Data_Ready() == 1)
{
receive = UART1_Read();
if (receive == '$') // Check if sentence begins.
{
received = 0;
do
{
if (UART1_Data_Ready() == 1)
{
UART1_Read_Text(DataType, ",", 10); // Capture GPXXX word
received = 1;
}
}
while(received == 0);
// If it is GPRMC Data, then acquire it.
if ((DataType[2] == 'R') && (DataType[3] == 'M') && (DataType[4] == 'C'))
{
received = 0;
do
{
if (UART1_Data_Ready() == 1)
{
UART1_Read_Text(NMEA, "*", 100); // Stop at *XX checksum data
received = 1;
}
}
while(received == 0);
Lcd_Cmd(_LCD_CLEAR);
// Latitude
LCD_Out(1,1, "La:");
LCD_Chr(1, 5, NMEA[13]);
LCD_Chr(1, 6, NMEA[14]);
LCD_Chr(1, 7, 223);
LCD_Chr(1, 8, NMEA[15]);
LCD_Chr(1, 9, NMEA[16]);
LCD_Chr(1, 10, NMEA[17]);
LCD_Chr(1, 11, NMEA[18]);
LCD_Chr(1, 12, NMEA[19]);
LCD_Chr(1, 13, NMEA[20]);
LCD_Chr(1, 14, NMEA[21]);
LCD_Chr(1, 16, NMEA[23]);
// Longitude
LCD_Out(2,1, "Lo:");
LCD_Chr(2, 5, NMEA[25]);
LCD_Chr(2, 6, NMEA[26]);
LCD_Chr(2, 7, 223);
LCD_Chr(2, 8, NMEA[27]);
LCD_Chr(2, 9, NMEA[28]);
LCD_Chr(2, 10, NMEA[29]);
LCD_Chr(2, 11, NMEA[30]);
LCD_Chr(2, 12, NMEA[31]);
LCD_Chr(2, 13, NMEA[32]);
LCD_Chr(2, 14, NMEA[33]);
LCD_Chr(2, 15, NMEA[34]);
LCD_Chr(2, 16, NMEA[36]);
Delay_Ms(1000);
Lcd_Cmd(_LCD_CLEAR);
//DATA
Lcd_Out(1,1,"Data:");
LCD_Chr(1, 7, NMEA[50]);
LCD_Chr(1, 8, NMEA[51]);
LCD_Chr(1, 9, '/');
LCD_Chr(1, 10, NMEA[52]);
LCD_Chr(1, 11, NMEA[53]);
LCD_Chr(1, 12, '/');
LCD_Chr(1, 13, NMEA[54]);
LCD_Chr(1, 14, NMEA[55]);
//ORA
Lcd_Out(2,1,"Ora:");
LCD_Chr(2, 6, NMEA[0]);
LCD_Chr(2, 7, NMEA[1]);
LCD_Chr(2, 8, ':');
LCD_Chr(2, 9, NMEA[2]);
LCD_Chr(2, 10, NMEA[3]);
LCD_Chr(2, 11, ':');
LCD_Chr(2, 12, NMEA[4]);
LCD_Chr(2, 13, NMEA[5]);
Delay_Ms(1000);
Lcd_Cmd(_LCD_CLEAR);
}
receive = "x";
}
}
}
}
}