aboveall
Newbie level 2
Hi guys,
I am currently working with a PIC 18F46k22 and inputing a NMEA data using a Garmin GPS and trying to get a output reading though hyperterminal. I am using the pic to decode and output the string of data nicely to Lat and long.
I previously use the p18f4431. Any idea how to convert it using a PIC 18F46k22? I now face some build errors.
#include <p18f4431.h>
#include <delays.h>
#include <usart.h>
#define MAXSIZE 50
void InitializeUSART()
{
TXSTA = 0x20;
RCSTA = 0x90;
SPBRG = 25; //baud rate declaration
TXSTAbits.TXEN = 1;
RCSTAbits.SPEN = 1;
}
void main()
{
unsigned char gps[MAXSIZE];
char time[9];
char lat[14];
char lon[15];
char sat[3];
int i;
TRISCbits.TRISC6 = 0; //SERIALB PORT DECLARATION
TRISCbits.TRISC7 = 1;
while(1)
{
InitializeUSART(); //usart serial port initialisation
i=0;
while(PIR1bits.RCIF == 0); //interrupt due to eusart
gps = RCREG; //register RCREG
if(gps =='$') //gps output is ‘$’
{
for(i=1; i<44; i++)
{
while(PIR1bits.RCIF == 0); //interrupt flag is zero
gps = RCREG; serial port input = lcd output
}
gps[i+1] = '\0';
time[0] = gps[7];
time[1] = gps[8];
time[2] = 58;
time[3] = gps[9];
time[4] = gps[10];
time[5] = 58;
time[6] = gps[11];
time[7] = gps[12];
time[8] = 0;
lat[0] = gps[14];
lat[1] = gps[15];
lat[2] = 248;
lat[3] = 32;
lat[4] = gps[16];
lat[5] = gps[17];
lat[6] = gps[18];
lat[7] = gps[19];
lat[8] = gps[20];
lat[9] = gps[21];
lat[10] = gps[22];
lat[11] = 39;
lat[12] = gps[24];
lat[13] = 0;
lon[0] = gps[26];
lon[1] = gps[27];
lon[2] = gps[28];
lon[3] = 248;
lon[4] = 32;
lon[5] = gps[29];
lon[6] = gps[30];
lon[7] = gps[31];
lon[8] = gps[32];
lon[9] = gps[33];
lon[10] = gps[34];
lon[11] = gps[35];
lon[12] = 39;
lon[13] = gps[37];
lon[14] = 0;
sat[0] = gps[41];
sat[1] = gps[42];
sat[2] = 0;
while(PIR1bits.TXIF ==0); //usart serial transmit flag =0
putrsUSART("Time:"); //change to putc2USART
while(PIR1bits.TXIF ==0);
putsUSART(time);
while(PIR1bits.TXIF ==0);
putrsUSART("UTC");
while(PIR1bits.TXIF ==0);
putrsUSART("\tLat:");
while(PIR1bits.TXIF ==0);
putsUSART(lat);
while(PIR1bits.TXIF ==0);
putrsUSART("\tLon:");
while(PIR1bits.TXIF ==0);
putsUSART(lon);
while(PIR1bits.TXIF ==0);
putrsUSART("\tSat:");
while(PIR1bits.TXIF ==0);
putsUSART(sat);
while(PIR1bits.TXIF ==0);
putrsUSART("\n\r");
CloseUSART();
}
}
}
I am currently working with a PIC 18F46k22 and inputing a NMEA data using a Garmin GPS and trying to get a output reading though hyperterminal. I am using the pic to decode and output the string of data nicely to Lat and long.
I previously use the p18f4431. Any idea how to convert it using a PIC 18F46k22? I now face some build errors.
#include <p18f4431.h>
#include <delays.h>
#include <usart.h>
#define MAXSIZE 50
void InitializeUSART()
{
TXSTA = 0x20;
RCSTA = 0x90;
SPBRG = 25; //baud rate declaration
TXSTAbits.TXEN = 1;
RCSTAbits.SPEN = 1;
}
void main()
{
unsigned char gps[MAXSIZE];
char time[9];
char lat[14];
char lon[15];
char sat[3];
int i;
TRISCbits.TRISC6 = 0; //SERIALB PORT DECLARATION
TRISCbits.TRISC7 = 1;
while(1)
{
InitializeUSART(); //usart serial port initialisation
i=0;
while(PIR1bits.RCIF == 0); //interrupt due to eusart
gps = RCREG; //register RCREG
if(gps =='$') //gps output is ‘$’
{
for(i=1; i<44; i++)
{
while(PIR1bits.RCIF == 0); //interrupt flag is zero
gps = RCREG; serial port input = lcd output
}
gps[i+1] = '\0';
time[0] = gps[7];
time[1] = gps[8];
time[2] = 58;
time[3] = gps[9];
time[4] = gps[10];
time[5] = 58;
time[6] = gps[11];
time[7] = gps[12];
time[8] = 0;
lat[0] = gps[14];
lat[1] = gps[15];
lat[2] = 248;
lat[3] = 32;
lat[4] = gps[16];
lat[5] = gps[17];
lat[6] = gps[18];
lat[7] = gps[19];
lat[8] = gps[20];
lat[9] = gps[21];
lat[10] = gps[22];
lat[11] = 39;
lat[12] = gps[24];
lat[13] = 0;
lon[0] = gps[26];
lon[1] = gps[27];
lon[2] = gps[28];
lon[3] = 248;
lon[4] = 32;
lon[5] = gps[29];
lon[6] = gps[30];
lon[7] = gps[31];
lon[8] = gps[32];
lon[9] = gps[33];
lon[10] = gps[34];
lon[11] = gps[35];
lon[12] = 39;
lon[13] = gps[37];
lon[14] = 0;
sat[0] = gps[41];
sat[1] = gps[42];
sat[2] = 0;
while(PIR1bits.TXIF ==0); //usart serial transmit flag =0
putrsUSART("Time:"); //change to putc2USART
while(PIR1bits.TXIF ==0);
putsUSART(time);
while(PIR1bits.TXIF ==0);
putrsUSART("UTC");
while(PIR1bits.TXIF ==0);
putrsUSART("\tLat:");
while(PIR1bits.TXIF ==0);
putsUSART(lat);
while(PIR1bits.TXIF ==0);
putrsUSART("\tLon:");
while(PIR1bits.TXIF ==0);
putsUSART(lon);
while(PIR1bits.TXIF ==0);
putrsUSART("\tSat:");
while(PIR1bits.TXIF ==0);
putsUSART(sat);
while(PIR1bits.TXIF ==0);
putrsUSART("\n\r");
CloseUSART();
}
}
}