当前位置:网站首页>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);
}
}
}
/*******************************************************************/
边栏推荐
猜你喜欢
Live tonight!
TCP百万并发服务器优化调参
SRM供应商管理系统如何助力口腔护理企业实现采购战略的转型升级
05 doris 集群搭建
zabbix部署和简单使用
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!.
05 Doris cluster construction
Good guy, the company server just crashed!
史上最全的Redis基础+进阶项目实战总结笔记
TCP million concurrent server optimization parameters
随机推荐
MySQL locking case analysis
年化收益高的理财产品
Complete knapsack problem to find the number of combinations and permutations
百度网盘下载速度提升100倍
Ali's official Redis development specification
关于Mysql服务无法启动的问题
SRM供应商管理系统如何助力口腔护理企业实现采购战略的转型升级
GTK修改pixmap像素,提取pixmap像素RGB值
2022年深圳市促进大健康产业集群高质量发展的若干措施
Description of common operations and help projects about DevExpress in C#
完美指南|如何使用 ODBC 进行无代理 Oracle 数据库监控?
SQL窗口函数
C # Excel helper classes
云商店携手快报税,解锁财务服务新体验!
MySQL's maximum recommended number of rows is 2000w, is it reliable?
【二叉树】奇偶树
快速抽取resnet_v2_152中间的特征层
成为优秀架构师必备技能:怎样才能画出让所有人赞不绝口的系统架构图?秘诀是什么?快来打开这篇文章看看吧!...
GridControl helper class for DevExpress
个人日记