Advertisement
nontawat1996

Interface-assignment

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