Table of contents
1. Schematic diagram and introduction of knowledge points
1.1. Schematic diagram of the buzzer:
foreword
The first experiment: 51 single-chip microcomputer (Puzhong HC6800-EM3 V3.0) experimental routine software analysis experiment one point lights up the first LED_ManGo CHEN's Blog-CSDN Blog
The second experiment: 51 single-chip microcomputer (Puzhong HC6800-EM3 V3.0) experimental routine software analysis experiment 2 LED flicker_ManGo CHEN's Blog-CSDN Blog
The third experiment: 51 single-chip microcomputer (Puzhong HC6800-EM3 V3.0) experimental routine software analysis experiment three LED water lights_ManGo CHEN's Blog-CSDN Blog
Fourth Experiment: Buzzer
1. Schematic diagram and introduction of knowledge points
1.1. Schematic diagram of the buzzer:
The buzzer circuit is as follows:
For the principle of the buzzer, please refer to the following blog post: MCU_CT107D Training Platform Circuit Schematic Diagram\Blue Bridge Cup Training Board\Input and Output Module\Matrix Button\Buzzer Circuit\Relay Circuit\LM386 Power Amplifier Circuit, Driving Speaker_ct107d MCU_ManGo CHEN's Blog-CSDN Blog
2. Code analysis
Let me introduce the project first:
Let's go directly to the code:
/**************************************************************************************
* 蜂鸣器实验 *
实现现象:下载程序后蜂鸣器发声
注意事项:无
***************************************************************************************/
#include "reg52.h" //此文件中定义了单片机的一些特殊功能寄存器
#include<intrins.h> //因为要用到左右移函数,所以加入这个头文件
typedef unsigned int u16; //对数据类型进行声明定义
typedef unsigned char u8;
sbit beep=P1^5;
/*******************************************************************************
* 函 数 名 : delay
* 函数功能 : 延时函数,i=1时,大约延时10us
*******************************************************************************/
void delay(u16 i)
{
while(i--);
}
/*******************************************************************************
* 函 数 名 : main
* 函数功能 : 主函数
* 输 入 : 无
* 输 出 : 无
*******************************************************************************/
void main()
{
while(1)
{
beep=~beep;
delay(10); //延时大约100us 通过修改此延时时间达到不同的发声效果
}
}
The program here is very simple. This section is mainly to understand the principle of the buzzer: for the principle of active and passive, please refer to: