芯片解密STM32单片机+TB6612模块智能小车程序原理图
- 芯片解密#include "stm32f10x.h"
- 芯片解密#include "bsp_tb6612.h"
- 芯片解密#include "bsp_motor.h"
- #include "bsp_usart.h"
- #include "car_ctrl.h"
- int main(void)
- {
- TB6612_FR_Init(); //TB6612模块1和模块2一起驱动
-
- MotorAllOFF(); //单片机上电默认先把4个电机关闭
-
- USART3_Config(); //初始化蓝牙模块的串口
-
- while(1)
- {
- RUN_Prg(); //小车蓝牙控制功能
- }
- }
- #include "bsp_tb6612.h"
- /*TB6612模块1,驱动前轮 F*/
- void TB6612_F_GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(TB6612_F_GPIO_AIN1_CLK | TB6612_F_GPIO_AIN2_CLK | \
- TB6612_F_GPIO_BIN1_CLK | TB6612_F_GPIO_BIN2_CLK , ENABLE);
-
- GPIO_InitStructure.GPIO_Pin = TB6612_F_GPIO_AIN1_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(TB6612_F_GPIO_AIN1_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = TB6612_F_GPIO_AIN2_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(TB6612_F_GPIO_AIN2_PORT, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = TB6612_F_GPIO_BIN1_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(TB6612_F_GPIO_BIN1_PORT, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = TB6612_F_GPIO_BIN2_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(TB6612_F_GPIO_BIN2_PORT, &GPIO_InitStructure);
- }
- void TB6612_F_PWM_GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(TB6612_F_GPIO_PWMA_CH1_CLK, ENABLE);
- GPIO_InitStructure.GPIO_Pin = TB6612_F_GPIO_PWMA_CH1_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(TB6612_F_GPIO_PWMA_CH1_PORT,&GPIO_InitStructure);
-
- RCC_APB2PeriphClockCmd(TB6612_F_GPIO_PWMB_CH2_CLK, ENABLE);
- GPIO_InitStructure.GPIO_Pin = TB6612_F_GPIO_PWMB_CH2_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(TB6612_F_GPIO_PWMB_CH2_PORT,&GPIO_InitStructure);
- }
- /*TB6612模块2,驱动后轮 R*/
- void TB6612_R_GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(TB6612_R_GPIO_AIN1_CLK | TB6612_R_GPIO_AIN2_CLK | \
- TB6612_R_GPIO_BIN1_CLK | TB6612_R_GPIO_BIN2_CLK , ENABLE);
-
- GPIO_InitStructure.GPIO_Pin = TB6612_R_GPIO_AIN1_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(TB6612_R_GPIO_AIN1_PORT, &GPIO_InitStructure);
-
- GPIO_InitStructure.GPIO_Pin = TB6612_R_GPIO_AIN2_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(TB6612_R_GPIO_AIN2_PORT, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = TB6612_R_GPIO_BIN1_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(TB6612_R_GPIO_BIN1_PORT, &GPIO_InitStructure);
- GPIO_InitStructure.GPIO_Pin = TB6612_R_GPIO_BIN2_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(TB6612_R_GPIO_BIN2_PORT, &GPIO_InitStructure);
- }
- void TB6612_R_PWM_GPIO_Config(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
-
- RCC_APB2PeriphClockCmd(TB6612_R_GPIO_PWMA_CH3_CLK, ENABLE);
- GPIO_InitStructure.GPIO_Pin = TB6612_R_GPIO_PWMA_CH3_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(TB6612_R_GPIO_PWMA_CH3_PORT,&GPIO_InitStructure);
- RCC_APB2PeriphClockCmd(TB6612_R_GPIO_PWMB_CH4_CLK, ENABLE);
- GPIO_InitStructure.GPIO_Pin = TB6612_R_GPIO_PWMB_CH4_PIN;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(TB6612_R_GPIO_PWMB_CH4_PORT,&GPIO_InitStructure);
- }

芯片解密