我正在開發一個gps代碼,它從gps獲取原始數據並解碼數據並將其保存到受尊重的變量(數組)中。每當我進行函數調用時,它都會執行直到函數結尾的函數語句,即「}」,然後控制進入一些未指定的存儲單元,並將控制權交給主函數。
它爲什麼會發生?沒有使用微控制器,代碼在編譯器中工作正常,爲什麼?有什麼步驟需要注意微控制器寄存器嗎?在程序中進行函數調用後,控制跳轉到未指定的內存位置
void gps_Gpgga_data_pro_funct(void)
{
int loop1 , loop2 , loop3 ;
unsigned char commapos = 0; //to hold the comma position
unsigned char tempbuff[100]; //temparary buffer
str_cpy(tempbuff,aa_GPS_GPGGA_RxBuffer); //received data taking into tempbuff
if(tempbuff[3] == 'G' && tempbuff[4] == 'G' && tempbuff[5] == 'A')
{
loop1 = 0;
loop2 = 7;
while(tempbuff[loop2] != COMMA) //getting the time
{
gga_time[loop1] = tempbuff[loop2];
loop1 ++;
loop2 ++;
}
//storing the comma position in a variable.
gga_time[loop1] = '\0'; //GPGGA time
commapos = loop2 ;
loop1 = 0;
loop2 = 0;
loop2 = commapos + 1; //setting the position for latitude
while(tempbuff[loop2] != COMMA) //receiving the latitude value
{
gga_lat[loop1] = tempbuff[loop2] ;
loop2 ++;
loop1 ++;
}
commapos = loop2; //saving the commaposition
gga_lat[loop1] = '\0'; //GPGGA latitude
loop1 = 0;
loop2 = 0;
loop2 = commapos + 3;
while(tempbuff[loop2] != COMMA) // receiving the longitude value
{
gga_long[loop1] = tempbuff[loop2] ;
loop1 ++;
loop2 ++;
}
commapos = loop2 ;
gga_long[loop1] = '\0'; //GPGGA longitude
}
else
{
/*do nothing*/
}
}
當輸入中沒有足夠的COMMA或者輸入長度超過99個字節時會發生什麼? –
這是我從gps連續獲取的原始數據。 $ GPGGA,060723.00,1234.5678,N,1234.5678,E ,,, M ,, M ,, * 81.從這個函數基於逗號位置我將這些值存儲到數組中。 –
不要依賴這個輸入!始終準備在輸入中輸入無效字符! – Olaf