Intelligent bedside lamp based on microcontroller

Author Home Page: Programming Compass

About the author: High-quality creator in the Java field, CSDN blog expert, CSDN content partner, Nuggets guest author, Alibaba Cloud blog expert, 51CTO guest author, many years of architect design experience, Tencent classroom resident lecturer

Main contents: Java projects, Python projects, front-end projects, artificial intelligence and big data, resume templates, study materials, interview question bank, technical mutual assistance

Collect, like and don’t get lost. It’s good to follow the author.

Get the source code at the end of the article 

Project number: BS-DPJ-004

1. Introduction to the environment

Locale: C language

Development technology: 51 microcontroller

2. Project Introduction

Scientific and technological progress has promoted the continuous improvement of people's lives. Various industries are gradually advancing intelligence. In our daily lives, the number of smart devices we are exposed to is also increasing, which brings us more choices. In real life, bedside lights are mainly switched on and off manually, which is very inconvenient especially at night. On this basis, an automatic bedside lighting control system based on 51 microcontroller is proposed. The system mainly includes: single-chip main control system, LCD liquid crystal display module, temperature and humidity detection, light intensity detection, heat emitted by the human body detection, automatic lighting adjustment, etc. It mainly completes the perception of human body position, intelligent control of lights, detection of temperature, humidity and light intensity, and display on LCD screen. This topic is combined with the current level of scientific and technological development, and it is proposed to use a single-chip microcomputer to realize the control of intelligent bedside lights. This is not only an innovation to the traditional family, but also an expectation of scientific researchers and the general public for a better life.

This article introduces an intelligent control method for microcomputers with a single-chip microcomputer as the core and a single-chip microprocessor as the core. In current real life, most bedside lights are controlled by manual switches, which is very inconvenient especially in a nighttime environment. Under such circumstances, this topic combines the current level of technological development to enable the control of bedside lights to be realized with a single-chip microcomputer. This not only brings innovation to traditional families, but also a yearning for a better life among scientific researchers and the general public. The intelligent bedside light control system improves the inconvenience caused by the multi-terminal control of traditional bedside lights, and takes this as the first priority to simplify the operation process and also improve the operability of the system. This brings convenience to people's lives to a certain extent, and at the same time saves energy consumption to a large extent, so it has good practical significance.

3. System display

4. Core code display

#include "reg52.h"
#include "stdio.h"
#include "1602.h"
#include "ds1302.h"
#include "pcf8591.h"
#include "dht11.h"
uchar buf[16]; //显示缓存
sbit  BEEP=P3^3;//蜂鸣器

sbit  JDQ1=P3^7;//开关
sbit  JDQ2=P3^2;//开关
sbit  JDQ3=P1^0;//开关	 .

sbit SYS_SET  = P1^1;//按键选择
sbit SYS_MD   = P1^2;//增加

sbit DCIN1   = P1^5;   //人体探头
sbit DCIN2   = P1^6; 
sbit DCIN3   = P1^7; 


int  f,PWM_T1=0,PWM_T2=0,PWM_T3=0;

void pwmtext(){
	TMOD = 0x02;   //定时器0,工作模式2,8位定时模式
	TH0=150;     //写入预置初值(取值1-255,数越大PWM频率越高)
	TL0=150;     //写入预置值 (取值1-255,数越大PWM频率越高)
	TR0=1;       //启动定时器
	ET0=1;       //允许定时器0中断
	EA=1;        //允许总中断
}
/**************中断服务程序*****************/
void timer0() interrupt	1			//2.5毫秒@11.0592MHz
{
    f++;    //每次定时器溢出加1
    	 
	 if(f==20)   //PWM周期 100个单位
		 {
			f=0;  //使t=0,开始新的PWM周期
			JDQ1=0;JDQ2=0;JDQ3=0;
		 }
	 
	 if(PWM_T1==f)  //按照当前占空比切换输出为高电平
		 {  
		 	JDQ1=1; //  
		 }
	 if(PWM_T2==f)  //按照当前占空比切换输出为高电平
		 {  
		 	JDQ2=1; //  
		 }
	 if(PWM_T3==f)  //按照当前占空比切换输出为高电平
		 {  
		 	JDQ3=1; //  
		 }	 
}


//标志位
void BEEPS(){ //蜂鸣器响一声
	BEEP=0;delay(100);BEEP=1;delay(100); 
}
			  
