【C51】Design and implementation of wireless remote control doorbell circuit based on 51 single chip microcomputer

Summary

Since the 20th century, the development of science and technology has entered the information age. The purpose of science and technology development is to serve the people so that we can have a better life. The living environment and quality are also becoming more and more important. Smart home is an innovation that has brought huge improvements to life. The wireless remote control doorbell studied in this project is part of it.

This design uses AT89C51 single-chip microcomputer as the main control chip, and effectively combines the coding function of the encoder, the real-time timing function of the clock chip, the LCD display function, and the wireless transmission circuit transmission function to complete this design by using the single-chip microcomputer. The functions of the wireless remote control music doorbell include: display time in real time, check visiting time, voice message, and automatically switch music. Because the presentation of the music is controlled by the program written into the microcontroller, the original music can be modified by itself. At the same time, this design also has the advantages of reliable and simple circuit, strong anti-interference ability and low power consumption.

This design uses Protel 2004DXP to draw the schematic diagram, keil software to write the single-chip program, and use the program to realize the visit record and music selection. The doorbell transmitter board and receiver board have two power supply modes, which can be powered by USB interface or battery, and can be used in more scenarios! The music of the doorbell is also diverse and optional, which is also one of its advantages, which can make the owner have a better mood.

Key words

Wireless transmission; music doorbell; microcontroller; DXP

Chapter 1 Introduction

1.1 . Background of topic selection

With the joint efforts of people from all walks of life, the development of science and technology is rapid, and our requirements for items are becoming more and more complex and diverse. Electronic devices can be further optimized in terms of size and power consumption on the premise of realizing their functions. The miniaturization of electronic equipment must mention the single-chip microcomputer.

A single-chip microcomputer can be regarded as a microcontroller, which integrates many logic functions on a small chip, and we can freely use various logic functions according to our own needs. To some extent, a single-chip microcomputer is a simplification of a computer. While retaining some functions, it also optimizes its size, power consumption, and application difficulty. The logic function of single-chip microcomputer is very clear. For those who are new to computers, starting with single-chip microcomputer can make it easier to understand the structure and principles of computers. Under the influence of the market, the development of single-chip microcomputer is diversified, and its price, volume, performance and other aspects also need to be further optimized.                  

The music doorbell based on the single chip microcomputer has melodious music and the record of the visiting time. Through the viewing of the visiting record, you can also know whether the doorbell has responded successfully, and can leave a voice message. It is more and more popular in modern homes.                                               

1.2 . Domestic research status

At present, most of the doorbells are ding-dong, and the music doorbell is not used, and the music is relatively monotonous. This music doorbell can make people feel refreshed. The current market mainly has the following doorbells:

1. Knock-type music doorbell, using BC piezoelectric ceramics instead of buttons, realizes that when visitors knock on the door, it can make a ding-dong sound, and the frequency of the "ding-dong" is also different depending on the frequency of the visitor's knocking. Different, the life is very long, and there is no need to consider the wear and tear of the button.

2. Infrared induction music doorbell is a kind of doorbell using reflective infrared sensor as the core. When the visitor is a certain distance away from the sensor, it will send out a signal. After a series of transformations, the bell will sound to inform the owner that there is a visitor. But when someone happens to pass by, an error alert will be issued.

3. Visual doorbell is a doorbell that transmits video information through the camera. It is mostly used in buildings. Visitors call through the host at the downstairs door. Residents can receive video images through the host’s camera downstairs to confirm the identity of the visitor and decide whether to press the button. The indoor extension unlock button provides a guarantee for the safety of the community.

4. The wireless remote control doorbell uses wireless signal sender/receiver and signal coding to realize wireless transmission of information. When the sender generates a signal, the receiver receives the signal and drives the audio module to emit music.

1.3 . Significance of topic selection

The wireless doorbell means that there is no need for a line connection between the guest plane and the host machine, and a 315MHz high-frequency signal can be sent directly through the super-regenerative wireless communication module, thereby realizing the signal transmission of the host plane and the guest plane, which brings great convenience to many families. First, the consumption and installation of lines can be avoided. Second, the host can be contacted without affecting the outside world, which is conducive to maintaining neighborhood relations. Third, it has a large transmission range, which can even reach a transmission distance of 3000 meters according to the selection of the device. Fourth, the power consumption is extremely low, no power is consumed when the button is not pressed, and the power consumption is less than 5 kilowatt-hours a year.

