【STM32】无源蜂鸣器播放音乐《千与千寻》,HAL库

news2025/1/10 14:28:01

目录

一、工程链接

二、简单介绍

主要特点:

应用:

驱动电路:

三、原理图

四、cubeMX配置

时钟配置

五、keil配置

六、驱动编写

演奏函数

主函数编写

七、效果展示

八、驱动附录

music.h

music.c


一、工程链接

STM32无源蜂鸣器播放音乐《千与千寻》资源-CSDN文库

二、简单介绍

        无源蜂鸣器(Passive Buzzer)是一种没有内建振荡器的蜂鸣器。它通常需要外部的信号来驱动发声。在工作时,无源蜂鸣器会根据输入的脉冲信号频率和波形来产生音频信号。简单来说,它通过震动产生声音,其声音的频率取决于输入信号的频率。

主要特点:

  1. 驱动方式:无源蜂鸣器需要一个方波信号或音频信号来驱动,通常由微控制器(如STM32)或其他信号源提供。
  2. 音调调节:音调是通过改变输入信号的频率来控制的,频率越高,声音越尖锐;频率越低,声音越低沉。
  3. 节能:无源蜂鸣器比有源蜂鸣器更节能,因为它没有内部的震荡电路,工作时消耗的功率较低。
  4. 灵活性:可以通过改变驱动信号的频率和占空比来调整音调和响度,适应不同的应用需求。

应用:

  • 在各种警告和提醒系统中,如电池电量低、设备故障提示等。
  • 用于电子设备中发出提示音,例如遥控器、计算器等。
  • 通过合成音调来播放简单的音乐或警报声。

驱动电路:

  • PWM(脉宽调制)驱动:微控制器生成一定频率的PWM信号,通过滤波器将其转化为模拟信号来驱动无源蜂鸣器。
  • 时钟信号驱动:无源蜂鸣器也可以直接用一个方波信号驱动,方波的频率决定声音的频率。

与有源蜂鸣器不同,使用无源蜂鸣器时,需要编程控制输出信号的频率和波形,因此提供了更大的灵活性来生成不同的音调和音效。

三、原理图

这里笔者采用的是自己绘制的STM32F407VET6开发板,无源蜂鸣器电路部分如下图所示:

BEEP引脚连接至MCU的PB4引脚

四、cubeMX配置

时钟配置

开启定时器9作为1ms定时器

定时器3的通道1作为PWM输出,分频系数设置为84-1,因为定时器3是挂载在APB1总线上的

开启晶振,调试口等常规项的配置就不赘述了

五、keil配置

这里笔者使用了自己写的keil脚本,添加music.c和music.h文件即可

六、驱动编写

笔者作为一个音乐小白,最基本的理解是:想用无源蜂鸣器来演奏音乐,需要控制声音的频率,持续时间。方便起见,这里参考了midi音乐的协议规范。

typedef struct
{
	uint8_t onoff; /* on or off*/
	uint8_t freq;  /* frequence */
	uint16_t tick; /* time */
}midiType;

定义三个参数:开启和关闭音符,频率,时间

配置PWM波的频率来改变无源蜂鸣器的声调高低,改变PWM波的持续时间来改变每一个音符的持续时间。

演奏函数

void play(midiType* mid)
{

   cnt++;

   if (cnt >= mid[noteIdx].tick)
   {
      switch (mid[noteIdx].onoff)
      {
         case 0x80:
         {
            HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
            break;
         }
         case 0x90:
         {
            __HAL_TIM_SET_AUTORELOAD(&htim3, 1000000u / midiFreq_table[mid[noteIdx].freq]);
            __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, 500000u / midiFreq_table[mid[noteIdx].freq]);
            HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
            break;
         }
         default:
            break;
      }
      noteIdx++;
      cnt = 0;
   }
}

主函数编写

在1ms的中断里反复地调用这个play函数,就可以完成音乐的播放了

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{

  /* USER CODE BEGIN 1 */

  /* USER CODE END 1 */

  /* MCU Configuration--------------------------------------------------------*/

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

  /* USER CODE BEGIN Init */

  /* USER CODE END Init */

  /* Configure the system clock */
  SystemClock_Config();

  /* USER CODE BEGIN SysInit */

  /* USER CODE END SysInit */

  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_TIM3_Init();
  MX_SPI2_Init();
  MX_TIM9_Init();
  /* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim3);
HAL_TIM_Base_Start_IT(&htim9);

  /* USER CODE END 2 */

  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
    /* USER CODE END WHILE */

    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

/**
  * @brief System Clock Configuration
  * @retval None
  */
void SystemClock_Config(void)
{
  RCC_OscInitTypeDef RCC_OscInitStruct = {0};
  RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

  /** Configure the main internal regulator output voltage
  */
  __HAL_RCC_PWR_CLK_ENABLE();
  __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);

  /** Initializes the RCC Oscillators according to the specified parameters
  * in the RCC_OscInitTypeDef structure.
  */
  RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
  RCC_OscInitStruct.HSEState = RCC_HSE_ON;
  RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
  RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
  RCC_OscInitStruct.PLL.PLLM = 4;
  RCC_OscInitStruct.PLL.PLLN = 168;
  RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
  RCC_OscInitStruct.PLL.PLLQ = 4;
  if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
  {
    Error_Handler();
  }

  /** Initializes the CPU, AHB and APB buses clocks
  */
  RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
                              |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
  RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
  RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
  RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4;
  RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;

  if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
  {
    Error_Handler();
  }
}

/* USER CODE BEGIN 4 */

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
{
  static unsigned int cnt_1ms = 0;
  static unsigned char cnt = 0;

  if (htim == &htim3)
  {
    
  }

  if (htim == &htim9)
  {
    cnt_1ms++;

    if (cnt_1ms >= 100)
    {
      cnt_1ms = 0;
      cnt = cnt % 8;
      
      cnt++;
    }
    play(Spirited_Away);
  }
}

/* USER CODE END 4 */

七、效果展示

Spirited_Away

八、驱动附录

music.h

#ifndef MUSIC_H
#define MUSIC_H


#include "main.h"
#include "tim.h"
#include "stdint.h"

typedef struct
{
	uint8_t onoff; /* on or off*/
	uint8_t freq;  /* frequence */
	uint16_t tick; /* time */
}midiType;

extern const midiType Spirited_Away[];

void play(midiType* mid);

#endif

music.c

#include "music.h"

uint16_t midiFreq_table[] = 
{
   8,
   9,
   9,
   10,
   10,
   11,
   12,
   12,
   13,
   14,
   15,
   15,
   16,
   17,
   18,
   19,
   21,
   22,
   23,
   24,
   26,
   27,
   29,
   31,
   33,
   35,
   37,
   39,
   41,
   44,
   46,
   49,
   52,
   55,
   58,
   62,
   65,
   69,
   74,
   78,
   82,
   87,
   92,
   98,
   104,
   110,
   116,
   123,
   130,
   138,
   146,
   155,
   164,
   174,
   184,
   195,
   207,
   220,
   233,
   247,
   261,
   277,
   293,
   311,
   329,
   349,
   370,
   392,
   415,
   440,
   466,
   493,
   523,
   554,
   587,
   622,
   659,
   698,
   740,
   784,
   830,
   880,
   932,
   987,
   1047,
   1109,
   1175,
   1245,
   1319,
   1397,
   1480,
   1568,
   1661,
   1760,
   1865,
   1975,
   2093,
   2217,
   2349,
   2489,
   2637,
   2794,
   2960,
   3136,
   3322,
   3520,
   3729,
   3951,
   4186,
   4435,
   4698,
   4978,
   5274,
   5588,
   5920,
   6272,
   6645,
   7040,
   7458,
   7902,
   8372,
   8870,
   9397,
   9956,
   10548,
   11176,
   11840,
   12544
};


const midiType Spirited_Away[] = 
{
0x90,0x59,0x14A0,
0x80,0x59,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x60,0x0018,
0x80,0x60,0x02B8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x01B0,
0x90,0x60,0x0030,
0x80,0x60,0x01B0,
0x90,0x5B,0x0030,
0x80,0x5B,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x00D8,
0x90,0x56,0x0018,
0x80,0x56,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x02B8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x58,0x0018,
0x80,0x58,0x0360,
0x90,0x58,0x0060,
0x80,0x58,0x01B0,
0x90,0x56,0x0030,
0x80,0x56,0x01B0,
0x90,0x58,0x0030,
0x80,0x58,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x54,0x0018,
0x80,0x54,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x01B0,
0x90,0x5B,0x0030,
0x80,0x5B,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5E,0x0018,
0x80,0x5E,0x01B0,
0x90,0x5E,0x0030,
0x80,0x5E,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x0360,
0x90,0x59,0x0060,
0x80,0x59,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x60,0x0018,
0x80,0x60,0x02B8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x01B0,
0x90,0x60,0x0030,
0x80,0x60,0x01B0,
0x90,0x5B,0x0030,
0x80,0x5B,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x00D8,
0x90,0x56,0x0018,
0x80,0x56,0x00D8,
0x90,0x56,0x0018,
0x80,0x56,0x01B0,
0x90,0x58,0x0030,
0x80,0x58,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x54,0x0018,
0x80,0x54,0x0360,
0x90,0x54,0x0060,
0x80,0x54,0x01B0,
0x90,0x56,0x0030,
0x80,0x56,0x01B0,
0x90,0x58,0x0030,
0x80,0x58,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x54,0x0018,
0x80,0x54,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x01B0,
0x90,0x5B,0x0030,
0x80,0x5B,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5E,0x0018,
0x80,0x5E,0x01B0,
0x90,0x5E,0x0030,
0x80,0x5E,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x0750,
0x90,0x5D,0x0210,
0x80,0x5D,0x00D8,
0x90,0x5E,0x0018,
0x80,0x5E,0x00D8,
0x90,0x60,0x0018,
0x80,0x60,0x01B0,
0x90,0x60,0x0030,
0x80,0x60,0x01B0,
0x90,0x60,0x0030,
0x80,0x60,0x01B0,
0x90,0x60,0x0030,
0x80,0x60,0x01B0,
0x90,0x60,0x0030,
0x80,0x60,0x00D8,
0x90,0x62,0x0018,
0x80,0x62,0x00D8,
0x90,0x60,0x0018,
0x80,0x60,0x00D8,
0x90,0x5E,0x0018,
0x80,0x5E,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x01B0,
0x90,0x5D,0x0030,
0x80,0x5D,0x01B0,
0x90,0x5D,0x0030,
0x80,0x5D,0x01B0,
0x90,0x5D,0x0030,
0x80,0x5D,0x01B0,
0x90,0x5D,0x0030,
0x80,0x5D,0x00D8,
0x90,0x5E,0x0018,
0x80,0x5E,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x00D8,
0x90,0x58,0x0018,
0x80,0x58,0x00D8,
0x90,0x56,0x0018,
0x80,0x56,0x01B0,
0x90,0x58,0x0030,
0x80,0x58,0x01B0,
0x90,0x58,0x0030,
0x80,0x58,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x01B0,
0x90,0x5B,0x0030,
0x80,0x5B,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x0360,
0x90,0x5D,0x0060,
0x80,0x5D,0x00D8,
0x90,0x5E,0x0018,
0x80,0x5E,0x00D8,
0x90,0x60,0x0018,
0x80,0x60,0x01B0,
0x90,0x60,0x0030,
0x80,0x60,0x01B0,
0x90,0x60,0x0030,
0x80,0x60,0x01B0,
0x90,0x60,0x0030,
0x80,0x60,0x01B0,
0x90,0x60,0x0030,
0x80,0x60,0x00D8,
0x90,0x62,0x0018,
0x80,0x62,0x00D8,
0x90,0x60,0x0018,
0x80,0x60,0x00D8,
0x90,0x5E,0x0018,
0x80,0x5E,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x01B0,
0x90,0x5D,0x0030,
0x80,0x5D,0x01B0,
0x90,0x5D,0x0030,
0x80,0x5D,0x01B0,
0x90,0x5D,0x0030,
0x80,0x5D,0x00D8,
0x90,0x5E,0x0018,
0x80,0x5E,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x58,0x0018,
0x80,0x58,0x00D8,
0x90,0x56,0x0018,
0x80,0x56,0x01B0,
0x90,0x56,0x0030,
0x80,0x56,0x00D8,
0x90,0x58,0x0018,
0x80,0x58,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x54,0x0018,
0x80,0x54,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x01B0,
0x90,0x5B,0x0030,
0x80,0x5B,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x0288,
0x90,0x5B,0x0048,
0x80,0x5B,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x0360,
0x90,0x59,0x0BA0,
0x80,0x59,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x60,0x0018,
0x80,0x60,0x02B8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x01B0,
0x90,0x60,0x0030,
0x80,0x60,0x01B0,
0x90,0x5B,0x0030,
0x80,0x5B,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x00D8,
0x90,0x56,0x0018,
0x80,0x56,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x02B8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x58,0x0018,
0x80,0x58,0x0360,
0x90,0x59,0x0060,
0x80,0x59,0x00D8,
0x90,0x58,0x0018,
0x80,0x58,0x00D8,
0x90,0x56,0x0018,
0x80,0x56,0x01B0,
0x90,0x58,0x0030,
0x80,0x58,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x54,0x0018,
0x80,0x54,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x01B0,
0x90,0x5B,0x0030,
0x80,0x5B,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5E,0x0018,
0x80,0x5E,0x01B0,
0x90,0x5E,0x0030,
0x80,0x5E,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x0360,
0x90,0x59,0x0060,
0x80,0x59,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x60,0x0018,
0x80,0x60,0x02B8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x01B0,
0x90,0x60,0x0030,
0x80,0x60,0x01B0,
0x90,0x5B,0x0030,
0x80,0x5B,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x56,0x0018,
0x80,0x56,0x00D8,
0x90,0x56,0x0018,
0x80,0x56,0x01B0,
0x90,0x58,0x0030,
0x80,0x58,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x54,0x0018,
0x80,0x54,0x0360,
0x90,0x54,0x0060,
0x80,0x54,0x01B0,
0x90,0x56,0x0030,
0x80,0x56,0x01B0,
0x90,0x58,0x0030,
0x80,0x58,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x54,0x0018,
0x80,0x54,0x01B0,
0x90,0x59,0x0030,
0x80,0x59,0x01B0,
0x90,0x5B,0x0030,
0x80,0x5B,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5E,0x0018,
0x80,0x5E,0x01B0,
0x90,0x5E,0x0030,
0x80,0x5E,0x00D8,
0x90,0x5D,0x0018,
0x80,0x5D,0x00D8,
0x90,0x5B,0x0018,
0x80,0x5B,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x00D8,
0x90,0x59,0x0018,
0x80,0x59,0x0360,
0x90,0x69,0x0BA0,
0x80,0x69,0x00D8,
0x90,0x6A,0x0018,
0x80,0x6A,0x00D8,
0x90,0x6C,0x0018,
0x80,0x6C,0x01B0,
0x90,0x6C,0x0030,
0x80,0x6C,0x01B0,
0x90,0x6C,0x0030,
0x80,0x6C,0x01B0,
0x90,0x6C,0x0030,
0x80,0x6C,0x01B0,
0x90,0x6C,0x0030,
0x80,0x6C,0x00D8,
0x90,0x6E,0x0018,
0x80,0x6E,0x00D8,
0x90,0x6C,0x0018,
0x80,0x6C,0x00D8,
0x90,0x6A,0x0018,
0x80,0x6A,0x00D8,
0x90,0x69,0x0018,
0x80,0x69,0x01B0,
0x90,0x69,0x0030,
0x80,0x69,0x01B0,
0x90,0x69,0x0030,
0x80,0x69,0x01B0,
0x90,0x69,0x0030,
0x80,0x69,0x01B0,
0x90,0x69,0x0030,
0x80,0x69,0x00D8,
0x90,0x6A,0x0018,
0x80,0x6A,0x00D8,
0x90,0x69,0x0018,
0x80,0x69,0x00D8,
0x90,0x67,0x0018,
0x80,0x67,0x00D8,
0x90,0x65,0x0018,
0x80,0x65,0x01B0,
0x90,0x65,0x0030,
0x80,0x65,0x01B0,
0x90,0x65,0x0030,
0x80,0x65,0x00D8,
0x90,0x64,0x0018,
0x80,0x64,0x00D8,
0x90,0x62,0x0018,
0x80,0x62,0x01B0,
0x90,0x64,0x0030,
0x80,0x64,0x01B0,
0x90,0x64,0x0030,
0x80,0x64,0x00D8,
0x90,0x65,0x0018,
0x80,0x65,0x00D8,
0x90,0x67,0x0018,
0x80,0x67,0x01B0,
0x90,0x67,0x0030,
0x80,0x67,0x00D8,
0x90,0x69,0x0018,
0x80,0x69,0x00D8,
0x90,0x67,0x0018,
0x80,0x67,0x00D8,
0x90,0x69,0x0018,
0x80,0x69,0x00D8,
0x90,0x67,0x0018,
0x80,0x67,0x0360,
0x90,0x69,0x0060,
0x80,0x69,0x00D8,
0x90,0x6A,0x0018,
0x80,0x6A,0x00D8,
0x90,0x6C,0x0018,
0x80,0x6C,0x01B0,
0x90,0x6C,0x0030,
0x80,0x6C,0x01B0,
0x90,0x6C,0x0030,
0x80,0x6C,0x01B0,
0x90,0x6C,0x0030,
0x80,0x6C,0x01B0,
0x90,0x6C,0x0030,
0x80,0x6C,0x00D8,
0x90,0x6E,0x0018,
0x80,0x6E,0x00D8,
0x90,0x6C,0x0018,
0x80,0x6C,0x00D8,
0x90,0x6A,0x0018,
0x80,0x6A,0x00D8,
0x90,0x69,0x0018,
0x80,0x69,0x01B0,
0x90,0x69,0x0030,
0x80,0x69,0x01B0,
0x90,0x69,0x0030,
0x80,0x69,0x01B0,
0x90,0x69,0x0030,
0x80,0x69,0x00D8,
0x90,0x6A,0x0018,
0x80,0x6A,0x00D8,
0x90,0x69,0x0018,
0x80,0x69,0x00D8,
0x90,0x67,0x0018,
0x80,0x67,0x00D8,
0x90,0x65,0x0018,
0x80,0x65,0x00D8,
0x90,0x64,0x0018,
0x80,0x64,0x00D8,
0x90,0x62,0x01F8,
0x80,0x62,0x00D8,
0x90,0x64,0x0018,
0x80,0x64,0x00D8,
0x90,0x65,0x0018,
0x80,0x65,0x00D8,
0x90,0x67,0x0018,
0x80,0x67,0x00D8,
0x90,0x60,0x0018,
0x80,0x60,0x01B0,
0x90,0x65,0x0030,
0x80,0x65,0x01B0,
0x90,0x67,0x0030,
0x80,0x67,0x00D8,
0x90,0x69,0x0018,
0x80,0x69,0x00D8,
0x90,0x67,0x0018,
0x80,0x67,0x0360,
0x90,0x67,0x0060,
0x80,0x67,0x00D8,
0x90,0x65,0x0018,
0x80,0x65,0x00D8,
0x90,0x65,0x0018,
0x80,0x59,0x0510,
0x90,0x59,0x0090,
0x80,0x65,0x0360,

};


static int16_t cnt = 0;
static uint16_t noteIdx = 1;

void play(midiType* mid)
{

   cnt++;

   if (cnt >= mid[noteIdx].tick)
   {
      switch (mid[noteIdx].onoff)
      {
         case 0x80:
         {
            HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
            break;
         }
         case 0x90:
         {
            __HAL_TIM_SET_AUTORELOAD(&htim3, 1000000u / midiFreq_table[mid[noteIdx].freq]);
            __HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, 500000u / midiFreq_table[mid[noteIdx].freq]);
            HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
            break;
         }
         default:
            break;
      }
      noteIdx++;
      cnt = 0;
   }
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2274382.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

在 Vue 3 集成 e签宝电子合同签署功能

实现 Vue 3 e签宝电子合同签署功能,需要使用 e签宝提供的实际 SDK 或 API。 e签宝通常提供针对不同平台(如 Web、Android、iOS)的 SDK,而 Web 端一般通过 WebView 或直接使用嵌入式 iframe 来加载合同签署页面。 下面举个 &…

04、Redis深入数据结构

一、简单动态字符串SDS 无论是Redis中的key还是value,其基础数据类型都是字符串。如,Hash型value的field与value的类型,List型,Set型,ZSet型value的元素的类型等都是字符串。redis没有使用传统C中的字符串而是自定义了…

如何用Python编程实现自动整理XML发票文件

传统手工整理发票耗时费力且易出错,而 XML 格式发票因其结构化、标准化的特点,为实现发票的自动化整理与保存提供了可能。本文将详细探讨用python来编程实现对 XML 格式的发票进行自动整理。 一、XML 格式发票的特点 结构化数据:XML 格式发票…

Linux——修改USB网卡设备节点名称

修改驱动: 测试: 参考资料: https://blog.csdn.net/ablexu2018/article/details/144868950

(STM32笔记)十二、DMA的基础知识与用法 第三部分

我用的是正点的STM32F103来进行学习,板子和教程是野火的指南者。 之后的这个系列笔记开头未标明的话,用的也是这个板子和教程。 DMA的基础知识与用法 三、DMA程序验证1、DMA 存储器到存储器模式实验(1)DMA结构体解释(2…

论文笔记(六十一)Implicit Behavioral Cloning

Implicit Behavioral Cloning 文章概括摘要1 引言2 背景:隐式模型的训练与推理3 隐式模型与显式模型的有趣属性4 policy学习成果5 理论见解:隐式模型的通用逼近性6 相关工作7 结论 文章概括 引用: inproceedings{florence2022implicit,titl…

高斯函数Gaussian绘制matlab

高斯 约翰卡尔弗里德里希高斯,(德语:Johann Carl Friedrich Gau,英语:Gauss,拉丁语:Carolus Fridericus Gauss)1777年4月30日–1855年2月23日,德国著名数学家、物理学家…

vue的路由守卫逻辑处理不当导致部署在nginx上无法捕捉后端异步响应消息等问题

近期对前端的路由卫士有了更多的认识。 何为路由守卫?这可能是一种约定俗成的名称。就是VUE中的自定义函数,用来处理路由跳转。 import { createRouter, createWebHashHistory } from "vue-router";const router createRouter({history: cr…

如何在 Ubuntu 22.04 上使用 LEMP 安装 WordPress 教程

简介: 本教程旨在指导你如何在 Ubuntu 22.04 上使用 LEMP 栈安装 WordPress。 WordPress 是一个用 PHP 编写的开源内容管理系统。LEMP 栈是 Linux,NGINX,MySQL 和 PHP 的缩写。WordPress 非常用户友好,并提供了多种选项&#xff…

PySide6基于QSlider实现QDoubleSlider

我在写小工具的时候,需要一个支持小数的滑动条。 我QSpinBox都找到了QDoubleSpinBox,QSlider愣是没找到对应的东西。 网上有好多对QSlider封装实现QDoubleSlider的文章。 似乎Qt真的没有这个东西,需要我们自行实现。 于是我也封装了一个&…

升级 Spring Boot 3 配置讲解 —— 支持断点传输的文件上传和下载功能

学会这款 🔥全新设计的 Java 脚手架 ,从此面试不再怕! 在现代 Web 应用中,文件上传和下载是非常常见的需求。然而,当文件较大时,传统的上传下载方式可能会遇到网络不稳定或传输中断的问题。为了解决这些问题…

Backend - C# EF Core 执行迁移 Migrate

目录 一、创建Postgre数据库 二、安装包 (一)查看是否存在该安装包 (二)安装所需包 三、执行迁移命令 1. 作用 2. 操作位置 3. 执行(针对visual studio) 查看迁移功能的常用命令: 查看…

KG-CoT:基于知识图谱的大语言模型问答的思维链提示

一些符号定义 知识图谱实体数量: n n n 知识图谱中关系类型数量: m m m 三元组矩阵: M ∈ { 0 , 1 } n n m \textbf{M} \in \{0, 1\}^{n \times n \times m} M∈{0,1}nnm, M i j k 1 M_{ij}^k 1 Mijk​1则说明实体 i i i和实…

HTML+CSS+JS制作中国传统节日主题网站(内附源码,含5个页面)

一、作品介绍 HTMLCSSJS制作一个中国传统节日主题网站,包含首页、节日介绍页、民俗文化页、节日活动页、联系我们页等5个静态页面。其中每个页面都包含一个导航栏、一个主要区域和一个底部区域。 二、页面结构 1. 顶部横幅区 包含传统中国风格的网站标题中国传统…

大模型WebUI:Gradio全解11——Chatbot:融合大模型的多模态聊天机器人(1)

大模型WebUI:Gradio全解11——Chatbots:融合大模型的聊天机器人(1) 前言本篇摘要11. Chatbot:融合大模型的多模态聊天机器人11.1 gr.ChatInterface()快速创建Chatbot11.1.1 定义聊天函数1. 随机回答“是”或“否”的聊…

springboot + vue+elementUI图片上传流程

1.实现背景 前端上传一张图片&#xff0c;存到后端数据库&#xff0c;并将图片回显到页面上。上传组件使用现成的elementUI的el-upload。、 2.前端页面 <el-uploadclass"upload-demo"action"http://xxxx.xxx.xxx:9090/file/upload" :show-file-list&q…

开源生成式物理引擎Genesis,可模拟世界万物

这是生成大模型时代 —— 它们能生成文本、图像、音频、视频、3D 对象…… 而如果将所有这些组合到一起&#xff0c;我们可能会得到一个世界&#xff01; 现在&#xff0c;不管是 LeCun 正在探索的世界模型&#xff0c;还是李飞飞想要攻克的空间智能&#xff0c;又或是其他研究…

【PPTist】批注、选择窗格

前言&#xff1a;本篇文章研究批注和选择窗格两个小功能 一、批注 批注功能就是介个小图标 点击可以为当前页的幻灯片添加批注&#xff0c;还能删除之前的批注 如果我们增加了登录功能&#xff0c;还可以在批注上显示当前的用户名和头像&#xff0c;不过现在是写死的。 左侧…

Vue进阶(贰幺贰)npm run build多环境编译

文章目录 一、前言二、实施三、总结&#xff1a;需要打包区分不同环境四、拓展阅读 一、前言 项目开发阶段&#xff0c;会涉及打包部署到多个环境应用场景&#xff0c;在不同环境中&#xff0c;需要进行项目层面的区分&#xff0c;做不同的操作&#xff0c;可以利用打包的--mo…

Elasticsearch—索引库操作(增删查改)

Elasticsearch中Index就相当于MySQL中的数据库表 Mapping映射就类似表的结构。 因此我们想要向Elasticsearch中存储数据,必须先创建Index和Mapping 1. Mapping映射属性 Mapping是对索引库中文档的约束&#xff0c;常见的Mapping属性包括&#xff1a; type&#xff1a;字段数据类…