Exemple #1
0
int main(void)
{ 
  RCC_Configuration();		 	//配置RCC
	initDesireAngles();
	
	TIMER4_Enable();					//定时器4
	TIMER4_Configuration();		//配置中断
	
  USART1_GPIO_Config();		 	//配置GPIO
	USART1_NVIC_Config();			//配置中断
  USART1_Configuration();	 	//配置串口1
	
	USART2_GPIO_Config();
	USART2_Configuration();

	I2C_GPIO_Config();				//配置IIC使用端口
  Delayms(10);				 			//延时
	Init_MPU6050();		     //初始化MPU6050
	
	PWM_Configuration();
		
	while(1)
	{

	}
	 			//回车
	
}
Exemple #2
0
void Init(void)
{
    //时钟配置
    RCC_Configuration();
    NVIC_Configuration();
    delay_init(72);

    //串口配置
    USART1_Configuration();
    USART2_Configuration();
    USART3_Configuration();
    UART4_Configuration();
    UART5_Configuration();
    USART_ITEnable();

    //PWM配置
    PWMTIM_Configuration(72000/5,0);	      //不分频。PWM频率=Freq

    //指南针配置
    COMPASS_Init();

    //舵机配置
    SERVOS_Init();

    //设置到初始值
    PWM_Configuration(MOTOR_Speed);
    s3010_SeTAngle(SERVOS_Angle);
}
Exemple #3
0
int main(void)
{
    // Hardware Init
    delay_init();	    	 //ÑÓʱº¯Êý³õʼ»¯
    pwr_init();
    #ifdef YANMING3
    charger_init();
    if (check_standby_flag() == SUCCESS && check_charging() != CHARGING) {
        Key_GPIO_Config();
        exti_key_init();
        #ifdef DEBUG_POWER_OFF_WAKE_UP
        Screen_Init();
        OLED_Clear();
        OLED_Display_On();
        draw_about_mesage();
        #endif
        check_standby_wakeup_button_press();
        // If we boot up from standby by pressing 5 times, the system will reboot again without
        // this code block.
    }
    #endif

    // OLED Init
    Screen_Init();
    OLED_Clear();
    
    //
    low_switch_power_init();

    TIMx_Int_DeInit();
    EXTIX_DeInit();
    
    // Key
    Key_GPIO_Config();
    
    // PID related code
    ADC1_Configuration();
    PWM_Configuration();
    VoltagePID_Init();

    TIMx_Int_Init();
    rtc_init();

    // Our Init
    system_init();
    #ifndef YANMING3
    //iwdg_init();
    #endif

    while(1) {
        #ifndef YANMING3
        //iwdg_feed();
        #endif
        task_schedule();
    }
}
/**
  * @brief  Main program.
  * @param  None
  * @retval None
  */
int main(void)
{
  /*!< At this stage the microcontroller clock setting is already configured, 
       this is done through SystemInit() function which is called from startup
       file (startup_stm32f10x_xx.s) before to branch to application main.
       To reconfigure the default setting of SystemInit() function, refer to
       system_stm32f10x.c file
     */ 
	LED_Configuration();
	SysTick_Configuration();
	USART_Configuration();
	Buzzer_Configuration();
	LED_Interrupt();//¿ªÆô¶¨Ê±Æ÷ÖжÏ
	PWM_Configuration();

	LED_Set(0x00);
  /* Infinite loop */
  while (1)										 
  {
// 	Set_Speed(1,50,0);
//	Set_Speed(2,50,0);
//	Buzzer_ON();
//	delay_ms(1000);
//	Set_Speed(1,50,1);
//	Set_Speed(2,50,1);
//	Buzzer_ON();
//	delay_ms(1000);
	switch(instruction)
	{
		case 'a': 
			Set_Speed(1,50,1);
			Set_Speed(2,50,1);
			break;
		case 'b': 
			Set_Speed(1,50,1);
			Set_Speed(2,50,0);
			break;	
		case 'c': 
			Set_Speed(1,50,0);
			Set_Speed(2,50,1);
			break;
		case 'd': 
			Set_Speed(1,50,0);
			Set_Speed(2,50,0);
			break;
		case 's': 
			Set_Speed(1,0,0);
			Set_Speed(2,0,0);
			break;
		case 'z':
				Buzzer_ON();
				break;
		case 'y':
				Buzzer_OFF();
				break;
		 default: break;
										
	}


  }
}
Exemple #5
0
int main()
{
    int x0 = 9;
    int y0 = 7;

    double MOTOR_Speed_Previous = MOTOR_Speed;
    double SERVOS_Angle_Previous = SERVOS_Angle;

    Init();		//加载

    //串行口
    USART_sendBuf(USART1, "STM32 USART TEST\r\n");

	DelayMs(100);
	
    //主循环
    while(1)
    {
        if(state==0) {
            //应用控制数据到电机和舵机
            if(MOTOR_Speed != MOTOR_Speed_Previous)
            {
                PWM_Configuration(MOTOR_Speed);
                MOTOR_Speed_Previous = MOTOR_Speed;
				continue;
            }

            if(SERVOS_Angle != SERVOS_Angle_Previous)
            {
                s3010_SeTAngle(SERVOS_Angle);
                SERVOS_Angle_Previous = SERVOS_Angle;
				continue;
            }
			
            ULTRASONIC_Read();
			COMPASS_Read();

            sprintf((char*)buf, "ULTRASONIC_Dist1:%f\r\n", ULTRASONIC_Dist1);
			USART_sendBuf(USART1, buf);
			
            sprintf((char*)buf, "ULTRASONIC_Dist2:%f\r\n", ULTRASONIC_Dist2);
			USART_sendBuf(USART1, buf);
			
            sprintf((char*)buf, "ULTRASONIC_Dist3:%f\r\n", ULTRASONIC_Dist3);
			USART_sendBuf(USART1, buf);
			
            sprintf((char*)buf, "COMPASS_Angle:%f\r\n", COMPASS_Angle);
            USART_sendBuf(USART1, buf);
			
        }
        if(state==1) {

            USART_sendBuf(USART1, "STM32 POWER ON\r\n");
			
			ULTRASONIC_Read();
            COMPASS_Read();
			
            //Calculate x0,y0 here
			//x0 = ULTRASONIC_Dist3;
			//y0 = ULTRASONIC_Dist1;
            //End of calculation

            sprintf((char*)buf, "%d\n", x0);
            USART_sendBuf(USART2,buf);
            USART_sendBuf(USART1,buf);
            sprintf((char*)buf, "%d\n", y0);
            USART_sendBuf(USART2,buf);
            USART_sendBuf(USART1,buf);

            state = 2;
        }
        if(state==2) {
            DelayMs(50);
			if(num == total_num * 2 + 1){
				USART_sendBuf(USART1, "DATA TRANSFER COMPLETE\r\n");
				state=3;
			}
        }
		if(state==3) {
			//Add PID here
			DelayMs(50);
		}
    }
}