Signed-off-by: kevin <kevin@lmve.net>
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
@@ -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_ */
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user