当前位置:网站首页>B005 – 基于STC8的单片机智能路灯控制系统
B005 – 基于STC8的单片机智能路灯控制系统
2022-08-01 17:33:00 【小小工程员】
任务详情
基于单片机的智能路灯控制系统
- 非节能模式下LED灯同时亮灭,凌晨0点——6点为节能模式,该模式下只亮LED灯
中的一部分。当有声响时则开启全部LED灯,延迟1分钟后重新变为一半LED灯处于点亮的状态。 - 时间功能:夏季19: 00———23∶00期间路灯常亮,冬季18:00———23∶00期间路灯常亮。
- 非设置时间段,系统通过检测光线强度和声响,在黑暗时若有声响则启动路灯,路灯延
迟1分钟后自动关闭。 - 使用光敏电阻检测路灯的故障情况,在路灯符合条件正常开启的情况下,若此时没有检
测到光线则启动蜂鸣器报警,故障短信提醒(GSM模块),并设置紧急故障处理按钮。 - LCD屏幕用作公告屏,显示公益信息以及一些商业广告
效果


功能设计资料

源代码
/******************************************************************************* * 文件名称:基于STC8的单片机智能路灯控制系统 * 实验目的:1. * 2. * 程序说明:完整程序Q:2772272579;@: [email protected] * 日期版本:基本设计如下,可定制。 *******************************************************************************/
#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);
}
}
}
/*******************************************************************/
边栏推荐
猜你喜欢

Ali's official Redis development specification

My new book has sold 10,000 copies!

How can become a good architect necessary skills: painting for all the people praise the system architecture diagram?What is the secret?Quick to open this article and have a look!.

C#中关于DevExpress的常用操作和帮助类项目工程内容说明

The site is not found after the website is filed. You have not bound this domain name or IP to the corresponding site! The configuration file does not take effect!

2022年MySQL最新面试题

The anxiety of the post-90s was cured by the vegetable market

Vulnhub target drone: HARRYPOTTER_ NAGINI

统信软件、龙芯中科等四家企业共同发布《数字办公安全创新方案》

史上最全的Redis基础+进阶项目实战总结笔记
随机推荐
金仓数据库 OCCI迁移指南(3. KingbaseES的OCCI特性支持)
成为优秀架构师必备技能:怎样才能画出让所有人赞不绝口的系统架构图?秘诀是什么?快来打开这篇文章看看吧!...
ROS2系列知识(7):用rqt_console查看日志logs
Sftp中文件名乱码
RecSys'22|CARCA: Cross-Attention-Aware Context and Attribute Recommendations
酷逼了 Pathetic Dog 第 304 场周赛
访问域名直接访问wordpress
主流小程序框架性能分析
广汽埃安“弹匣电池”,四大核心技术,出行安全保障
金仓数据库KingbaseES安全指南--6.4. RADIUS身份验证
史上最全的Redis基础+进阶项目实战总结笔记
C#的FTP帮助类
极化微波成像概述
SQL窗口函数
小贝拉机器人是朋友_普渡科技召开新品发布会,新一代送餐机器人“贝拉”温暖登场...
Unity ui点击事件只响应最上层ui的方式
百度网盘下载速度提升100倍
存储日报-数据湖架构权威指南(使用 Iceberg 和 MinIO)
关于Mysql服务无法启动的问题
好家伙,公司服务器直接热崩掉了!