Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.11 KB | None | 0 0
  1. /**
  2.   ******************************************************************************
  3.   * File Name          : main.c
  4.   * Description        : Main program body
  5.   ******************************************************************************
  6.   ** This notice applies to any and all portions of this file
  7.   * that are not between comment pairs USER CODE BEGIN and
  8.   * USER CODE END. Other portions of this file, whether
  9.   * inserted by the user or by software development tools
  10.   * are owned by their respective copyright owners.
  11.   *
  12.   * COPYRIGHT(c) 2017 STMicroelectronics
  13.   *
  14.   * Redistribution and use in source and binary forms, with or without modification,
  15.   * are permitted provided that the following conditions are met:
  16.   *   1. Redistributions of source code must retain the above copyright notice,
  17.   *      this list of conditions and the following disclaimer.
  18.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  19.   *      this list of conditions and the following disclaimer in the documentation
  20.   *      and/or other materials provided with the distribution.
  21.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  22.   *      may be used to endorse or promote products derived from this software
  23.   *      without specific prior written permission.
  24.   *
  25.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  26.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  27.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  28.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  29.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  30.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  31.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  34.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  35.   *
  36.   ******************************************************************************
  37.   */
  38. /* Includes ------------------------------------------------------------------*/
  39. #include "main.h"
  40. #include "stm32f4xx_hal.h"
  41. #include "gpio.h"
  42.  
  43. /* USER CODE BEGIN Includes */
  44.  
  45. /* USER CODE END Includes */
  46.  
  47. /* Private variables ---------------------------------------------------------*/
  48.  
  49. /* USER CODE BEGIN PV */
  50. /* Private variables ---------------------------------------------------------*/
  51.  
  52. /* USER CODE END PV */
  53.  
  54. /* Private function prototypes -----------------------------------------------*/
  55. void SystemClock_Config(void);
  56.  
  57. /* USER CODE BEGIN PFP */
  58. /* Private function prototypes -----------------------------------------------*/
  59.  
  60. /* USER CODE END PFP */
  61.  
  62. /* USER CODE BEGIN 0 */
  63.  
  64. // Variaveis auxiliares
  65.       int estoura_tempo=0;
  66.       int pressionado=0;
  67.  
  68.   /* USER CODE END 0 */
  69.  
  70. int main(void)
  71. {
  72.  
  73.   /* USER CODE BEGIN 1 */
  74.  
  75.   /* USER CODE END 1 */
  76.  
  77.   /* MCU Configuration----------------------------------------------------------*/
  78.  
  79.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  80.   HAL_Init();
  81.  
  82.   /* USER CODE BEGIN Init */
  83.  
  84.   /* USER CODE END Init */
  85.  
  86.   /* Configure the system clock */
  87.   SystemClock_Config();
  88.  
  89.   /* USER CODE BEGIN SysInit */
  90.  
  91.   /* USER CODE END SysInit */
  92.  
  93.   /* Initialize all configured peripherals */
  94.   MX_GPIO_Init();
  95.  
  96.   /* USER CODE BEGIN 2 */
  97.  
  98.   /* USER CODE END 2 */
  99.  
  100.   /* Infinite loop */
  101.   /* USER CODE BEGIN WHILE */
  102.   while (1)
  103.   {
  104.   /* USER CODE END WHILE */
  105.  
  106.   /* USER CODE BEGIN 3 */
  107.  
  108.  
  109.       // Liga Bloco Esq->Dir
  110.       if (pressionado==0) {
  111.           estoura_tempo=0;
  112.           HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_10);
  113.           HAL_Delay(100);
  114.           HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_11);
  115.           HAL_Delay(100);
  116.           HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_12);
  117.           HAL_Delay(100);
  118.           HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_13);
  119.           HAL_Delay(100);
  120.       }
  121.       else
  122.       {
  123.           HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_13);
  124.           HAL_Delay(100);
  125.           HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_12);
  126.           HAL_Delay(100);
  127.           HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_11);
  128.           HAL_Delay(100);
  129.           HAL_GPIO_TogglePin(GPIOE, GPIO_PIN_10);
  130.           HAL_Delay(100);
  131.       }
  132.   }
  133.   /* USER CODE END 3 */
  134.  
  135. }
  136.  
  137. /** System Clock Configuration
  138. */
  139. void SystemClock_Config(void)
  140. {
  141.  
  142.   RCC_OscInitTypeDef RCC_OscInitStruct;
  143.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  144.  
  145.     /**Configure the main internal regulator output voltage
  146.     */
  147.   __HAL_RCC_PWR_CLK_ENABLE();
  148.  
  149.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE3);
  150.  
  151.     /**Initializes the CPU, AHB and APB busses clocks
  152.     */
  153.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
  154.   RCC_OscInitStruct.HSIState = RCC_HSI_ON;
  155.   RCC_OscInitStruct.HSICalibrationValue = 16;
  156.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
  157.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  158.   {
  159.     _Error_Handler(__FILE__, __LINE__);
  160.   }
  161.  
  162.     /**Initializes the CPU, AHB and APB busses clocks
  163.     */
  164.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  165.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  166.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
  167.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  168.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  169.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
  170.  
  171.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)
  172.   {
  173.     _Error_Handler(__FILE__, __LINE__);
  174.   }
  175.  
  176.     /**Configure the Systick interrupt time
  177.     */
  178.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  179.  
  180.     /**Configure the Systick
  181.     */
  182.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  183.  
  184.   /* SysTick_IRQn interrupt configuration */
  185.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  186. }
  187.  
  188. /* USER CODE BEGIN 4 */
  189. void HAL_SYSTICK_Callback(void)
  190. {
  191.     if ( HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_4)== 1 ) {
  192.         estoura_tempo++;
  193.     }
  194.     if (estoura_tempo >= 20) {
  195.         pressionado=1;
  196.     }
  197. }
  198. /* USER CODE END 4 */
  199.  
  200. /**
  201.   * @brief  This function is executed in case of error occurrence.
  202.   * @param  None
  203.   * @retval None
  204.   */
  205. void _Error_Handler(char * file, int line)
  206. {
  207.   /* USER CODE BEGIN Error_Handler_Debug */
  208.   /* User can add his own implementation to report the HAL error return state */
  209.   while(1)
  210.   {
  211.   }
  212.   /* USER CODE END Error_Handler_Debug */
  213. }
  214.  
  215. #ifdef USE_FULL_ASSERT
  216.  
  217. /**
  218.    * @brief Reports the name of the source file and the source line number
  219.    * where the assert_param error has occurred.
  220.    * @param file: pointer to the source file name
  221.    * @param line: assert_param error line source number
  222.    * @retval None
  223.    */
  224. void assert_failed(uint8_t* file, uint32_t line)
  225. {
  226.   /* USER CODE BEGIN 6 */
  227.   /* User can add his own implementation to report the file name and line number,
  228.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  229.   /* USER CODE END 6 */
  230.  
  231. }
  232.  
  233. #endif
  234.  
  235. /**
  236.   * @}
  237.   */
  238.  
  239. /**
  240.   * @}
  241. */
  242.  
  243. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement