Use the AT89C51 single-chip microcomputer to generate the "beep, beep,..." alarm sound and output it from the P1.0 port. The frequency is 1KHz. According to the above figure, we can see that: a 1KHZ square wave is output from P1.0 for 0.2 seconds, and then a level signal is output from P1.0 for 0.2 seconds. This cycle continues to form the alarm sound we need.
2. Circuit diagram
3. Programming content
In our daily life, we often hear various alarm sounds, such as "beep, beep,..." is a common sound alarm sound. However, for this kind of alarm sound, the beep sound is 0.2 seconds, then off for 0.2 seconds, and so on. Assuming that the frequency of the beep sound is 1KHz, the alarm sound timing diagram is as shown in the figure below:
How to generate the above waveform signal using a single-chip microcomputer?
In order to generate the above signal, we divide the above signal into two parts, one part is a 1KHZ square wave, which takes 0.2 seconds; the other part is a level, which also takes 0.2 seconds; therefore, we use the timer/counter T0 of the single-chip microcomputer as the timing, which can be timed for 0.2 seconds; at the same time, we also need to use the single-chip microcomputer to generate a 1KHZ square wave. The period of the 1KHZ square wave signal is 1ms, the high level takes 0.5ms, and the low level takes 0.5ms, so timer T0 is also used to complete the 0.5ms timing; finally, the timing time of the timer/counter T0 can be selected as 0.5ms, and the timing of 0.2 seconds is 400 times of 0.5ms, that is to say, 0.5ms timing 400 times will reach a timing time of 0.2 seconds.