Secondly, this doorbell adds access time record and message function, which adds a lot of convenience to the user. When there is no one at home, you can leave a message, briefly describe your own incident or contact information, so as to better solve the problem.

1.4 Chapter introduction

The main content of the first chapter is the background and significance of the topic, and introduces the development of the doorbell and the significance of the topic in detail.

The main content of Chapter 2 is the overall idea of ​​hardware design, including the requirements for realizing functions, the process of hardware design, and the principle of device selection.

The main content of Chapter 3 is the detailed design of hardware modules. This chapter divides the hardware circuit into eight modules, and then introduces the design principles and functions of each module.

The main content of Chapter 4 is the design of the software. Firstly, it introduces the software used, then briefly introduces the method of use, and then introduces the program flow used by the single-chip microcomputer.

The main content of Chapter 5 is implementation and debugging. Firstly, it introduces the rules that need to be followed for hardware welding, then the debugging and downloading of the program, and finally, the overall debugging, detection and testing of the doorbell and the problems and solutions encountered in the testing process.

Chapter 2 Design Requirements and System Block Diagram

2.1 . Design requirements

Before starting the design, it is necessary to roughly understand the design requirements, so that the design can be targeted. The design requirements of this design are as follows:

1. The driving voltage of the transmitting/receiving board is about 5V, and the quiescent current is small;

2. It can be driven by batteries or charging treasures, and there is no potential safety hazard;

3. The signal is first encoded and then transmitted to reduce the influence of the external environment;

4. The signal is transmitted with 315MHz current wave through the super regenerative wireless module;

5. The LCD on the launch board can display time and date, and can be adjusted by buttons;

6. Record the visiting time, and it can be viewed on the LCD;

7. Voice messages can be sent;

8. The receiving board can play 6 pieces of music, which can be modified through the program;

2.2 System block diagram

 

Figure 2.1 System flow chart

As shown in Figure 2.1, the doorbell is divided into two parts: the sending board and the receiving board. When the doorbell button on the sending board is pressed, the buzzer itself will prompt that the button is pressed successfully, and an electrical signal will be generated, which will be transmitted to the C51 microcontroller, and the time will be recorded through the program. At the same time, the electrical signal will output a complete signal after passing through the encoder. The coded signal, the coded signal is sent to the super regenerative wireless transmitting module, and the super wireless regenerative module will generate a 315MHz current wave, waiting for the receiving board to receive it. The super-regenerative wireless receiving module of the receiving board detects the current wave, decodes the coded signal through a decoder, and inputs the electrical signal into the C51 single-chip microcomputer, calls the music program, and transmits it to the speaker for playback. The programs used in this design are all written according to the required functions based on keil software. And added a recording function, when the owner is not at home, you can leave a message, and you can check it when the owner comes back, so that it is convenient for the next contact.

2.3 Device selection

The selection of design devices is unavoidable. We need to select reasonable and efficient device specifications based on design requirements and at a cost-effective situation.

  2.3.1 , Main control chip selection

The main control chip of this design adopts AT89C51 single-chip microcomputer, which has on-chip data memory and Flash memory, and saves the contents of RAM when power off, which meets the functional requirements of this design. This chip has low power consumption and high performance and is widely used. Moreover, the price is very cheap in the C51 single-chip microcomputer, which can effectively save the design cost.

2.3.2 Display screen

This design uses LCD1602 liquid crystal display module, LCD1602 is a character liquid crystal, the advantages are: it is more convenient to display numbers and letters, simple to control, low cost, and can also be directly connected with the single chip microcomputer. This design does not need to display curves or images, and it is more cost-effective to choose LCD1602 in terms of cost performance.

2.3.3 . Wireless transmission

This design uses 315 wireless transmitter/receiver module for data transmission, ASK modulation is used for transmission, and the power consumption is very low. As the working voltage changes, the transmission distance will also change accordingly. The working voltage of this design is 4.5V, so the transmission distance is not large, which is conducive to the research and study of functions, and the actual application is not wide enough.

Chapter 3 Hardware Circuit Design

This chapter divides the hardware circuit into eight modules: button, clock, power supply, recording, wireless transmission, single-chip microcomputer, LCD display, and audio. Dividing the overall design into small module designs can make the design ideas clearer, and then design the schematic diagram and explain the corresponding principles according to the functions that each module needs to realize.

3.1 . Button module

 

Figure 3.1 Button module

