3719 views|0 replies

1379

Posts

0

Resources
The OP

"Beep, beep,..." alarm sound [Copy link]

1. Design tasks

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.
4. Flowchart
Main program flow chart
Interrupt program flow chart
5. Assembly source program

T02SAEQU 30H

T02SBEQU 31H

FLAGBIT 00H

ORG 00H

LJMP START

ORG 0BH

LJMP INT_T0

START:MOV T02SA,#00H

MOV T02SB,#00H

CLR FLAG

MOV TMOD,#01H

MOV TH0,#(65536-500) / 256

MOV TL0,#(65536-500) MOD 256

SETB TR0

SETB ET0

SETB EA

SJMP$

INT_T0:

MOV TH0,#(65536-500) / 256

MOV TL0,#(65536-500) MOD 256

INC T02SA

MOV A,T02SA

CJNE A,#100,NEXT

INC T02SB

MOV A,T02SB

CJNE A,#04H,NEXT

MOV T02SA,#00H

MOV T02SB,#00H

CPL FLAG

NEXT:JB FLAG,DONE

CPL P1.0

DONE:RETI

END

6. C language source program

#include <AT89X51.H>

unsigned int t02s;

unsigned char t05ms;

bit flag;

void main(void)

{

TMOD=0x01;

TH0=(65536-500)/256;

TL0=(65536-500)%256;

TR0=1;

ET0=1;

EA=1;

while(1);

}

void t0(void) interrupt 1 using 0

{

TH0=(65536-500)/256;

TL0=(65536-500)%256;

t02s++;

if(t02s==400)

{

t02s=0;

flag=~flag;

}

if(flag==0)

{

P1_0=~P1_0;

}

}

This post is from MCU

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Related articles more>>
    Copyright © 2005-2025 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
    快速回复 返回顶部 Return list