平衡车全部资料
合集下载
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
}
//PA0的引脚中断函数
void EXTI0_IRQHandler(void)
{
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1)==1) //检测B相位高电平,正转
{
count_left++;
}
else //反转
{
count_left--;
}
//清除中断标志位
EXTI_ClearITPendingBit(EXTI_Line0);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
GPIO_Initstructure.GPIO_Mode = GPIO_Mode_IPU; //设置端口为上拉输入模式
GPIO_Initstructure.GPIO_Pin = GPIO_Pin_1;
}
//PB12的引脚中断函数
void EXTI15_10_IRQHandler(void)
{
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13)==1) //检测B相位高电平,正转
{
count_right++;
}
else //反转
{
count_right--;
}
//清除中断标志位
GPIO_Init(GPIOA,&GPIO_Initstructure); //初始化端口
GPIO_Initstructure.GPIO_Mode = GPIO_Mode_IPU; //设置端口为上拉输入模式
GPIO_Initstructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOB,&GPIO_Initstructure); //初始化端口
EXTI_Initstructure.EXTI_Line = EXTI_Line12;
EXTI_Initstructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_Initstructure.EXTI_Trigger = EXTI_Trigger_Falling; //xiajiang沿触发中断
NVIC_Initstructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_Initstructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_Initstructure.NVIC_IRQChannelSubPriority = 3;
GPIO_Initstructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Initstructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOB,&GPIO_Initstructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource12);
EXTI_Initstructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_Initstructure);
}
static void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_Initstructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk;
USART1_Config(); //======串口1初始化,用于调试设备
PWM_Init(); //======初始化PWM,控制电机
USART3_Config(); //======串口3初始化,用于蓝牙的数据传输
EXTI_PA0_Config(); //======编码器的中断初始化
{
GPIO_InitTypeDef GPIO_Initstructure;
EXTI_InitTypeDef EXTI_Initstructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);
NVIC1_Configuration();
EXTI_ClearITPendingBit(EXTI_Line12);
}
/**************************************************************************
函数功能:把TIM4初始化为编码器接口模式
入口参数:无
返回值:无
**************************************************************************/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//使能PB端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;//端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
GPIO_Initstructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Initstructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA,&GPIO_Initstructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
EXTI_Initstructure.EXTI_Line = EXTI_Line0;
EXTI_Initstructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_Initstructure.EXTI_Trigger = EXTI_Trigger_Falling; //上升沿触发中断
NVIC_Initstructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_Initstructure);
}
//外部中断PB12的中断引脚初始化
static void NVIC1_Configuration(void)
{
NVIC_InitTypeDef NVIC_Initstructure;
{
GPIO_InitTypeDef GPIO_Initstructure;
EXTI_InitTypeDef EXTI_Initstructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);
NVIC_Configuration();
如图片所示
想要有关平衡车
倒立摆
四轴无人机的全部资料
就加QQ1127738761
#include "encoder.h"
#include "bsp_usart1.h"
int16_t count_left, count_right;
//外部中断PA0的中断引脚初始化
void EXTI_PA0_Config(void)
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter = 10;
TIM_ICInit(TIM4, &TIM_ICInitStructure);
TIM_ClearFlag(TIM4, TIM_FLAG_Update);//清除TIM的更新标志位
NVIC_Initstructure.NVIC_IRQChannelSubPriority = 3;
NVIC_Initstructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_Initstructure);
}
void EXTI_PB12_Config(void)
#include "Timer2.h"
#include "encoder.h"
#include "motor.h"
#include "bsp_usart1.h"
#include "control.h"
#include "bule_tooth.h"
int main(void)Biblioteka Baidu
{
SysTick_Init(); //=====初始化systick
GPIO_Init(GPIOB, &GPIO_InitStructure);//根据设定参数初始化GPIOB
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Prescaler = 0x0; // 预分频器
TIM2_NVIC_Configuration();
while(1)
{
//printf("Z%d:%d:%fL$", speed_left, speed_right, Pitch); //利用蓝牙的串口输出三个参数在手机上进行显示
}
}
/*********************************************END OF FILE**********************/
#include "stm32f10x.h"
#include "stm32f10x_it.h"
#include "bsp_SysTick.h"
#include "mpu6050.h"
#include "bsp_i2c.h"
#include "5110.h"
#include "output.h"
#include "filter.h"
EXTI_PB12_Config();
encoder_GPIO_Config();
i2c_GPIO_Config(); //======I2C初始化
MPU6050_Init(); //======MPU6050初始化
TIM2_Configuration(); //======MPU6050的5ms的定时中断
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM4, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);//使用编码器模式3
TIM_TimeBaseStructure.TIM_Period = ENCODER_TIM_PERIOD; //设定计数器自动重装值
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;//选择时钟分频:不分频
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;////TIM向上计数
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_Initstructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_Initstructure.NVIC_IRQChannelPreemptionPriority = 1;
void Encoder_Init_TIM4(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);//使能定时器4的时钟
EXTI_Initstructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_Initstructure);
}
//读取左右两个编码器的B相的电平信号
void encoder_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_Initstructure;
//PA0的引脚中断函数
void EXTI0_IRQHandler(void)
{
if(GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_1)==1) //检测B相位高电平,正转
{
count_left++;
}
else //反转
{
count_left--;
}
//清除中断标志位
EXTI_ClearITPendingBit(EXTI_Line0);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB, ENABLE);
GPIO_Initstructure.GPIO_Mode = GPIO_Mode_IPU; //设置端口为上拉输入模式
GPIO_Initstructure.GPIO_Pin = GPIO_Pin_1;
}
//PB12的引脚中断函数
void EXTI15_10_IRQHandler(void)
{
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_13)==1) //检测B相位高电平,正转
{
count_right++;
}
else //反转
{
count_right--;
}
//清除中断标志位
GPIO_Init(GPIOA,&GPIO_Initstructure); //初始化端口
GPIO_Initstructure.GPIO_Mode = GPIO_Mode_IPU; //设置端口为上拉输入模式
GPIO_Initstructure.GPIO_Pin = GPIO_Pin_13;
GPIO_Init(GPIOB,&GPIO_Initstructure); //初始化端口
EXTI_Initstructure.EXTI_Line = EXTI_Line12;
EXTI_Initstructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_Initstructure.EXTI_Trigger = EXTI_Trigger_Falling; //xiajiang沿触发中断
NVIC_Initstructure.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_Initstructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_Initstructure.NVIC_IRQChannelSubPriority = 3;
GPIO_Initstructure.GPIO_Pin = GPIO_Pin_12;
GPIO_Initstructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOB,&GPIO_Initstructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOB,GPIO_PinSource12);
EXTI_Initstructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_Initstructure);
}
static void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_Initstructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
SysTick->CTRL|=SysTick_CTRL_ENABLE_Msk;
USART1_Config(); //======串口1初始化,用于调试设备
PWM_Init(); //======初始化PWM,控制电机
USART3_Config(); //======串口3初始化,用于蓝牙的数据传输
EXTI_PA0_Config(); //======编码器的中断初始化
{
GPIO_InitTypeDef GPIO_Initstructure;
EXTI_InitTypeDef EXTI_Initstructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);
NVIC1_Configuration();
EXTI_ClearITPendingBit(EXTI_Line12);
}
/**************************************************************************
函数功能:把TIM4初始化为编码器接口模式
入口参数:无
返回值:无
**************************************************************************/
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);//使能PB端口时钟
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8|GPIO_Pin_9;//端口配置
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; //浮空输入
GPIO_Initstructure.GPIO_Pin = GPIO_Pin_0;
GPIO_Initstructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_Init(GPIOA,&GPIO_Initstructure);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA,GPIO_PinSource0);
EXTI_Initstructure.EXTI_Line = EXTI_Line0;
EXTI_Initstructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_Initstructure.EXTI_Trigger = EXTI_Trigger_Falling; //上升沿触发中断
NVIC_Initstructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_Initstructure);
}
//外部中断PB12的中断引脚初始化
static void NVIC1_Configuration(void)
{
NVIC_InitTypeDef NVIC_Initstructure;
{
GPIO_InitTypeDef GPIO_Initstructure;
EXTI_InitTypeDef EXTI_Initstructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);
NVIC_Configuration();
如图片所示
想要有关平衡车
倒立摆
四轴无人机的全部资料
就加QQ1127738761
#include "encoder.h"
#include "bsp_usart1.h"
int16_t count_left, count_right;
//外部中断PA0的中断引脚初始化
void EXTI_PA0_Config(void)
TIM_ICStructInit(&TIM_ICInitStructure);
TIM_ICInitStructure.TIM_ICFilter = 10;
TIM_ICInit(TIM4, &TIM_ICInitStructure);
TIM_ClearFlag(TIM4, TIM_FLAG_Update);//清除TIM的更新标志位
NVIC_Initstructure.NVIC_IRQChannelSubPriority = 3;
NVIC_Initstructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_Initstructure);
}
void EXTI_PB12_Config(void)
#include "Timer2.h"
#include "encoder.h"
#include "motor.h"
#include "bsp_usart1.h"
#include "control.h"
#include "bule_tooth.h"
int main(void)Biblioteka Baidu
{
SysTick_Init(); //=====初始化systick
GPIO_Init(GPIOB, &GPIO_InitStructure);//根据设定参数初始化GPIOB
TIM_TimeBaseStructInit(&TIM_TimeBaseStructure);
TIM_TimeBaseStructure.TIM_Prescaler = 0x0; // 预分频器
TIM2_NVIC_Configuration();
while(1)
{
//printf("Z%d:%d:%fL$", speed_left, speed_right, Pitch); //利用蓝牙的串口输出三个参数在手机上进行显示
}
}
/*********************************************END OF FILE**********************/
#include "stm32f10x.h"
#include "stm32f10x_it.h"
#include "bsp_SysTick.h"
#include "mpu6050.h"
#include "bsp_i2c.h"
#include "5110.h"
#include "output.h"
#include "filter.h"
EXTI_PB12_Config();
encoder_GPIO_Config();
i2c_GPIO_Config(); //======I2C初始化
MPU6050_Init(); //======MPU6050初始化
TIM2_Configuration(); //======MPU6050的5ms的定时中断
TIM_TimeBaseInit(TIM4, &TIM_TimeBaseStructure);
TIM_EncoderInterfaceConfig(TIM4, TIM_EncoderMode_TI12, TIM_ICPolarity_Rising, TIM_ICPolarity_Rising);//使用编码器模式3
TIM_TimeBaseStructure.TIM_Period = ENCODER_TIM_PERIOD; //设定计数器自动重装值
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;//选择时钟分频:不分频
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;////TIM向上计数
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_Initstructure.NVIC_IRQChannel = EXTI15_10_IRQn;
NVIC_Initstructure.NVIC_IRQChannelPreemptionPriority = 1;
void Encoder_Init_TIM4(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_ICInitTypeDef TIM_ICInitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE);//使能定时器4的时钟
EXTI_Initstructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_Initstructure);
}
//读取左右两个编码器的B相的电平信号
void encoder_GPIO_Config(void)
{
GPIO_InitTypeDef GPIO_Initstructure;