Project actual combat: 51 single-chip wireless music doorbell design materials, five songs freely switch (including physical drawing program simulation)

Wireless doorbell is also called wireless remote control doorbell or remote control doorbell. The wireless doorbell uses the ultra-regenerative wireless module to realize wireless remote control. The wireless doorbell does not require wiring and is simple and flexible to install, but the transmission distance is greatly affected by the transmission distance and the site environment. Wired doorbell is just the opposite.
Including, program physical drawing program simulation

The expected effect of the project:
1. There are 5 songs that can be switched, and each time you press to sing a different song.
2. The wireless transmission distance is more than 10m, and can pass through walls and doors.
3. Compact design, easy to install and use
4. High stability and no false alarms.

Physical diagram:
Insert picture description here
schematic diagram:

Insert picture description here
Simulation diagram

Insert picture description here
Code screenshot
Insert picture description here

Wireless music doorbell bill of
1.7 9-purpose board
2.8Ω0.25w trumpet
3. DC power socket
4. Self-locking switch
5.12m crystal
6.10k resistor
8
7.2.2k resistor
8.30pf capacitor 2
9.10uf capacitor
10.40 foot IC holder
11. Button
2
12. stc89c51
13.315M launch module
14. Receive module
15.2272-M4 chip
16.2262 chip
17.12v battery
18.820k chip resistor
19.4.7M chip resistor
20.9012
21.9013
22. Some wires
23. Solder some
24.23cm long antenna * 2
25. USB power cord (battery box + DC plug)

C language reference source code

//////////////////////////////////////////////
// 51 microcontroller Wireless remote control doorbell program
/////////////////////////////////////////////////
#include <REG51.H>
#define sound_amount 5 // Number of songs
sbit pause = P2 ^ 5; // Play \ pause
sbit speaker = P2 ^ 7; // Passive buzzer
///////// /////////////////////////////////////
unsigned char timer0h, timer0l, time; // timer0h, timer0l is the initial value of the high and low bits of timer T0, time is the corresponding tick time
unsigned char music_num, num; // music_num is the song number, music_num = 0 indicates the state at the time of starting up, num is the address to find the song data table
signed char fre; // Address corresponding to the frequency data table
bit play_enable; // Enable flag bit for song playback, used for playback \ pause
void delay (unsigned char t); // Delay subfunction, control the length of pronunciation
void delayms (unsigned int t); // Ordinary delay subroutine, can be used for key debouncing
void song (void); // Play a note
void music_play (void); // Play song
//////////////////////////////////////////////
// every three Digits, representing a note
// The first digit is one of the numeric values ​​of the 1234567 of the note (the few notes), representing Doraemon…
// The second digit is one of 0123, representing bass \ middle \ treble \ Super treble (several octave)
// The third number is the length of time, in half-beat units, the end of the music data table is three 0
/////////////// ////////////////////////////////
// Happy Birthday to you
unsigned char code song1 [] = {
5,1 , 1, 5,1,1, 6,1,2, 5,1,2, 1,2,2, 7,1,4,
5,1,1, 5,1,1, 6,1,2 , 5,1,2, 2,2,2, 1,2,4,
5,1,1, 5,1,1, 5,2,2, 3,2,2, 1,2,2, 7 , 1,2, 6,1,2, 4,2,1, 4,2,1, 3,2,2,
1,2,2, 2,2,2, 1,2,4, 0,0 , 0};

// "Only mother is good in the world"
unsigned char code song2 [] = {
6,2,3, 5,2,1, 3,2,2, 5,2,2, 1,3,2, 6,2, 1,
// 6,2,3 represents 6, midrange, 3 half beats;
// 5,2,1 represents 5, midrange, 1 half beat;
// 3,2,2 represents 3, midrange , 2 half beats;
// 5,2,2 means 5, midrange, 2 half beats;
// 1,3,2 means 1, treble, 2 half beats;
//…
5,2,1, 6,2,4, 3,2,2, 5,2,1, 6,2,1, 5,2,2, 3,2,2, 1,2,1,6,1,1, 5, 2,1,
3,2,1, 2,2,4, 2,2,3, 3,2,1, 5,2,2, 5,2,1, 6,2,1, 3,2, 2, 2,2,2,
1,2,4, 5,2,3, 3,2,1,2,2,1, 1,2,1, 6,1,1, 1,2,1, 5,1,6, 0,0,0};

// "Who do you think of when you are alone"
unsigned char code song3 [] = {3,2,2
, 3,2,1, 4,2,1, 3,2,2, 2,2,1, 1 , 2,1, 2,2,2, 5,2,2, 2,2,2, 2,2,3,
1,2,2, 1,2,1, 2,2,1, 1,2 , 2, 7,1,1, 6,1,1, 7,1,2, 3,2,2, 7,1,2,
7,1,3, 6,1,2, 2,2,1 , 3,2,1, 2,2,1, 1,2,1, 6,1,2, 5,1,2, 2,2,1, 3,2,1, 2,2,1,
1 , 2,1, 6,1,2, 6,1,2, 2,2,1, 3,2,1, 2,2,1, 1,2,1, 6,1,1, 7,1 , 1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1,1,4, 0,0,0};

