The microcontroller drive buzzer principle design

  The buzzer is a structure of an integrated electronic transducers, this article describes how to use the microcontroller to drive the buzzer for sound devices are widely used in electronic products such as computers, printers, copiers, alarm, telephone.
The buzzer is divided into two types of piezoelectric buzzer and electromagnetic buzzer.
  Electromagnetic buzzer by the oscillator, the electromagnetic coil, magnet, diaphragm and housing. After power on, the audio signal generated by the oscillator current through the electromagnetic coil, the electromagnetic coil generates a magnetic field, the diaphragm is in the interaction of the electromagnetic coil and a magnet, periodically sound vibration.
  The piezoelectric buzzer mainly by the the multivibrator, piezoelectric buzzer impedance matching and resonance box, such as Shell. The multivibrator transistors or integrated circuits, (1.5 ~ 15V DC operating voltage) when the power is turned on, the multivibrator start-up output a 1.5 ~ 2.5kHZ audio signals, impedance matching is to promote the piezoelectric buzzer sound.
   Here is the picture the shape of the electromagnetic buzzer and structural plans
The electromagnetic buzzer physical map: the the electromagnetic buzzer structure diagram:
Electromagnetic buzzer internal structure:
1. Waterproof stickers
2 spools
3 coil
4 magnets
5 base
6 Pin
7 shell
8 core
9. Sealant
Small iron piece 10.
11. Diaphragm
12. Circuit board
 Electromagnetic buzzer driving principle
  The buzzer sounds principle is current through the solenoid coil, solenoid coil produces a magnetic field to drive the sound of the diaphragm, and therefore requires a certain amount of current to drive it, small microcontroller IO pin output current, the microcontroller output of TTL level basically can not drive the buzzer, and therefore the need to increase a current amplification circuit. S51 enhanced micro-controller board through a transistor C8550 zoom drive the buzzer.
The S51 MCU Board Enhanced buzzer driver schematic:
  The buzzer positive to VCC (+5 V) power above, the negative terminal of the buzzer connected to the transistor emitter E the transistor base class B after limiting resistor R1 P3.7 pin is controlled by a microcontroller, P3 .7 output is high, the transistor T1 is turned off, no current flows through the coil, the buzzer does not sound; When the the P3.7 output low, the transistor turns, to form a loop, this current buzzer sound. Therefore, we can through process control P3.7 foot level to the buzzer sound on and off.
The program change the MCU P3.7 pin output waveform frequency can be adjusted to control the buzzer tones, produce a variety of different timbre, tone of voice. In addition, change the the P3.7 output level high and low duty cycle, you can control the size of the buzzer sound, we are programming experiments to validate.
Second, the buzzer Liezi
  Here we give you a few simple microcontroller drive the buzzer programming and circuit design Liezi.
