jlxaiyjx

导航

STM32蜂鸣器(2023/7/19)

1.接线图(蜂鸣器低电平发声,高电平不发声)

 2.程序编写

#include "stm32f10x.h" // Device header
#include "Delay.h"
int main(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Pin=GPIO_Pin_12;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStructure);
//GPIO_WriteBit(GPIOC,GPIO_Pin_13,Bit_RESET);高电平为Bit_SET,低电平为Bit_RESET
//GPIO_ResetBits(GPIOC,GPIO_Pin_13);高电平为Bit_SET,低电平为Bit_RESET
while(1)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_12);
Delay_ms(100);
GPIO_SetBits(GPIOB,GPIO_Pin_12);//这里要注意:上面复制下来如果报错的话,记得检查一下S是否更改了大小写
Delay_ms(100);

}
}

 

posted on 2023-07-19 13:15  蒋果是果  阅读(70)  评论(0编辑  收藏  举报