A simple electronic keyboard designed based on the STC89C52RC microcontroller. The microcontroller and peripheral circuits form the main control circuit, 8 buttons form the control circuit, 8 LEDs form the display circuit, and the transistor and buzzer form the driving sound circuit. By pressing different buttons, you can control the buzzer to emit tones of different frequencies, light up the corresponding LED display, and play any music at will.
The block diagram of the electronic keyboard circuit system is shown in Figure 2-1 . The main control microcontroller uses STC89C52RC , the power input uses a 5V power supply, the control input terminal only has button input, the LED displays the corresponding button, and the passive buzzer outputs the electronic keyboard sound effect. The overall design is simple and efficient, without cumbersome and complicated driving components.
Figure 2-1 Electronic keyboard system structure block diagram
The electronic keyboard based on the STC89C52RC microcontroller is mainly composed of a power supply circuit, a microcontroller minimum system circuit, a program download circuit, a button control circuit, an LED display circuit and a buzzer drive circuit. The circuit principles of each module will be analyzed below.
The power part is mainly the Micro USB female socket as the power input port, SW1 is the toggle switch, C1/C2 is the power filter capacitor, and POWER is the power indicator light. Turn on the USB , flip the SW1 switch, the POWER power indicator light will light up, and power the entire board.
Figure 3-1 Power input circuit
The main control microcontroller uses STC89C52RC ( LQFP-44 package), which is cheap, high-speed, reliable, low power consumption, and has strong anti-interference. The instruction code is fully compatible with the traditional 8051 microcontroller. The operating voltage is 3.3~5.5V . The operating frequency range is 0~40MHz , which is equivalent to the 0~80MHz of the ordinary 8051. The actual operating frequency can reach 48MHz . The Flash program memory space size is 8K bytes. On-chip integrated 512 -byte RAM data memory, operating temperature range is -40~85 ℃.
Figure 3-2 STC89C52RC minimum system circuit
The program is downloaded using a Micro USB data cable. The USB to serial port chip uses CH340C ( SOP-16 package), which has a built-in clock and does not require an external crystal oscillator. The D+/D- pin of the CH340C chip is connected to the D+/D- of the Micro USB . TXD/ The RXD pin is connected to the RXD/TXD pin of the microcontroller, the VCC pin inputs an external 5V power supply, C7 is the decoupling capacitor of the power supply, and C8 is the filter capacitor.
Figure 3-3 USB to TTL program download circuit
8 LEDs form a display circuit, which is directly connected to a set of I/O ports of the microcontroller. The 8 buttons correspond to 8 LED indicators. When the button is pressed, the corresponding LED light lights up.
The control part is mainly composed of 8 independent buttons, which are directly connected to a set of 8 -bit I/O ports of the microcontroller. The 8 buttons correspond to the 8 scale keys of the electronic keyboard. The sounds of various keys are realized through software and hardware design, and the corresponding keys and LEDs are The notes are shown in Table 3-1 .
Table 3-1 Note table corresponding to buttons and LEDs
button |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
led |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
Note |
do |
re |
mi |
fa |
so |
la |
Si |
do~ |
图3-4 LED显示电路 图3-5按键控制电路
采用PNP型三极管的作驱动,三极管工作在开关状态时,放大驱动电流,使得蜂鸣器发出声音。三极管上拉电阻作用是使三极管能够保持可靠的开关状态,基极串联电阻作用是防止受到单片机干扰而导致三极管状态发生意外翻转,进入不期望的放大状态。
图3-6 蜂鸣器驱动电路
打开嘉立创EDA,创建新工程并命名为【单片机】电子琴电路设计,将原理图文件命名为:SCH_电子琴电路设计。根据以下电路进行绘制电路原理图。
图4-1 SCH_电子琴电路设计
在本项目的元器件选型中,所有元器件可直接在嘉立创EDA的元件库中进行搜索。如果对元器件不熟悉,也可以通过复制物料中的商品编号进行搜索(每一个元器件在立创商城都有唯一的商品编号),如果出现物料缺货情况,亦可选择其他可替换物料,通过以上电路的分析,相信聪明的你对各个元器件在电路中的作用有所了解,那么更换个别物料也不会影响到电路的工作性能的,了解电路工作特性后,电路选型也就变得简单了。
图4-2 元器件搜索示意图
图4-3 通过商品编号搜索示意图
电子琴电路设计项目物料清单 |
||||||
序号 |
名称 |
参数 |
位号 |
数量 |
封装 |
商品编号 |
1 |
电阻 |
1K |
R1~R8,R10,R11 |
10 |
R0805 |
C17513 |
10K |
R9,R12 |
2 |
R0805 |
C17414 |
||
2 |
电容 |
10uF |
C1,C5 |
2 |
C0805 |
C386019 |
30pF |
C2,C3 |
2 |
C0805 |
C43094 |
||
100nF |
C4,C6,C7,C8 |
4 |
C0805 |
C38141 |
||
3 |
二极管 |
LED-0805_R |
LED1~LED8,POWER |
9 |
LED0805 |
C72037 |
4 |
三极管 |
2N3906 |
Q1 |
1 |
SOT-23-3 |
C147294 |
5 |
按键 |
K4-6x6_SMD |
KEY1~KEY8,RST |
9 |
KEY-SMD_4P |
C191626 |
6 |
开关 |
SS-12D02-VG4 |
SW1 |
1 |
SW-TH_SS-12D02-VG4 |
C136719 |
7 |
晶振 |
12MHz |
X1 |
11 |
HC-49S/SMD |
C14871 |
8 |
蜂鸣器 |
5V |
BUZZER1 |
1 |
BUZ-TH_BD9.0-P4.00-D0.6-FD |
C409839 |
9 |
单片机 |
STC89C52RC |
U1 |
1 |
LQFP-44 |
C8707 |
10 |
USB芯片 |
CH340C |
U2 |
1 |
SOP-16 |
C84681 |
11 |
USB连接器 |
Mirco USB |
USB1 |
1 |
MICRO-USB-SMD_5P |
C40957 |
12 |
排针 |
2.54*2P |
J1 |
1 |
HDR-M-2.54_1X2 |
C124375 |
13 |
短路帽 |
2.54mm |
J1 |
1 |
HDR-M-2.54_1X2 |
C5305 |
14 |
铜柱 |
M3 |
TP1~TP4 |
1 |
M3X10-6 |
C551322 |
完成原理图设计后,经过检查电路与网络连接正确后点击顶部菜单栏的 “设计 ”→ “原理图转PCB”(快捷键为Alt+P),随即会生成一个PCB设计界面,可先暂时忽略弹出的边框设置,然后将PCB文件保存到工程文件中,并命名为:PCB_电子琴电路设计。
在绘制PCB前需根据个人意愿以及元器件数量所占空间确定PCB的形状及边框大小,若无特殊外壳要求,一般设计成矩形、圆形以及正方形。在设计该项目时,秉承着大小合适,美观大方的原则,我们在顶部工具菜单栏下的边框设置选型中设定了一个长为85mm、宽50mm、圆角半径为2mm的圆角矩形。实际板框大小会随着布局布线中进行调整,如果太小可适当放大,太大也可缩小边框,风格样式可自由发挥,但尽量控制在10cm*10cm之内,这样就可以到嘉立创免费打样啦~
图5-1 边框设置 图5-2 边框示意图
在绘制完板框外形后,接下来进行PCB设计的第二步,对元器件进行分类和布局,分类指的是按照电路原理图的功能模块把各个元器件进行分类,图中有很多按键和对外的接口,这里需要我们用到嘉立创EDA所提供的布局传递功能,首先确保PCB工程已保存到原理图文件的同一个工程文件夹中,然后框选原理图中的某一电路模块,比如选中按键电路,然后点击顶部菜单栏中的 “工具” → “布局传递”(快捷键为Ctrl+Shift+X),PCB页面所对应的元器件就好进行选中并按照原理图布局进行摆放, 使用这个方法将各个电路模块进行分类后依次摆放在前面所放置的边框中。
在布局的时候注意摆放整齐,可根据飞线的指引进行摆放,按照原理图信号的流向和器件连接关系进行摆放,是可以把原理图器件摆放非常整齐的,在布局的过程中注意接口位置。 在该项目的布局中提供以下几点参考建议:
① Mirco USB and toggle switches are placed on the left side of the board;
② Place the decoupling capacitor of CH340C as close to the connected pin as possible, and the D+/D- signal line as close to parallel wiring;
③ Try not to route wires under the crystal oscillator, and place it close to the microcontroller to reduce interference;
④ 8 keys are equally spaced on the lower side, and 8 indicator lights are equally spaced on the upper side;
⑤ Place M3 copper pillar holes at the four corners of the board for fixed support;
Figure 5-3 PCB layout reference diagram
Next is the third step of PCB design: PCB routing, which is called printed circuit board wiring ( PCB LAYOUT ). Since the circuit board has two sides, the top and the bottom, the PCB traces can be divided into top and bottom traces. The top trace is red by default and the bottom is blue. You can also set other colors according to personal preference. , wiring means connecting wires according to flying wires in the circuit board, and connecting the same networks.
First select the layer to be routed among the layers and elements, and then click the wire tool to connect (the shortcut key is W ). The seemingly simple Lianliankan requires us to make adjustments patiently. The placement and layout of components will also affect the difficulty of wiring, so we need to further adjust the layout and optimize it during the wiring process. The PCB layout introduced earlier is equivalent to paving the way for wiring. Once the wiring is laid out, the wiring will naturally flow smoothly. The following suggestions are provided for the wiring of this project:
①Set the power line to 25mil and the signal line to 15mil width;
② The wiring is mainly on the top layer. If it cannot be routed, you can switch to the bottom layer for connection;
③ During the wiring process, give priority to straight lines, and use arc turns or obtuse angles where corners are needed;
④Finally add teardrops and add silk screen to mark the button function and interface function;
Figure 5-4 PCB routing reference diagram
After the PCB traces are drawn and copper is poured, the GND network can be connected. Silk screen characters follow the principle from top to bottom and from left to right. Add silk screen labels to the toggle switches, power indicators, buttons, etc., and add the project name and LOGO comments to the board.
Figure 5-5 PCB top layer copper pouring and silk screen reference diagram
Figure 5-6 PCB bottom copper coating and silk screen reference diagram
( 1 ) Device welding
First, solder the Micro USB interface first; second, solder CH340C and STC89C52RC (pay attention to the direction when soldering the chip, don't solder it backwards) ; third, resistors, capacitors, transistors and LEDs ; fourth, crystal oscillators and buttons ; fifth, Switches and buzzers.
Figure 6-1 PCB assembly diagram
Figure 6-2 Unsoldered PCB board
Be careful not to touch the soldering iron tip with electrically safe hands during the welding process to avoid burns. Align the components during welding and check whether the model is correct . When holding SMD components with tweezers, wait until the solder solidifies before removing the tweezers, otherwise it may cause false soldering. During the welding process, pay attention to whether the tin wire is missing or missing , so as to avoid affecting the circuit performance and causing the circuit to not work properly.
Figure 6-3 PCBA physical diagram
Figure 6-4 PCB-3D rendering
(2) Hardware debugging
If the welder is rough, after welding a component, he can visually check whether there is a short circuit or use a multimeter to check. After the welding is completed, you need to use a multimeter to check whether the power supply and the ground are short-circuited. Whether there is a short-circuit or open circuit during the welding process, the power-on test can only be carried out after the inspection is correct.
All reference designs on this site are sourced from major semiconductor manufacturers or collected online for learning and research. The copyright belongs to the semiconductor manufacturer or the original author. If you believe that the reference design of this site infringes upon your relevant rights and interests, please send us a rights notice. As a neutral platform service provider, we will take measures to delete the relevant content in accordance with relevant laws after receiving the relevant notice from the rights holder. Please send relevant notifications to email: bbs_service@eeworld.com.cn.
It is your responsibility to test the circuit yourself and determine its suitability for you. EEWorld will not be liable for direct, indirect, special, incidental, consequential or punitive damages arising from any cause or anything connected to any reference design used.
Supported by EEWorld Datasheet