[Bridge Cup Blue chip development board buzzer relay] (3)

[Bridge Cup Blue chip development board buzzer relay] (3)

A buzzer circuit

Here Insert Picture Description
Buzzer cathode connected VCC 5V, a negative electrode connected to the N_BUZZ Darlington, Darlington circuit is a NAND gate: 1 when the input IN, the output OUT 0; 0 if the input IN, the output OUT 1; to make the buzzer, the low level 0 OUT7.
Here Insert Picture Description
Look at the decoder, the decoder then wants to open Y5C must be high, Y5C control by the decoder 38, when P27 = 1, P26 = 0, P25 = 1 when Y5 output low, the output Y5C high, the latch open.
Truth table

After open decoder assignment of P0 port, so OUT7 0 is low, i.e., so that P06 = 1, so that the buzzer sounded. code show as below:

#include"reg52.h"  //包含头文件

sbit Buzz = P0^6;      //定义蜂鸣器
sbit HC138_A = P2^5;  //定义译码器中ABC所在引脚
sbit HC138_B = P2^6;
sbit HC138_C = P2^7;

void Delay(unsigned int t)  //延时函数
{
	while(t--);
}

void Buzz(unsigned char State)
{
	HC138_C = 1;  //给CBA赋值
	HC138_B = 0;
	HC138_A = 1;
	
	if(State == 1)  //蜂鸣器响
	  Buzz = 1;
	if(State == 0)  //蜂鸣器不响
	  Buzz = 0;
}


void main()  //主函数
{
	while(1)  //死循环
	{
	Buzz(1);
	Delay(50000);
	Buzz(0);
	Delay(50000);  //让它响一会儿后不响
	}
}

Second, the relay circuit


Relay N_RELAY likewise connected to a negative electrode on the first Darlington diagram, P04 is controlled by a latch. To relay, then P04 = 1. code show as below:

#include"reg52.h"

sbit Relay = P0^4;    //定义继电器
sbit HC138_A = P2^5;
sbit HC138_B = P2^6;
sbit HC138_C = P2^7;

void Delay(unsigned int t)
{
	while(t--);
}

void RELAY(unsigned char State)
{
	HC138_C = 1;
	HC138_B = 0;
	HC138_A = 1;

	if(State == 1)  //继电器吸合
	  Relay = 1;
	if(State == 0)  //继电器不吸合
	  Relay = 0;
}

void main()
{
	while(1)
	{
		RELAY(1);
		Delay(50000);
		RELAY(0);
		Delay(50000);  //继电器一吸一合
	}
}
Released three original articles · won praise 1 · views 2769

Guess you like

Origin blog.csdn.net/qq_45382733/article/details/104068313