2.6 蜂鸣器(含代码)
配置原理和配LED是一样的- #include "stm32f10x.h" // Device header
- #include "Delay.h"
- int main(void)
- {
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB ,ENABLE );//使能GPIO时钟
-
- GPIO_InitTypeDef A;
-
- A.GPIO_Mode=GPIO_Mode_Out_PP;//设置为推挽输出模式
- A.GPIO_Pin=GPIO_Pin_12; //设置为Pin0口
- A.GPIO_Speed=GPIO_Speed_50MHz; //输出速度为50MHz
- GPIO_Init( GPIOB,&A); //以上三个都要传入该函数初始化
- while(1)
- {
- GPIO_ResetBits(GPIOB,GPIO_Pin_12);//低电平触发
- Delay_ms (100);
- GPIO_SetBits(GPIOB,GPIO_Pin_12);//不响
- Delay_ms (100);
- }
- }
|