51 single-chip microcomputer (Puzhong HC6800-EM3 V3.0) experimental routine software analysis experiment five relays

Table of contents

foreword

1. Schematic diagram and introduction of knowledge points

1.1. Relay schematic diagram:

 2. Code Analysis


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

The fourth experiment: 51 single-chip microcomputer (Puzhong HC6800-EM3 V3.0) experimental routine software analysis experiment four buzzers_ManGo CHEN's Blog-CSDN Blog

Experiment 5: Relay

1. Schematic diagram and introduction of knowledge points

1.1. Relay schematic diagram:

The relay circuit is as follows:

 

The principle of the relay refers to the following blog post: SCM_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, drive 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:

/**************************************************************************************
*		              继电器实验												  *
实现现象:下载程序后继电器模块指示灯DK亮,会听到继电器吸合的声音
注意事项:无																				  
***************************************************************************************/

#include "reg52.h"			 //此文件中定义了单片机的一些特殊功能寄存器

typedef unsigned int u16;	  //对数据类型进行声明定义
typedef unsigned char u8;

sbit relay=P1^4;	   


/*******************************************************************************
* 函 数 名       : main
* 函数功能		 : 主函数
* 输    入       : 无
* 输    出    	 : 无
*******************************************************************************/
void main()
{	
	relay=0;
	while(1);
}

The program here is very simple. This section is mainly the understanding of the relay circuit: it can be seen that when the relay is 0, the J2 port in the schematic diagram is at a low level, so that the Q1 transistor is turned on, and the relay coil is turned on and closed. , so that the normal opening is closed to achieve the effect of the switch being closed.

Guess you like

Origin blog.csdn.net/qq_42700289/article/details/132219189