Design of automatic horn tone player based on AT89C51 microcontroller

Publisher:老实巴交的大叔Latest update time:2006-07-26 Source: 国外电子元器件Keywords:horn  memory  timing Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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.

Keywords:horn  memory  timing Reference address:Design of automatic horn tone player based on AT89C51 microcontroller

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

Chapter 7: Tiny4412 U-BOOT transplantation DDR memory configuration
Last time, we finished talking about the low-level initialization of Nand Flash. The operation of Nand Flash is mainly in board_init_f_nand(), which involves copying the code from Nand Flash to DDR. This will be analyzed in the actual transplantation process later in combination with the source code flow. Normally, DD
[Microcontroller]
Chapter 7: Tiny4412 U-BOOT transplantation DDR memory configuration
stm32 memory space allocation learning
The figure is a memory map of stm32, where the code area starts at 0x0800 0000, and its end address is 0x0800 0000 plus the actual chip flash size. Its ram start address is 0x2000 0000, and the end address is still the actual chip ram size.
[Microcontroller]
stm32 memory space allocation learning
iDIMMs that support wide temperature range for industrial computers
In 2010, the industrial control memory manufacturer Innodisk launched a series of wide temperature memory iDIMMs that support professional industrial control computer designs. iDIMMs can provide the system with higher quality signals, more stable system performance, and lower risk of system crashes than stan
[Analog Electronics]
iDIMMs that support wide temperature range for industrial computers
ARM memory address access
1. Access the memory location of the absolute address:      #define pISR_EINT0 (*(unsigned *) (_ISR_STRATADDRESS+0x74))      The above statement casts the unsigned integer _ISR_STRATADDRESS+0x74 to a pointer to RAM, which can be accessed using the following statement: pISR_EINT0 = (int)Eint0_ISR      To access a
[Microcontroller]
MCU APROM: RAM: Flash: Difference
APROM is the user program storage area. The code of the microcontroller program we write is placed here. APROM is, APROM is a part of Flash. RAM, random access memory, is mainly used to store dynamic data. For example, the variables defined in our program are placed here, and the intermediate results gene
[Microcontroller]
Black Shark Gaming Phone 2 Pro comes standard with 12GB of RAM + UFS 3.0 flash memory, priced at 2999
This afternoon, Black Shark held a press conference and officially released the Black Shark Gaming Phone 2 Pro. Black Shark Gaming Phone 2 Pro is available in two versions, the 12+128GB version is priced at 2,999 yuan, and the 12+256GB version is priced at 3,499 yuan. It will go on sale at China Joy at 10:00 on August
[Mobile phone portable]
Breaking the memory wall and power consumption wall, the present and future of domestic chip AI-NPU
With the implementation of 5G, the cost-effectiveness of the Internet of Things has become apparent, and the evolutionary trends of industrial digitization and urban intelligence have become increasingly obvious. More and more companies and cities have begun to add disruptive concepts such as digital twins to IoT inno
[Internet of Things]
Breaking the memory wall and power consumption wall, the present and future of domestic chip AI-NPU
Some understanding of C language memory
 The big topic of memory key: You must have a logical diagram of memory in your mind. What is the procedure? Program = Code + Data The code is placed in the code segment in Flash, and the variable data (global variables, local variables) is placed in the memory. What is the purpose of running the program?
[Microcontroller]
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号