The button module circuit is shown in Figure 3.1. The output of the five buttons is in a low level state. The reason is that the pin has a pull-up resistor inside, and the low level is effective. The button K1 realizes the "setting" function through the program. When the button is pressed, the displayed data can be adjusted; K2 realizes the "plus one" function, and the selected data is displayed by +1 when the button is pressed; K3 realizes the "minus one" function, and the button is pressed Display the selected data-1; K4 realizes the function of "checking" the visiting time, press the button to display the time when the doorbell is successfully reminded; K5 realizes the "doorbell" function, and sends out a signal when the button is pressed. K1-K3 jointly realize the adjustment of clock data and date data.

Most of the buttons are used to control components and realize man-machine dialogue. The button is a button switch. Since the contact will be very unstable when pressed manually, it will be accompanied by vibration elimination when using it, so that it can correctly identify whether it is pressed every time.

There are generally two ways to eliminate jitter. The first is to use software to eliminate jitter. By writing a program, add a 10ms delay between two judgments. If the second button still shows that it is pressed, it is considered that the button is pressed. , and vice versa; the second is to use two hardware RS flip-flops composed of NAND gates to realize the debounce processing of the keys.

Diodes are used in this design. Diodes have unidirectional conduction characteristics, and are generally used to indicate state changes. This design embodies the pressing of buttons, and uses gallium arsenide phosphorous diodes, which emit red light when they are turned on, and the turn-on voltage is about 1.2V. , the forward current is about 20mA, and the power supply voltage E is 5V. According to the calculation, the current limiting resistor is set to 190 ohms.

3.2 . Clock module

 

Figure 3.3 Clock chip

The circuit of the clock module is shown in Figure 3.3. It is powered by an independent 3V button battery. DS1302 (clock chip) generates clock pulses through the internal circuit and the external crystal oscillator on X1 and X2 pins. 32768 is 2 to the 15th power. After the conversion of the chip, a more accurate second signal can be obtained, so as to realize the function of recording time and date. SCLK is connected to the single-chip microcomputer, and the single-chip microcomputer inputs a pulse. When the SCLK terminal has a rising edge, the I/O port performs a read operation; A falling edge occurs, and the I/O performs a write operation, and the time information is transmitted to the microcontroller through the I/O port.

3.2.1 Clock chip

This design uses DS1302 clock chip. DS1302 is a trickle charging clock chip launched by DALLAS company. It uses battery to supply power to ensure time retention, which can make the sending board in a power-saving state when it is not pressed. The main performance indicators of DS1302 are:

1. DS1302 is a clock chip that can record year, month, day, second, minute and hour.

2. There are two 31-byte (8-bit) data temporary storage registers inside, which realize the recording of clock and calendar respectively.

3. Data communication is only through one serial input and output port.

4. Working voltage 2.0V~5.5V, working temperature 0℃~70℃. 

5. Low power consumption, when working at 2V, the working current is less than 300nA.

6. Double power supply.

The pin functions of DS1302 are shown in Table 3.1. It should be noted that this clock chip is different from other chips. It has two power pins, which are powered by the higher level pin when in use.

Table 3.1 DS1302 pin functions

pin number

Pin name

Function

1

Vcc2

main power

2、3

X1、X2

32.768KHz

4

GND

grounding

5

RST

Reset chip select (active high)

6

I/O

Serial data input/output

7

SCLK

serial clock input

8

VCC1

backup power

As shown in Table 3.2, the transmission of each byte is specified by the control byte, the highest bit Bit7 of the control byte must be high level, if it is low level, information writing will be prohibited. When Bit6 is low level, it specifies the clock/calendar register to control read and write operations. When it is high level, it specifies the read and write operations of RAM data control. Bit1~Bit5 specifies that the relevant registers are to be input and output operations, and the lowest bit Bit0 specifies the Input or output depends on whether the SCLK pulse rises or falls.

Table 3.2 Control Instructions

1

RAM/

A4

A3

A2

A1

A0

RD/

No. 7 No. 6 5 4 3 2 1 0

3.3 . Power module

The circuit of the power module is shown in Figure 3.4. The external power supply is connected to pins 5 and 6. When the switch is pressed, pin 3 provides a ground terminal for the entire circuit, and pin 4 provides a Vcc voltage of 5V for the entire circuit. This powers the entire circuit. There are also many other connection methods. The functions required in this design are very simple, so not all pins are used.

 

Figure 3.4 Power Module

The six-pin self-locking switch is a double-pole double-throw switch. The pin diagram is shown in Figure 3.5, and the function is the same as that shown in the two connection diagrams. It can be seen that when the switch is released, 1 and 3 are connected, and 2 and 3 are connected. 4 connected. When the switch is pressed, 3 and 5 are connected, and 4 and 6 are connected.

 

