*  Proteus Schematic diagram is interpretation

The passive buzzer is selected for this experiment (500Hz~4.5KHz), That is, its oscillation source is not fixed , It can be set by program , Pay attention to the difference between active and passive ( Whether there is vibration source ), The vulgar point is that the passive frequency can be adjusted .

The working principle of the buzzer is to conduct electricity and stop after , Generate a magnetic field on both pins , Suck down the iron sheet , Restore the original state after the magnetic field disappears , To make a sound . Schematic diagram utilization PNP Type a triode acts as a switch in the amplification area , Using common emitter amplifier circuit , So as to control the generation and disappearance of magnetic field .Ri Act as input resistance , The higher the input resistance , The input voltage obtained by the amplification circuit is closer to the power supply voltage .R1 Act as current limiting resistor , The purpose is to prevent the buzzer from being damaged by excessive current . in addition , Because the buzzer is internally a solenoid coil , When the magnetic field disappears , The current will not disappear immediately , Therefore, the diode is connected to consume the current .

*  keil programming

In order to produce the sound of corresponding frequency more accurately , You can use the delay timer under the burner software . The program cannot display the desired frequency , Because when executing instructions , Statement also takes time , So it will take longer . Because the time we set is very small , So the impact is relatively large . If the delay time is large , such as 1ms, Then the impact of the execution time of the statement will not be so great .
#include<reg51.h> #include<intrins.h> sbit BUZZ=P2^1; void Delay100us(unsigned
int j); void HZ(unsigned int k) { int j; j=10000/k/2;
// Since the calculation time is 1/f,1 The unit of is s, Take here 10000 Yes, how many 100us Delay100us(j); } /* Calculate how many there are at this frequency 100us*/
void Delay100us(unsigned int j) // Crystal oscillator @11.0592MHz { unsigned char i; while(j--) {
_nop_(); i = 43; while (--i); } } void main() { while(1) { BUZZ=1; HZ(2500);
BUZZ=0; HZ(2500); } }
* Error points in personal program and simulation debugging  
1. No custom function declared , Because when the program encounters a custom function when executing instructions , It's looking up , If the function is not placed in the front , It should be stated in front with a semicolon . And the format is similar to the function header .

 2.while(--j) and while(j--) Differences between . The former runs less than the latter .

3._nop_() Is in intrins.h In header file , Therefore, it should be defined .

4. Questions caused by oscilloscope

Doubtful points 1: Why is it low , Voltage is <0 of ? 

Technology
Daily Recommendation