蜂鸣器的呐喊

来源:互联网 发布:mysql qq充值 编辑:程序博客网 时间:2024/04/25 21:50

main.c

#include "led.h"#include "delay.h"#include "beep.h"int main(){    delay_init();    LED_Init();    BEEP_Init();    while(1)    {        //GPIO_SetBits(GPIOB, GPIO_Pin_8);        GPIO_ResetBits(GPIOB, GPIO_Pin_5);        GPIO_ResetBits(GPIOE, GPIO_Pin_5);        delay_ms(300);        //GPIO_ResetBits(GPIOB, GPIO_Pin_8);        GPIO_SetBits(GPIOB, GPIO_Pin_5);        GPIO_SetBits(GPIOE, GPIO_Pin_5);        delay_ms(300);    }}

beep.h

#ifndef __BEEP_H#define __BEEP_Hvoid BEEP_Init(void);#endif

beep.c

#include "beep.h"#include "stm32f10x_gpio.h"#include "stm32f10x_rcc.h"void BEEP_Init(void){    GPIO_InitTypeDef GPIO_InitStructure;    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);    // BEEP-->GPIOB.8    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8;    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;    GPIO_Init(GPIOB, &GPIO_InitStructure);    GPIO_ResetBits(GPIOB, GPIO_Pin_8);  // 输出低电平;}

led.h

#ifndef __LED_H#define __LED_Hvoid LED_Init(void);#endif

led.c

#include "led.h"#include "stm32f10x_gpio.h"#include "stm32f10x_rcc.h"void LED_Init(void){    GPIO_InitTypeDef GPIO_InitStructure;    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOE,ENABLE);    // LED0-->PB.5    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 推挽输出;    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;    GPIO_Init(GPIOB, &GPIO_InitStructure);    GPIO_SetBits(GPIOB, GPIO_Pin_5);    // PB.5 输出高电平;    // LED1-->PE.5    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5;    GPIO_Init(GPIOE, &GPIO_InitStructure);    GPIO_SetBits(GPIOE, GPIO_Pin_5);    // PE.5 输出高电平;}
0 0
原创粉丝点击