3.STM32F4蜂鸣器

推挽输出,输出高蜂鸣器响,输出低电平蜂鸣器停.

#include <stm32f4xx.h>
 
void Delay(__IO uint32_t nCount){
	while(nCount--);
}
void GPIO_Con(){
	GPIO_InitTypeDef GPIO_Struct;
	RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF,ENABLE);
	GPIO_Struct.GPIO_Pin=GPIO_Pin_6;
	GPIO_Struct.GPIO_Mode=GPIO_Mode_OUT;
	GPIO_Struct.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_Struct.GPIO_OType=GPIO_OType_PP;
	GPIO_Struct.GPIO_PuPd=GPIO_PuPd_DOWN;
	GPIO_Init(GPIOF,&GPIO_Struct);
}
 
int main(void){
	 GPIO_Con();
   while(1){
		GPIO_SetBits(GPIOF,GPIO_Pin_6);
		Delay(1000);
		GPIO_ResetBits(GPIOF,GPIO_Pin_6);
		Delay(1000);
	}
}

猜你喜欢

转载自blog.csdn.net/weixin_42480952/article/details/82559658