1 Introduction
The daily routine of institutions and colleges requires timing and beep prompts. The author uses AT89C51 microcontroller and LM386 audio power amplifier to form an automatic timing and beep player. It is low cost, effective and worthy of promotion.
2 Main features and pin functions of AT89C51
AT89C51 is a low-voltage, high-performance CMOS 8-bit microprocessor (commonly known as a single-chip microcomputer) with a 4K-byte flash programmable and erasable read-only memory (EPEROM). The microcontroller is compatible with the instruction set and output pins of the industry standard MCS-51 machine. The AT89C51 combines a multi-functional 8-bit CPU and flash memory in a single chip, providing a highly flexible and low-cost solution for many embedded controls.
The main features of AT89C51 are as follows:
Lifespan reaches 1000 write/erase cycles;
Data retention time: 10 years;
Fully static operation: 0Hz-24MHz;
Level 3 program memory lock;
128×8-bit internal RAM;
32 programmable I/O lines;
2 16-bit timers/counters;
5 interrupt sources;
Programmable serial channel;
Low-power idle and power-down modes;
On-chip oscillator and clock circuitry.
The AT89C51 pin arrangement is shown in Figure 1, and the pin functions are as follows:
VCC (40): +5V.
GND (20): Ground.
Port P0 (39-32): Port P0 is an 8-bit open-drain bidirectional I/O port. Each pin can absorb 8 TTL gate currents.
P1 port (1-8): P1 port is an 8-bit bidirectional I/O port that provides a pull-up resistor internally. The P1 port buffer can receive and output 4 TTL gate currents.
P2 port (21-28): P2 port is an 8-bit bidirectional I/O port with an internal pull-up resistor. The P2 port buffer can receive and output 4 TTL gate currents.
P3 port (10-17): P3 port is 8 bidirectional I/O ports with internal pull-up resistors. It can receive and output 4 TTL gate currents. P3 port can also be used as a special function port of AT89C51.
RST(9): reset input. When the oscillator is reset, the RST pin is held high for 2 machine cycles.
ALE/PROG (30): When accessing external memory, the output level allowed by the address latch is used to latch the low-order byte of the address. During FLASH programming, this pin is used to input the programming pulse. In normal times, the ALE terminal outputs a positive pulse signal at a constant frequency period. This frequency is 1/6 of the oscillator frequency. It can be used as a pulse for external output or for timing purposes. It should be noted that whenever external data is accessed memory, 1 ALE pulse will be skipped.
PSEN(29): Strobe signal for external program memory. During the instruction fetch from the external program memory, PSEN is valid twice per machine cycle, but when accessing the external data memory, these two valid PSEN signals will not appear.
EA/VPP (31): When EA remains low, the external program memory address is (0000H-FFFFH) regardless of whether there is internal program memory. During FLASH programming, this pin is also used to apply the 12V programming power (VPP).
XTAL1 (19): Input of the inverting oscillator amplifier and input of the internal clock operating circuit.
XTAL2(18): Output from the inverting oscillator.
Design of automatic playback system for No. 3 tone
The horn tone automatic playback system is shown in Figure 2. The P1.0 terminal of AT89C51 is connected to the IN+ port of the audio amplifier module, and an 8 ohm or 16 ohm speaker is connected to the VOUT terminal of the audio amplifier module.
3.1 Circuit design and music programming principles
To generate audio pulses, just calculate the period of a certain audio frequency (1/frequency), and then divide this period by 2, which is the half-cycle time. Use a timer to count the half-cycle time, invert P1.0 every time the timer expires, and then repeat the timing and then invert. You can get pulses of this frequency on the P1.0 pin.
Use the internal timer of AT89C51 to work in counter mode (MODE1), and change the count values TH0 and TL0 to generate different frequencies to generate different scales. For example, the frequency is 523Hz, and its period T=1/523=1912μs, so as long as Let the counter count 956μs/1μs=956, and invert the I/O every 956 times to get the midrange DO (523Hz).
The relationship between counting pulse value and frequency is:
N=f i ÷2÷f r
In the formula, N is the count value; f i is the machine frequency (when the crystal oscillator is 12MHz, its frequency is 1MHz); f r is the frequency you want to generate.
The method to find the initial counting value T is as follows:
T=65536-N=65536-f i ÷2÷f r
For example: Suppose K = 65536, f i = 1MHz, find the count values of bass DO (261Hz), midrange DO (523Hz), and treble DO (1046Hz).
T=65536-N=65536-f i ÷2÷f r=65536-1000000÷2÷f r=65536-500000/f r
T=65536-500000/262=63627 for bass DO
T of alto DO=65536-500000/523=64580
T of treble DO=65536-500000/1046=65059
The frequency of each note in the key of C is compared with the initial counting value T as shown in Table 1.
3.2 Main program flow
This system mainly completes work and rest timing and horn playback functions, so it uses the timer T1 interrupt method to generate a 100ms benchmark time, and then uses software to time the benchmark time according to the length of each period on the schedule. You can use table lookup to obtain the counting parameters. After the timer expires, send the playback subroutine address to DPTR, transfer to the playback subroutine, and play the corresponding signal tone twice before continuing to count. The main program flow is shown in Figure 3.
The playback subroutine uses the T0 interrupt method to control P1.0 to continuously invert to produce notes of different frequencies. The length of the beat is determined by the number of calls to the 200ms delay subroutine. Subroutines are also implemented using lookup tables.
Previous article:Design of automatic horn tone player based on AT89C51 microcontroller
Next article:Interface Design of 51XA Microcontroller and Graphic LCD Display
Recommended ReadingLatest update time:2024-11-16 22:53
- Popular Resources
- Popular amplifiers
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- Solutions to the "Disconnected-you are now offline" issue when connecting to the Ubuntu system
- 【Perf-V Evaluation】UART
- Download the new issue of Analog Dialogue for free!
- Are there step by step instructions for adding a custom service?
- ESP8266 Getting Started Guide
- MSP430FR2355 LaunchPad Development Kit
- Millimeter wave sensors bring new intelligence to industrial applications
- Switching Power Supply Interest Group Task 05
- DC/DC power supply circuit (MP2562 chip) chip breakdown failure when powering on
- [Chuanglong TL570x-EVM] Establish startup service - print helloworld