[CODE]
//ISR Routine
ISR(USART1_RX_vect)
{
inData[index] = UDR1;
index++;
inData[index] = '\0';
}
///////////////////////////////// Reading Value after GPS AT Command.//////////////////
void read_String() {
index=0;
if(index < 199) // One less than the size of the array
{
inChar = USART_Receive(); // Read a character
inData[index] = inChar; // Store it
index++ ; // Increment where to write next
inData[index] = '\0'; // Null terminate the string
}
}
/////////////////////// Splitting into Lat & Long ///////////////////////////////
token = strtok(inData, ",");
//decode string into comma separated values
_delay_ms(100);
strcpy(longitude,strtok(NULL, ",")); // Gets longitude
token = strtok(NULL, ",");
_delay_ms(100);
//sendstring_softuart("LONGITUDE= ");
sendstring_softuart(longitude);
_delay_ms(200);
strcpy(latitude,strtok(NULL, ",")); // Gets latitude
token = strtok(NULL, ",");
_delay_ms(100);
// sendstring_softuart("& LATITUDE= ");
sendstring_softuart("\r\n");
sendstring_softuart(latitude);
//ISR Routine
ISR(USART1_RX_vect)
{
inData[index] = UDR1;
index++;
inData[index] = '\0';
}
///////////////////////////////// Reading Value after GPS AT Command.//////////////////
void read_String() {
index=0;
if(index < 199) // One less than the size of the array
{
inChar = USART_Receive(); // Read a character
inData[index] = inChar; // Store it
index++ ; // Increment where to write next
inData[index] = '\0'; // Null terminate the string
}
}
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 unsigned char msg[] = {'0', ',', '7', '7', '3', '9', '.', '1', '4', '4', '6', '6', '3', ',', '1', '2', '5', '8', '.', '0', '6', '1', '2', '4', '8', ',', '8', '2', '7', '.', '0', '6', '1', '5', '8', '4', ',', '2', '0', '1', '3', '0', '9', '1', '9', '1', '3', '3', '2', '4', '8', '.', '3', '0', '7', ',', '4', ',', '1', '1', ',', '0', '.', '0', '0', '0', '0', '0', '0', ',', '0', '.', '0', '0', '0', '0', '0', '0', ',' }; unsigned char myData[18]; void PORT_Init(){ TRISA = 0xC1; PORTA = 0x00; TRISB = 0x00; PORTB = 0x00; TRISC = 0x80; PORTC = 0x00; TRISD = 0x00; PORTD = 0x00; TRISE = 0x00; PORTE = 0x00; ADCON1 = 0x8E; CMCON = 0x07; CVRCON = 0x00; } void extractData(){ unsigned int i = 0, j = 0, gotData = 0; if(msg[0] == '0'){ i = j = 0; getNext: while(msg[i] != ',')i++; ++i; ++gotData; j = 0; while(msg[i] != ','){ myData[j] = msg[i]; ++i; ++j; } myData[j] = '\0'; UART1_Write_Text(myData); UART1_Write(13); UART1_Write(10); if(gotData < 8)goto getNext } } void main(){ PORT_Init(); UART1_Init(9600); Delay_ms(200); while(1){ extractData(); Delay_ms(5000); } }
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 void extractData(){ unsigned int i = 0, j = 0, gotData = 0; if(msg[0] == '0'){ i = j = 0; do{ while(msg[i] != ',')i++; ++i; ++gotData; j = 0; while(msg[i] != ','){ myData[j] = msg[i]; ++i; ++j; } myData[j] = '\0'; }while(gotData < 8); } }
Code C - [expand] 1 volatile unsigned char inData[80]= "";
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?