Advertisement
nontawat1996

Assignment-Interface V.1 (not Completed)

Apr 19th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 16.81 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 "stm32f1xx_hal.h"
  35.  
  36. /* USER CODE BEGIN Includes */
  37. #include <string.h>
  38. #include <stdlib.h>
  39. /* USER CODE END Includes */
  40.  
  41. /* Private variables ---------------------------------------------------------*/
  42. ADC_HandleTypeDef hadc1;
  43.  
  44. SPI_HandleTypeDef hspi3;
  45.  
  46. TIM_HandleTypeDef htim1;
  47.  
  48. UART_HandleTypeDef huart2;
  49.  
  50. /* USER CODE BEGIN PV */
  51. /* Private variables ---------------------------------------------------------*/
  52. int Time = 30;
  53. int Timeleft = 30;
  54. char StartMessage[] = "Start Game !!\r\n";
  55. char ADCBarMessage[] = "Your Password bar at below !!\r\n";
  56. int Password[4];
  57. int randomNumber;
  58. int countMs=0;
  59. int currentDigit;
  60. /* USER CODE END PV */
  61.  
  62. /* Private function prototypes -----------------------------------------------*/
  63. void SystemClock_Config(void);
  64. static void MX_GPIO_Init(void);
  65. static void MX_ADC1_Init(void);
  66. static void MX_SPI3_Init(void);
  67. static void MX_TIM1_Init(void);
  68. static void MX_USART2_UART_Init(void);
  69.  
  70. /* USER CODE BEGIN PFP */
  71. /* Private function prototypes -----------------------------------------------*/
  72. void displayGate();
  73. void displayBar(uint16_t);
  74. int reverse_bits(int);
  75. /* USER CODE END PFP */
  76.  
  77. /* USER CODE BEGIN 0 */
  78. int reverse_bits (int num)
  79. {
  80.    int result;
  81.  
  82.    result = (16 & (num<<4));
  83.  
  84.    result = (result | ((8 & num<<2)));
  85.  
  86.    result = (result | (4 & num));
  87.  
  88.    result = (result | ((2 & num>>2)));
  89.  
  90.    result = (result | ((1 & num>>4)));
  91.  
  92.    return result;
  93. }
  94.  
  95. void displayGate(){
  96.   char str [] = "\n\r0 1 2 3 4 5 6 7 8 9\n\r";
  97.                    
  98.   while(__HAL_UART_GET_FLAG(&huart2,UART_FLAG_TC)==RESET){}
  99.   HAL_UART_Transmit(&huart2, (uint8_t*) str, strlen(str),1000);
  100. }
  101.  
  102. void displayBar(uint16_t level){
  103.   char str[20];
  104.   char bar = 178;  
  105.   int i = 0;
  106.  
  107.   switch(level){
  108.     case 0 : i = 1; break;
  109.     case 1 : i = 3; break;
  110.     case 2 : i = 5; break;
  111.     case 3 : i = 7; break;
  112.     case 4 : i = 9; break;
  113.     case 5 : i = 11; break;
  114.     case 6 : i = 13; break;
  115.     case 7 : i = 15; break;
  116.     case 8 : i = 17; break;
  117.     case 9 : i = 19; break;  
  118.   }
  119.   int k;
  120.  
  121.   for(k=0;k<i;k++)
  122.     str[k] = bar;
  123.   for(k=i;k<20;k++)
  124.     str[k] = ' ';
  125.   str[20] = '\0';
  126.  
  127.   while(__HAL_UART_GET_FLAG(&huart2,UART_FLAG_TC)==RESET){}
  128.   HAL_UART_Transmit(&huart2, (uint8_t*) "\r", 2,1000);
  129.  
  130.   while(__HAL_UART_GET_FLAG(&huart2,UART_FLAG_TC)==RESET){}
  131.   HAL_UART_Transmit(&huart2, (uint8_t*) str, strlen(str),1000);
  132. }
  133. /* USER CODE END 0 */
  134.  
  135. int main(void)
  136. {
  137.  
  138.   /* USER CODE BEGIN 1 */
  139.  
  140.   /* USER CODE END 1 */
  141.  
  142.   /* MCU Configuration----------------------------------------------------------*/
  143.  
  144.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  145.   HAL_Init();
  146.  
  147.   /* Configure the system clock */
  148.   SystemClock_Config();
  149.  
  150.   /* Initialize all configured peripherals */
  151.   MX_GPIO_Init();
  152.   MX_ADC1_Init();
  153.   MX_SPI3_Init();
  154.   MX_TIM1_Init();
  155.   MX_USART2_UART_Init();
  156.  
  157.   /* USER CODE BEGIN 2 */
  158.  
  159.   /* USER CODE END 2 */
  160.  
  161.   /* Infinite loop */
  162.   /* USER CODE BEGIN WHILE */
  163.   volatile uint16_t adc_val;
  164.   volatile uint16_t level;
  165.  
  166.   while (1)
  167.   {
  168.     // if press start button
  169.     if(HAL_GPIO_ReadPin(TCS_GPIO_PORT,TCS_PEN_PIN)== GPIO_PIN_RESET){
  170.  
  171.       //Output to UART2
  172.       HAL_UART_Transmit(&huart2, (uint8_t*) StartMessage, strlen(StartMessage), 500);
  173.  
  174.       HAL_GPIO_WritePin(GPIOE, GPIO_PIN_ALL, GPIO_PIN_RESET);
  175.  
  176.       //random Password
  177.       srand(time(NULL));
  178.       randomNumber = rand()%10;
  179.       Password[0] = randomNumber;
  180.  
  181.       srand(time(NULL));
  182.       randomNumber = rand()%10;
  183.       Password[1] = randomNumber;
  184.  
  185.       srand(time(NULL));
  186.       randomNumber = rand()%10;
  187.       Password[2] = randomNumber;
  188.  
  189.       srand(time(NULL));
  190.       randomNumber = rand()%10;
  191.       Password[3] = randomNumber;
  192.  
  193.       // Create Screen to playing
  194.  
  195.       //Playing Screen
  196.       // Settime
  197.       Timeleft = Time;
  198.       countMs = 0;
  199.       currentDigit = 0;
  200.       HAL_UART_Transmit(&huart2, (uint8_t*) ADCBarMessage, strlen(ADCBarMessage), 500);
  201.  
  202.       While(Timeleft>0) {
  203.         displayGate();
  204.         while(HAL_ADC_PollForConversion(&hadc1,100)!=HAL_OK){}
  205.         adc_val = HAL_ADC_GetValue(&hadc1);
  206.  
  207.         int level = adc_val/409.6;
  208.         displayBar(level);
  209.  
  210.         level = reverse_bits(level);
  211.  
  212.         GPIOE->BSRR = 0xFF000000;
  213.         GPIOE->BSRR = level<<8;
  214.  
  215.         HAL_Delay(300);
  216.  
  217.         if (level == Password[currentDigit])
  218.         {
  219.           //next password
  220.           currentDigit++;
  221.           if (currentDigit == 4)
  222.           {
  223.             // Winner !!!!!!!!
  224.           }
  225.         }
  226.       }
  227.       //End Screen
  228.  
  229.     }
  230.   /* USER CODE END WHILE */
  231.  
  232.   /* USER CODE BEGIN 3 */
  233.  
  234.   }
  235.   /* USER CODE END 3 */
  236.  
  237. }
  238.  
  239. /** System Clock Configuration
  240. */
  241. void SystemClock_Config(void)
  242. {
  243.  
  244.   RCC_OscInitTypeDef RCC_OscInitStruct;
  245.   RCC_ClkInitTypeDef RCC_ClkInitStruct;
  246.   RCC_PeriphCLKInitTypeDef PeriphClkInit;
  247.  
  248.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  249.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  250.   RCC_OscInitStruct.HSEPredivValue = RCC_HSE_PREDIV_DIV5;
  251.   RCC_OscInitStruct.Prediv1Source = RCC_PREDIV1_SOURCE_PLL2;
  252.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  253.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  254.   RCC_OscInitStruct.PLL.PLLMUL = RCC_PLL_MUL9;
  255.   RCC_OscInitStruct.PLL2.PLL2State = RCC_PLL2_ON;
  256.   RCC_OscInitStruct.PLL2.PLL2MUL = RCC_PLL2_MUL8;
  257.   RCC_OscInitStruct.PLL2.HSEPrediv2Value = RCC_HSE_PREDIV2_DIV5;
  258.   HAL_RCC_OscConfig(&RCC_OscInitStruct);
  259.  
  260.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1;
  261.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  262.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  263.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2;
  264.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
  265.   HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2);
  266.  
  267.   PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_ADC;
  268.   PeriphClkInit.AdcClockSelection = RCC_ADCPCLK2_DIV6;
  269.   HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
  270.  
  271.   HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
  272.  
  273.   HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
  274.  
  275.   __HAL_RCC_PLLI2S_ENABLE();
  276.  
  277.   /* SysTick_IRQn interrupt configuration */
  278.   HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
  279. }
  280.  
  281. /* ADC1 init function */
  282. void MX_ADC1_Init(void)
  283. {
  284.  
  285.   ADC_ChannelConfTypeDef sConfig;
  286.  
  287.     /**Common config
  288.     */
  289.   hadc1.Instance = ADC1;
  290.   hadc1.Init.ScanConvMode = ADC_SCAN_DISABLE;
  291.   hadc1.Init.ContinuousConvMode = ENABLE;
  292.   hadc1.Init.DiscontinuousConvMode = DISABLE;
  293.   hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  294.   hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  295.   hadc1.Init.NbrOfConversion = 1;
  296.   HAL_ADC_Init(&hadc1);
  297.  
  298.     /**Configure Regular Channel
  299.     */
  300.   sConfig.Channel = ADC_CHANNEL_14;
  301.   sConfig.Rank = 1;
  302.   sConfig.SamplingTime = ADC_SAMPLETIME_1CYCLE_5;
  303.   HAL_ADC_ConfigChannel(&hadc1, &sConfig);
  304.  
  305. }
  306.  
  307. /* SPI3 init function */
  308. void MX_SPI3_Init(void)
  309. {
  310.  
  311.   hspi3.Instance = SPI3;
  312.   hspi3.Init.Mode = SPI_MODE_MASTER;
  313.   hspi3.Init.Direction = SPI_DIRECTION_2LINES;
  314.   hspi3.Init.DataSize = SPI_DATASIZE_8BIT;
  315.   hspi3.Init.CLKPolarity = SPI_POLARITY_HIGH;
  316.   hspi3.Init.CLKPhase = SPI_PHASE_2EDGE;
  317.   hspi3.Init.NSS = SPI_NSS_SOFT;
  318.   hspi3.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
  319.   hspi3.Init.FirstBit = SPI_FIRSTBIT_MSB;
  320.   hspi3.Init.TIMode = SPI_TIMODE_DISABLED;
  321.   hspi3.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLED;
  322.   hspi3.Init.CRCPolynomial = 10;
  323.   HAL_SPI_Init(&hspi3);
  324.  
  325. }
  326.  
  327. /* TIM1 init function */
  328. void MX_TIM1_Init(void)
  329. {
  330.  
  331.   TIM_ClockConfigTypeDef sClockSourceConfig;
  332.   TIM_MasterConfigTypeDef sMasterConfig;
  333.  
  334.   htim1.Instance = TIM1;
  335.   htim1.Init.Prescaler = 72-1;
  336.   htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
  337.   htim1.Init.Period = 1000-1;
  338.   htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
  339.   htim1.Init.RepetitionCounter = 0;
  340.   HAL_TIM_Base_Init(&htim1);
  341.  
  342.   sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
  343.   HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig);
  344.  
  345.   sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
  346.   sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
  347.   HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig);
  348.  
  349. }
  350.  
  351. /* USART2 init function */
  352. void MX_USART2_UART_Init(void)
  353. {
  354.  
  355.   huart2.Instance = USART2;
  356.   huart2.Init.BaudRate = 115200;
  357.   huart2.Init.WordLength = UART_WORDLENGTH_8B;
  358.   huart2.Init.StopBits = UART_STOPBITS_1;
  359.   huart2.Init.Parity = UART_PARITY_NONE;
  360.   huart2.Init.Mode = UART_MODE_TX_RX;
  361.   huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  362.   huart2.Init.OverSampling = UART_OVERSAMPLING_16;
  363.   HAL_UART_Init(&huart2);
  364.  
  365. }
  366.  
  367. /** Configure pins as
  368.         * Analog
  369.         * Input
  370.         * Output
  371.         * EVENT_OUT
  372.         * EXTI
  373. */
  374. void MX_GPIO_Init(void)
  375. {
  376.  
  377.   GPIO_InitTypeDef GPIO_InitStruct;
  378.  
  379.   /* GPIO Ports Clock Enable */
  380.   __HAL_RCC_GPIOE_CLK_ENABLE();
  381.   __HAL_RCC_GPIOC_CLK_ENABLE();
  382.   __HAL_RCC_GPIOD_CLK_ENABLE();
  383.  
  384.   /*Configure GPIO pins : PE3 PE4 */
  385.   GPIO_InitStruct.Pin = GPIO_PIN_3|GPIO_PIN_4;
  386.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  387.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  388.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  389.  
  390.   /*Configure GPIO pins : PE5 PE6 PE7 */
  391.   GPIO_InitStruct.Pin = GPIO_PIN_5|GPIO_PIN_6|GPIO_PIN_7;
  392.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  393.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  394.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  395.  
  396.   /*Configure GPIO pins : PE8 PE9 PE10 PE11
  397.                            PE12 PE13 PE14 PE15 */
  398.   GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
  399.                           |GPIO_PIN_12|GPIO_PIN_13|GPIO_PIN_14|GPIO_PIN_15;
  400.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  401.   GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
  402.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
  403.  
  404.   /*Configure GPIO pin : PC8 */
  405.   GPIO_InitStruct.Pin = GPIO_PIN_8;
  406.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  407.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  408.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
  409.  
  410.   /*Configure GPIO pin : PD7 */
  411.   GPIO_InitStruct.Pin = GPIO_PIN_7;
  412.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  413.   GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
  414.   HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
  415.  
  416. }
  417.  
  418. /* USER CODE BEGIN 4 */
  419.  
  420. /* USER CODE END 4 */
  421.  
  422. #ifdef USE_FULL_ASSERT
  423.  
  424. /**
  425.    * @brief Reports the name of the source file and the source line number
  426.    * where the assert_param error has occurred.
  427.    * @param file: pointer to the source file name
  428.    * @param line: assert_param error line source number
  429.    * @retval None
  430.    */
  431. void assert_failed(uint8_t* file, uint32_t line)
  432. {
  433.   /* USER CODE BEGIN 6 */
  434.   /* User can add his own implementation to report the file name and line number,
  435.     ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  436.   /* USER CODE END 6 */
  437.  
  438. }
  439.  
  440. #endif
  441.  
  442. /**
  443.   * @}
  444.   */
  445.  
  446. /**
  447.   * @}
  448. */
  449.  
  450. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
  451.  
  452.  
  453.  
  454. -------------------------------------------------------------------------------------------------------------------
  455. /**
  456.   ******************************************************************************
  457.   * @file    stm32f1xx_it.c
  458.   * @brief   Interrupt Service Routines.
  459.   ******************************************************************************
  460.   *
  461.   * COPYRIGHT(c) 2016 STMicroelectronics
  462.   *
  463.   * Redistribution and use in source and binary forms, with or without modification,
  464.   * are permitted provided that the following conditions are met:
  465.   *   1. Redistributions of source code must retain the above copyright notice,
  466.   *      this list of conditions and the following disclaimer.
  467.   *   2. Redistributions in binary form must reproduce the above copyright notice,
  468.   *      this list of conditions and the following disclaimer in the documentation
  469.   *      and/or other materials provided with the distribution.
  470.   *   3. Neither the name of STMicroelectronics nor the names of its contributors
  471.   *      may be used to endorse or promote products derived from this software
  472.   *      without specific prior written permission.
  473.   *
  474.   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  475.   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  476.   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  477.   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  478.   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  479.   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  480.   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  481.   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  482.   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  483.   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  484.   *
  485.   ******************************************************************************
  486.   */
  487. /* Includes ------------------------------------------------------------------*/
  488. #include "stm32f1xx_hal.h"
  489. #include "stm32f1xx.h"
  490. #include "stm32f1xx_it.h"
  491.  
  492. /* USER CODE BEGIN 0 */
  493. #include "string.h"
  494. #include <stdlib.h>
  495. extern Time, Timeleft;
  496. extern UART_HandleTypeDef huart2;
  497. extern int Password[400;
  498. extern countMs;
  499. /* USER CODE END 0 */
  500.  
  501. /* External variables --------------------------------------------------------*/
  502. extern TIM_HandleTypeDef htim1;
  503.  
  504. /******************************************************************************/
  505. /*            Cortex-M3 Processor Interruption and Exception Handlers         */
  506. /******************************************************************************/
  507.  
  508. /**
  509. * @brief This function handles System tick timer.
  510. */
  511. void SysTick_Handler(void)
  512. {
  513.   /* USER CODE BEGIN SysTick_IRQn 0 */
  514.  
  515.   /* USER CODE END SysTick_IRQn 0 */
  516.   HAL_IncTick();
  517.   HAL_SYSTICK_IRQHandler();
  518.   /* USER CODE BEGIN SysTick_IRQn 1 */
  519.  
  520.   /* USER CODE END SysTick_IRQn 1 */
  521. }
  522.  
  523. /******************************************************************************/
  524. /* STM32F1xx Peripheral Interrupt Handlers                                    */
  525. /* Add here the Interrupt Handlers for the used peripherals.                  */
  526. /* For the available peripheral interrupt handler names,                      */
  527. /* please refer to the startup file (startup_stm32f1xx.s).                    */
  528. /******************************************************************************/
  529.  
  530. /**
  531. * @brief This function handles TIM1 update interrupt.
  532. */
  533. void TIM1_UP_IRQHandler(void)
  534. {
  535.   /* USER CODE BEGIN TIM1_UP_IRQn 0 */
  536.   if (countMs == 1000)
  537.   {
  538.     countMs = 0;
  539.     Timeleft--;
  540.   }
  541.   /* USER CODE END TIM1_UP_IRQn 0 */
  542.   HAL_TIM_IRQHandler(&htim1);
  543.   /* USER CODE BEGIN TIM1_UP_IRQn 1 */
  544.   countMs++;
  545.   /* USER CODE END TIM1_UP_IRQn 1 */
  546. }
  547.  
  548. /* USER CODE BEGIN 1 */
  549.  
  550. /* USER CODE END 1 */
  551. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement