/* USER CODE BEGIN 1 */
void play_little_star(void)
{
enum
{
UNUSED=0,
DO,
RE,
MI,
FA,
SO,
LA,
XI,
DO1,
RI1,
TONE_MAX,
};
uint16_t tone_freq[TONE_MAX] = {0, 1047, 1175, 1319, 1397, 1568, 1760, 1967, 4186, 4698 };
typedef struct tone_s
{
int tone;
int delay_ms;
} tone_t;
#define DEF_DELAY 350
static tone_t tiger_notation[]=
{
{DO, DEF_DELAY},
{RE, DEF_DELAY},
{MI, DEF_DELAY},
{DO, DEF_DELAY*2},
{DO, DEF_DELAY},
{RE, DEF_DELAY},
{MI, DEF_DELAY},
{DO, DEF_DELAY*2},
{MI, DEF_DELAY},
{FA, DEF_DELAY},
{SO, DEF_DELAY*2},
{MI, DEF_DELAY},
{FA, DEF_DELAY},
{SO, DEF_DELAY*2},
{SO, DEF_DELAY},
{LA, DEF_DELAY},
{SO, DEF_DELAY},
{FA, DEF_DELAY},
{MI, DEF_DELAY},
{DO, DEF_DELAY*2},
{SO, DEF_DELAY},
{LA, DEF_DELAY},
{SO, DEF_DELAY},
{FA, DEF_DELAY},
{MI, DEF_DELAY},
{DO, DEF_DELAY*2},
{RE, DEF_DELAY},
{SO, DEF_DELAY},
{DO, DEF_DELAY*2},
{RE, DEF_DELAY},
{SO, DEF_DELAY},
{DO, DEF_DELAY*2},
};
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]));
int turn_passive_beep(int cmd, int freq)
{
int range;
if(OFF == cmd)
{
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_2) ;
}
else
{
if(freq<1000 || freq>5000)
{
printf("Beep set invalid PWM frequency[%d]!\n",freq);
return -1;
}
/* Set PWM clock: 80MHz/169=500KHz */
htim2.Init.Prescaler = 160-1;
/* Set PWM frequency */
range=500000/freq;
htim2.Init.Period = range;
if (HAL_TIM_PWM_Init(&htim2) != HAL_OK)
{
Error_Handler();
}
/* Set PWM duty 50% */
TIM_OC_InitTypeDef sConfigOC;
sConfigOC.OCMode = TIM_OCMODE_PWM1;
sConfigOC.Pulse = (htim2.Init.Period/3);
sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
if (HAL_TIM_PWM_ConfigChannel(&htim2, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
{
Error_Handler();
}
HAL_TIM_MspPostInit(&htim2);
char HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_2);
}
return 0;
}
static inline void play_tone(int tone, int delay)
{
if(tone<DO || tone>RI1)
return ;
turn_passive_beep(ON, tone_freq[tone]);
Delay_ms(delay);
turn_passive_beep(OFF, 0);
}
void play_tiger(void)
{
int i;
for(i=0; i<ARRAY_SIZE(tiger_notation); i++)
{
play_tone(tiger_notation[i].tone, tiger_notation[i].delay_ms);
Delay_ms(30);
}
};
}
/* USER CODE END 1 */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
![](https://profile-avatar.csdnimg.cn/312c9af830d343d88065240d49f7ad13_qq_45276147.jpg!4)
关于#stm32#的问题,各位能不能看一下啊
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
2条回答 默认 最新
悬赏问题
- ¥15 苹果系统的mac m1芯片的笔记本使用ce修改器使用不了
- ¥15 单相逆变的电压电流双闭环中进行低通滤波PID算法改进
- ¥15 关于#java#的问题,请各位专家解答!
- ¥15 如何卸载arcgis 10.1 data reviewer for desktop
- ¥15 共享文件夹会话中为什么会有WORKGROUP
- ¥15 关于#python#的问题:使用ATL02数据解算光子脚点的坐标(操作系统-windows)
- ¥115 关于#python#的问题:未加密前两个软件都可以打开,加密后只有A软件可打开,B软件可以打开但读取不了数据
- ¥15 在matlab中Application Compiler后的软件无法打开
- ¥15 想问一下STM32创建工程模板时遇到得问题
- ¥15 Fiddler抓包443