bldc/firmware/src/User/main.c

101 lines
3.4 KiB
C
Raw Normal View History

2020-10-20 14:43:40 +00:00
/*******************************************************************************
* @file main.c
* @author: MQjehovah mail:MQjehovah@hotmail.com
* @version 1.0.0
* @date 2017.5.9
* @brief
******************************************************************************
* @attention
*******************************************************************************/
/* Includes ------------------------------------------------------------------*/
#include "main.h"
#include "stdio.h"
/* Definition ----------------------------------------------------------------*/
/* Functions -----------------------------------------------------------------*/
/*******************************************************************************
* @brief
* @param None
* @retval None
* @Note None
*******************************************************************************/
void RCC_Config()
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOC, ENABLE);
2020-10-21 09:28:47 +00:00
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_USART1, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_TIM1, ENABLE);
2020-10-20 14:43:40 +00:00
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4, ENABLE);
}
2020-10-23 11:11:06 +00:00
/*******************************************************************************
* @brief
* @param None
* @retval None
* @Note None
*******************************************************************************/
void test(void)
{
motor_init();
motor_start();
delay_ms(5000);
motor_set_speed(100);
delay_ms(5000);
motor_set_speed(300);
delay_ms(5000);
motor_set_speed(500);
delay_ms(5000);
motor_set_speed(700);
motor_info.dir = MOTOR_DIR_CW;
delay_ms(5000);
motor_set_speed(900);
delay_ms(5000);
motor_set_speed(1200);
delay_ms(5000);
motor_set_speed(1400);
delay_ms(5000);
}
2020-10-20 14:43:40 +00:00
/*******************************************************************************
* @brief
* @param None
* @retval None
* @Note None
*******************************************************************************/
void NVIC_Config(void) //配置中断优先级
{
// NVIC_InitTypeDef NVIC_InitStructure;
//
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
// NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
// NVIC_Init(&NVIC_InitStructure);
}
2020-10-23 11:11:06 +00:00
2020-10-20 14:43:40 +00:00
/*******************************************************************************
* @brief
* @param None
* @retval None
* @Note None
*******************************************************************************/
int main(void)
{
RCC_Config();
NVIC_Config();
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable, ENABLE); //关闭jtag保留swd。
SysTick_init();
HALL_Config();
2020-10-21 09:28:47 +00:00
PWM_Config();
2020-10-23 11:11:06 +00:00
CAN1_Config();
test();
2020-10-20 14:43:40 +00:00
while (1)
{
2020-10-23 11:11:06 +00:00
LED_ON(1);
2020-10-22 11:35:40 +00:00
delay_ms(500);
2020-10-23 11:11:06 +00:00
LED_OFF(1);
2020-10-20 14:43:40 +00:00
delay_ms(500);
}
}
2020-10-23 11:11:06 +00:00
2020-10-20 14:43:40 +00:00
/*********************************END OF FILE**********************************/