OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 13415|回复: 4

关于GPS接收回来的地面速率转换小算法

[复制链接]

7

主题

165

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
213
金钱
213
注册时间
2013-6-18
在线时间
0 小时
发表于 2013-8-2 20:48:59 | 显示全部楼层 |阅读模式
 GPS(GPRMC)接收回来的数据中的地面速率,假如为118.6      此时的118.6单位为海里每小时  ,      现在我要把转换成公里每小时,   请问代码该如何写才算好。。。。。。。 
     1公里/小时=1.825海里/小时。。。。。。。。。    我卡在了这里,想不出好的算法!!!
只求每天都能把小事做好。
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2013-8-2 20:50:49 | 显示全部楼层
你的速度=118.6/1.825  公里/小时.
哇靠,64公里每小时,你在车上啊?
我是开源电子网www.openedv.com站长,有关站务问题请与我联系。
正点原子STM32开发板购买店铺http://openedv.taobao.com
正点原子官方微信公众平台,点击这里关注“正点原子”
回复 支持 反对

使用道具 举报

7

主题

165

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
213
金钱
213
注册时间
2013-6-18
在线时间
0 小时
 楼主| 发表于 2013-8-3 10:22:02 | 显示全部楼层
回复【2楼】正点原子:
---------------------------------
不是的,那个数是我举例子用了,也是在接收回来的范围之内。。。。。    昨晚灵光一闪,算法写出来的。。。。。
只求每天都能把小事做好。
回复 支持 反对

使用道具 举报

7

主题

165

帖子

0

精华

中级会员

Rank: 3Rank: 3

积分
213
金钱
213
注册时间
2013-6-18
在线时间
0 小时
 楼主| 发表于 2013-8-3 10:41:49 | 显示全部楼层

回复【2楼】正点原子:
---------------------------------
来这里也有一段时间了,也来分享一下昨晚想出来的算法,本人刚刚接触STM32这个东西,写得有点低端,还望各位不要见笑!!