Figure 3.5 Six-pin switch

3.4 . Recording module

The recording module circuit is shown in Figure 3.6. When the button S1 is pressed, the REC pin gets a high level state, and the ISD1820P (recording module) receives the instruction to start recording, and the voice is transmitted to the MIC pin of the chip through the electret, and the coupling capacitor The minimum frequency of recording is determined by the resistance value of the resistor, and the MICREF pin can reduce noise and improve the common mode rejection ratio. The recording time is determined by the resistance value connected to the ROSC. In this design, a 100K resistance is connected, and the maximum recording time is 10s.

When the button S2 is pressed, a rising edge pulse information will be generated. ISD1820P detects the rising edge information and starts to play. Since an audio power amplifier is connected externally, the playback information first passes through the LM386 power amplifier to amplify the small signal. Then transmit to the speaker for voice playback. This time, pins 1 and 8 are left empty, and the magnification is 20 times. Pin 7 can be grounded through a capacitor to reduce noise to a certain extent.

 

Figure 3.6 Recording module

3.4.1 , ISD1820P Y recording module

The recording of this design uses the ISD1820PY recording module, which can achieve controllable 8-12 seconds recording through an external resistor. The functional characteristics are:

  1. Automatic power saving, maintain current 0.5uA.           

  2. Edge/level trigger playback.                 

  3. Adjust the recording time through an external resistor.                                 

 

Figure 3.7 ISD1820 package pin diagram

The package pin diagram of the recording module is shown in 3.7. The chip has 14 pins, and some things need to be paid attention to when using it. The pin functions of the chip are shown in Table 3.3. First of all, for playback, recording has a higher priority. When a recording instruction is received, no matter whether the playback is in progress or not, it needs to enter the recording link immediately until the end of the recording instruction or the end of the recording time. And the chip contains a processing circuit for eliminating jitter, so you don't need to add it yourself.

When using the recording input terminal, it should be noted that the lowest frequency of recording is controlled by the user himself, and the user can jointly control the lowest frequency band of recording by changing the external resistor and external capacitor.

The function of the external capacitor at the automatic gain end is to reduce the distortion as much as possible, and the degree of distortion can be indirectly changed by changing the external capacitor when using it.

Table 3.3 ISD1820PY pin function

REC

Recording (active high)

PLAYE

Rising edge triggers playback

PLAYL

High level trigger playback

MIC

Microphone input

MICREF

Microphone Reference Terminal

AGC

automatic gain

SP-、SP+

Speaker output

VSSA、VSSD

ground terminal

RECLED

recording indicator

FT

direct mode

ROSC

Oscillating resistance

VCC

Power terminal

The resistance value of the oscillating resistor is directly related to the recording time. We can reasonably choose the resistance value of the oscillating resistor according to the required recording time. For details, refer to Table 3.4.

Table 3.4 The role of oscillating resistance (ROSC)

ROSC(KΩ)

Recording and playback time (S)

Sampling frequency (KHz)

Typical bandwidth (KHz)

80

8

8.0

3.4

100

10

6.4

2.6

120

12

5.3

2.3

160

16

4.0

1.7

200

20

3.2

1.3

Direct mode (FT): When connected to high level, the direct mode will be turned on, and the voice signal at the MIC terminal will directly reach the speaker output terminal through the AGC circuit, filter and speaker driver. When speaking into the electret, the sound will be played directly from the speaker. If the pass-through function is not required, it can be connected to a low level when in use.

3.4.2 . Principle and function of triode

This design uses a triode. The function of the triode is to amplify the weak signal input by the base into a signal with a larger amplitude value, and output the signal amplified by a certain multiple at the collector. It is widely used. The magnification of the current is usually calculated and expressed with the symbol "β".

The transistor is composed of two PN junctions, which coexist on a semiconductor with a small spacing. The semiconductor can be divided into three parts by the two PN junctions. The base area refers to the middle part of the semiconductor, and the parts on both sides of the base area are collectors. area and launch area. Due to the different arrangement of PN junctions, triodes are divided into PNP and NPN types.

As shown in Figure 3.8, PN positive bias refers to the positive voltage applied at both ends. Taking the PNP type as an example, when the emitter junction is forward biased, the majority carriers of the lower PN junction will flow, forming an emission Current Ie, when the collector junction is reverse biased, forms collector current Ic.

 

Figure 3.8 Current flow diagram of triode

