101 lines
3.4 KiB
C
101 lines
3.4 KiB
C
/*******************************************************************************
|
||
* @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);
|
||
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_USART1, ENABLE);
|
||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_TIM1, ENABLE);
|
||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 | RCC_APB1Periph_TIM3 | RCC_APB1Periph_TIM4, ENABLE);
|
||
}
|
||
|
||
/*******************************************************************************
|
||
* @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);
|
||
}
|
||
|
||
/*******************************************************************************
|
||
* @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);
|
||
}
|
||
|
||
/*******************************************************************************
|
||
* @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();
|
||
PWM_Config();
|
||
CAN1_Config();
|
||
test();
|
||
while (1)
|
||
{
|
||
LED_ON(1);
|
||
delay_ms(500);
|
||
LED_OFF(1);
|
||
delay_ms(500);
|
||
}
|
||
}
|
||
|
||
/*********************************END OF FILE**********************************/
|