PIC Microcontroller - Buzzer Usage Example

Publisher:幸福之星Latest update time:2018-08-04 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

PIC mid-range microcontroller buzzer schematic diagram:PIC microcontroller buzzer schematic diagram

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 RB0 external interrupt routine
Next article:PIC microcontroller clock settings

Recommended ReadingLatest update time:2024-11-16 19:40

51 single chip microcomputer (AT89C52) controls buzzer
#include reg52.h   #define uchar unsigned char   #define uint unsigned int   sbit beep=P0^0;   void delay(uint z)   {       uint x,y;       for(x=z;x 0;x--)           for(y=111;y 0;y--);   }   void main()   {       while(1)       {           beep=0;           delay(500);           beep=1;           delay(500);       }
[Microcontroller]
51 single chip microcomputer (AT89C52) controls buzzer
Tiny210 bare metal PWM controlled buzzer
start.S source code: .global _start _start:     ldr sp, =0xD0030000 // Initialize the stack because the C function will be called later      bl clock_init // Initialize the clock      bl ddr_init // Initialize memory      bl nand_init // Initialize NAND      ldr r0, =0x36000000 // location to be copied to DDR      ldr
[Microcontroller]
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
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号