introduction
With the penetration of computers in various fields of society, the application of single-chip microcomputers is becoming increasingly in-depth, while driving the rapid updating of industry, agriculture, commerce, home appliances and toys, greatly improving the quality and efficiency of electronic circuit and system design.
The single-chip electronic keyboard with storage function designed in this paper is composed of STC89C51 single-chip computer, small keyboard, LCD, audio power amplifier circuit and speaker. With this electronic keyboard circuit, users can freely input notes, use the single-chip computer to generate different frequencies to obtain the required scale, make the speaker emit pleasant music, and finally play the music they want to express at will. At the same time, the design process and key technologies of the system are discussed in detail.
1 System Hardware Composition
The control circuit of the electronic keyboard is divided into several parts, including single-chip microcomputer STC89C51, working indicator LED, LCD display, key input, speaker interface, etc. Its hardware circuit structure block diagram is shown in Figure 1.
1.1 Introduction to the STC89C51 microcontroller
The STC microcontroller is an enhanced 5l microcontroller, fully compatible with MCS-51. STC89C51 can replace AT89C51, and it is more powerful, faster, longer life and cheaper. The microcontroller has 40 pins and is packaged in a dual in-line DIP-40 package. STC89C51 can complete the ISP online programming function, while AT89C51 cannot. Therefore, after the program in AT89C51 is directly burned into STC89C51, STC89C5l can directly replace AT89C51 to work. The series 51 microcontroller chips launched by STC are fully compatible with other 51 microcontrollers. STC89C51 has an internal E2PROM, which can be modified in the program, and the data will not be lost when the power is off. In addition, two levels of interrupt priority are added, etc. The basic characteristics of the STC89 series microcontrollers are shown in Figure 2.
Usually, the scale values entered by the electronic keyboard are first stored in the variable array, and then taken out one by one to play the single tone when playing. The variables in the program use the internal memory RAM, which ranges from space 30H to 7FH. Therefore, the program memory planning is: RAM address 30H to 70H stores the scale value, and the maximum memory space is 64 bytes; RAM address 71H to 7FH stores other program variables. After the program is executed, the work indicator LED flashes, indicating that the program has started to execute. When the relative key in the keyboard group is pressed, the piezoelectric speaker will emit a relative scale single tone. The whole system has 2 octave scales, DO~SI, HI DO~HI SI, 14 scales, and the input single tone will be stored in 89C5l. Up to 64 single tones can be entered and played together. There is also a clear storage function, which can clear the original data and re-enter it.
1.2 LCD Hardware Interface
The pins of the LCD used in this design are shown in Figure 3, where DO~D7 are bidirectional data buses, and the LCD data read and write methods can be divided into 8-bit and 4-bit. If 8-bit data is read and written, DO~D7 are all valid. If 4-bit data is read and written, only D7~D4 are used. RS is the register selection control line. When RS is 0 and a write operation is performed, the instruction register can be written; if RS is 1, it is used to read and write data registers. P/W is the LCD read and write control line. When R/W is 0, the LCD performs writing. When R/W is 1, a read operation is performed. VO is the brightness adjustment voltage input control pin. When 0V is input, the character display is the brightest.
The LCD can display the currently played single note code in real time, and can display the stored single note count in real time. Button 9 is the clear key, which can clear the stored single note count to 0; button 8 is the play key, which can play the single notes in the memory one by one. You can press the K4 key to interrupt during the performance. This design uses a general LCD display to display music performance messages and single note codes. Press the keyboard group button, and the speaker will emit a relative scale. By storing these scales and then playing them, it can become an automatic playing electronic piano.
1.3 Keyboard Scanning
Each key on the keyboard is identified by two unique values. Why two values instead of one? This is because a key can be pressed and released. When a key is pressed, it generates a unique value, and when a key is released, it also generates a unique value. We save these values in a table, and then we can know which key was hit by looking up the table, and whether it was pressed or released.
The schematic diagram of the distribution and configuration of the entire 4x4 keyboard keys is shown in Figure 4. Figure 4 shows the 16-key control circuit, which uses the 8 I/O lines of AT89S51 port 2 to scan the 16 keys, and P2.0~P2.3 sends the scan signal, while P2.4~P2.7 reads the key data return code. Table 1 lists the correspondence between 4x4 keys and scales.
[page]
Keyboard (keys): The keyboard of the electronic piano is divided into standard force keyboard, semi-weighted keyboard, fully weighted keyboard, and graded weighted keyboard (also called graded hammer keyboard).
Standard force keyboard: a tension spring structure keyboard, which is used from low-end pianos to mid-to-high-end pianos. Its advantage is its fast key return speed (that is, the speed at which the key bounces back after being pressed), and its disadvantage is its inaccurate force transition and positioning.
Semi-weighted keyboard: It is also a keyboard with tension spring structure, but it has more weighted lead blocks than ordinary tension spring keyboard. This kind of keyboard structure has been used in mid-to-high-end synthesizers before, but now many popular pianos also have this configuration. The advantage of the standard velocity keyboard is that the velocity positioning is more precise.
Fully weighted keyboard: This keyboard is constructed to imitate the piano, simulating the action structure, and there is a fixed weighted lead block under each key, so it is called a fully weighted keyboard. It gives the player a "piano feeling". The advantage is that it is more suitable for the initial replacement of the piano for learning to play, and it has good performance for various playing strengths. The disadvantage is that it is not suitable for playing some songs that require fast playing speed (slow rebound).
Stepped weighted keyboard: Like the fully weighted keyboard, it also simulates the action structure. The difference is that the keys of the stepped weighted keyboard are heavier in the bass range and lighter in the treble range, which imitates the feel of a grand piano.
3 System Software Design
Since this system can generate sounds of various frequencies, the speaker can emit the scale of "DO", "RE", "ME"... Timer O in the system works in mode 0, and the timing duration can be determined according to the frequency of the sound. Table 2 lists the frequency values corresponding to each note. The initial value of the timer count derived from the frequency value can be obtained by the following relationship:
In the formula, f is the frequency value; t is the width of the square wave, expressed in μs; co is the number of times counted by the timer, lo is the low byte of the initial count value, and hi is the high byte of the initial count value. Figure 5 shows the workflow of the main program.
4 Conclusion
By changing the control program of the key-operated electronic keyboard, different types of electronic keyboards can be designed. The memory capacity can also be increased by expanding the RAM, thereby giving full play to the storage function of the electronic keyboard.
Previous article:An assembly lookup program
Next article:Design of smart home security system based on single chip microcomputer
Recommended ReadingLatest update time:2024-11-17 04:45
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
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!
- Rambus Launches Industry's First HBM 4 Controller IP: What Are the Technical Details Behind It?
- 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
- RSL10 Data Set
- Could you please tell me which category this photoelectric switch belongs to?
- Regarding chip thermal calculations, this article is worth reading!
- Can anyone share a set of interview questions & answers for embedded software engineer/microcontroller software engineer? THX!
- C66x instruction set - initial exploration of instruction set architecture
- Has anyone learned SOLIDWORKS? How long does it take to learn it? What are the commonly used discussion forums?
- Help with porting ad5941 to stm32f407
- Explanation of the parameters and terms of the power module
- Revealing how eLTE-loT builds the Industrial Internet of Things?
- How to know the power consumption of feedback resistor without knowing the internal resistance of battery?