/***************主程序****************/		   
void main()
{	int mds=0,cd=0,flag=0;
	uchar temp1,gzmax=20,wenmax=30,shimax=70;
	pwmtext();	//PWM初始化
	lcd1602_init();//液晶初始化
	init_ds1302();//ds1302初始化
//	write_time();//写数据
//	BEEPS(); 

	while(1)
	{									   
			    read_time();//获取时间
			   	temp1=(float)((float)Read_PCF8591(1)/255.0)*100.0;	    //读取模拟量1  光照值
				Read_PCF8591(2);	    //读取模拟量2
				Read_PCF8591(3);	    //读取模拟量3
				Read_PCF8591(4);	    //读取模拟量4
			 	
			 cd++;
			 if(cd>25){cd=0;
			 flag=!flag; lcd_Write_com(0x01);	//清屏
			   EA=0;DHT11_receive();EA=1;
			  	
			 }
				if(flag){
				 //显示数据
				 hz_lcdDis(0,0,"Te:"); hz_lcdDis(0,6,"C");
				 hz_lcdDis(1,0,"Hu:");fuhao(5);
				 hz_lcdDis(1,5,"%");
				 hz_lcdDis(1,9,"Gz:");
				 hz_lcdDis(1,14,"%");
				 num_lcdDis(0,3,temp_value,2);
			     num_lcdDis(1,3,humi_value,2);
				 num_lcdDis(1,12,(int)temp1,2);
	
				}else{

				 sprintf(buf,"Date:%02d-%02d-%02d ",2000+(int)nians,(int)yues,(int)ris);	//年月日
				 hz_lcdDis(0,0,buf);//显示在第一行
				 sprintf(buf,"Time:%02d:%02d:%02d ",(int)shis,(int)fens,(int)miaos);//时分秒
				 hz_lcdDis(1,0,buf); //显示在第二行	 
				
				}

			  if(temp_value>wenmax|humi_value>shimax){	  //阈值超标报警
			   BEEPS(); 
			  }
//
			  if(temp1<gzmax){ //光照过低
			  		 if(DCIN1==1){	//1位置有人
						 if(PWM_T1<20){
						 	 PWM_T1++;	 //开灯
						 }
					 
					 }else{
					  if(PWM_T1>0){
					  	  PWM_T1--;	 //关灯
					  }
					 }

					 if(DCIN2==1){	//2位置有人
					  if(PWM_T2<20){
						 	 PWM_T2++;  //开灯
						 }
					 }else{
					  if(PWM_T2>0){
					  	  PWM_T2--;		 //关灯
					  }
					 }

					 if(DCIN3==1){		 //3位置有人
					  if(PWM_T3<20){
						 	 PWM_T3++; //开灯
						 }
					 }else{
					  if(PWM_T3>0){
					  	  PWM_T3--;	    //关灯
					  }
					 }
			  }else{
			  
			   if(PWM_T3>0){
					  	  PWM_T3--;
					  };if(PWM_T2>0){
					  	  PWM_T2--;
					  }	 if(PWM_T1>0){
					  	  PWM_T1--;
					  }
			  }
			 

			 

			 if(SYS_SET==0){
			 	BEEPS();
			    lcd_Write_com(0x01);	//清屏
				while(SYS_SET==0);
				mds=1;
				lcd_Write_com(0x01);
					       nian  = read_ds1302(read_add[5]);
						   sprintf(buf,"nian:%d ",(int)nians);
			 			   hz_lcdDis(0,0,buf); //显示在第1行 
						   hz_lcdDis(0,14,"<=");
						   hz_lcdDis(1,14,"  ");
					
				while(1){
				 if(SYS_SET==0){
				 	mds++;BEEPS();
					
					if(mds==2){
						   yue  = read_ds1302(read_add[4]);
						   sprintf(buf,"yue:%d ",(int)yues);
			 			   hz_lcdDis(1,0,buf); //显示在第2行 
						   hz_lcdDis(0,14,"  ");
						   hz_lcdDis(1,14,"<=");
					}
					if(mds==3){lcd_Write_com(0x01);
					       ri  = read_ds1302(read_add[3]);
						   sprintf(buf,"ri:%d ",(int)ris);
			 			   hz_lcdDis(0,0,buf); //显示在第3行				 
						   hz_lcdDis(0,14,"<=");
						   hz_lcdDis(1,14,"  ");
					}
					if(mds==4){
					       
						   shi  = read_ds1302(read_add[2]);
						   sprintf(buf,"shi:%d ",(int)shis);
			 			   hz_lcdDis(1,0,buf); //显示在第4行
						   hz_lcdDis(0,14,"  ");
						   hz_lcdDis(1,14,"<=");
					}
					if(mds==5){
					lcd_Write_com(0x01);
						   fen  = read_ds1302(read_add[1]);	
						   sprintf(buf,"fen:%d ",(int)fens);
			 			   hz_lcdDis(0,0,buf); //显示在第5行
						   hz_lcdDis(0,14,"<=");
						   hz_lcdDis(1,14,"  ");
						   
					}
					if(mds==6){
						   miao  = read_ds1302(read_add[0]);
						   sprintf(buf,"miao:%d ",(int)miaos);
			 			   hz_lcdDis(1,0,buf); //显示在第4行
						   hz_lcdDis(0,14,"  ");
						   hz_lcdDis(1,14,"<=");
					}								   
					if(mds==7){
					lcd_Write_com(0x01);	   
						   sprintf(buf,"gzmax:%d ",(int)gzmax);
			 			   hz_lcdDis(0,0,buf); //显示在第4行
						   hz_lcdDis(0,14,"<=");
						   hz_lcdDis(1,14,"  ");
					}							
					if(mds==8){
						   
						   sprintf(buf,"wenmax:%d ",(int)wenmax);
			 			   hz_lcdDis(1,0,buf); //显示在第4行
						   hz_lcdDis(0,14,"  ");
						   hz_lcdDis(1,14,"<=");
					}
					if(mds==9){
						 	lcd_Write_com(0x01);  
						   sprintf(buf,"shimax:%d ",(int)shimax);
			 			   hz_lcdDis(0,0,buf); //显示在第4行
						   hz_lcdDis(0,14,"<=");
						   hz_lcdDis(1,14,"  ");
					}
					if(mds>9){lcd_Write_com(0x01);
					  write_time();//写数据	 
					  break;
					}
					while(SYS_SET==0);
				  }
				  if(mds==1){
				  	   if(SYS_MD==0){BEEPS();
					   	   nian=nian+1;	
						   nians=nians+1; 
						   if(nians>25){
						   nian=nians=23;
						   }
						   sprintf(buf,"nian:%d ",(int)nians);//时分秒
			 			   hz_lcdDis(0,0,buf); //显示在第二行 
						   while(SYS_MD==0);
					   }
				  }
				  if(mds==2){
				  	   if(SYS_MD==0){ BEEPS();
					   	   yue=yue+1;	
						   yues=yues+1; 
						   if(yues>12){
						   yues=yue=1;
						   }
						   sprintf(buf,"yue:%d ",(int)yues);//时分秒
			 			   hz_lcdDis(1,0,buf); //显示在第二行 
						   while(SYS_MD==0);
					   }
				  }
				  if(mds==3){
				  	   if(SYS_MD==0){ BEEPS();
					   	   ri=ri+1;	
						   ris=ris+1; 
						   if(ris>31){
						   	 ris=ri=1;
						   }
						   sprintf(buf,"ri:%d ",(int)ris);//时分秒
			 			   hz_lcdDis(0,0,buf); //显示在第二行 
						   while(SYS_MD==0);
					   }
				  }
				  if(mds==4){
				  	   if(SYS_MD==0){ BEEPS();
					   	   shi=shi+1;	
						   shis=shis+1;
						   if(shis>23){
						   	  shis=shi=0;
						   } 
						   sprintf(buf,"shi:%d ",(int)shis);//时分秒
			 			   hz_lcdDis(1,0,buf); //显示在第二行 
						   while(SYS_MD==0);
					   }
				  }
				  if(mds==5){
				  	   if(SYS_MD==0){ BEEPS();
					   	   fen=fen+1;	
						   fens=fens+1; 
						   if(fens>59){
						   	 fens=fen=0;
						   }
						   sprintf(buf,"fen:%d ",(int)fens);//时分秒
			 			   hz_lcdDis(0,0,buf); //显示在第二行 
						   while(SYS_MD==0);
					   }
				  }if(mds==6){
				  	   if(SYS_MD==0){	BEEPS();
					   	   miao=miao+1;	
						   miaos=miaos+1; 
						   if(miaos>59){
						   	 miaos=miao=0;
						   }
						   sprintf(buf,"miao:%d ",(int)miaos);//时分秒
			 			   hz_lcdDis(1,0,buf); //显示在第二行 
						   while(SYS_MD==0);
					   }
				  }
				  if(mds==7){
				  	   if(SYS_MD==0){	BEEPS();
					   	   gzmax=gzmax+1;	
						  
						   if(gzmax>80){
						   	 gzmax=10;
						   }
						   sprintf(buf,"gzmax:%d ",(int)gzmax);//时分秒
			 			   hz_lcdDis(0,0,buf); //显示在第二行 
						   while(SYS_MD==0);
					   }
				  }
				  if(mds==8){
				  	   if(SYS_MD==0){	BEEPS();
					   	  ;	
						   wenmax=wenmax+1; 
						   if(wenmax>45){
						   	 wenmax=10;
						   }
						   sprintf(buf,"wenmax:%d ",(int)wenmax);//时分秒
			 			   hz_lcdDis(1,0,buf); //显示在第二行 
						   while(SYS_MD==0);
					   }
				  }
				  if(mds==9){
				  	   if(SYS_MD==0){	BEEPS();
					   	   shimax=shimax+1;	 
						   if(shimax>80){
						   	 shimax=10;
						   }
						   sprintf(buf,"shimax:%d ",(int)shimax);//时分秒
			 			   hz_lcdDis(0,0,buf); //显示在第二行 
						   while(SYS_MD==0);
					   }
				  }
			}
		}
   }
 }

5. Display of related works

Practical projects based on Java development, Python development, PHP development, C# development and other related languages

Front-end practical projects developed based on Nodejs, Vue and other front-end technologies

Related works based on WeChat applet and Android APP application development

Development and application of embedded Internet of Things based on 51 microcontroller and other embedded devices

AI intelligent applications based on various algorithms

Various data management and recommendation systems based on big data

 

 

おすすめ

転載: blog.csdn.net/whirlwind526/article/details/133014648