Sunteți pe pagina 1din 3

#include <hidef.h> /* for EnableInterrupts macro */ #include "derivative.h" /* include peripheral declarations */ #include "funes.

h" #ifdef __cplusplus extern "C" #endif void MCU_init(void); /* Device initialization function declaration */ void main(void) { byte dadoRecebido; MCU_init(); /* call Device Initialization */ zerastr(datagps); while(1){ //loop infinito

/* include your code here */ dadoRecebido = ReadSCI2(); //Rx da serial 2 o pino 38 WriteSCI1(teste); //envia pelo Tx da serial 1 Getlatlng((char)dadoRecebido);

// //

} for(;;) { /* __RESET_WATCHDOG(); by default, COP is disabled with device init. When en abling, also reset the watchdog. */ } /* loop forever */ /* please make sure that you never leave main */ } unsigned char lat[11],lng[12],datagps[15][12]; //declarar no inicio do programa //funo para zerar string void zerastr(unsigned char **datagps) { unsigned int tam; for(tam = 0; tam < 16; tam++) { strcpy( datagps[tam], "" ); } } /* Funo que extrai latitude e longitude de uma mensagem NMEA da porta serial */ void Getlatlng(unsigned char data) { unsigned int i,j,k; // unsigned char data; start:

j=0; k=0; zerastr(datagps); //while (!(Usart_Data_Ready()) ) ; data = fgetc(COM_B); // Teste do Receive data COM_Blado //delay_ms(2); if(data == '$') { // while (!(Usart_Data_Ready()) ) ; data = fgetc(COM_B); // Teste do Receive data emulado if(data == 'G') { // fputc(data,COM_A); //while (!(Usart_Data_Ready()) ) ; data = fgetc(COM_B); // Receive data if(data == 'P') { //while (!(Usart_Data_Ready()) ) ; data = fgetc(COM_B); // Receive data if(data == 'G') { //while (!(Usart_Data_Ready()) ) ; data = fgetc(COM_B); // Receive data if(data == 'G') { //while (!(Usart_Data_Ready()) ) ; data = fgetc(COM_B); // Receive data if(data == 'A') { zerastr(datagps); do { // while (!(Usart_Data_Ready()) ) ; data = fgetc(COM_B); if(data==',') { // fputc('x',COM_A); datagps[j][k] = '\0'; j++; k=0 ; } else { datagps[j][k] = data; k++; } }while(data!='\r'); else { goto start;} else { goto start;} } else { goto start;} } else { goto start;} } else { goto start;} } else { goto start; } } /* fprintf(COM_A,"%s",datagps[0]); novalinha(); fprintf(COM_A,"%s",datagps[1]); novalinha(); fprintf(COM_A,"%s",datagps[2]); novalinha(); fprintf(COM_A,"%s",datagps[3]); novalinha(); fprintf(COM_A,"%s",datagps[4]); novalinha(); fprintf(COM_A,"%s",datagps[5]); novalinha(); fprintf(COM_A,"%s",datagps[6]);novalinha();*/ strcpy(lat,datagps[1]); //copio 2 string com latitude strcat(lat,datagps[2]); //adiciono no final 'N' ou 'S' strcpy(lng,datagps[3]); strcat(lng,datagps[4]); //copio a 4 string com longitude //adiciono no final 'E' ou 'W' }

for ( int count = 0 ; count < 11 ; count++){ printf("Latitude: %c",lat[count]); } printf("\n"); for ( int count1 = 0 ; count1 < 12 ; count1++){ printf("Longitude: %c",lng[count1]); } }

S-ar putea să vă placă și