B005 – 基于STC8的单片机智能路灯控制系统

任务详情

基于单片机的智能路灯控制系统

  1. 非节能模式下LED灯同时亮灭,凌晨0点——6点为节能模式,该模式下只亮LED灯
    中的一部分。当有声响时则开启全部LED灯,延迟1分钟后重新变为一半LED灯处于点亮的状态。
  2. 时间功能:夏季19: 00———23∶00期间路灯常亮,冬季18:00———23∶00期间路灯常亮。
  3. 非设置时间段,系统通过检测光线强度和声响,在黑暗时若有声响则启动路灯,路灯延
    迟1分钟后自动关闭。
  4. 使用光敏电阻检测路灯的故障情况,在路灯符合条件正常开启的情况下,若此时没有检
    测到光线则启动蜂鸣器报警,故障短信提醒(GSM模块),并设置紧急故障处理按钮。
  5. LCD屏幕用作公告屏,显示公益信息以及一些商业广告

效果

在这里插入图片描述
在这里插入图片描述

功能设计资料

在这里插入图片描述

源代码

/*******************************************************************************

* 文件名称:基于STC8的单片机智能路灯控制系统

* 实验目的:1.

* 2.

* 程序说明:完整程序Q:2772272579;@: itworkstation@hotmail.com

* 日期版本:基本设计如下,可定制。

*******************************************************************************/
#include"config.h"
void check_light(void);
void key_test(void);

sbit GMLight_gpio= P1^0;
sbit GM_gpio= P1^4;
sbit BEEP_gpio = P3^3;
sbit SY_gpio = P3^4;
sbit key01_gpio = P3^5;
void GPIO_config(void)
{
	P1M1 &= ~(1<<0);	//设置成准双向IO
	P1M0 &= ~(1<<0);

	P1M1 &= ~(1<<4);	//设置成准双向IO
	P1M0 &= ~(1<<4);

	P3M1 &= ~(1<<3);	//设置成推挽输出
	P3M0 |=  (1<<3);

	P3M1 &= ~(1<<4);	//设置成准双向IO
	P3M0 &= ~(1<<4);

	P3M1 &= ~(1<<5);	//设置成准双向IO
	P3M0 &= ~(1<<5);
}
/*************************************************************************
                               主函数
**************************************************************************/
bit flag_jieneng=0,flag_on=0;  //节能模式
bit flag_on_time=0;



uchar GuangGao=0; uint LCD_count01=0;
bit flag_distime=0;
void main (void)
{	
	int ret=0;	 //GSM信号提示
	uchar i=0;
	Proc_Init();

	GPIO_config();
	LED_Init();		//LED灯函数初始化
	LED_Control(LED_ALL,ON);
	Ds1302Init();

	UART3_Init();
	UART4_Init();
	BEEP_gpio=0;
	Delay_ms(1000);	
	BEEP_gpio=1;	
	LED_Control(LED_ALL,OFF);
	printf("CLR(%hd);DIR(3);SBC(%hd);FSIMG(2097152,0,0,376,240,1);\r\n",LCD_ColorStructure.LCD_BackColor,LCD_ColorStructure.LCD_SBCColor); 
	USART4_CheckBusy(); 	
	printf("CLR(%hd);DIR(3);SBC(%hd);FSIMG(2277632,0,0,376,240,0);\r\n",LCD_ColorStructure.LCD_BackColor,LCD_ColorStructure.LCD_SBCColor); 
	USART4_CheckBusy(); 
	printf("DCV32(124,8,'初始化界面',%hd);\r\n",LCD_ColorStructure.LCD_TextColor);
	USART4_CheckBusy();
	printf("DCV32(12,40,'制作人:***',%hd);\r\n",LCD_ColorStructure.LCD_TextColor); 
	USART4_CheckBusy(); 
	printf("DCV32(12,72,'制作单位:****',%hd);\r\n",LCD_ColorStructure.LCD_TextColor); 
	USART4_CheckBusy(); 
	Timer0_Init(20);
	printf("DCV32(12,200,'GSM:',%hd);\r\n",LCD_ColorStructure.LCD_TextColor); 
	USART4_CheckBusy(); 
	for(i = 0;i < STABLE_TIMES;i++)//等待GSM网络稳定
	{
		delay_20ms(1);
		printf("DCV32(108,200,'等待网络%bu  ',%hd);\r\n",i,LCD_ColorStructure.LCD_TextColor); 
		USART4_CheckBusy(); 
	}
	printf("DCV32(108,200,'检查配置  ',%hd);\r\n",LCD_ColorStructure.LCD_TextColor); 
	USART4_CheckBusy(); 
	ret = check_status();			 //初始化配置	  
	if(ret == 1)
	{
		printf("DCV32(108,200,'通信成功  ',%hd);\r\n",LCD_ColorStructure.LCD_TextColor); 
		USART4_CheckBusy(); 
		delay_ms(2000);
		ret = config_format();//配置
		if(ret == 1)
		{
			printf("DCV32(108,200,'配置成功  ',%hd);\r\n",2); 
			USART4_CheckBusy(); 
			delay_ms(2000);
		}
		else
		{
		    printf("DCV32(108,200,'配置失败  ',%hd);\r\n",1); 
		    USART4_CheckBusy(); 
			delay_ms(2000);
		}
	}
	else
	{
	    printf("DCV32(108,200,'通信失败  ',%hd);\r\n",1); 
		USART4_CheckBusy(); 
		delay_ms(2000);
	}
	CLR_Buf();//清空串口数组,准备接收 GSM信息	
	printf("DCV32(108,200,'结束配置  ',%hd);\r\n",LCD_ColorStructure.LCD_TextColor); 
	USART4_CheckBusy(); 
	while (1)       //主循环
	{
		key_test();
	   if(Flag_Time_Ms(200))
	   {
	   		LCD_count01++;
			if(LCD_count01>20)//切换时间
			{
				LCD_count01=0;
				GuangGao++;
				if(GuangGao>5)
				{
					GuangGao=0;
					flag_distime=0;
				}
				if(GuangGao==0)
				{
					printf("CLR(%hd);DIR(3);SBC(%hd);FSIMG(2097152,0,0,376,240,1);\r\n",LCD_ColorStructure.LCD_BackColor,LCD_ColorStructure.LCD_SBCColor); 
					USART4_CheckBusy(); 
				}
				else if(GuangGao==1)
				{
					printf("CLR(%hd);DIR(3);SBC(%hd);FSIMG(2458112,0,0,376,240,1);\r\n",LCD_ColorStructure.LCD_BackColor,LCD_ColorStructure.LCD_SBCColor); 
					USART4_CheckBusy(); 
				}
				else if(GuangGao==2)
				{
					printf("CLR(%hd);DIR(3);SBC(%hd);FSIMG(2638592,0,0,376,240,1);\r\n",LCD_ColorStructure.LCD_BackColor,LCD_ColorStructure.LCD_SBCColor); 
					USART4_CheckBusy(); 
				}
				else if(GuangGao==3)
				{
					printf("CLR(%hd);DIR(3);SBC(%hd);FSIMG(2819072,0,0,376,240,1);\r\n",LCD_ColorStructure.LCD_BackColor,LCD_ColorStructure.LCD_SBCColor); 
					USART4_CheckBusy(); 
				}
				else if(GuangGao==4)
				{
					printf("CLR(%hd);DIR(3);SBC(%hd);FSIMG(2999552,0,0,376,240,1);\r\n",LCD_ColorStructure.LCD_BackColor,LCD_ColorStructure.LCD_SBCColor); 
					USART4_CheckBusy(); 
				}
				else
				{	
					flag_distime=1;										
				}
			}
			Ds1302ReadTime();	
			if(flag_distime)   	
			{
				LCD_Display();
			}	
			if(TIME[2]<6)
			{
				 flag_jieneng=1;
			}
			else
			{
				flag_jieneng=0;
			}
			if(TIME[4]<8)  //前八个月
			{
				if(TIME[2]>=19 && TIME[2]< 23)
				{
					flag_on_time=1;
				} 
				else
				{
					flag_on_time=0;
				}
			}
			else	   //后四个月
			{
				if(TIME[2]>=18 && TIME[2]< 23)
				{
					flag_on_time=1;
				} 
				else
				{
					flag_on_time=0;
				}
			}			
	   }
	    if(flag_jieneng && SY_gpio==0)	//夜间节能模式识别到声音
		{
			flag_shengyin=1;
		}	
		if(flag_jieneng)	 //节能模式
		{
			flag_GMSY=0;
			if(flag_shengyin)
			{
				LED_Control(LED_ALL,ON);
			}
			else
			{
				LED_Control(1,ON);
				LED_Control(3,ON);
				LED_Control(5,ON);
				LED_Control(2,OFF);
				LED_Control(4,OFF);
			}
			check_light();
		}
		else if(flag_on_time)  //夏季,冬季全亮时间
		{
			flag_GMSY=0;
			LED_Control(LED_ALL,ON);
			check_light();
		}
	   else			//其他时间段
	   {
	   	   if(GM_gpio==1 && SY_gpio==0)//亮度较暗为高电平	  有声响为低电平
		   {
		   		flag_GMSY=1;
		   }
		   else
		   {
		   		if(flag_GMSY==0)
				{
					BEEP_gpio=1;
		   			LED_Control(LED_ALL,OFF);
				}
		   }
		   if(flag_GMSY==1)
		   {
		   		LED_Control(LED_ALL,ON);
				check_light();
		   }	
	   	   else
		   {
		   		BEEP_gpio=1;
		   		LED_Control(LED_ALL,OFF);
		   }
	   }	   
	}
}
bit flag_senderro=0;
void check_light(void)
{
	if(GMLight_gpio==0)	//检查该亮灯时有没有亮
	{
		BEEP_gpio=1;
		flag_senderro=0;	
	}
	else	//没有的话,报警
	{
	    BEEP_gpio=0;
		if(flag_senderro==0)
		{
			flag_senderro=1;
			//发送一次报警信息
//			send_text_message_set("There seems to be something wrong with the street lamp. Please check it in time!!!");
		}
	}
}
void key_test(void)
{
	if(key01_gpio==0)
	{
		Delay_ms(10);
		if(key01_gpio==0)
		{
			if(BEEP_gpio==0) //如果本来就处于报警模式
			{
				BEEP_gpio=1;
			}
			else	 //否则进行测试模式
			{
				do{
					LED_Control(LED_ALL,OFF);
					check_light();
					BEEP_gpio=0;
					send_text_message_set("There seems to be something wrong with the street lamp. Please check it in time!!!");
				}while(key01_gpio==0);
				BEEP_gpio=1;
			}
	
//			send_text_message_set("There seems to be something wrong with the street lamp. Please check it in time!!!");	
//			while(key01_gpio==0);	
		}
	}
}
/*******************************************************************/

  • 3
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值