⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 公交车到站判断程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "option.h"
#include "def.h"
#include "44b.h"
#include "44blib.h"

#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include<string.h>

#define   R_1     1.86
#define   PI      3.1415926f 
#define   R       6378137.0f              /*地球半径 */
#define STAT_NUM  6	      /*最大站点数*/
#define MaxBeepFreq   3000

U8 i=0,j=0,a=0,k=0;
char temp[65];
char Dis[17];
char time[16];
char date[20];
char pos1[20];
char pos2[17];
char Latd[18];
char Lotd[18];
char T[17];
char M[10];
long double H,x_d,y_d,xx,yy,xxx,yyy;
long double out,out1,out2,out_put;
long double distance,distance1,distance2,distance_min,distance_max;
int s=0;
volatile char which_int=0;

/********************************************************************
 Function name	: sruct
 Description	: 定义结构
 Return type	: struct
*********************************************************************/

struct position
{
        char *name;
        char *latitude;                         /* 纬度 */
        char *longitude;                        /* 经度 */
}POS[4]={{"  师大院楼        ","2303.4396","11322.2671"},{"  师大生活区    ","2303.1549","11322.8740"},{"  星海音乐学院  ","2303.5999","11322.0000"},{"  中大生活区    ","2303.4396","11322.2671"}};

struct utc_time
{
        unsigned char hh;
        unsigned char mm;
        unsigned char ss;
};
struct utc_date
{
        unsigned char dd;
        unsigned char mm;
        unsigned char yy;
};

/********************************************************************
 Function name	: Get_MsgHeader
 Description	: 判断并且预存数据
 Return type	: int
*********************************************************************/
 
int Get_MsgHeader(void)
{
      char h;
      char dd;
      char mm;
      char yy;
      char  mes_id[6+1] = "$GPRMC";		/*抬头判断*/
      unsigned char i=0;
      unsigned char k=0,L=0,p=0,q=0,w=0;  
      
      while (i < 6)
        {      

          if (mes_id[i] == Uart_Getch())

                i++;
          else 
               i = 0;
           }
                
      for ( i = 0; i < 65; i++)      /* 数据传输速度比较快,所以预存 */
        {    
            temp[i] = Uart_Getch();
                        
             }
                        
      h = (temp[1] - '0') * 10 + (temp[2] +8 -'0');

      while(k<9)
        {
           time[k++]=h/10+'0';
           time[k++]=h%10+'0';
           time[k++]=':';
           time[k++]=temp[3];
           time[k++]=temp[4];
           time[k++]=':';
           time[k++]=temp[5];
           time[k++]=temp[6];
           time[k++]='@';
               }
      if (temp[12] == 'V') // 信息不可用则返回                    
         {
             return 0;  
                }                                
      
      do
         { 
           pos1[p++]=temp[14];
           pos1[p++]=temp[15];
           pos1[p++]=0xA1;
           pos1[p++]=0xE3;
           pos1[p++]=temp[16];
           pos1[p++]=temp[17];
           pos1[p++]=temp[18];
           pos1[p++]=temp[19];
           pos1[p++]=temp[20];
           pos1[p++]=temp[21];
           pos1[p++]=temp[22];
           pos1[p++]=0;
           pos1[p++]=temp[24];
           pos1[p++]='@';
              }while(p<5);
      
     while(q<16)
       {
           pos2[q++]=temp[26];
           pos2[q++]=temp[27];
           pos2[q++]=temp[28];
           pos2[q++]=0;
           pos2[q++]=0xA1;
           pos2[q++]=0xE3;
           pos2[q++]=temp[29];
           pos2[q++]=temp[30];
           pos2[q++]=temp[31];
           pos2[q++]=temp[32];
           pos2[q++]=temp[33];
           pos2[q++]=temp[34];
           pos2[q++]=temp[35];
           pos2[q++]=0;    
           pos2[q++]=temp[37];
           pos2[q++]='@';
                 }            
               
      for(w=0,i=14;w<9&&i<23;w++,i++)
        {
           Latd[w]=temp[i];
                 }//纬度
         
      for(w=0,i=26;w<10&&i<36;w++,i++)
        {
           Lotd[w]=temp[i];
                 }//经度 
  
      for (j = 3, i = 37; j != 0 && i < 65; i++) //判断日期信息的位置
        {
           if (temp[i] == ',') 
              {  
                  j--;  
                     }                                                  
               }
        
      if (i != 65)
        {               
            dd = (temp[i++] - '0') * 10 + (temp[i++] - '0');
            mm = (temp[i++] - '0') * 10 + (temp[i++] - '0');
            yy = (temp[i++] - '0') * 10 + (temp[i++] - '0');
                  }
      while(L<8)   
        {      
           date[L++]=2+'0';
           date[L++]=0+'0';
           date[L++]=yy%10+'0';
           date[L++]=yy/10+'0';
           date[L++]=0xc4;
           date[L++]=0xea;
           date[L++]=mm%10+'0';
           date[L++]=mm/10+'0';
           date[L++]=0xd4;
           date[L++]=0xc2;
           date[L++]=dd%10+'0';
           date[L++]=dd/10+'0';
           date[L++]=0xc8;
           date[L++]=0xd5;
           date[L++]='@';
               }
              
      return 1;
} 


