找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 36|回复: 0
打印 上一主题 下一主题
收起左侧

为什么STM32F407VGT6蜂鸣器不响?

[复制链接]
跳转到指定楼层
楼主
ID:61140 发表于 2026-9-7 10:04 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
使用CubeMX生成的工程框架,只是让蜂鸣器开机响一下,但是蜂鸣器不响,两个晶振和旁边的电容都是全新的,仔细查了线路硬件没问题,请教大神指导,在线等。。。
  1. /* USER CODE BEGIN Header */
  2. /**
  3.   ******************************************************************************
  4.   * @file           : main.c
  5.   * @brief          : Main program body
  6.   ******************************************************************************
  7.   * @attention
  8.   *
  9.   * Copyright (c) 2026 STMicroelectronics.
  10.   * All rights reserved.
  11.   *
  12.   * This software is licensed under terms that can be found in the LICENSE file
  13.   * in the root directory of this software component.
  14.   * If no LICENSE file comes with this software, it is provided AS-IS.
  15.   *
  16.   ******************************************************************************
  17.   */
  18. /* USER CODE END Header */
  19. /* Includes ------------------------------------------------------------------*/
  20. #include "main.h"

  21. /* Private includes ----------------------------------------------------------*/
  22. /* USER CODE BEGIN Includes */

  23. /* USER CODE END Includes */

  24. /* Private typedef -----------------------------------------------------------*/
  25. /* USER CODE BEGIN PTD */

  26. /* USER CODE END PTD */

  27. /* Private define ------------------------------------------------------------*/
  28. /* USER CODE BEGIN PD */

  29. /* USER CODE END PD */

  30. /* Private macro -------------------------------------------------------------*/
  31. /* USER CODE BEGIN PM */

  32. /* USER CODE END PM */

  33. /* Private variables ---------------------------------------------------------*/
  34. ADC_HandleTypeDef hadc1;
  35. ADC_HandleTypeDef hadc2;
  36. ADC_HandleTypeDef hadc3;

  37. RTC_HandleTypeDef hrtc;

  38. SPI_HandleTypeDef hspi1;

  39. UART_HandleTypeDef huart1;

  40. /* USER CODE BEGIN PV */

  41. /* USER CODE END PV */

  42. /* Private function prototypes -----------------------------------------------*/
  43. void SystemClock_Config(void);
  44. static void MX_GPIO_Init(void);
  45. static void MX_ADC1_Init(void);
  46. static void MX_ADC2_Init(void);
  47. static void MX_ADC3_Init(void);
  48. static void MX_RTC_Init(void);
  49. static void MX_SPI1_Init(void);
  50. static void MX_USART1_UART_Init(void);
  51. /* USER CODE BEGIN PFP */

  52. /* USER CODE END PFP */

  53. /* Private user code ---------------------------------------------------------*/
  54. /* USER CODE BEGIN 0 */

  55. /* USER CODE END 0 */

  56. /**
  57.   * @brief  The application entry point.
  58.   * @retval int
  59.   */
  60. int main(void)
  61. {

  62.   /* USER CODE BEGIN 1 */

  63.   /* USER CODE END 1 */

  64.   /* MCU Configuration--------------------------------------------------------*/

  65.   /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  66.   HAL_Init();

  67.   /* USER CODE BEGIN Init */

  68.   /* USER CODE END Init */

  69.   /* Configure the system clock */
  70.   SystemClock_Config();

  71.   /* USER CODE BEGIN SysInit */

  72.   /* USER CODE END SysInit */

  73.   /* Initialize all configured peripherals */
  74.   MX_GPIO_Init();
  75.   MX_ADC1_Init();
  76.   MX_ADC2_Init();
  77.   MX_ADC3_Init();
  78.   MX_RTC_Init();
  79.   MX_SPI1_Init();
  80.   MX_USART1_UART_Init();
  81.   /* USER CODE BEGIN 2 */
  82.   HAL_GPIO_WritePin(BUZZ_GPIO_Port, BUZZ_Pin, GPIO_PIN_RESET);
  83.   HAL_Delay(500);
  84.   HAL_GPIO_WritePin(BUZZ_GPIO_Port, BUZZ_Pin, GPIO_PIN_SET);
  85.   HAL_Delay(500);
  86.   /* USER CODE END 2 */

  87.   /* Infinite loop */
  88.   /* USER CODE BEGIN WHILE */
  89.   while (1)
  90.   {
  91.     /* USER CODE END WHILE */

  92.     /* USER CODE BEGIN 3 */
  93.   }
  94.   /* USER CODE END 3 */
  95. }

  96. /**
  97.   * @brief System Clock Configuration
  98.   * @retval None
  99.   */
  100. void SystemClock_Config(void)
  101. {
  102.   RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  103.   RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  104.   /** Configure the main internal regulator output voltage
  105.   */
  106.   __HAL_RCC_PWR_CLK_ENABLE();
  107.   __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  108.   /** Initializes the RCC Oscillators according to the specified parameters
  109.   * in the RCC_OscInitTypeDef structure.
  110.   */
  111.   RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE|RCC_OSCILLATORTYPE_LSE;
  112.   RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  113.   RCC_OscInitStruct.LSEState = RCC_LSE_ON;
  114.   RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  115.   RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  116.   RCC_OscInitStruct.PLL.PLLM = 12;
  117.   RCC_OscInitStruct.PLL.PLLN = 168;
  118.   RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  119.   RCC_OscInitStruct.PLL.PLLQ = 4;
  120.   if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  121.   {
  122.     Error_Handler();
  123.   }

  124.   /** Initializes the CPU, AHB and APB buses clocks
  125.   */
  126.   RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
  127.                               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  128.   RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  129.   RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  130.   RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  131.   RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  132.   if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  133.   {
  134.     Error_Handler();
  135.   }
  136. }

  137. /**
  138.   * @brief ADC1 Initialization Function
  139.   * @param None
  140.   * @retval None
  141.   */
  142. static void MX_ADC1_Init(void)
  143. {

  144.   /* USER CODE BEGIN ADC1_Init 0 */

  145.   /* USER CODE END ADC1_Init 0 */

  146.   ADC_ChannelConfTypeDef sConfig = {0};

  147.   /* USER CODE BEGIN ADC1_Init 1 */

  148.   /* USER CODE END ADC1_Init 1 */

  149.   /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  150.   */
  151.   hadc1.Instance = ADC1;
  152.   hadc1.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  153.   hadc1.Init.Resolution = ADC_RESOLUTION_12B;
  154.   hadc1.Init.ScanConvMode = DISABLE;
  155.   hadc1.Init.ContinuousConvMode = DISABLE;
  156.   hadc1.Init.DiscontinuousConvMode = DISABLE;
  157.   hadc1.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  158.   hadc1.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  159.   hadc1.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  160.   hadc1.Init.NbrOfConversion = 1;
  161.   hadc1.Init.DMAContinuousRequests = DISABLE;
  162.   hadc1.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  163.   if (HAL_ADC_Init(&hadc1) != HAL_OK)
  164.   {
  165.     Error_Handler();
  166.   }

  167.   /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  168.   */
  169.   sConfig.Channel = ADC_CHANNEL_2;
  170.   sConfig.Rank = 1;
  171.   sConfig.SamplingTime = ADC_SAMPLETIME_480CYCLES;
  172.   if (HAL_ADC_ConfigChannel(&hadc1, &sConfig) != HAL_OK)
  173.   {
  174.     Error_Handler();
  175.   }
  176.   /* USER CODE BEGIN ADC1_Init 2 */

  177.   /* USER CODE END ADC1_Init 2 */

  178. }

  179. /**
  180.   * @brief ADC2 Initialization Function
  181.   * @param None
  182.   * @retval None
  183.   */
  184. static void MX_ADC2_Init(void)
  185. {

  186.   /* USER CODE BEGIN ADC2_Init 0 */

  187.   /* USER CODE END ADC2_Init 0 */

  188.   ADC_ChannelConfTypeDef sConfig = {0};

  189.   /* USER CODE BEGIN ADC2_Init 1 */

  190.   /* USER CODE END ADC2_Init 1 */

  191.   /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  192.   */
  193.   hadc2.Instance = ADC2;
  194.   hadc2.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  195.   hadc2.Init.Resolution = ADC_RESOLUTION_12B;
  196.   hadc2.Init.ScanConvMode = DISABLE;
  197.   hadc2.Init.ContinuousConvMode = DISABLE;
  198.   hadc2.Init.DiscontinuousConvMode = DISABLE;
  199.   hadc2.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  200.   hadc2.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  201.   hadc2.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  202.   hadc2.Init.NbrOfConversion = 1;
  203.   hadc2.Init.DMAContinuousRequests = DISABLE;
  204.   hadc2.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  205.   if (HAL_ADC_Init(&hadc2) != HAL_OK)
  206.   {
  207.     Error_Handler();
  208.   }

  209.   /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  210.   */
  211.   sConfig.Channel = ADC_CHANNEL_2;
  212.   sConfig.Rank = 1;
  213.   sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
  214.   if (HAL_ADC_ConfigChannel(&hadc2, &sConfig) != HAL_OK)
  215.   {
  216.     Error_Handler();
  217.   }
  218.   /* USER CODE BEGIN ADC2_Init 2 */

  219.   /* USER CODE END ADC2_Init 2 */

  220. }

  221. /**
  222.   * @brief ADC3 Initialization Function
  223.   * @param None
  224.   * @retval None
  225.   */
  226. static void MX_ADC3_Init(void)
  227. {

  228.   /* USER CODE BEGIN ADC3_Init 0 */

  229.   /* USER CODE END ADC3_Init 0 */

  230.   ADC_ChannelConfTypeDef sConfig = {0};

  231.   /* USER CODE BEGIN ADC3_Init 1 */

  232.   /* USER CODE END ADC3_Init 1 */

  233.   /** Configure the global features of the ADC (Clock, Resolution, Data Alignment and number of conversion)
  234.   */
  235.   hadc3.Instance = ADC3;
  236.   hadc3.Init.ClockPrescaler = ADC_CLOCK_SYNC_PCLK_DIV4;
  237.   hadc3.Init.Resolution = ADC_RESOLUTION_12B;
  238.   hadc3.Init.ScanConvMode = DISABLE;
  239.   hadc3.Init.ContinuousConvMode = DISABLE;
  240.   hadc3.Init.DiscontinuousConvMode = DISABLE;
  241.   hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
  242.   hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
  243.   hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
  244.   hadc3.Init.NbrOfConversion = 1;
  245.   hadc3.Init.DMAContinuousRequests = DISABLE;
  246.   hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
  247.   if (HAL_ADC_Init(&hadc3) != HAL_OK)
  248.   {
  249.     Error_Handler();
  250.   }

  251.   /** Configure for the selected ADC regular channel its corresponding rank in the sequencer and its sample time.
  252.   */
  253.   sConfig.Channel = ADC_CHANNEL_2;
  254.   sConfig.Rank = 1;
  255.   sConfig.SamplingTime = ADC_SAMPLETIME_3CYCLES;
  256.   if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
  257.   {
  258.     Error_Handler();
  259.   }
  260.   /* USER CODE BEGIN ADC3_Init 2 */

  261.   /* USER CODE END ADC3_Init 2 */

  262. }

  263. /**
  264.   * @brief RTC Initialization Function
  265.   * @param None
  266.   * @retval None
  267.   */
  268. static void MX_RTC_Init(void)
  269. {

  270.   /* USER CODE BEGIN RTC_Init 0 */

  271.   /* USER CODE END RTC_Init 0 */

  272.   /* USER CODE BEGIN RTC_Init 1 */

  273.   /* USER CODE END RTC_Init 1 */

  274.   /** Initialize RTC Only
  275.   */
  276.   hrtc.Instance = RTC;
  277.   hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
  278.   hrtc.Init.AsynchPrediv = 127;
  279.   hrtc.Init.SynchPrediv = 255;
  280.   hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
  281.   hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
  282.   hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
  283.   if (HAL_RTC_Init(&hrtc) != HAL_OK)
  284.   {
  285.     Error_Handler();
  286.   }
  287.   /* USER CODE BEGIN RTC_Init 2 */

  288.   /* USER CODE END RTC_Init 2 */

  289. }

  290. /**
  291.   * @brief SPI1 Initialization Function
  292.   * @param None
  293.   * @retval None
  294.   */
  295. static void MX_SPI1_Init(void)
  296. {

  297.   /* USER CODE BEGIN SPI1_Init 0 */

  298.   /* USER CODE END SPI1_Init 0 */

  299.   /* USER CODE BEGIN SPI1_Init 1 */

  300.   /* USER CODE END SPI1_Init 1 */
  301.   /* SPI1 parameter configuration*/
  302.   hspi1.Instance = SPI1;
  303.   hspi1.Init.Mode = SPI_MODE_MASTER;
  304.   hspi1.Init.Direction = SPI_DIRECTION_2LINES;
  305.   hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
  306.   hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
  307.   hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
  308.   hspi1.Init.NSS = SPI_NSS_SOFT;
  309.   hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
  310.   hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
  311.   hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
  312.   hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  313.   hspi1.Init.CRCPolynomial = 10;
  314.   if (HAL_SPI_Init(&hspi1) != HAL_OK)
  315.   {
  316.     Error_Handler();
  317.   }
  318.   /* USER CODE BEGIN SPI1_Init 2 */

  319.   /* USER CODE END SPI1_Init 2 */

  320. }

  321. /**
  322.   * @brief USART1 Initialization Function
  323.   * @param None
  324.   * @retval None
  325.   */
  326. static void MX_USART1_UART_Init(void)
  327. {

  328.   /* USER CODE BEGIN USART1_Init 0 */

  329.   /* USER CODE END USART1_Init 0 */

  330.   /* USER CODE BEGIN USART1_Init 1 */

  331.   /* USER CODE END USART1_Init 1 */
  332.   huart1.Instance = USART1;
  333.   huart1.Init.BaudRate = 115200;
  334.   huart1.Init.WordLength = UART_WORDLENGTH_8B;
  335.   huart1.Init.StopBits = UART_STOPBITS_1;
  336.   huart1.Init.Parity = UART_PARITY_NONE;
  337.   huart1.Init.Mode = UART_MODE_TX_RX;
  338.   huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
  339.   huart1.Init.OverSampling = UART_OVERSAMPLING_16;
  340.   if (HAL_UART_Init(&huart1) != HAL_OK)
  341.   {
  342.     Error_Handler();
  343.   }
  344.   /* USER CODE BEGIN USART1_Init 2 */

  345.   /* USER CODE END USART1_Init 2 */

  346. }

  347. /**
  348.   * @brief GPIO Initialization Function
  349.   * @param None
  350.   * @retval None
  351.   */
  352. static void MX_GPIO_Init(void)
  353. {
  354.   GPIO_InitTypeDef GPIO_InitStruct = {0};
  355.   /* USER CODE BEGIN MX_GPIO_Init_1 */

  356.   /* USER CODE END MX_GPIO_Init_1 */

  357.   /* GPIO Ports Clock Enable */
  358.   __HAL_RCC_GPIOE_CLK_ENABLE();
  359.   __HAL_RCC_GPIOC_CLK_ENABLE();
  360.   __HAL_RCC_GPIOH_CLK_ENABLE();
  361.   __HAL_RCC_GPIOA_CLK_ENABLE();
  362.   __HAL_RCC_GPIOB_CLK_ENABLE();
  363.   __HAL_RCC_GPIOD_CLK_ENABLE();

  364.   /*Configure GPIO pin Output Level */
  365.   HAL_GPIO_WritePin(GPIOA, DS18B20_Pin|SPI1_NSS_Pin, GPIO_PIN_RESET);

  366.   /*Configure GPIO pin Output Level */
  367.   HAL_GPIO_WritePin(GPIOE, SPI2_DREQ_Pin|SPI2_XRESET_Pin, GPIO_PIN_RESET);

  368.   /*Configure GPIO pin Output Level */
  369.   HAL_GPIO_WritePin(GPIOB, SPI2_XDCS_Pin|SPI2_NSS_Pin|SPI2_SCK_Pin|SPI2_MOSI_Pin
  370.                           |SPI2_MISO_Pin, GPIO_PIN_RESET);

  371.   /*Configure GPIO pin Output Level */
  372.   HAL_GPIO_WritePin(GPIOD, CH375_D0_Pin|CH375_D1_Pin|CH375_D2_Pin|CH375_D3_Pin
  373.                           |CH375_D4_Pin|CH375_D5_Pin|CH375_D6_Pin|CH375_D7_Pin
  374.                           |LCD_D0_Pin|LCD_D1_Pin|LCD_D2_Pin|LCD_D3_Pin
  375.                           |LCD_D4_Pin|LCD_D5_Pin|LCD_D6_Pin|LCD_D7_Pin, GPIO_PIN_RESET);

  376.   /*Configure GPIO pin Output Level */
  377.   HAL_GPIO_WritePin(GPIOC, CH375_A0_Pin|CH375_RD_Pin|CH375_WR_Pin|LCD_RW_Pin
  378.                           |LCD_E_Pin, GPIO_PIN_SET);

  379.   /*Configure GPIO pin Output Level */
  380.   HAL_GPIO_WritePin(GPIOA, CH375_CS_Pin|BUZZ_Pin, GPIO_PIN_SET);

  381.   /*Configure GPIO pin Output Level */
  382.   HAL_GPIO_WritePin(GPIOB, LCD_CS_Pin|LCD_RES_Pin|LCD_RS_Pin, GPIO_PIN_SET);

  383.   /*Configure GPIO pins : KEY_1_Pin KEY_2_Pin KEY_3_Pin KEY_4_Pin */
  384.   GPIO_InitStruct.Pin = KEY_1_Pin|KEY_2_Pin|KEY_3_Pin|KEY_4_Pin;
  385.   GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
  386.   GPIO_InitStruct.Pull = GPIO_PULLUP;
  387.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  388.   /*Configure GPIO pins : DS18B20_Pin SPI1_NSS_Pin CH375_CS_Pin BUZZ_Pin */
  389.   GPIO_InitStruct.Pin = DS18B20_Pin|SPI1_NSS_Pin|CH375_CS_Pin|BUZZ_Pin;
  390.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  391.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  392.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  393.   HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

  394.   /*Configure GPIO pin : HWJS_Pin */
  395.   GPIO_InitStruct.Pin = HWJS_Pin;
  396.   GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
  397.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  398.   HAL_GPIO_Init(HWJS_GPIO_Port, &GPIO_InitStruct);

  399.   /*Configure GPIO pins : SPI2_DREQ_Pin SPI2_XRESET_Pin */
  400.   GPIO_InitStruct.Pin = SPI2_DREQ_Pin|SPI2_XRESET_Pin;
  401.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  402.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  403.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  404.   HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);

  405.   /*Configure GPIO pins : SPI2_XDCS_Pin SPI2_NSS_Pin SPI2_SCK_Pin SPI2_MOSI_Pin
  406.                            SPI2_MISO_Pin LCD_CS_Pin LCD_RES_Pin LCD_RS_Pin */
  407.   GPIO_InitStruct.Pin = SPI2_XDCS_Pin|SPI2_NSS_Pin|SPI2_SCK_Pin|SPI2_MOSI_Pin
  408.                           |SPI2_MISO_Pin|LCD_CS_Pin|LCD_RES_Pin|LCD_RS_Pin;
  409.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  410.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  411.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  412.   HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);

  413.   /*Configure GPIO pins : CH375_D0_Pin CH375_D1_Pin CH375_D2_Pin CH375_D3_Pin
  414.                            CH375_D4_Pin CH375_D5_Pin CH375_D6_Pin CH375_D7_Pin
  415.                            LCD_D0_Pin LCD_D1_Pin LCD_D2_Pin LCD_D3_Pin
  416.                            LCD_D4_Pin LCD_D5_Pin LCD_D6_Pin LCD_D7_Pin */
  417.   GPIO_InitStruct.Pin = CH375_D0_Pin|CH375_D1_Pin|CH375_D2_Pin|CH375_D3_Pin
  418.                           |CH375_D4_Pin|CH375_D5_Pin|CH375_D6_Pin|CH375_D7_Pin
  419.                           |LCD_D0_Pin|LCD_D1_Pin|LCD_D2_Pin|LCD_D3_Pin
  420.                           |LCD_D4_Pin|LCD_D5_Pin|LCD_D6_Pin|LCD_D7_Pin;
  421.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  422.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  423.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  424.   HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);

  425.   /*Configure GPIO pins : CH375_A0_Pin CH375_RD_Pin CH375_WR_Pin LCD_RW_Pin
  426.                            LCD_E_Pin */
  427.   GPIO_InitStruct.Pin = CH375_A0_Pin|CH375_RD_Pin|CH375_WR_Pin|LCD_RW_Pin
  428.                           |LCD_E_Pin;
  429.   GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
  430.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  431.   GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
  432.   HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);

  433.   /*Configure GPIO pin : CH375_INT_Pin */
  434.   GPIO_InitStruct.Pin = CH375_INT_Pin;
  435.   GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING;
  436.   GPIO_InitStruct.Pull = GPIO_NOPULL;
  437.   HAL_GPIO_Init(CH375_INT_GPIO_Port, &GPIO_InitStruct);

  438.   /* EXTI interrupt init*/
  439.   HAL_NVIC_SetPriority(EXTI1_IRQn, 0, 0);
  440.   HAL_NVIC_EnableIRQ(EXTI1_IRQn);

  441.   HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
  442.   HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);

  443.   /* USER CODE BEGIN MX_GPIO_Init_2 */

  444.   /* USER CODE END MX_GPIO_Init_2 */
  445. }

  446. /* USER CODE BEGIN 4 */

  447. /* USER CODE END 4 */

  448. /**
  449.   * @brief  This function is executed in case of error occurrence.
  450.   * @retval None
  451.   */
  452. void Error_Handler(void)
  453. {
  454.   /* USER CODE BEGIN Error_Handler_Debug */
  455.   /* User can add his own implementation to report the HAL error return state */
  456.   __disable_irq();
  457.   while (1)
  458.   {
  459.   }
  460.   /* USER CODE END Error_Handler_Debug */
  461. }
  462. #ifdef USE_FULL_ASSERT
  463. /**
  464.   * @brief  Reports the name of the source file and the source line number
  465.   *         where the assert_param error has occurred.
  466.   * @param  file: pointer to the source file name
  467.   * @param  line: assert_param error line source number
  468.   * @retval None
  469.   */
  470. void assert_failed(uint8_t *file, uint32_t line)
  471. {
  472.   /* USER CODE BEGIN 6 */
  473.   /* User can add his own implementation to report the file name and line number,
  474.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  475.   /* USER CODE END 6 */
  476. }
  477. #endif /* USE_FULL_ASSERT */
复制代码




分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏 分享淘帖 顶 踩
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表