// The upper eight bits of the frequency-half period data table saves 28 frequency data of four octaves
unsigned char code FREQH [] = {
0xF2, 0xF3, 0xF5, 0xF5, 0xF6, 0xF7, 0xF8, // bass 1234567
0xF9 , 0xF9, 0xFA, 0xFA, 0xFB, 0xFB, 0xFC, 0xFC, // 1,2,3,4,5,6,7, i
0xFC, 0xFD, 0xFD, 0xFD, 0xFD, 0xFE, // treble 234567
0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFE, 0xFF}; // super treble 1234567

// Lower eight bits of frequency-half period data table
unsigned char code FREQL [] = {
0x42, 0xC1, 0x17, 0xB6, 0xD0, 0xD1, 0xB6, // Bass 1234567
0x21, 0xE1, 0x8C, 0xD8, 0x68, 0xE9, 0x5B , 0x8F, // 1,2,3,4,5,6,7, i
0xEE, 0x44, 0x6B, 0xB4, 0xF4, 0x2D, ​​// treble 234567
0x47, 0x77, 0xA2, 0xB6, 0xDA, 0xFA, 0x16} ; // super treble 1234567

void main (void)
{
TMOD = 0x11; // T0 T1 are in working mode 1
ET0 = 1; // T0 open interrupt
EA = 1; // CPU open interrupt
while (1)
{
music_play (); // According to the current Play a note of the corresponding song in state

if (! pause) // Pause key processing
{
delayms (5);
if (! pause)
{
if (music_num0) // music_num = 0 only exists when it is just turned on, and the pause button is not pressed, indicating the state when it is turned on. After pressing, it starts playing from the first song
{
music_num = 1; // The song number is set to 1
num = 0; // Play from the
beginning play_enable = 1; // Allow playback
}
else
{
play_enable = ~ play_enable;
speaker = 1;
}
while (! Pause) // Handle when you press the pause button and do n’t let go
{
if (play_enable
0) {} // If it is paused, the display time will remain unchanged // (play_enable == 0 when paused)
}

} // Pause key processing ends
} // while ends
}
}

void delayms(unsigned int t) //MS延时子程序
{
unsigned int i,j;
for(i=0;i<t;i++)
{
for(j=0;j<123;j++)
;
}
}

void delay (unsigned char t) // Delay sub-function, control the length of time of pronunciation, 0.4S per beat
(
unsigned char t1;
unsigned long t2;
for (t1 = 0; t1 <t; t1 ++) // nesting Loop, delay a total of t half shots
{
for (t2 = 0; t2 <8000; t2 ++) // During the delay, you can enter T0 interrupt to pronounce
{
;
}
}
TR0 = 0; // Turn off T0, stop pronunciation
}

void timer0 (void) interrupt 1 // T0 interrupt program, control the tone of the pronunciation
{
speaker =! speaker; // Output square wave, pronunciation
TH0 = timer0h; // Next interruption time, this time controls the tone level
TL0 = timer0l ;
}

void song (void) // Play a note
{
TH0 = timer0h; // Control tone
TL0 = timer0l;
TR0 = 1; // Start T0, output square wave pronunciation from T0
delay (time); // Performance of each note Time
}
///////////////////////////////////////////////// /////////////////////////////////////
void music_play (void) // Play a note of the corresponding song
{
if ((music_num1)&&(play_enable1))
{
fre = song1 [num] +7 song1 [num + 1] -1; // The i-th is a note, the i + 1-th is the octave
timer0h = FREQH [fre]; // From The frequency value read out in the data table is actually the time length of the timer.
Timer0l = FREQL [fre];
time = song1 [num + 2]; // The value of the read time length
num + = 3;
if (fre ==-1) // Determine the ending position of the song, and go to the next song after the end
{
num = 0; // The next song will be played from the
beginning music_num = 2;
play_enable = 0;
}
song (); // Sound a note
}
//// ////////////////////////////////////////////////// //////////////////////////////
if ((music_num2)&&(play_enable1))
{
fre=song2[num]+7
song2[num+1]-1;
timer0h=FREQH[fre];
timer0l=FREQL[fre];
time=song2[num+2];
num+=3;
if(fre==-1)
{
num=0;
music_num=3;
play_enable=0;
}
song();
}
////////////////////////////////////////////////////////////////////////////////////
if((music_num3)&&(play_enable1))
{
fre=song3[num]+7song3[num+1]-1;
timer0h=FREQH[fre];
timer0l=FREQL[fre];
time=song3[num+2];
num+=3;
if(fre==-1)
{
num=0;
music_num=4;
play_enable=0;
}
song();
}
////////////////////////////////////////////////////////////////////////////////////
if((music_num4)&&(play_enable1))
{
fre=song4[num]+7
song4[num+1]-1;
timer0h=FREQH[fre];
timer0l=FREQL[fre];
time=song4[num+2];
num+=3;
if(fre==-1)
{
num=0;
music_num=5;
play_enable=0;
}
song();
}
////////////////////////////////////////////////////////////////////////////////////
if((music_num5)&&(play_enable1))
{
fre=song5[num]+7*song5[num+1]-1;
timer0h=FREQH[fre];
timer0l=FREQL[fre];
time=song5[num+2];
num+=3;
if(fre==-1)
{
num=0;
music_num=1;
play_enable=0;
}
song();
}
////////////////////////////////////////////////////////////////////////////////////
}
//程序结束

Finally, if you have any comments or suggestions, you are welcome to leave a message to me, let us learn together and progress together.
If you need the complete code or design file, please leave a message or private message me below.

Thank you!

Published 97 original articles · 200 praises · 80,000+ views

Guess you like

Origin blog.csdn.net/weixin_44212493/article/details/104335263