There are three working states of transistors in the circuit, which are static state, amplified state, and saturated conduction state. The static state means that the voltage applied to both ends of the emitter junction is too small, the PN junction cannot be turned on normally, the base current is almost zero, and the collector has no current output. The amplification state is that the emitter junction is forward biased, and the voltage at both ends is appropriate, the collector junction is reverse biased, and the collector current is controlled by the base current. The saturated conduction state is that the emitter junction is forward biased and the collector junction is reverse biased, but as ib increases to a certain value, the collector current ic no longer increases accordingly.

There are three connection methods in the circuit: common base, common collector, common emitter amplifier circuit. The common-emitter circuit can amplify current and voltage, and is often used as a unit circuit of a low-frequency voltage amplifying circuit; the common-collector circuit can only amplify current but not voltage, and has the characteristics of voltage follower, and is often used in the input and output stages of a voltage amplifying circuit; The base circuit can only amplify voltage but not current. It has good high-frequency characteristics and is often used as a broadband amplifier circuit.

3.4.3 LM386 Power Amplifier

This design uses an LM386 integrated power amplifier between the small signal and the speaker. It contains a three-stage amplifier circuit inside, which can amplify the small signal with a certain gain and drive the speaker for playback. The main features are:

1. Low static power consumption, about 4mA, can be powered by batteries.

2. Wide working voltage range, 4~12V or 5~18V.

3. Less external components, easy to use.

4. The voltage gain is adjustable, controlled according to the parameters of external components, and the gain range is 20-200.

 

Figure 3.9 LM386 pin diagram

The LM386 pin diagram is shown in Figure 3.9. GAIN (gain setting) controls the gain multiple through the capacitor between pin 1 and pin 8. When the two pins are open, the voltage magnification is 20 times. When the two pins are connected When the capacitor is 10uf, the voltage amplification factor is 200 times. -INPUT (inverting input terminal) and +INPUT (positive input terminal) constitute the first stage differential amplifier circuit, and then amplify the amplified voltage at pin 5 through the second stage and the third stage. Pin 4 is ground and pin 6 is power. Pin 7 is a bypass, and a bypass capacitor is indispensable in practical applications. BYPASS is connected to a capacitor to ground, which can filter out noise.

3.5 . Wireless transmission module

 

 

Figure 3.10 Wireless transmission module

As shown in Figure 3.10, the pins 1 to 8 of the encoder (PT2262) are in the same state as the pins of the decoder (PT2272). Only when these pins are in the same state can they be correctly matched for correct decoding, otherwise they cannot be decoded. This can ensure that multiple doorbells work without interfering with each other. After the button is pressed, the encoder is energized to work, and the encoder outputs a complete coded signal. The coded signal is transmitted to CON3 through TE (code start terminal). CON3 is a super-regenerative wireless transmission circuit. After receiving the coded signal , ASK modulation will generate a 315MHz high-frequency signal for wireless transmission, which can minimize external environmental interference.

CON4 is a super-regenerative wireless receiver, it will always detect, when it detects a 315MHz high-frequency signal, it will output a coded signal after demodulation, the coded signal is input into the decoder through the DIN pin of the decoder 2272, and the decoder's Pins 10 to 13 are used as data pins to transmit coded information to the microcontroller.

3.5.1 Principle and function of PT2262 / 2272

PT2262/2272 is a pair of infrared remote control transmitter/receiver chips with address and data encoding functions. The transmitter chip PT2262-IR is an integrated chip that makes the transmitter circuit very simple. The data output bit of the receiving chip PT2272 is different according to its suffix, and the data output has two modes of "temporary storage" and "latch", which are convenient for users to use. The suffix "M" is "temporary storage type" and the suffix "L" is "latch type".

The encoding signal sent by the encoding chip is composed of 8 bytes, which are divided into address code, data code and synchronization code. Only after the button is pressed, the encoding chip will be powered on and output the encoded data signal. Generally, the power is not turned on, which can better save power.

During wireless signal transmission, it is easily affected by the environment, and encoding can effectively reduce the influence of the outside world.

Figure 3.11 PT2262/2272 pin diagram

 

The pin diagram of PT2262/2272 is shown in Figure 3.11, and the corresponding functions of each pin are shown in Table 3.5.

Table 3.5 PT2262/2272 pin functions

PT2262(2272)

pin

Description PT2262 (2272)

A0~A11

1~8、10~13

Address pins, used for address encoding (decoding), can be set to "0" "1" "f", the two must be consistent or not decode

D0~D5

7~8、10~13

