Ejemplo n.º 1
0
void MPU6050_GyroCalibration()
{
    int cycles = 7000;
    int i;
    int32_t x, y, z;
    GPIOPinWrite(GPIO_PORTE_BASE, GPIO_PIN_5, 0 );
    Gyro_Offset.X = 0;
    Gyro_Offset.Y = 0;
    Gyro_Offset.Z = 0;
    x = 0;
    y = 0;
    z = 0;
    Update_1000Hz = false;
    for(i = 0 ; i < cycles ; i++)
    {
        while (!Update_1000Hz);
        Update_1000Hz = false;
    	MPU9250_GetGyro();
    	x += Gyro.X;
    	y += Gyro.Y;
    	z += Gyro.Z;
    }
    Gyro_Offset.X = -x / cycles;
    Gyro_Offset.Y = -y / cycles;
    Gyro_Offset.Z = -z / cycles;
    EEPROM_Write();
	BEEP_On();
	Update_5Hz = false;
	while (!Update_5Hz);
	BEEP_Off();
    return ;
}
Ejemplo n.º 2
0
//蜂鸣器控制,每10ms执行一次
void BuzzerCtrl(void* arg)
{
  (void)(arg);
  static TONE_Def Tone;
 
  switch (BuzzerStatus)
  {
	case 0:
	  Tone = *pTone;
	  if (Tone.Freq != FREQ_NO) //非结束符
	  {
		//先判断供电持续时间
		if (Tone.PWRTime != 0)
		{
		  Tone.PWRTime --;
		  BeepPwrOn();
		}
		else 
		{
		  BuzzerStatus = 2;
		  break;
		}
		//再判断振荡持续时间
		if (Tone.OSCTime != 0)
		{
		  Tone.OSCTime --;
		  BEEP_SetFreq(Tone.Freq);
		  BEEP_On();
		}
		else 
		{
		  BeepPwrOff();
		  BuzzerStatus = 2;
		  break;
		}
		//判断完成,开始递减计时
		BuzzerStatus = 1;
	  }
	  else // Tone.Freq == FREQ_NO  //是结束符
	  {
		BuzzerStatus = 2;
	  }
	  break;
	case 1:
	  if (Tone.PWRTime != 0)
	  {
		Tone.PWRTime --;
	  }
	  else
	  {
		BeepPwrOff();
	  }
	  if (Tone.OSCTime != 0)
	  {
		Tone.OSCTime --;
	  }
	  else
	  {
		BEEP_Off();
		pTone ++;   //取下一个音调
		BuzzerStatus = 0;
	  }
	  break;
	default:
	  break;
  }
  return;
}