这是一套完整的stm32f103的平衡车程序,大家可以参考一下
单片机源程序如下:
- #include "delay.h"
- #include "sys.h"
- #include "usart.h"
- #include "led.h"
- #include "bluetooth.h"
- #include "motor.h"
- #include "speed.h"
- #include "mp6050.h"
- #include "key.h"
- #include "ultrasonic.h"
- #include "DataScope_DP.h"
-
-
- int main(void)
- {
- u8 i,Send_Count;
-
- delay_init(72);
- NVIC_Configuration();
- uart_init(9600);
- LED_Init();
- KEY_Init();
- BLUETOOTH_Init(9600);
- MPU6050_Init();
- PID_Init();
- ENCODER_Init();
- ULTRASONIC_Init();
- MOTOR_Init();
- while (1)
- {
- // DataScope_Get_Channel_Data( acc_x, 1 ); //上位机波形显示
- // DataScope_Get_Channel_Data( gyro_y, 2 );
- // DataScope_Get_Channel_Data( angle_ax, 3 );
- // DataScope_Get_Channel_Data( angle_gy , 4 );
- // DataScope_Get_Channel_Data(angle, 5 );
- // DataScope_Get_Channel_Data(Kp , 6 );
- // DataScope_Get_Channel_Data(speed, 7 );
- // DataScope_Get_Channel_Data( 0, 8 );
- // DataScope_Get_Channel_Data(0, 9 );
- // DataScope_Get_Channel_Data( 0 , 10);
- // Send_Count = DataScope_Data_Generate(10);
- // for( i = 0 ; i < Send_Count; i++)
- // {
- // while((USART1->SR&0X40)==0);
- // USART1->DR = DataScope_OutPut_Buffer[i];
- // }
- // delay_ms(50); //20HZ
-
-
- ULTRASONIC_Distance();//600ms测距一次
- //USART_ITConfig(USART3, USART_IT_TXE, ENABLE);//使能USART3发送中断
- delay_ms(600);
- }
- }
复制代码
所有资料51hei提供下载:
平衡车.rar
(331.46 KB, 下载次数: 233)
|