TIM

貌似只能执行到 HAL_GPIO_WritePin(GPIOA, BCM_CLOSE_OUT_Pin, GPIO_PIN_SET); 看了两天了,新手求指教

#include "main.h"

#include "tim.h"

#include "usart.h"

#include "gpio.h"


#include "anjianzhuangtai.h"


void SystemClock_Config(void);


extern uint8_t BCM_CLOSE_STATE;


uint16_t timer_count;



int main(void)

{

  HAL_Init();


  SystemClock_Config();


  MX_GPIO_Init();

  MX_USART2_UART_Init();

  MX_TIM2_Init();


  HAL_TIM_Base_Start_IT(&htim2);


  while (1)

  {

if(BCM_CLOSE_STATE == 0)

{

timer_count=0;

++timer_count;

HAL_GPIO_WritePin(GPIOA, BCM_CLOSE_OUT_Pin, GPIO_PIN_SET);

if(timer_count == 1000)

{

BCM_CLOSE_STATE = 1 ;

HAL_GPIO_WritePin(GPIOA, BCM_CLOSE_OUT_Pin, GPIO_PIN_SET);

timer_count=0;

}

}

anjianzhuangtai();

  }

}



void SystemClock_Config(void)

{

  RCC_OscInitTypeDef RCC_OscInitStruct = {0};

  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};


  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;

  RCC_OscInitStruct.HSEState = RCC_HSE_ON;

  RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV2;

  RCC_OscInitStruct.HSIState = RCC_HSI_ON;

  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;

  RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;

  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

  {

    Error_Handler();

  }


  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;

  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;


  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)

  {

    Error_Handler();

  }

}


/* USER CODE BEGIN 4 */


void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* tim_baseHandle)

{


  if(tim_baseHandle->Instance==TIM2)

  {

timer_count++;

}

}


/* USER CODE END 4 */


void Error_Handler(void)

{


}


#ifdef  USE_FULL_ASSERT


void assert_failed(uint8_t *file, uint32_t line)


}

#endif 



已邀请:

colin2135 - 我长得很帅,大家都这么说。

赞同来自:

Debug模式,单步执行就知道了

要回复问题请先登录注册