光敏电阻控制蜂鸣器
This commit is contained in:
27
BSP/Buzzer.c
Normal file
27
BSP/Buzzer.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "stm32f10x.h"
|
||||
|
||||
void Buzzer_Init(void) {
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
|
||||
GPIO_InitTypeDef GPIO_InitStructure;
|
||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;
|
||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||
|
||||
GPIO_SetBits(GPIOB, GPIO_Pin_12);
|
||||
}
|
||||
|
||||
void Buzzer_ON(void) {
|
||||
GPIO_ResetBits(GPIOB, GPIO_Pin_12);
|
||||
}
|
||||
|
||||
void Buzzer_OFF(void) {
|
||||
GPIO_SetBits(GPIOB, GPIO_Pin_12);
|
||||
}
|
||||
void Buzzer_TOGGLE(void) {
|
||||
if (GPIO_ReadOutputDataBit(GPIOB, GPIO_Pin_12) == 0) {
|
||||
GPIO_SetBits(GPIOB, GPIO_Pin_12);
|
||||
}else {
|
||||
GPIO_ResetBits(GPIOB, GPIO_Pin_12);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user