At the data input end, there is a "1" code sent out, and the internal pull-down. (Address or data pin, when used as a data pin, only when the address is consistent with 2262, the data pin can output the corresponding high level)

Vcc

18

Positive power supply

Vss

9

Negative terminal of power supply

YOU (from)

14

Coding start terminal, used for multi-data code transmission, active low (data signal input terminal, from the output terminal of the receiving module)

OSC1

16

Oscillating resistor input terminal, and the OSC2 street resistor determines the oscillation frequency

OSC2

15

Oscillation resistor Oscillator output

Dout(VT)

17

The encoding output terminal is normally low level (the decoding is valid to confirm the output terminal, and the decoding is valid to become a high level transient)

3.5.2 、Wireless transmitting /receiving module

As shown in Figure 3.12, on the left is XD-FST, a transmitter module without encoding. A total of three pins, DATA (1) is the data input terminal, VCC (2) is the positive pole of the power supply, and GND (3) is the negative pole of the power supply. It is often used in wireless calls, wireless transmission, etc. Its characteristics are: stable performance, wide working voltage range (3 ~ 12V), and high cost performance.

The XD-RF-5V on the right is a 5V high frequency super regenerative receiver module. There are four pins, VCC (1) is the positive pole of the power supply, GND (4) is the negative pole of the power supply, and DATA (2) is the data output terminal. It is often used in wireless remote control switch, data transmission, etc. The super-regenerative receiving module contains LC oscillator circuit, amplification and shaping, and the output data is TTL level, which can be directly output to the decoder, and the application is simple.

 

 

Figure 3.12 Wireless Transmitter/Receiver Module

3 .6 AT89 C 51 microcontroller

The single-chip microcomputer circuit of the receiving board is shown in Figure 3.13. When the reset terminal receives a high level state and lasts for 2 machine cycles, the single-chip microcomputer performs a reset operation. Whenever the power is turned on, the capacitor is charged, and the charging time can be calculated. After verifying the time required for charging in this design, the reset terminal becomes a high level state for a reset. Whenever the button S5 is pressed, the reset terminal is pulled up to a high level state, and the single-chip microcomputer will also perform a reset.

本型号单片机没有内置晶振,外加晶振电路如图3.13所示,晶振引脚之间外接晶体振荡器,并且并联电容容值相同,一般为10pf-30pf。晶振电路的目的是给单片机提供脉冲信号,这个脉冲就是单片机正常时候的运行速度,晶振一般选择11.0592MHz,由于本设计要求不需要过于精准,所以选择12MHz。

当无线接收模块输出信号进入P2.7引脚,单片机接收到信号调用程序,把需要播放的音乐程序信号经P2.6输出。

 

图3.13 单片机接收电路

本设计采用AT59C51单片机作为主控芯片,单片机是指集成在一块芯片上的完整计算机系统。它具有CPU、存储器、总线系统等,可以通过程序的控制实现很多功能。单片机有40个引脚,不同的引脚有不同的功能和不同的使用方法,我们在使用的时候要仔细查看相应资料,本次门铃设计用到的引脚及功能如表3.6所示。

表3.6 使用的单片机引脚功能

引脚名称

功能

引脚名称

功能

VCC

供电电压

P3.0 RXD

串行输入口

GND

接地

P3.1 TXD

串行输出口

P1

准双向口,内有上拉电阻

RST

复位输入

P2

准双向口,内有上拉电阻

EA

为高电平时,内部存储器

XTAL1

反向震荡放大器的输入及内部时钟工作电路

XTAL2

来自反向震荡器的输出

ALE/

ALE为第一功能,访问外部存储器时,地址锁存允许的输出电平用于锁存地址的地位字节。

片外程序存储器的读选通信号,低电平有效

3.7、LCD显示模块

本设计采用LCD1602进行数据显示,LCD1602可以显示符号、数字、字母,每行最多可显示16个字符,它是一种点阵型显示模块,不能显示图片,一般被使用都是显示字符。引脚及功能如表3.7所示。

表3.7 LCD引脚及功能

GND

接地端

VCC

电源端

V0

对比调整端(电平越低对比度越高)

RS

选择寄存器

R/W

读写管脚

EN

使能端

D0~D7

数据端

A

背光正极

K

背光负极

在电路图中LCD1602的接法如图3.14所示,单片机通过程序控制屏幕的显示内容,数据在D0~D7引脚传输,通过8个数据通道,控制需要显示的数据。1602液晶屏内部存储了160个不同的点阵字符图形,有阿拉伯数字、英文字母、常用的符号等,只需要查表,把所需要显示的字符调用出来就可以正常显示。