/********************************************************************
 Function name	:Change_String()
 Description	:取经纬度后小数部分
 Return type	:long double
*********************************************************************/

long double Change_String(char *str)
{  
      for(i=0;i<10;i++)
        {
          M[i]=*str++;
             }
           
      if((strlen(M))==0x0000000a)
        {                
         out1=(M[3]-'0')*10+(M[4]-'0')+(M[6]-'0')*0.1+(M[7]-'0')*0.01+(M[8]-'0')*0.001+(M[9]-'0')*0.0001;  
             }
      else if((strlen(M))==0x00000009)
        {
         out1=(M[2]-'0')*10+(M[3]-'0')+(M[5]-'0')*0.1+(M[6]-'0')*0.01+(M[7]-'0')*0.001+(M[8]-'0')*0.0001; 
             }
            
      out_put=out1;
      return out_put;     
}

/********************************************************************
 Function name	:Compare_Float()
 Description	:比较经纬度差值范围
 Return type	:int 
*********************************************************************/

int Compare_Float(long double x,long double y)
{
      if((x>0.06)||(y>0.06))//-160
        return 0;
      else if((x>0.04)&&(x<0.06)||(y>0.04)&&(y<0.06))//-100m
        return 1;
      else if((x>0.02)&&(x<0.04)&&((y>0.02)&&(y<0.04)))//-60m
        return 2;
      else if((0<x)&&(x<0.02)&&(y<0.02))//-40m
        return 3;

}


/********************************************************************
 Function name	: Chg_to_Radian
 Description	: 角度转换成弧度
 Return type	: long double
*********************************************************************/    
long double Chg_to_Radian(char *str)
{
      for(i=0;i<10;i++)
        {
           M[i]=*str++;
              }
           
      if((strlen(M))==0x0000000a)
        {                
           out1=(M[0]-'0')*100+(M[1]-'0')*10+(M[2]-'0')*1;
           out2=(M[3]-'0')*10+(M[4]-'0')+(M[6]-'0')*0.1+(M[7]-'0')*0.01+(M[8]-'0')*0.001+(M[9]-'0')*0.0001;  
              }
      else if((strlen(M))==0x00000009)
        {
           out1=(M[0]-'0')*10+(M[1]-'0');
           out2=(M[2]-'0')*10+(M[3]-'0')+(M[5]-'0')*0.1+(M[6]-'0')*0.01+(M[7]-'0')*0.001+(M[8]-'0')*0.0001; 
              }
           
      out=out1+out2/60; 
      out = out * PI / 180;                     
            
      return out;
}

/********************************************************************
 Function name	: Start_Beep
 Description	: 驱动蜂鸣器
 Return type	: void
*********************************************************************/

void Start_Beep(U16 Freq, U8 HiRatio)
{
	  if(Freq>MaxBeepFreq)
		Freq = MaxBeepFreq;
	  if(HiRatio>100)
		HiRatio = 100;	
	  rTCON  	&= 0xffff0fff;					// clear manual update bit, stop Timer2
	  rTCFG0 	&= 0xffff00ff;					// set Timer 2&3 prescaler 0
	  rTCFG1 	&= 0xfffff0ff;					// set Timer 2 MUX 1/16
	  rTCFG1  |= 0x00000300;	
	  rTCNTB2	 = MCLK/(Freq*16);				//if set inverter off, when TCNT2<=TCMP2, TOUT is high, TCNT2>TCMP2, TOUT is low
	  rTCMPB2  = (rTCNTB2*(100-HiRatio))/100;	//if set inverter on,  when TCNT2<=TCMP2, TOUT is low,  TCNT2>TCMP2, TOUT is high
	  rTCON	|= 0x00002000;					// manual update
	  rTCON	&= 0xffff0fff;	  				// clear manal update bit
	  rTCON   |= 0x0000d000;					// auto reload, inverter on, start Timer 2
}

/********************************************************************
 Function name	: StopBeepPwm
 Description	: 停响蜂鸣器
 Return type	: void
*********************************************************************/

void StopBeepPwm(void)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -