蜂鸣器

–Beep.h

#ifndef __Beep_h
#define __Beep_h

#define  Beep_ON        (GPIOB->ODR |= 0x0020)   
//   GPIO_SetBits(GPIOB,GPIO_Pin_5)
#define  Beep_OFF       (GPIOB->ODR &= 0xFFDF)   
//   GPIO_ResetBits(GPIOB,GPIO_Pin_5)

void Beep_Init(void);
void Beep_breath(void);
void Beep_delay(int ms);

#endif

–Beep.c

#include <stdio.h>
#include "stm32f10x.h"
#include "Beep.h"

#define T 300
static  int i = 0;
static  int j = 0;

void Beep_Init(void)
{
    RCC->APB2ENR |= 0x0008;  
    GPIOB->CRL = (GPIOB->CRL&0xFF0FFFFF)|0x00300000;
    //需要用到PB5端口
}

void Beep_breath(void)
{
    int time;
    for( time = 1 ; time < T ; time += 1)
    {
      Beep_ON;
            Beep_delay(15000);
          Beep_OFF;
            Beep_delay(5000);
    }   
}

void Beep_delay(int ms)
{
    for( i = 0 ; i < 100 ; i++)
        for(j = 0 ; j < ms ; j++);
}
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值