对比调整端接电阻和高电平,可以保证对比度的情况下,避免出现重影,读写管脚接低电平,数据只需要写入,显示器根据程序显示相应的信息。

 

图3.14 液晶显示屏

3.8、音频模块

使用方式如图3.15所示,当门铃按键下后,发射板产生原始电信号,经过无线模块进行编码之后产生315MHz的高频信号,可以有效地防止外界环境的影响。在接收板的无线接收模块会检测到这个信号,并且得到编码信号,经过译码恢复出原始电信号,传到单片机里面,通过单片机程序控制发音的时间和震荡频率来实现各个音符效果,传输出的小信号经过三极管可以放大一定倍数然后输出,使音乐可以更好的呈现出来。

 

图3.15 音频模块

第4章 系统软件设计

硬件原理图模块设计完成后,就要进行软件的设计,首先搞清楚音乐怎么控制,然后编写发射板和接收板单片机的程序。 

4.1、音乐的实现

单片机做不到发出各种各样的音色,只能通过控制振荡频率和发声时间,实现一些简单声音,为了音乐的呈现,我们需要先了解音调和节拍的概念,然后通过调试找到对应的实现方法。

4.1.1音调

基本音主要有7个,简谱为1234567,又分为中音、高音、低音等。在数字上面带一个点的代表高音,在数字下面带一个点代表低音,以此类推。众所周知声音的多姿多彩,本质是频率的不同,不同的振荡频率就可以发出不同的音色,当我们清楚每个音符对应的频率,就可以通过向单片机写入不同程序实现不同乐音的呈现。

4.1.2节拍

表4.1 音符

音符名称

写法

时值

全音符

5---

四拍

二分音符

5-

二拍

四分音符

5

一拍

八分音符

5

半拍

十六分音符

5

四分之一拍

如表4.1所示,最常见的节拍是四分音符,被当做一个基本参照度量长度。这里一拍的概念是一个相对时间度量单位。通过单片机程序延时实现不同音符对应的节拍。一拍的长度没有限制,可以是1秒 也可以是2秒或半秒。在音乐简谱里面用一条横线“-”在四分音符的右面或下面来标注,以此来定义该音符的长短。

4.2、软件的使用

4.2.1、原理图设计软件

 

图4.1 DXP工作窗口

Protel DXP2004软件工作窗口如图4.1所示,是一款具有设计功能的一体化电子产品开发系统环境,由Altium公司研发推出,与之前的版本软件相比,Altium Designer 2004有了很多方面的改进,比较明显的就是在外观上进行了优化,同时也极大地强化了电路设计的同步化,整合了VHDL和FPGA设计系统,其功能大大加强了,可以实现更多元化的应用。

原理图绘制步骤:

创建一个项目。点击【文件】【创建】【项目】。

创建一个画图窗口。点击【文件】【创建】【原理图】。

保存项目文件,并且对其重命名,方便识别。

选择元件。页面右边框有一个【元件库】,输入想要的元件,并搜索。

连接元件。在工作栏中找到连线工具,按照功能需求进行连接。

在绘制过程中发现集成元件在元件库里是搜不到的,只能根据器件的功能自己绘制元件库。首先新建一个PCB项目,然后点击【文件】【创建】【库】【原理图库】,新建一个元件库,根据自己的需求画出主体和引脚。选中默认元件Component-1,执行【工具】【重新命名元件】菜单命令,将元件重新命名。在自己的原理图中【设计】【追加/删除元件库】把自己创建的元件库添加,就可以在右边框元件库里面添加自己画的原件了。

4.2.2、程序设计软件

 

图4.2  keil 工作窗口

程序设计主要用到了keil5软件,工作窗口如图4.2所示,是目前ARM内核单片机开发的主流工具。keil c51是一款应用于plc编程的软件开发工具,它拥有强大的仿真器、调试器、宏汇编器、单板计算机以及符合生产标准的Keil C编译器,在嵌入式软件开发的基础上有深层次的研发进展。

编写程序步骤:

1、新建一个工程

2、CPU选型AT89C51.

3、组建选择,选择需要的组件GPIO、CORE,之后也可以补充。

4、设置属性。选中【Options for Target‘Target1’】设置晶振频率24MHz。

5、创建.c文件添加到工程里面。

6、编写好程序之后进行编译。

 4.3程序设计流程

