buzzer.c文件
#include "stm32f10x.h"
#include "buzzer.h"
void buzzer_Init(void)
{
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.GPIO_Pin=GPIO_Pin_0;
GPIO_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(GPIOB,&GPIO_InitStruct);
}
buzzer.h文件
#ifndef _BUZZER_H_
#define _BUZZER_H_
void buzzer_Init(void);
#endif
main.c文件
#include "stm32f10x.h"
#include "buzzer.h"
#include "delay.h"
int main (void)
{
buzzer_Init();
while(1)
{
GPIO_ResetBits(GPIOB,GPIO_Pin_0);
delay_ms(500);
GPIO_SetBits(GPIOB,GPIO_Pin_0);
delay_ms(500);
}
}