1, simple buzzer experimental procedures: the program by a range of audio output in P3.7 square wave, driven experimental board buzzer beeps DELAY delay subroutine which the output square-wave frequency the 20KHZ following the hearing ability of the human ear, if there is no delay in this program, the output frequency will be far beyond the hearing ability of the human ear, we will not be able to hear the sound. Change the delay constant, the output frequency can be changed, it can adjust the tone of the buzzer. Experiment, we can change the # 228 to hear the the buzzer tones of change for other values,
ORG 0000H
AJMP MAIN; Jump to the main program
ORG 0030H
MAIN: CPL P3.7; buzzer driver level negated
LCALL DELAY; Delay
AJMP MAIN; repeated cycles
DELAY: MOV R7, # 228; delay subroutine, change the delay constant can change the tone of the buzzer
DE1: DJNZ R7, DE1
RET
END
2, reversing warning sound experimental procedure: We know that all kinds of trucks, container trucks reversing when the issue of reversing beep warning tone, while warning yellow light also flashes in synchronization, remind the attention of the person or vehicle behind. The routine of the experiment on the the reverse alarm function, through experimental panel buzzer alert tone, to issue a warning light at the same time by two light-emitting diode on the experimental board P1.2 and P1.5.
ORG 0000H
Jump to the initialization procedure AJMP START;
ORG 0033H
START:
MOV SP, # 60H; SP initialization
MOV P3, # 0FFH; port initialization
MAIN: ACALL SOUND; buzzer sounds
ACALL YS500M; Delay
AJMP MAIN
SOUND:
MOV P1, # 11011011B; lit two warning ** light-emitting diodes
MOV R2, # 200; ring for 200 cycles
SND1: CLR P3.7; output low T1 turns on the buzzer
ACALL YS1ms; Delay
SETB P3.7; the output high T1 Deadline buzzer does not sound
ACALL YS1ms; Delay
DJNZ R2, SND1
MOV P1, # 0FFH; extinguished ** warning lights
RET
YS1ms:; 1ms delay subroutine
MOV R0, # 2
YL1: MOV R1, # 250; changing of R0 values ​​can change the frequency of the sound
DJNZ R1, $
DJNZ R0, YL1
RET
YS500M:; 500ms delay subroutine
MOV R0, # 6
YL2: MOV R1, # 200
YL3: MOV R2, # 250
DJNZ R2, $
DJNZ R1, YL3
DJNZ R0, YL2
RET
END
3, "ding-dong" the electronic doorbell experimental program: common household electronic doorbell visitor when, if the doorbell button is pressed, the interior will be issued a "ding-dong" sound, the pronunciation of the experimental program to simulate electronic doorbell, when we pressed the experimental board K1 button when the the buzzer "ding-dong" sound of music, is a more practical program.
"BUZZ" the electronic doorbell experiment ASM source: "ding-dong" the electronic doorbell C language source:
ORG 0000H
Jump to the initialization procedure LJMP START;
ORG 000BH
Jump to T0 interrupt service routine LJMP PGT0;
START:
OBUF1 EQU 30H; initialization procedure
OBUF2 EQU 31H
OBUF3 EQU 32H
OBUF4 EQU 33H
FLAGB BIT 00H
STOPB BIT 01H
K1 BIT P3.2; custom button K1, as the doorbell button
MOV TMOD, # 02H; timer initialization
MOV TH0, # 06H
MOV TL0, # 06H
SETB ET0; start timer T0
SETB EA; startup total interruption
MAIN:; main program
JB K1, MAIN; detection K1 button
The LCALL YS10M; Delay debounce
JB K1, MAIN
SETB TR0; effective button
MOV P1, # 00H; lit button indicator
MOV OBUF1, # 00H
MOV OBUF2, # 00H
MOV OBUF3, # 00H
MOV OBUF4, # 00H
CLR FLAGB
CLR STOPB
JNB STOPB, $
MOV P1, # 0FFH
LJMP MAIN; issued a "ding-dong" finished, return to re-detect button
YS10M:; 10ms delay subroutine
MOV R6, # 20
D1: MOV R7, # 248
DJNZ R7, $
DJNZ R6, D1
RET
PGT0:; timer T0 interrupt service routine
INC OBUF3; uttered a "ding-dong" sound in the interrupt service routine
MOV A, OBUF3
CJNE A, # 100, NEXT
MOV OBUF3, # 00H
INC OBUF4
MOV A, OBUF4
CJNE A, # 20, NEXT
MOV OBUF4, # 00H
JB FLAGB, PGSTP
CPL FLAGB
AJMP NEXT
PGSTP:
SETB STOPB
CLR TR0
LJMP INT0RET
NEXT: JB FLAGB, SOU2
INC OBUF2
MOV A, OBUF2
CJNE A, # 03H, INT0RET
MOV OBUF2, # 00H
CPL P3.7
LJMP INT0RET
SOU2: INC OBUF1
MOV A, OBUF1
CJNE A, # 04H, INT0RET
MOV OBUF1, # 00H
CPL P3.7
LJMP INT0RET
INT0RET:
RETI
END
# Include
unsigned char obuf1;
unsigned char obuf2;
unsigned int obuf3;
bit stopb;
bit flagb;
void main (void)
{
unsigned char i, j;
TMOD = 0x02; / / Timer T0 initialization
TH0 = 0x06;
TL0 = 0x06;
ET0 = 1;
EA = 1; / / total allowable interrupt
while (1)
{
if (P3_2 == 0) / / detect K1 key
{
P1 = 0x00;
for (i = 10; i> 0; i -)
for (j = 248; j> 0; j -);
if (P3_2 == 0)
{
obuf1 = 0;
obuf2 = 0;
obuf3 = 0;
flagb = 0;
stopb = 0;
TR0 = 1; / / start timer T0, issue a "ding-dong" sound
while (stopb == 0);
P1 = 0xff;
}
}
}
}
void t0 (void) interrupt 1 using 0
{
obuf3 + +;
if (obuf3 == 2000)
{
obuf3 = 0;
if (flagb == 0)
{
flagb = ~ flagb;
}
else
{
stopb = 1;
TR0 = 0;
}
}
if (flagb == 0)
{
obuf2 + +;
if (obuf2 == 3)
{
obuf2 = 0;
P3_7 = ~ P3_7;
}
}
else
{
obuf1 + +;
if (obuf1 == 4)
{
obuf1 = 0;
P3_7 = ~ P3_7;
}
}
}