41 lines
918 B
C
41 lines
918 B
C
#include "beep.h"
|
|
#include "bitband.h"
|
|
|
|
// 蜂鸣器初始化
|
|
void beep_init(void)
|
|
{
|
|
// 定义一个 GPIO 初始化啊的结构体
|
|
GPIO_InitTypeDef GPIO_InitStruct;
|
|
|
|
// 初始化时钟
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOA, ENABLE);
|
|
// 将 PC8 和 PC9 设置成上拉输入 1000
|
|
// up 上拉
|
|
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
// 针脚
|
|
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
|
|
// 输出速度
|
|
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
|
|
GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
}
|
|
|
|
// 蜂鸣器开
|
|
void beep_on(void)
|
|
{
|
|
// GPIOC_ODR |= (0x1 << 7);
|
|
PCOut(7) = 1;
|
|
}
|
|
|
|
// 蜂鸣器关
|
|
void beep_off(void)
|
|
{
|
|
// GPIOC_ODR &= ~(0x1 << 7);
|
|
PCOut(7) = 0;
|
|
}
|
|
|
|
// 获取蜂鸣器状态,返回 0 为关,1 为开
|
|
int beep_get_status(void)
|
|
{
|
|
return (GPIOC->ODR & (0x1 << 7)) ? 1 : 0;
|
|
}
|