hi
this the code
////////////
#include "C:\Users\student\Desktop\gps\gps.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7,stream = xbee,errors) // xbee serial
#use rs232(baud=9600, xmit=PIN_C0,rcv=PIN_C1,stream = gps,errors) // gps serial
char comandoGPR[7] = "$GPRMC";
int i;
char linea[75] = "";
int bien=0;
int indices[13];
int cont=0;
int j;
int conta=0;
int byteGPS=-1;
void main()
{
setup_adc_ports(ALL_ANALOG);
setup_adc(ADC_CLOCK_INTERNAL);
setup_psp(PSP_DISABLED);
setup_counters(RTCC_INTERNAL,RTCC_DIV_1);
setup_timer_1(T1_DISABLED);
setup_timer_2(T2_DIV_BY_1,0,1);
// byteGPS=Serial.read(); // Read a byte of the serial port
// if (byteGPS == -1) { // See if the port is empty yet
// delay(100);
// } else {
// if(kbhit(gps)==true)
//{
while(1)
{
if(kbhit(gps))
{
byteGPS = fgetc(gps);
// if (byteGPS == -1) { // See if the port is empty yet
// delay_ms(100);
// } else {
fprintf(xbee,"jjff ");
linea[conta]=byteGPS; // If there is serial port data, it is put in the buffer
conta++;
// fprintf(byteGPS, BYTE);
fprintf(xbee,"%u",byteGPS);
//}
if (byteGPS==13){ // If the received byte is = to 13, end of transmission
// digitalWrite(ledPin, LOW);
cont=0;
bien=0;
for (i=1;i<7;i++){ // Verifies if the received command starts with $GPR
if (linea[i-1]==comandoGPR[i-1]){
bien++;
}
}
if(bien==6){ // If yes, continue and process the data
for (i=0;i<75;i++){
if (linea==','){ // check for the position of the "," separator
indices[cont]=i;
cont++;
}
if (linea=='*'){ // ... and the "*"
indices[12]=i;
cont++;
}
}
fprintf(xbee,"/r"); // ... and write to the serial port
fprintf(xbee,"/r");
fprintf(xbee,"---------------/r");
for (i=0;i<12;i++){
switch(i){
case 0 :fprintf(xbee,"Time in UTC (HhMmSs): ");break;
case 1 :fprintf(xbee,"Status (A=OK,V=KO): ");break;
case 2 :fprintf(xbee,"Latitude: ");break;
case 3 :fprintf(xbee,"Direction (N/S): ");break;
case 4 :fprintf(xbee,"Longitude: ");break;
case 5 :fprintf(xbee,"Direction (E/W): ");break;
case 6 :fprintf(xbee,"Velocity in knots: ");break;
case 7 :fprintf(xbee,"Heading in degrees: ");break;
case 8 :fprintf(xbee,"Date UTC (DdMmAa): ");break;
case 9 :fprintf(xbee,"Magnetic degrees: ");break;
case 10 :fprintf(xbee,"(E/W): ");break;
case 11 :fprintf(xbee,"Mode: ");break;
case 12 :fprintf(xbee,"Checksum: ");break;
}
for (j=indices;j<(indices[i+1]-1);j++){
fprintf(xbee,"%c",linea[j+1]);
}
fprintf(xbee,"/r");
}
fprintf(xbee,"---------------/r");
}
conta=0; // Reset the buffer
for (i=0;i<75;i++){ //
linea=' ';
}
}
}
}
}
////////////
regards,