创建过项目之后就要着手程序的设计,首先需要有清晰的程序流程,本次涉及的目的是,当门铃按键按下并且成功播放门铃音乐,进行按下时刻的时间记录,未成功响铃则提示接收板未响应。另外时间日期数据可以自己调整。

系统主流程如图4.3所示,先对LCD、按键、延时、DS1302等模块进行初始化,这些固定模块都是可以在网上找到的,可以直接使用。初始化之后就需要进入循环语句了,判断门铃按键是否按下,如若按下则进行下一步,反之跳出本语句重新开始循环,按键按下后需要判断接收板是否响应,响应则记录本次按下时间以便之后查看,并且接收板调用编辑好的音乐程序进行响铃。

流程清楚之后,就可以进行C语言的程序编辑,根据流程进行每个环节的编写,完成程序编辑。

 

图4.3 主流程图

程序的主流程说完之后就要说一下主程序中的数据设置子程序,数据设置流程如图4.4所示,判断设置按键是否按下,如若按下则继续运行,不然则跳出子程序。当按键按下后,LCD显示进入设置模式,第一项数字会闪动,表示我们可以用按键进行上调或下调,进行时间的调整。设置按键再次按下则进入下一项数据的调整。直至调整完成,退出设置模式保存设置的内容并显示。

流程清楚之后,我们就可以编写程序,首先定义子程序函数,把需要实现的功能进行编程,完成程序的编写。

 

图4.4 数据设置流程

第5章 调试与实现

在各种设计中,调试都是一大难关,无论哪个环节出现了问题都会导致实现的失败,所以我们应该把这个设计分为很多模块,保证每个模块都没问题的前提下在进行综合的实现。

软件方面是比较容易进行调试的,因为可以明显的看到哪里有错误,我经过多次查询资料。发射板主要目的是时间和日期的设置、门铃按键和按键时间查看。接收板是在一个简单程序上进行修改,首先是多首音乐的选取,选过音乐之后找到对应的音乐简谱,把每个音符转换成三个数据分别控制音调、频率和时间,然后需要实现音乐轮流播放。

程序编写好之后,需要进行编译,生成一个后缀名为hex的文件,通过烧录软件和下载器把这个文件下载到单片机里面,之后进行硬件的调试和实现。

硬件的实现就需要根据原理图进行一步步的实现,首先需要根据原理图进行元件的购买,然后安装。安装的时候我们先把元件按一定的规则插到板子上,一般是先小后大、先里后外,这样比较容易安插。安装好之后我们需要进行焊接,焊接的时候需要注意几点,首先必须确认各个引脚的连接,尽量避免误焊,因为焊错之后是非常麻烦的,另外焊接的时候应该保证电烙铁温度足够,保证没有虚焊。焊接之后把多余的引脚剪短。

焊接完成后,我们可以安装上电池进行调试,如果安装好之后门铃可以正常运行那本次设计就大致结束了。不过我第一次安装好之后,并没有实现所需要求,我先找了一个小音箱,将音响插上电源同时声音调到最大,让发射板与音箱离的进一些,之后按下门铃按键。音箱会发出滋滋的干扰声,证明有信号发出,说明发射板是没啥大问题的。经过多种测试之后,发现是无线模块天线的问题,经过查询资料后,改变它的缠绕方式之后实现了发射板接收板之间的连接。

 

图5.1 实物图

※※※※※※※※※※※※※※※※※※※※※※※※※※※※※※

附录:

原理图

 

 

元件清单

元件清单

元件名称

数量

元件名称

数量

元件名称

数量

8Ω喇叭

2

22uf电容

4

9x15万能板       

2

8550 PNP三极管

2

100/220uf电容

2

PT2262通用编码器

1

10欧电阻

1

104电容

4

PT2272通用解码器

1

1k电阻

7

30pf瓷片电容

3

315接收模块

1

4.7/3.3k电阻

2

驻极体

1

315发射模块

1

10kΩ电阻

3

轻触按键

6

电池盒

2

100k电阻

1

LCD1602

1

lm386功率放大器

1

820k电阻

1

AT89C51单片机

2

CR2032电池座

1

3V纽扣电池

1

Isd1820

1

有源蜂鸣器

1

32.768MHz晶振

1

led红色小灯

3

电源自锁开关

2

12mhz晶振

2

SIP3母座

1

ds1302时钟芯片

1

4.7M震荡电阻

1

CR2032纽扣电池

1

usb电源线dc插座

2

Guess you like

Origin blog.csdn.net/qq_58404700/article/details/131447487