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

📄 mainc.txt

📁 ARM7 中对GPS信号的接受部分
💻 TXT
字号:
// ----------------------------------------------------------------------------
//         ATMEL Microcontroller Software Support  -  ROUSSET  -
// ----------------------------------------------------------------------------
// DISCLAIMER:  THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR
// IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
// DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT, INDIRECT,
// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
// OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
// EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// ----------------------------------------------------------------------------
// File Name           : main.c
// Object              : main application written in C
// Creation            : JPP   08-Sep-2005
// ----------------------------------------------------------------------------

// Include Standard LIB  files
#include "project.h"
#include "math.h"

//*   Waiting time between AT91B_LED1 and AT91B_LED2
#define     WAIT_TIME       AT91B_MCK

#define PIO_INTERRUPT_LEVEL     6
#define SOFT_INTERRUPT_LEVEL	2
#define FIQ_INTERRUPT_LEVEL     7  // Always high
#define pi 3.1415926

//* Global variable
int count_timer0_interrupt;
int count_timer1_interrupt;
extern unsigned int latitude=0;
extern unsigned int longitude=0;
extern unsigned int latitude_fromtalk=0;
extern unsigned int longitude_fromtalk=0;
extern unsigned int jjj=0;
extern float is_distance=0.0;



// Use the Library Handler defined in file periph/pio/pio_irq/irq_pio.s

extern void FIQ_init_handler(void);

// External Function Prototype
extern void timer_init (void );
extern void Usart_init (void);
extern unsigned char rec[200];
extern unsigned char val[200];
extern void judgeGPS();
extern float Distance(float latitude2,float longitude2);
extern void AT91F_DBGU_Init(void);
extern unsigned int AT91F_DBGU_Get( char *val);
extern void AT91F_DBGU_scanf(char * type,unsigned int * val);
extern void AT91F_DBGU_Printk(char *);
//extern unsigned char temp2;



//*----------------------------------------------------------------------------
//* Function Name       : aic_software_interrupt
//* Object              : Software interrupt function
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions calAT91B_LED    : at91_pio_write
//*----------------------------------------------------------------------------
__ramfunc void aic_software_interrupt(void)
{
    //* Read the output state
    if ( (AT91F_PIO_GetInput(AT91C_BASE_PIOB) & AT91B_LED2 ) == AT91B_LED2 )
    {
        AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, AT91B_LED2 );
    }
    else
    {
        AT91F_PIO_SetOutput( AT91C_BASE_PIOB, AT91B_LED2 );
    }
}

//*----------------------------------------------------------------------------
//* Function Name       : pio_c_irq_handler
//* Object              : Irq Handler calAT91B_LED by the irq_pio.s
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions calAT91B_LED    : at91_pio_read, at91_pio_write
//*----------------------------------------------------------------------------
//__ramfunc void pio_c_irq_handler ( void )
 void pio_c_irq_handler ( void )
{
int dummy;
    //* Read the output state
    if ( (AT91F_PIO_GetInput(AT91C_BASE_PIOB) & AT91B_LED2 ) == AT91B_LED2 )
    {
       AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, AT91B_LED2);
    }
    else
    {
       AT91F_PIO_SetOutput( AT91C_BASE_PIOB, AT91B_LED2);
    }
    //* enable the next PIO IRQ
    dummy =AT91C_BASE_PIOA->PIO_ISR;
    //* suppress the compilation warning
    dummy =dummy;
    //* while SW3 is push wait
    while ( (AT91F_PIO_GetInput(AT91C_BASE_PIOA) & AT91B_SW5 ) != AT91B_SW5 );
}

//*----------------------------------------------------------------------------
//* Function Name       : delay
//* Object              : Wait
//* Input Parameters    : none
//* Output Parameters   : none
//* Functions calAT91B_LED    : none
//*----------------------------------------------------------------------------
void delay ( void )

{
//* Set in Volatile for Optimisation
    volatile unsigned int    i ;
//* loop delay
    for ( i = 0 ;(i < WAIT_TIME/100 );i++ ) ;
}

//*catch the latitude and longitude
void judgeGPS ( void )
{
 unsigned char temp1;
 volatile unsigned int temp2;


 if(jjj>43)
 { volatile unsigned int  i=0;
   temp1=rec[i];
 if (temp1=='$')
  { i+=1;
    temp1=rec[i];
     if (temp1=='G')
     { i+=1;
      temp1=rec[i];
      if (temp1=='P')
      { i+=1;
        temp1=rec[i];
        if (temp1=='R')
        {i+=1;
        temp1=rec[i];
        if(temp1=='M')
        { i+=1;
          temp1=rec[i];
          if (temp1=='C')
          {i+=1;
           temp1=rec[i];
            if (temp1==',')
           {i+=12;
           temp1=rec[i];
           if (temp1=='A')
           { i+=2;
             temp2=rec[i]-48;
             latitude=temp2*10000000;
             i++;
             temp2=rec[i]-48;
             latitude+=temp2*1000000;
             i++;
             temp2=rec[i]-48;
             latitude+=temp2*100000;
              i++;
             temp2=rec[i]-48;
             latitude+=temp2*10000;
             i+=2;
             temp2=rec[i]-48;
             latitude+=temp2*1000;
             i++;
              temp2=rec[i]-48;
             latitude+=temp2*100;
             i++;
             temp2=rec[i]-48;
             latitude+=temp2*10;
             i++;
             temp2=rec[i]-48;
             latitude+=temp2;
             i+=4;
             temp2=rec[i]-48;
             longitude=temp2*100000000;
             i++;
             temp2=rec[i]-48;
             longitude+=temp2*10000000;
             i++;
             temp2=rec[i]-48;
             longitude+=temp2*1000000;
             i++;
             temp2=rec[i]-48;
             longitude+=temp2*100000;
             i++;
             temp2=rec[i]-48;
             longitude+=temp2*10000;
             i+=2;
             temp2=rec[i]-48;
             longitude+=temp2*1000;
             i++;
             temp2=rec[i]-48;
             longitude+=temp2*100;
               i++;
             temp2=rec[i]-48;
             longitude+=temp2*10;
                  i++;
             temp2=rec[i]-48;
             longitude+=temp2;

             }
             }
           }
         }
        }
      }
   }
  }
 }
}
void getlatitude_long(void)
{
  volatile unsigned int  i=0;
   unsigned char temp3;
   temp3=val[i];
      temp3=val[i]-48;
             latitude_fromtalk=temp3*10000000;
             i++;
             temp3=val[i]-48;
             latitude_fromtalk+=temp3*1000000;
             i++;
             temp3=val[i]-48;
             latitude_fromtalk+=temp3*100000;
              i++;
             temp3=val[i]-48;
             latitude_fromtalk+=temp3*10000;
             i+=2;
             temp3=val[i]-48;
             latitude_fromtalk+=temp3*1000;
             i++;
              temp3=val[i]-48;
             latitude_fromtalk+=temp3*100;
             i++;
             temp3=val[i]-48;
             latitude_fromtalk+=temp3*10;
             i++;
             temp3=val[i]-48;
             latitude_fromtalk+=temp3;
             i+=4;
             temp3=val[i]-48;
             longitude_fromtalk=temp3*100000000;
             i++;
             temp3=val[i]-48;
             longitude_fromtalk+=temp3*10000000;
             i++;
             temp3=val[i]-48;
             longitude_fromtalk+=temp3*1000000;
             i++;
             temp3=val[i]-48;
             longitude_fromtalk+=temp3*100000;
             i++;
             temp3=val[i]-48;
             longitude_fromtalk+=temp3*10000;
             i+=2;
             temp3=val[i]-48;
             longitude_fromtalk+=temp3*1000;
             i++;
             temp3=val[i]-48;
             longitude_fromtalk+=temp3*100;
               i++;
             temp3=val[i]-48;
             longitude_fromtalk+=temp3*10;
                  i++;
             temp3=val[i]-48;
             longitude_fromtalk+=temp3;
}

void getlatitude_long(void)
//*caculate the distance betweem two points
float Distance(float latitude2,float longitude2)
{ float radius=6371.004;
  volatile float p=0.0;
  volatile float q=0.0;
  volatile float x1;
  volatile float y1;
  volatile float z1;
  volatile float x2;
  volatile float y2;
  volatile float z2;
  volatile float is_length;
 // volatile float is_distance;
  volatile float latitude1=0.0;
  volatile float longitude1=0.0;

  p=latitude%1000000/600000.0;//把分换成度
  q=latitude/1000000;//取出整度数
  latitude1=q+p;//第一个纬度值

  p=longitude%1000000/600000.0;//把分换成度
  q=longitude/1000000;//取出整度数
  longitude1=q+p;//第一个经度值

  x1=radius*cos(latitude1*pi/180)*cos(longitude1*pi/180);
  y1=radius*cos(latitude1*pi/180)*sin(longitude1*pi/180);
  z1=radius*sin(latitude1*pi/180);

  x2=radius*cos(latitude2*pi/180)*cos(longitude2*pi/180);
  y2=radius*cos(latitude2*pi/180)*sin(longitude2*pi/180);
  z2=radius*sin(latitude2*pi/180);
  is_length=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));
  is_distance=2*radius*asin(0.5*is_length/radius);

  return is_distance;
 }





//*----------------------------------------------------------------------------
//* Function Name       : main
//* Object              : Main interrupt function
//* Input Parameters    : none
//* Output Parameters   : TRUE
//*----------------------------------------------------------------------------
int main( void )
//* Begin
{
    unsigned int   loop_count ;
    unsigned int   get_num ;

     volatile char message[80];

    AT91PS_AIC     pAic;
    //* Load System pAic Base address
        pAic = AT91C_BASE_AIC;

    //* Enable User Reset and set its minimal assertion to 960 us
        AT91C_BASE_RSTC->RSTC_RMR = AT91C_RSTC_URSTEN | (0x4<<8) | (unsigned int)(0xA5<<24);

    //* Init
     	loop_count = 0 ;
    // First, enable the clock of the PIOB
        AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOB ) ;

   	//* then, we configure the PIO Lines corresponding to AT91B_LEDx
   	//* to be outputs. No need to set these pins to be driven by the PIO because it is GPIO pins only.
        AT91F_PIO_CfgOutput( AT91C_BASE_PIOB, AT91B_LED_MASK ) ;
   	//* Clear the AT91B_LED's. On the EK we must apply a "1" to turn off AT91B_LEDs
   	AT91F_PIO_SetOutput( AT91C_BASE_PIOB, AT91B_LED_MASK ) ;
   	//* Clear the AT91B_LED's. On the EK we must apply a "1" to turn off AT91B_LEDs


    //* open external PIO interrupt
        //* define switch SW5 at PIO input for interrupt IRQ loop
   	AT91F_PMC_EnablePeriphClock ( AT91C_BASE_PMC, 1 << AT91C_ID_PIOA ) ;
	AT91F_PIO_CfgInput(AT91C_BASE_PIOA, AT91B_SW5 | AT91B_SW4);

	AT91F_AIC_ConfigureIt ( pAic, AT91C_ID_PIOA, PIO_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, pio_c_irq_handler);
	AT91F_PIO_InterruptEnable(AT91C_BASE_PIOA,AT91B_SW4);
	//* set the interrupt by software
	AT91F_AIC_EnableIt (pAic, AT91C_ID_PIOA);

    //* Open the software interrupt on the AIC
        AT91F_AIC_ConfigureIt ( pAic, AT91C_ID_SYS, SOFT_INTERRUPT_LEVEL, AT91C_AIC_SRCTYPE_INT_POSITIVE_EDGE,  aic_software_interrupt);
        AT91F_AIC_EnableIt (pAic, AT91C_ID_SYS);

    //* open  FIQ interrupt
        AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA,AT91B_SW1,0);
	AT91F_AIC_ConfigureIt ( pAic, AT91C_ID_FIQ, FIQ_INTERRUPT_LEVEL,AT91C_AIC_SRCTYPE_EXT_NEGATIVE_EDGE, FIQ_init_handler);
	AT91F_AIC_EnableIt (pAic, AT91C_ID_FIQ);
        //* generate FIQ interrupt by software
	AT91F_AIC_Trig (pAic,AT91C_ID_FIQ) ;

    //* Init timer interrupt
        timer_init();

    //* Init Usart
        Usart_init();
     //* Init DBGU
        AT91F_DBGU_Init();

    //* generate software interrupt
        AT91F_AIC_Trig (pAic,AT91C_ID_SYS) ;

for (;;)
    {
        AT91F_PIO_ClearOutput( AT91C_BASE_PIOB, AT91B_LED1 );
        delay () ;
        AT91F_PIO_SetOutput( AT91C_BASE_PIOB, AT91B_LED1 );
        delay () ;

        loop_count ++ ;
    //* Set AT91B_LED by software interrupt
        if (loop_count == 10)
        {
             loop_count=0;
         //* Software interrupt
             AT91F_AIC_Trig (pAic,AT91C_ID_SYS) ;
        }
         get_num=AT91F_DBGU_Get(&message);
        if(get_num=0)
        {
          getlatitude_long();
        }




        judgeGPS();
        float ab;
        ab=Distance(39.9727216,116.493508);
        fnLCMInit();
        cls();
        cursor(0,0);

 //dprintf("%s","This is a test:中文测试");

    }
//unsigned char temp2;

//temp2='a';

//* End
}

⌨️ 快捷键说明

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