点击查看代码
/**
******************************************************************************
* @file main.c
* @author
* @version
* @date 2024/06/28
* @brief 实现利用MCU的PF8引脚控制开发板的BEEP的鸣叫
******************************************************************************
**/
#include "stm32f4xx.h" //必须包含
int main()
{
//1.定义GPIO外设的结构体变量
GPIO_InitTypeDef GPIO_InitStructure;
//2.打开GPIOF端口的时钟
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);
//3.配置PF9引脚为输出模式
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
//4.对GPIOF端口进行初始化
GPIO_Init(GPIOF, &GPIO_InitStructure);
while(1)
{
//5.控制PF8引脚输出高电平,则BEEP会响
GPIO_SetBits(GPIOF,GPIO_Pin_8);
}
}