|
发表于 2013-4-24 16:31:45
|
显示全部楼层
这个是我之前做的一个提取 经纬度的 函数,楼主可以参考一下。
//需要接收的数据格式:$GPRMC,090113.00,A,3958.2847,N,11616.6454,E,0.00,0.00,080110,,,A*60
//$在第一个字节处,M在第5个字节处,A在第18处,纬度数据在20~28处,经度数据在32~41处。
void GPSReceive(uchar temp)
{
if (temp == '$')//收到协议头
{
ReceiveFlag = 1;//协议数据标志位置1
Bytes_counter = 0;//接收数据字节个数清0
}
if (ReceiveFlag == 1)
{
Bytes_counter++;
if (Bytes_counter == 5 && temp == 'M')//收到GPRMC格式数据
{
RMCFlag = 1;
}
if (RMCFlag == 1)
{
if (Bytes_counter == 18 && temp == 'A')//GPS处于有效状态
{
GPSValidFlag = 1;
}
if (GPSValidFlag == 1 && DataProcOKFlag == 1)//上一次接收的数据已经处理转换完毕,才能接收新的经纬度信息
{
if (Bytes_counter >= 20 && Bytes_counter <= 28)//接收纬度信息,并进行初步转换
{
#if GPS_DEBUG
Lat[Bytes_counter - 20] = temp;
#endif
LatArray[Bytes_counter - 20] = temp - '0';
}
if (Bytes_counter >= 33 && Bytes_counter <= 42)//接收经度信息,并进行初步转换
{
#if GPS_DEBUG
Long[Bytes_counter - 33] = temp;
#endif
LongArray[Bytes_counter - 33] = temp - '0';
}
if(Bytes_counter >= 43) //接收经纬度信息完毕,清除所有标志位
{
GPSValidFlag = 0;
RMCFlag = 0;
ReceiveFlag = 0;
DataProcOKFlag =0;
//关闭UART接收使能和中断
UCSRB &= ~(_BV(RXEN) | _BV(RXCIE));
}
// USART_PutChar(temp);
}//end if if (StatusFlag == 1)
}//end of if (RMCFlag == 1)
}//end of if (ReceiveFlag == 1)
}
//在串口接收中断中 提取 经纬度信息
ISR(USART_RXC_vect)
{
char temp = 0;
temp = UDR;
GPSReceive(temp);
} |
|