Ding Dong doorbell

Publisher:BlossomSunriseLatest update time:2011-02-27 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

1. Experimental tasks

When the switch SP1 is pressed , the AT89S51 microcontroller generates a "ding dong" sound which is output from the P1.0 port to the LM386 and then sent to the speaker after being amplified.

2. Circuit diagram

Figure 4.19.1

3. Hardware connection on the system board

(1. Connect the P1.0 port in the "MCU System" area to the SPK IN port in the "Audio Amplifier Module" area with a wire ;

(2. Connect an 8 ohm or 16 ohm speaker to the SPK OUT port in the "Audio Amplifier Module" area ;

(3. Connect the P3.7/RD port in the "MCU System" area to the SP1 port in the "Standalone Keyboard" area with a wire ;

4. Programming methods

(1. We use the MCU real timer / counter T0 to generate 700HZ and 500HZ frequencies. According to the timer / counter T0 , we take the timing of 250us . Therefore, the frequency of 700HZ needs to go through 3 times of 250us timing, and the frequency of 500HZ needs to go through 4 times of 250us timing.

(2. During the design process, only when SP1 is pressed will T0 start working. When T0 is finished working, it returns to the initial state.

(3. The "ding" and "dong" sounds each take 0.5 seconds, so the timer / counter T0 needs to complete the 0.5 second timing, which requires 2000 times based on the 250us benchmark .

6. Assembly source program

T5HZ EQU 30H

T7HZ EQU 31H

T05SA EQU 32H

T05SB EQU 33H

FLAG BIT 00H

STOP BIT 01H

SP1 BIT P3.7

ORG 00H

LJMP START

ORG 0BH

LJMP INT_T0

START: MOV TMOD,#02H

MOV TH0, #06H

MOV TL0, #06H

SETB ET0

SETB OF

NSP: JB SP1,NSP

LCALL DELY10MS

JB SP1,NSP

SETB TR0

MOV T5HZ, #00H

MOV T7HZ,#00H

MOV T05SA,#00H

MOV T05SB,#00H

CLR FLAG

CLR STOP

JNB STOP,$

LJMP NSP

DELY10MS: MOV R6,#20

D1: MOV R7,#248

DJNZ R7,$

DJNZ R6,D1

RIGHT

INT_T0: INC T05SA

MOV A,T05SA

CJNE A,#100,NEXT

MOV T05SA,#00H

INC T05SB

MOV A,T05SB

CJNE A,#20,NEXT

MOV T05SB,#00H

JB FLAG,STP

CPL FLAG

LJMP NEXT

STP: SETB STOP

CLR TR0

LJMP DONE

NEXT: JB FLAG,S5HZ

INC T7HZ

MOV A,T7HZ

CJNE A,#03H,DONE

MOV T7HZ,#00H

CPL P1.0

LJMP DONE

S5HZ: INC T5HZ

MOV A,T5HZ

CJNE A,#04H,DONE

MOV T5HZ, #00H

CPL P1.0

LJMP DONE

DONE: NETWORKS

END

7. C language source program

#include

unsigned char t5hz;

unsigned char t7hz;

unsigned int tcnt;

bit stop;

bit flag;

void main(void)

{

unsigned char i,j;

TMOD=0x02;

TH0=0x06;

TL0=0x06;

ET0=1;

EA=1;

while(1)

{

if(P3_7==0)

{

for(i=10;i>0;i--)

for(j=248;j>0;j--);

if(P3_7==0)

{

t5hz=0;

t7hz=0;

tcnt=0;

flag=0;

stop=0;

TR0=1;

while(stop==0);

}

}

}

}

void t0(void) interrupt 1 using 0

{

tcnt++;

if(tcnt==2000)

{

tcnt=0;

if(flag==0)

{

flag=~flag;

}

else

{

stop=1;

TR0=0;

}

}

if(flag==0)

{

t7hz++;

if(t7hz==3)

{

t7hz=0;

P1_0=~P1_0;

}

}

else

{

t5hz++;

if(t5hz==4)

{

t5hz=0;

P1_0=~P1_0;

}

}

}

Reference address:Ding Dong doorbell

Previous article:Dynamic digital display technology
Next article:Timing counter T0 as timing application technology (Part 2)

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号