1.Beep.h
#ifndef __Beep_H
#define __Beep_H
#include "sys.h"
//Beep GPIOÅäÖÃ
#define Beep_GPIO_CLK RCC_APB2Periph_GPIOB //GPIOBʱÖÓ
#define Beep_GPIO_PORT GPIOB //GPIOB
#define Beep_GPIO_Mode GPIO_Mode_Out_PP //ÍÆÍìÊä³ö
#define Beep_GPIO_Pin GPIO_Pin_8 //Pin_8
#define Beep PBout(8)// PB8
void Beep_Init(void);
#endif
2.Beep.c
#include "Beep.h"
void Beep_Init(void)
{
RCC_APB2PeriphClockCmd(Beep_GPIO_CLK,ENABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode=Beep_GPIO_Mode;
GPIO_InitStructure.GPIO_Pin=Beep_GPIO_Pin;
GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz;
GPIO_Init(Beep_GPIO_PORT,&GPIO_InitStructure);
GPIO_ResetBits(Beep_GPIO_PORT,Beep_GPIO_Pin);
}
3.main
#include "stm32f10x.h" // Device header
#include "Delay.h"
#include "sys.h"
#include "stdio.h"
#include "Led.h"
#include "Key.h"
#include "Beep.h"
int main(void)
{
Led_Init();
Key_Init();
Beep_Init();
while(1)
{
Beep = 0;
Delay_s(1);
Beep = 1;
Delay_s(1);
}
}