uuu000

blinknew001 f103c8t6

Nov 13th, 2023
1,000
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.94 KB | None | 0 0
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * Copyright (c) 2023 STMicroelectronics.
  10.   * All rights reserved.
  11.   *
  12.   * This software is licensed under terms that can be found in the LICENSE file
  13.   * in the root directory of this software component.
  14.   * If no LICENSE file comes with this software, it is provided AS-IS.
  15.   *
  16.   ******************************************************************************
  17.   */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"
  21.  
  22. /* Private includes ----------------------------------------------------------*/
  23. /* USER CODE BEGIN Includes */
  24. #include "stdbool.h"
  25. /* USER CODE END Includes */
  26.  
  27. /* Private typedef -----------------------------------------------------------*/
  28. /* USER CODE BEGIN PTD */
  29. bool flag;
  30. unsigned long T;
  31. /* USER CODE END PTD */
  32.  
  33. /* Private define ------------------------------------------------------------*/
  34. /* USER CODE BEGIN PD */
  35. /* USER CODE END PD */
  36.  
  37. /* Private macro -------------------------------------------------------------*/
  38. /* USER CODE BEGIN PM */
  39.  
  40. /* USER CODE END PM */
  41.  
  42. /* Private variables ---------------------------------------------------------*/
  43.  
  44. /* USER CODE BEGIN PV */
  45.  
  46. /* USER CODE END PV */
  47.  
  48. /* Private function prototypes -----------------------------------------------*/
  49. void SystemClock_Config(void);
  50. static void MX_GPIO_Init(void);
  51. /* USER CODE BEGIN PFP */
  52.  
  53. /* USER CODE END PFP */
  54.  
  55. /* Private user code ---------------------------------------------------------*/
  56. /* USER CODE BEGIN 0 */
  57.  
  58. /* USER CODE END 0 */
  59.  
  60. /**
  61.   * @brief  The application entry point.
  62.   * @retval int
  63.   */
  64. int main(void)
  65. {
  66.   /* USER CODE BEGIN 1 */
  67.  
  68.   /* USER CODE END 1 */
  69.  
  70.   /* MCU Configuration--------------------------------------------------------*/
  71.  
  72.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  73.   HAL_Init();
  74.  
  75.   /* USER CODE BEGIN Init */
  76.  
  77.   /* USER CODE END Init */
  78.  
  79.   /* Configure the system clock */
  80.   SystemClock_Config();
  81.  
  82.   /* USER CODE BEGIN SysInit */
  83.  
  84.   /* USER CODE END SysInit */
  85.  
  86.   /* Initialize all configured peripherals */
  87.   MX_GPIO_Init();
  88.   /* USER CODE BEGIN 2 */
  89.  
  90.   /* USER CODE END 2 */
  91.  
  92.   /* Infinite loop */
  93.   /* USER CODE BEGIN WHILE */
  94.   while (1)
  95.   {
  96.         /* USER CODE BEGIN 3 */
  97.      // HAL_GPIO_WritePin(GPIOC,blink_Pin,0);
  98.          //HAL_Delay(500);
  99.          //HAL_GPIO_WritePin(GPIOC,blink_Pin,1);
  100.               //HAL_Delay(1500);
  101.       if(flag==1){
  102.           if(HAL_GetTick()-T>=2500)
  103.           {
  104.               flag=0;
  105.               T=HAL_GetTick();
  106.           }
  107.       }
  108.  
  109.       if(flag==0){
  110.               if(HAL_GetTick()-T>=500)
  111.               {
  112.                   flag=1;
  113.                   T=HAL_GetTick();
  114.               }
  115.           }
  116.       HAL_GPIO_WritePin(GPIOC,blink_Pin,flag);
  117.     /* USER CODE END WHILE */
  118.  
  119.     /* USER CODE BEGIN 3 */
  120.   }
  121.   /* USER CODE END 3 */
  122. }
  123.  
  124. /**
  125.   * @brief System Clock Configuration
  126.   * @retval None
  127.   */
  128. void SystemClock_Config(void)
  129. {
  130.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  131.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
  132.  
  133.   /** Initializes the RCC Oscillators according to the specified parameters
  134.   * in the RCC_OscInitTypeDef structure.
  135.   */
  136.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  137.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  138.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV1;
  139.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  140.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  141.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  142.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  143.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  144.   {
  145.     Error_Handler();
  146.   }
  147.  
  148.   /** Initializes the CPU, AHB and APB buses clocks
  149.   */
  150.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  151.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  152.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  153.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  154.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  155.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  156.  
  157.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2) != HAL_OK)
  158.   {
  159.     Error_Handler();
  160.   }
  161. }
  162.  
  163. /**
  164.   * @brief GPIO Initialization Function
  165.   * @param None
  166.   * @retval None
  167.   */
  168. static void MX_GPIO_Init(void)
  169. {
  170.   GPIO_InitTypeDef GPIO_InitStruct = {0};
  171.  
  172.   /* GPIO Ports Clock Enable */
  173.   __HAL_RCC_GPIOC_CLK_ENABLE();
  174.   __HAL_RCC_GPIOD_CLK_ENABLE();
  175.   __HAL_RCC_GPIOA_CLK_ENABLE();
  176.  
  177.   /*Configure GPIO pin Output Level */
  178.   HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, GPIO_PIN_RESET);
  179.  
  180.   /*Configure GPIO pin : PC13 */
  181.   GPIO_InitStruct.Pin = GPIO_PIN_13;
  182.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  183.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  184.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  185.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  186.  
  187. }
  188.  
  189. /* USER CODE BEGIN 4 */
  190.  
  191. /* USER CODE END 4 */
  192.  
  193. /**
  194.   * @brief  This function is executed in case of error occurrence.
  195.   * @retval None
  196.   */
  197. void Error_Handler(void)
  198. {
  199.   /* USER CODE BEGIN Error_Handler_Debug */
  200.   /* User can add his own implementation to report the HAL error return state */
  201.   __disable_irq();
  202.   while (1)
  203.   {
  204.   }
  205.   /* USER CODE END Error_Handler_Debug */
  206. }
  207.  
  208. #ifdef  USE_FULL_ASSERT
  209. /**
  210.   * @brief  Reports the name of the source file and the source line number
  211.   *         where the assert_param error has occurred.
  212.   * @param  file: pointer to the source file name
  213.   * @param  line: assert_param error line source number
  214.   * @retval None
  215.   */
  216. void assert_failed(uint8_t *file, uint32_t line)
  217. {
  218.   /* USER CODE BEGIN 6 */
  219.   /* User can add his own implementation to report the file name and line number,
  220.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  221.   /* USER CODE END 6 */
  222. }
  223. #endif /* USE_FULL_ASSERT */
  224.  
Advertisement
Add Comment
Please, Sign In to add comment