Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.70 KB | None | 0 0
  1. /**
  2. ******************************************************************************
  3. * File Name : main.c
  4. * Description : Main program body
  5. ******************************************************************************
  6. *
  7. * COPYRIGHT(c) 2016 STMicroelectronics
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. * 1. Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright notice,
  14. * this list of conditions and the following disclaimer in the documentation
  15. * and/or other materials provided with the distribution.
  16. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. ******************************************************************************
  32. */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "stm32l1xx_hal.h"
  35.  
  36. /* USER CODE BEGIN Includes */
  37.  
  38. /* USER CODE END Includes */
  39.  
  40. /* Private variables ---------------------------------------------------------*/
  41.  
  42. /* USER CODE BEGIN PV */
  43. /* Private variables ---------------------------------------------------------*/
  44. int n;
  45. int m;
  46. /* USER CODE END PV */
  47.  
  48. /* Private function prototypes -----------------------------------------------*/
  49. void SystemClock_Config(void);
  50. static void MX_GPIO_Init(void);
  51. void bluu(){
  52.  
  53. HAL_Delay(100);
  54. HAL_GPIO_WritePin (GPIOB, LED_Pin, GPIO_PIN_SET);
  55. HAL_Delay(100);
  56. HAL_GPIO_WritePin (GPIOB, LED3_Pin, GPIO_PIN_SET);
  57. HAL_GPIO_WritePin (GPIOB, LED_Pin, GPIO_PIN_RESET);
  58. HAL_Delay(100);
  59. HAL_GPIO_WritePin (GPIOB, LED_Pin, GPIO_PIN_SET);
  60.  
  61. HAL_Delay(100);
  62. HAL_GPIO_WritePin (GPIOB, LED_Pin, GPIO_PIN_RESET);
  63. HAL_GPIO_WritePin (GPIOB, LED3_Pin, GPIO_PIN_RESET);
  64. // if (n < 30000) HAL_GPIO_WritePin (GPIOB, LED_Pin, GPIO_PIN_SET);
  65. // else HAL_GPIO_WritePin (GPIOB, LED_Pin, GPIO_PIN_RESET);
  66. }
  67. void gree(int m){
  68.  
  69.  
  70. HAL_Delay(2000);
  71. HAL_GPIO_WritePin (GPIOB, LED3_Pin, GPIO_PIN_SET);
  72. HAL_Delay(2000);
  73. HAL_GPIO_WritePin (GPIOB, LED3_Pin, GPIO_PIN_RESET);
  74.  
  75. // if (m < 3000) HAL_GPIO_WritePin (GPIOB, LED3_Pin, GPIO_PIN_SET);
  76. // else HAL_GPIO_WritePin (GPIOB, LED3_Pin, GPIO_PIN_RESET);
  77. }
  78.  
  79.  
  80.  
  81. /* USER CODE BEGIN PFP */
  82. /* Private function prototypes -----------------------------------------------*/
  83.  
  84. /* USER CODE END PFP */
  85.  
  86. /* USER CODE BEGIN 0 */
  87.  
  88. /* USER CODE END 0 */
  89.  
  90. int main(void)
  91. {
  92.  
  93. /* USER CODE BEGIN 1 */
  94.  
  95. /* USER CODE END 1 */
  96.  
  97. /* MCU Configuration----------------------------------------------------------*/
  98.  
  99. /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  100. HAL_Init();
  101.  
  102. /* Configure the system clock */
  103. SystemClock_Config();
  104.  
  105. /* Initialize all configured peripherals */
  106. MX_GPIO_Init();
  107.  
  108. /* USER CODE BEGIN 2 */
  109.  
  110. /* USER CODE END 2 */
  111.  
  112. /* Infinite loop */
  113. /* USER CODE BEGIN WHILE */
  114. while (1)
  115. {
  116.  
  117.  
  118. /* USER CODE END WHILE */
  119.  
  120. /* USER CODE BEGIN 3 */
  121. bluu();
  122.  
  123.  
  124. }
  125. /* USER CODE END 3 */
  126.  
  127. }
  128.  
  129. /** System Clock Configuration
  130. */
  131. void SystemClock_Config(void)
  132. {
  133.  
  134. RCC_OscInitTypeDef RCC_OscInitStruct;
  135. RCC_ClkInitTypeDef RCC_ClkInitStruct;
  136.  
  137. __PWR_CLK_ENABLE();
  138.  
  139. __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
  140.  
  141. RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_MSI;
  142. RCC_OscInitStruct.MSIState = RCC_MSI_ON;
  143. RCC_OscInitStruct.MSICalibrationValue = 0;
  144. RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_5;
  145. RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  146. HAL_RCC_OscConfig(&RCC_OscInitStruct);
  147.  
  148. RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK;
  149. RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_MSI;
  150. RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  151. RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
  152. RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  153. HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
  154.  
  155. HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  156.  
  157. HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  158.  
  159. /* SysTick_IRQn interrupt configuration */
  160. HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  161. }
  162.  
  163. /** Configure pins as
  164. * Analog
  165. * Input
  166. * Output
  167. * EVENT_OUT
  168. * EXTI
  169. */
  170. void MX_GPIO_Init(void)
  171. {
  172.  
  173. GPIO_InitTypeDef GPIO_InitStruct;
  174.  
  175. /* GPIO Ports Clock Enable */
  176. __GPIOB_CLK_ENABLE();
  177.  
  178. /*Configure GPIO pin : LED_Pin */
  179. GPIO_InitStruct.Pin = LED_Pin;
  180. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  181. GPIO_InitStruct.Pull = GPIO_NOPULL;
  182. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  183. HAL_GPIO_Init(LED_GPIO_Port, &GPIO_InitStruct);
  184.  
  185.  
  186. GPIO_InitStruct.Pin = LED3_Pin;
  187. GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  188. GPIO_InitStruct.Pull = GPIO_NOPULL;
  189. GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  190. HAL_GPIO_Init(LED3_GPIO_Port, &GPIO_InitStruct);
  191.  
  192.  
  193. }
  194.  
  195. /* USER CODE BEGIN 4 */
  196.  
  197. /* USER CODE END 4 */
  198.  
  199. #ifdef USE_FULL_ASSERT
  200.  
  201. /**
  202. * @brief Reports the name of the source file and the source line number
  203. * where the assert_param error has occurred.
  204. * @param file: pointer to the source file name
  205. * @param line: assert_param error line source number
  206. * @retval None
  207. */
  208. void assert_failed(uint8_t* file, uint32_t line)
  209. {
  210. /* USER CODE BEGIN 6 */
  211. /* User can add his own implementation to report the file name and line number,
  212. ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  213. /* USER CODE END 6 */
  214.  
  215. }
  216.  
  217. #endif
  218.  
  219. /**
  220. * @}
  221. */
  222.  
  223. /**
  224. * @}
  225. */
  226.  
  227. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement