PIC Microcontroller - Buzzer Usage Example

Publisher:AngelicWhisperLatest update time:2019-05-11 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

Example of use:


/****************************************************** ******************************

* Jumper connection: short-circuit P2 2 and 3

* Function description: Passive buzzer sound

*************************************************** *******************************/

#include

#include

 

#define uint8 unsigned char

#define uint16 unsigned int

 

__CONFIG(WDTDIS & LVPDIS & HS & PWRTDIS & BORDIS); //Set configuration bits

//WDTDIS:disable watchdog timer

//LVPDIS: low voltage programming disabled

//HS:high speed crystal/resonator

//PWRTDIS:disable power up timer

//BORDIS:disable brown out reset

 

/***************************Declare function*******************************************/

 

void DelayUS(uint8 delay);

 

/****************************************************** ******************************

* Function name: DelayUS(uint8 delay)

* Function: microsecond delay for 20MHZ

* Input parameter: delay

* Return: None

*************************************************** *******************************/

 

void DelayUS(uint8 delay)

{

while(--delay);

}

 

/****************************************************** *****************************

* Function name: main(void)

* Function: drive the passive buzzer to sound

* Input parameters: None

* Return: None

*************************************************** *******************************/

 

void main(void)

{

ADCON1 = 0x86; //PORTA is set as digital IO port

TRISA0 = 0; //RA0 is set to output mode

while(1)

{

RA0 = 1;

DelayUS(400);

RA0 = 0;

DelayUS(400);    

}

}


Reference address:PIC Microcontroller - Buzzer Usage Example

Previous article:PIC Microcontroller - Relay Usage Example
Next article:PIC microcontroller-RS232 serial communication

Recommended ReadingLatest update time:2024-11-15 17:25

LPC2103 Learning Board - Buzzer Practice Program
  /**************ARM7(LPC2103) exercise program**************************/ /************************************************************************/ /*****File Function : Buzzer test *****/ /*****Program Author : ClimberWin *****/ / *****MCU : LPC2103F external 11.0592M crystal oscillator*****/ /*****Compile
[Microcontroller]
LPC2103 Learning Board - Buzzer Practice Program
Efficiency Programming of Single Chip Microcomputer Active Buzzer Driver
Buzzers are very common devices, divided into passive and active types. Choose different types of buzzers according to project requirements. In recent projects, active buzzers are used. It's still the same old routine. Draw the circuit board and then program it. The schematic diagram in the project is as follows:
[Microcontroller]
Efficiency Programming of Single Chip Microcomputer Active Buzzer Driver
Multi-mode 51 single-chip heart-shaped water light + breathing light + buzzer music
1. Basic hardware DIY design Circuit Hardware: STC89C52RC Buzzer/24 LEDs/4 corner buttons 1) Overall schematic diagram 2) PCB circuit 3) 3D_PCB TOP layer 2. MCU Programming 1) Breathing light //Breathing light while(1) { for(high=1;high cycle;high++) { P2=P1=P0=0XFF; delay2(high); P2=P1=P0=0X00;
[Microcontroller]
Multi-mode 51 single-chip heart-shaped water light + breathing light + buzzer music
51 MCU Introduction - Buzzer
1. What is a buzzer? Buzzers can be divided into piezoelectric buzzers and electromagnetic buzzers based on their structures. Piezoelectric buzzers use piezoelectric ceramics to make sounds, and the current is relatively small, while electromagnetic buzzers use coils to vibrate and make sounds, and are relatively smal
[Microcontroller]
51 MCU Introduction - Buzzer
Buzzer driver
The buzzer is a hardware device on the S3C6410 development board. You can control the buzzer to make a scream by writing a specific value to the register. (1) The prerequisite is that the CDT plug-in is installed in Eclipse. (2) In eclipse, click File-New-Other, select C Project, click Next to make corresp
[Microcontroller]
STM32F030 control buzzer
(1) In the main() function: int BeeTime=0; int soundSta=0;   void main() { TIM2_Init(); soundBee(1); //One long beep soundBee(0); //short beep   }   void TIM2_Init()  {     TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);       TIM_TimeBaseStructure.TIM_Perio
[Microcontroller]
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号