STM32 buzzer - library function

Publisher:老王古玩店Latest update time:2019-03-29 Source: eefocusKeywords:STM32 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

It should be noted that when using the template of the library function, you cannot apply the register operation randomly. I wanted to use a big move before but ended up making a fool of myself. The experimental requirements here are that the green light is on and the buzzer sounds, the red light is on and the buzzer stops, and the buzzer sounds every half a second. I will not give the LED file here, but mainly release the beep file. The PF8 port is operated here.



1.beep.h


#ifndef __BEEP_H

#define __BEEP_H

#include "sys.h"

 

#define BEEP PFout(8)

 

void beep_init(void);

 

#endif

 

 


2.beep.c


#include "beep.h"

 

void beep_init()

{

    GPIO_InitTypeDef GPIO_InitStructure;

 

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 ;

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

    GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

    GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_100MHz;

 

    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOF, ENABLE);

    GPIO_Init(GPIOF, &GPIO_InitStructure);

    GPIO_SetBits(GPIOF, GPIO_Pin_8);

}

 


3.main.c


#include "stm32f4xx.h"

#include "usart.h"

#include "delay.h"

#include "led.h"

#include "beep.h"

 

 

int main(void)

{

uart_init(115200);

delay_init(84);


  led_heat();

  beep_init();

 

  while(1){

    GPIO_ResetBits(GPIOF, GPIO_Pin_9);

    GPIO_SetBits(GPIOF, GPIO_Pin_10);

    GPIO_ResetBits(GPIOF, GPIO_Pin_8);

    delay_ms(500);

 

    GPIO_SetBits(GPIOF, GPIO_Pin_9);

    GPIO_ResetBits(GPIOF, GPIO_Pin_10);

    GPIO_SetBits(GPIOF, GPIO_Pin_8);

    delay_ms(500);

 

}

}


Keywords:STM32 Reference address:STM32 buzzer - library function

Previous article:STM32 study notes 2——GPIO lighting
Next article:Light up LED lamp using buttons based on STM32

Recommended ReadingLatest update time:2024-11-23 16:43

Stm32 clock analysis
Most of the analysis materials come from the opendev forum. All I did was add some of my own analysis and collation. Due to my limited personal ability, omissions are inevitable. I welcome your corrections. The Stm32 clock structure diagram is as follows, ( http://www.openedv.com/posts/list/302.htm ) The analysis
[Microcontroller]
Stm32 clock analysis
STM32 startup code analysis problem
Could you explain the meaning of startup_stm32f10x_cl.s startup code, thank you! I now see the disassembly as follows 0x08000000 0678 LSLS r0,r7,#25 (check the Memory window 0x08000000: 78 06 00 20 --- STM32 little endian) 0x08000002 2000 MOVS r0,#0x00 0x08000004 1105 ASRS r5,r0,#408 0x08000006 0800 LSRS r0,r0,#
[Microcontroller]
STM32 issues regarding external interrupt lines, interrupt sources and interrupt service functions
Interrupt line problem: From the above figure, we can see that the EXTI0 interrupt line shared by PA0, PB0...PG0, and the EXTI1 interrupt line shared by PA1, PB2...PG1, that is, in the programming (as shown in the following library file), correspond to 16 interrupt lines. The last three are dedicated interrupt li
[Microcontroller]
STM32 issues regarding external interrupt lines, interrupt sources and interrupt service functions
Understanding of STM32
Now let's talk about some simple knowledge about single-chip microcomputers and the advantages of STM32 compared with other single-chip microcomputers. The minimum system of single-chip microcomputers needs a crystal oscillator circuit, a reset circuit, a power supply and grounding. In simple terms, a single-chip micr
[Microcontroller]
STM32 timer study notes
TIMx is composed of a 16-bit counter, a prescaler, and an automatic load register. Counter: 16 bits (0-65535) Prescaler 16 bits (register controlled counter) When the pre-scaling frequency is 1, the counter increases by 1 for each time pulse, and when the pre-scaling frequency is 2, the counter increases by 1 for ever
[Microcontroller]
Pay attention to the problem of RCC opening when configuring stm32 peripherals
The full name of RCC is Reset and Clock Control  There is no need to talk about reset, as it has little to do with actual programming. The clock must be understood, otherwise the program will not run as designed. For example: GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;   GPIO_InitStructure.GPIO_Mode = GPIO_Mo
[Microcontroller]
STM32 interrupt priority setting
The STM32 manual does not mention the setting of interrupt priority, but only lists the interrupt vector table. Based on the vector table, an enumeration data of the interrupt number can be created to facilitate the use of setting priority and enabling. Let me first talk about how to set priorities. The priority s
[Microcontroller]
STM32 interrupt priority setting
STM32 internal FLASH read and write interface function
Because the internal FLASH is used instead of the external EEPROM, the parameters are placed at 0x08000000+320K of the STM32, of which 20K is the bootloader and 300K is the application. Principle: First move the contents of the entire FLASH page to RAM, then modify it in RAM, then erase the entire FLASH page, and th
[Microcontroller]
Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号