/*把海里每小时换成公里每小时*/
void Show_GPS_Speed(void)   //GPS接收回来的地面速率海里每小时转换成公里每小时
{
  float hl, gl;   //hl海里/H    gl 公里/H
 
  if(speed[1]=='.')
  {
   hl=(speed[0]-0x30)+((speed[2]-0x30)*(0.1))+((speed[3]-0x30)*(0.01))+((speed[4]-0x30)*(0.001));
   
   //hl=4.234;
   gl=hl*1.852;
   if(gl>=10)
     {
      speed1[0]=gl/10;
      speed1[1]=gl-speed1[0]*10;
      speed1[2]=0x2E;
      speed1[3]=(gl-speed1[0]*10-speed1[1])/(0.1);
      speed1[4]=(gl-speed1[0]*10-speed1[1]-speed1[3]*0.1)/(0.01);

      //显示公里每小时的速度
      LCD_ShowChar(261, 196, speed1[0]+0x30, 12, 0);
      LCD_ShowChar(267, 196, speed1[1]+0x30, 12, 0);
      LCD_ShowChar(273, 196, speed1[2], 12, 0);
      LCD_ShowChar(279, 196, speed1[3]+0x30, 12, 0);
      LCD_ShowChar(285, 196, speed1[4]+0x30, 12, 0);
     }
   else
    {
      speed1[0]=gl;
      speed1[1]=0x2E;
      speed1[2]=(gl-speed1[0])/(0.1);
      speed1[3]=(gl-speed1[0]-(speed1[2]*0.1))/(0.01);
      speed1[4]=(gl-speed1[0]-(speed1[2]*0.1)-(speed1[3]*0.01))/(0.001);

      //显示公里每小时的速度
      LCD_ShowChar(261, 196, speed1[0]+0x30, 12, 0);
      LCD_ShowChar(267, 196, speed1[1], 12, 0);
      LCD_ShowChar(273, 196, speed1[2]+0x30, 12, 0);
      LCD_ShowChar(279, 196, speed1[3]+0x30, 12, 0);
      LCD_ShowChar(285, 196, speed1[4]+0x30, 12, 0);
   }
  }
 
 if(speed[2]=='.')
  {
   hl=(speed[0]-0x30)*10+(speed[1]-0x30)+((speed[3]-0x30)*(0.1))+((speed[4]-0x30)*(0.01));
   
   //hl=77.78;
   gl=hl*1.852;


   if(gl>=100)
    {
     speed1[0]=gl/100;
     speed1[1]=(gl-speed1[0]*100)/(10);
     speed1[2]=(gl-speed1[0]*100-(speed1[1]*10));
     speed1[3]=0x2E;
     speed1[4]=(gl-speed1[0]*100-(speed1[1]*10)-speed1[2])/(0.1);

     //显示公里每小时的速度
     LCD_ShowChar(261, 196, speed1[0]+0x30, 12, 0);
     LCD_ShowChar(267, 196, speed1[1]+0x30, 12, 0);
     LCD_ShowChar(273, 196, speed1[2]+0x30, 12, 0);
     LCD_ShowChar(279, 196, speed1[3], 12, 0);
     LCD_ShowChar(285, 196, speed1[4]+0x30, 12, 0);
    }
   else
    {
     speed1[0]=gl/10;
     speed1[1]=gl-speed1[0]*10;
     speed1[2]=0x2E;
     speed1[3]=(gl-speed1[0]*10-speed1[1])/(0.1);
     speed1[4]=(gl-speed1[0]*10-speed1[1]-speed1[3]*0.1)/(0.01);

     //显示公里每小时的速度
     LCD_ShowChar(261, 196, speed1[0]+0x30, 12, 0);
     LCD_ShowChar(267, 196, speed1[1]+0x30, 12, 0);
     LCD_ShowChar(273, 196, speed1[2], 12, 0);
     LCD_ShowChar(279, 196, speed1[3]+0x30, 12, 0);
     LCD_ShowChar(285, 196, speed1[4]+0x30, 12, 0);
    }
   
  }
 if(speed[3]=='.')
  {
   hl=(speed[0]-0x30)*100+((speed[1]-0x30)*(10))+((speed[2]-0x30))+((speed[4]-0x30)*(0.1));
   
   //hl=668.6;
   gl=hl*1.852;
   
   
   if(gl>=1000)
    {
     speed1[0]=gl/1000;
     speed1[1]=(gl-speed1[0]*1000)/(100);
     speed1[2]=(gl-speed1[0]*1000-(speed1[1]*100))/10;
     speed1[3]=(gl-speed1[0]*1000-(speed1[1]*100)-speed1[2]*10);
     speed1[4]=0x20;

     //显示公里每小时的速度
     LCD_ShowChar(261, 196, speed1[0]+0x30, 12, 0);
     LCD_ShowChar(267, 196, speed1[1]+0x30, 12, 0);
     LCD_ShowChar(273, 196, speed1[2]+0x30, 12, 0);
     LCD_ShowChar(279, 196, speed1[3]+0x30, 12, 0);
     LCD_ShowChar(285, 196, speed1[4], 12, 0);
    }
   else
    {
     speed1[0]=gl/100;
     speed1[1]=(gl-speed1[0]*100)/(10);
     speed1[2]=(gl-speed1[0]*100-(speed1[1]*10));
     speed1[3]=0x2E;
     speed1[4]=(gl-speed1[0]*100-(speed1[1]*10)-speed1[2])/(0.1);

     //显示公里每小时的速度
     LCD_ShowChar(261, 196, speed1[0]+0x30, 12, 0);
     LCD_ShowChar(267, 196, speed1[1]+0x30, 12, 0);
     LCD_ShowChar(273, 196, speed1[2]+0x30, 12, 0);
     LCD_ShowChar(279, 196, speed1[3], 12, 0);
     LCD_ShowChar(285, 196, speed1[4]+0x30, 12, 0);
    }
    
  }

}

只求每天都能把小事做好。
回复 支持 反对

使用道具 举报

530

主题

11万

帖子

34

精华

管理员

Rank: 12Rank: 12Rank: 12

积分
165540
金钱
165540
注册时间
2010-12-1
在线时间
2117 小时
发表于 2013-8-3 11:11:50 | 显示全部楼层
谢谢分享
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2025-7-15 21:00

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表