Advertisement
Guest User

Untitled

a guest
Dec 12th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.25 KB | None | 0 0
  1.  
  2. /**
  3. * @brief The application entry point.
  4. * @retval None
  5. */
  6. int main(void)
  7. {
  8. HAL_Init();
  9. SystemClock_Config();
  10. MX_GPIO_Init(); // init GPIO PA5, PB4 and PA0
  11.  
  12. // endless loop
  13. while (1)
  14. {
  15. Buttons_GetState ();
  16. grafiaks2 ();
  17. //grafikas1 ();
  18. //ms1020 ();
  19. // LEDsSwitching();
  20. // LEDsSwitchingDelay();
  21. }
  22. }
  23.  
  24. /**
  25. * @brief System Clock Configuration
  26. * @retval None
  27. */
  28. void SystemClock_Config(void)
  29. {
  30.  
  31. RCC_OscInitTypeDef RCC_OscInitStruct;
  32. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  33.  
  34. /**Configure the main internal regulator output voltage
  35. */
  36. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  37.  
  38. /**Initializes the CPU, AHB and APB busses clocks
  39. */
  40. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  41. RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  42. RCC_OscInitStruct.HSICalibrationValue = 16;
  43. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  44. RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
  45. RCC_OscInitStruct.PLL.PLLMUL = RCC_PLLMUL_4;
  46. RCC_OscInitStruct.PLL.PLLDIV = RCC_PLLDIV_2;
  47. if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  48. {
  49. _Error_Handler(__FILE__, __LINE__);
  50. }
  51.  
  52. /**Initializes the CPU, AHB and APB busses clocks
  53. */
  54. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  55. |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  56. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  57. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  58. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  59. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  60.  
  61. if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)
  62. {
  63. _Error_Handler(__FILE__, __LINE__);
  64. }
  65.  
  66. /**Configure the Systick interrupt time for 1ms
  67. */
  68. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  69.  
  70. /**Configure the Systick
  71. */
  72. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  73.  
  74. /* SysTick_IRQn interrupt configuration */
  75. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  76. }
  77.  
  78. /** Configure pins as
  79. * Analog
  80. * Input
  81. * Output
  82. * EVENT_OUT
  83. * EXTI
  84. */
  85. static void MX_GPIO_Init(void)
  86. {
  87.  
  88. GPIO_InitTypeDef GPIO_InitStruct;
  89.  
  90. /* GPIO Ports Clock Enable */
  91. __HAL_RCC_GPIOA_CLK_ENABLE();
  92. __HAL_RCC_GPIOB_CLK_ENABLE();
  93.  
  94. /*Configure GPIO pin Output Level */
  95. HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET);
  96.  
  97. /*Configure GPIO pin : PA0 */
  98. GPIO_InitStruct.Pin = GPIO_PIN_0;
  99. GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  100. GPIO_InitStruct.Pull = GPIO_NOPULL;
  101. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  102.  
  103.  
  104. /*Configure GPIO pin : PB4 */
  105. GPIO_InitStruct.Pin = GPIO_PIN_4;
  106. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  107. GPIO_InitStruct.Pull = GPIO_NOPULL;
  108. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  109. HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
  110.  
  111. GPIO_InitStruct.Pin = GPIO_PIN_5;
  112. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  113. GPIO_InitStruct.Pull = GPIO_NOPULL;
  114. GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  115. HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
  116.  
  117. }
  118.  
  119. /* USER CODE BEGIN 4 */
  120.  
  121. /* USER CODE END 4 */
  122.  
  123. /**
  124. * @brief This function is executed in case of error occurrence.
  125. * @param file: The file name as string.
  126. * @param line: The line in file as a number.
  127. * @retval None
  128. */
  129. void _Error_Handler(char *file, int line)
  130. {
  131. /* USER CODE BEGIN Error_Handler_Debug */
  132. /* User can add his own implementation to report the HAL error return state */
  133. while(1)
  134. {
  135. }
  136. /* USER CODE END Error_Handler_Debug */
  137. }
  138.  
  139. #ifdef USE_FULL_ASSERT
  140. /**
  141. * @brief Reports the name of the source file and the source line number
  142. * where the assert_param error has occurred.
  143. * @param file: pointer to the source file name
  144. * @param line: assert_param error line source number
  145. * @retval None
  146. */
  147. void assert_failed(uint8_t* file, uint32_t line)
  148. {
  149. /* USER CODE BEGIN 6 */
  150. /* User can add his own implementation to report the file name and line number,
  151. tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  152. /* USER CODE END 6 */
  153. }
  154. #endif /* USE_FULL_ASSERT */
  155.  
  156. /**
  157. * @}
  158. */
  159.  
  160. /**
  161. * @}
  162. */
  163.  
  164. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement