Signed-off-by: kevin <kevin@lmve.net>

This commit is contained in:
2022-04-02 18:13:21 +08:00
parent e95a273ea5
commit f6b46cb51c
18 changed files with 37 additions and 3 deletions
+16
View File
@@ -0,0 +1,16 @@
/*
* buzzer.c
*
* Created on: 2022年4月2日
* Author: wuwen
*/
#include "buzzer.h"
void play_ones(uint16_t freq,uint8_t dutya)
{
//寄存器写法 需要根据单片机的时钟来写。
TIM14->ARR = (uint32_t)((48000000/freq)-1);TIM14->CCR1 = (uint32_t)(((48000000/freq)-1)*((float)dutya/100));
}
+18
View File
@@ -0,0 +1,18 @@
/*
* buzzer.h
*
* Created on: 2022年4月2日
* Author: wuwen
*/
#ifndef BUZZER_H_
#define BUZZER_H_
#include "main.h"
extern TIM_HandleTypeDef htim14;
void play_ones(uint16_t freq,uint8_t dutya);
#endif /* BUZZER_H_ */
+2 -2
View File
@@ -173,8 +173,8 @@ void mymain()
OLED_Init_Display_Buffer(0);
//OLED_ShowStr(0,0,"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
//HAL_TIM_PWM_Start(&htim14,TIM_CHANNEL_1);//启动n通道的pwm
//play_ones(1000,50);
while(1)
{
+1 -1
View File
@@ -10,7 +10,7 @@
#include "main.h"
#include "OLED.h"
#include "buzzer.h"
#define KEY0 HAL_GPIO_ReadPin(tack_A_GPIO_Port, tack_A_Pin)
#define KEY1 HAL_GPIO_ReadPin(tack_B_GPIO_Port, tack_B_Pin)
#define SW_C HAL_GPIO_ReadPin(SW_C_GPIO_Port, SW_C_Pin)