Author: GWD Time: 2019.7.1
KY-031 knock sensor module (switch-type sensor)
First, learning points: None
Second, manual analysis of
1,
2, there is a little plastic tube spring, produces a low level after the closing motion;
three program
1, program functions: When P3.2 (INT0) of the sensor for detecting the percussion to the tap, the external interrupt (low level triggered), LED lamp lighting lS P2 ^ 1;
2, - procedures:
3, Code
#include<reg52.h> //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义
#include "intrins.h"
typedef unsigned int uInt16;
typedef unsigned char uChar8;
sbit relay = P2^1;
void Delay1000ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
i = 8;
j = 1;
k = 243;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
main()
{
P1=0x55; //P1口初始值
EA=1; //全局中断开
EX0=1; //外部中断0开
IT0=1; //下降沿触发
while(1)
{
//在此添加其他程序
}
}
void ISR_Key(void) interrupt 0 using 1
{
relay=0;
Delay1000ms();
relay=1;
}
Mini magnetic switch (switch-type sensor)
First, learning points: None
Second, manual analysis:
1,
2, when a magnet pin outputs a low level signal is close to
three, program
1, program functions: When the magnetic sensor Mini P3.2 (INT0) of the detected magnetic signal, the external interrupt (low level triggered), LED lamp lighting lS P2 ^ 1;
2, the effect of the program:
3, Code: supra
Metal touch switch (switch-type sensor)
First, learning points: None
Second, manual analysis:
1,
three, program
1, program functions: When P3.2 (INT0) touch switch detects the touch signal, the external interrupt (low level triggered), P2 ^ 1 LED lamp is lit lS;
2, the effect of the program:
3, Code: supra
Analog, digital temperature (switch-type sensor)
一、 学习要点:
1、 工作原理:
电阻类传感器与LM393结合使用,在温度低时,热敏电阻的电阻值很大,电阻R23与该热敏电阻组成的分压点电压升高,使同相端INB+电压大于反相端INA-端电压,电压比较器的输出端OUT输出高电平电压,此时Light LED灯不亮。在温度高时,热敏电阻的的电阻值很小,电阻R23与该光敏二极管组成的分压点电压下降,使同相端INB+电压小于反相端INB-端电压,电压比较器的输出端OUT输出低电平电压,此时Light LED灯亮。接在反相端INA-端的电位器VR2用于调节该端的电位电压,这个电压也就是电压比较器输入的阀值翻转电压,用于温度敏度调节。
二、 手册分析:
1、该模块是基于热敏电阻(阻值随外界环境温度变化而变化,温度越高电阻越小) 的工作原理,借此广泛应用于园艺、家庭警报系统等装置中。
三、 编程
1、代码功能:温度升高大于LM393的阈值电压时,LM393输出低电平,触发中断P3.2(INT0)引脚后P2.1引脚的小灯点亮1S;
2、 实验现象:
3、代码:
#include<reg52.h> //包含头文件,一般情况不需要改动,头文件包含特殊功能寄存器的定义
#include "intrins.h"
typedef unsigned int uInt16;
typedef unsigned char uChar8;
sbit relay = P2^1;
void Delay1000ms() //@11.0592MHz
{
unsigned char i, j, k;
_nop_();
i = 8;
j = 1;
k = 243;
do
{
do
{
while (--k);
} while (--j);
} while (--i);
}
main()
{
P1=0x55; //P1口初始值
EA=1; //全局中断开
EX0=1; //外部中断0开
IT0=1; //下降沿触发
while(1)
{
//在此添加其他程序
}
}
void ISR_Key(void) interrupt 0 using 1
{
relay=0;
Delay1000ms();
relay=1;
}
线性霍尔(开关量类传感器)
First, the learning points:
1. Q: What is the Hall element?
A: The Hall element is a magnetic sensor based on the Hall effect. They can be detected by a magnetic field and variations thereof, may be used in various occasions related to the magnetic field. Hall elements have many advantages, their solid structure, small volume, light weight, long life, easy installation, low power consumption, high frequency (up to 1MHZ), shock resistant, not afraid of dust, oil, salt spray and water vapor and the like contamination or corrosion.
Second, manual analysis of
three program
1, code Function: When the magnetic field is detected LM393 output low, triggers an interrupt P3.2 (INT0) of the pin after the pin P2.1 small lamp lighting lS;
2, Experiment phenomena :
3, Code: analog same temperature