基于51单片机的声控灯设计【光照,声音,红外】(仿真)

本文描述了一个基于51单片机的门灯控制系统,利用光敏、声音和红外传感器,白天自动关闭,夜晚在声音或人体靠近时点亮,30秒延时后自动熄灭。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

设计一个声、光、红外同时控制的门灯系统

1、光敏控制灯在白天不亮,只在晚上声控检测到声音或者红外检测到人靠近时灯亮

2、声音消失或人离开后延时30秒灯熄灭

#include<reg52.h>
#include<intrins.h>
#define uchar unsigned char
#define uint unsigned int

sbit ADCLK=	P1^0;//时钟,初始状态为0
sbit ADDI=	P1^1;//数据输入
sbit ADDO =	P1^2; // 数据输出
sbit ADCS=	P1^3;

sbit led=P3^3;//灯

sbit man=P3^2;//人体

sbit voice=P3^1;//声音

uint miao=0;//计时

//将AD转换来的二进制数转换为十进制数
unsigned int zhuanhuan()  //AD转换,返回结果
{
	unsigned char i = 0,channel=2;
	unsigned char j;
	unsigned int dat = 0;
	unsigned char ndat = 0;

	ADDI = 1;//输入引脚拉高
	_nop_();//延时1us
	_nop_();//延时1us
	ADCS = 0;//片选
	_nop_();//延时1us
	_nop_();//延时1us
	ADCLK = 1;//拉高时钟
	_nop_();//延时1us
	_nop_();//延时1us
	ADCLK = 0;//拉低时钟
	_nop_();//延时1us
	_nop_();//延时1us
	ADCLK = 1;//拉高时钟
	ADDI = channel & 0x1;
	_nop_();//延时1us
	_nop_();//延时1us
	ADCLK = 0;//拉低时钟
	_nop_();//延时1us
	_nop_();//延时1us
	ADCLK = 1;//拉高时钟
	ADDI = (channel >> 1) & 0x1;
	_nop_();//延时1us
	_nop_();//延时1us
	ADCLK = 0;//拉低时钟
	ADDI = 1;//输出1
	_nop_();//延时1us
	_nop_();//延时1us
	dat = 0; //存储清零
	for (i = 0; i < 8; i++)	//循环8次
	{
		dat |= ADDO;//读取引脚
		ADCLK = 1; //拉高时钟
		_nop_();//延时1us
		_nop_();//延时1us
		ADCLK = 0;//拉低时钟
		_nop_();//延时1us
		_nop_();//延时1us
		dat <<= 1;//左移
		if (i == 7) dat |= ADDO;//读取引脚
	}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

白茶丫

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值