51 single chip microcomputer buzzer

Publisher:VelvetWhisperLatest update time:2017-01-08 Source: eefocus Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The principle of buzzer sound is that the current passes through the electromagnetic coil, which makes the electromagnetic coil generate a magnetic field to drive the vibration membrane to make sound. Therefore, a certain current is required to drive it. The current output by the IO pin of the microcontroller is small, and the TTL level output by the microcontroller basically cannot drive the buzzer. Therefore, a current amplification circuit is needed. The role of the transistor is to drive, and the driving current is amplified by the transistor, so that the buzzer can make a sound.

 

The difference between active buzzer and passive buzzer:

The "source" here does not refer to the power supply. It refers to the oscillation source. In other words, the active buzzer has an oscillation source inside, so it will buzz as soon as it is powered on. The  passive buzzer
does not have an oscillation source inside, so it cannot be made to buzz if a DC signal is used. It must be driven by a 2K~5K square wave. 
Active buzzers are often more expensive than passive ones because they have multiple oscillation circuits inside. 
The advantages of passive buzzers are: 1. Cheap, 2. The sound frequency is controllable, and the "Doremi Fasolaxi" effect can be produced. 3. In some special cases, it can reuse a control port with the LED. The advantages of active buzzers are: convenient program control.

 

 

 

Routine, reference from the Internet.

  1 /************************************************ ************************  

  2 [File Name] C51 Music Program (August Osmanthus)  

  3 [Function] Playing music through microcontroller  

  4   

  5/************************************************ ************************/   

  6 #include    

  7 #include    

  8 //This example uses 89C52, the crystal oscillator is 11.0592MHZ    

  9 // Regarding how to compile music code, it is actually very simple. You can see the following code.    

 10 //The frequency constant is the pitch in musical terms, and the beat constant is the number of beats in musical terms;    

 11 //So take out the music score and try to edit it!    

 12 

 13 sbit Beep = P1^5 ; 

 14    

 15 unsigned char n=0; //n is the beat constant variable    

 16 unsigned char code music_tab[] ={   

 17 0x18, 0x30, 0x1C, 0x10, //Format: frequency constant, beat constant, frequency constant, beat constant,    

 18 0x20, 0x40, 0x1C , 0x10,   

 19 0x18, 0x10, 0x20 , 0x10,   

 20 0x1C, 0x10, 0x18, 0x40,   

 21 0x1C, 0x20, 0x20 , 0x20,   

 22 0x1C, 0x20, 0x18, 0x20,   

 23 0x20, 0x80, 0xFF , 0x20,   

 24 0x30, 0x1C, 0x10, 0x18,   

 25 0x20, 0x15, 0x20 , 0x1C,   

 26 0x20, 0x20, 0x20 , 0x26,   

 27 0x40, 0x20, 0x20 , 0x2B,   

 28 0x20, 0x26, 0x20 , 0x20,   

 29 0x20, 0x30, 0x80, 0xFF,   

 30 0x20, 0x20, 0x1C , 0x10,   

 31 0x18, 0x10, 0x20, 0x20,   

 32 0x26, 0x20, 0x2B , 0x20,   

 33 0x30, 0x20, 0x2B , 0x40,   

 34 0x20, 0x20, 0x1C , 0x10,   

 35 0x18, 0x10, 0x20, 0x20,   

 36 0x26, 0x20, 0x2B , 0x20,   

 37 0x30, 0x20, 0x2B , 0x40,   

 38 0x20, 0x30, 0x1C , 0x10,   

 39 0x18, 0x20, 0x15 , 0x20,   

 40 0x1C, 0x20, 0x20 , 0x20,   

 41 0x26, 0x40, 0x20 , 0x20,   

 42 0x2B, 0x20, 0x26 , 0x20,   

 43 0x20, 0x20, 0x30, 0x80,   

 44 0x20, 0x30, 0x1C , 0x10,   

 45 0x20, 0x10, 0x1C , 0x10,   

 46 0x20, 0x20, 0x26 , 0x20,   

 47 0x2B, 0x20, 0x30, 0x20,   

 48 0x2B, 0x40, 0x20, 0x15,   

 49 0x1F, 0x05, 0x20, 0x10,   

 50 0x1C, 0x10, 0x20, 0x20,   

 51 0x26, 0x20, 0x2B , 0x20,   

 52 0x30, 0x20, 0x2B , 0x40,   

 53 0x20, 0x30, 0x1C , 0x10,   

 54 0x18, 0x20, 0x15 , 0x20,   

 55 0x1C, 0x20, 0x20 , 0x20,   

 56 0x26, 0x40, 0x20 , 0x20,   

 57 0x2B, 0x20, 0x26 , 0x20,   

 58 0x20, 0x20, 0x30, 0x30,   

 59 0x20, 0x30, 0x1C , 0x10,   

 60 0x18, 0x40, 0x1C , 0x20,   

 61 0x20, 0x20, 0x26 , 0x40,   

 62 0x13, 0x60, 0x18, 0x20,   

 63 0x15, 0x40, 0x13 , 0x40,   

 64 0x18, 0x80, 0x00   

 65 };   

 66    

 67 void int0() interrupt 1 //Use interrupt 0 to control the beat    

 68 {TH0=0xd8;   

 69 TL0=0xef;   

 70 n--;   

 71 }   

 72    

 73 void delay (unsigned char m) //Control frequency delay    

 74 {   

 75 unsigned i=3*m;   

 76 while(--i);   

 77 }   

 78    

 79 void delayms(unsigned char a) // millisecond delay subroutine    

 80 {   

 81 while(--a); //Use while(--a) Do not use while(a--); You can compile and see the assembly result to know!    

 82 }   

 83    

 84 void main()   

 85 { unsigned char p,m; //m is the frequency constant variable    

 86 unsigned char i=0;   

 87 TMOD&=0x0f;   

 88 TMOD|=0x01;   

 89 TH0=0xd8;TL0=0xef;   

 90 IE=0x82;   

 91 play:   

 92 while(1)   

 93 {   

 94 a: p=music_tab[i];   

 95 if(p==0x00) { i=0, delayms(1000); goto play;} //If the end character is encountered, delay 1 second and go back to the beginning and play again    

 96 else if(p==0xff) { i=i+1;delayms(100),TR0=0; goto a;} //If a rest is encountered, delay 100ms and continue to pick the next note    

 97 else {m=music_tab[i++], n=music_tab[i++];} //Get the frequency constant and beat constant    

 98 TR0=1; //Start timer 1    

 99 while(n!=0) Beep=~Beep,delay(m); //Wait for the beat to finish, output audio through P1 port (multi-channel is possible!)    

100 TR0=0; //Turn off timer 1    

101 }   

102 }  


Reference address:51 single chip microcomputer buzzer

Previous article:51 MCU AD conversion
Next article:51 MCU buttons, keyboard detection

Recommended ReadingLatest update time:2024-11-16 17:46

How to make a buzzer make a sound? Does the sound of a buzzer have anything to do with frequency?
How to make the buzzer sound To make the buzzer sound, you usually need to connect it to a suitable power source and provide the corresponding signal input. The following are the steps for connecting and using the buzzer in general: 1. **Determine polarity:** If the buzzer is unipolar (only two pins), gene
[Embedded]
Buzzer plays music + Puzhong 51 single chip microcomputer + Jiangke University Automation Association
1 Phenomenon Use the buzzer to realize the music playback function and play "Castle in the Sky". 2 Principle (1) Music score of Castle in the Sky 3 Reference Program 3.1 Main Program #include REGX52.H #include "delayms.h" #include "timer0.h" //Buzzer
[Microcontroller]
Buzzer plays music + Puzhong 51 single chip microcomputer + Jiangke University Automation Association
Programming example of driving buzzer under S3F9454/9444
A. The first method is the ordinary IO high and low level driving method               ; operating environment: S3F9454, Fosc = 3.2MHz without frequency division               ; P2.0 is the buzzer output port               ;In this example, the output frequency is 4KHZ, that is, one cycle is 250US, and the high and lo
[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号