B005 – 基于STC8的单片机智能路灯控制系统
生活随笔
收集整理的這篇文章主要介紹了
B005 – 基于STC8的单片机智能路灯控制系统
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
任務詳情
基于單片機的智能路燈控制系統
中的一部分。當有聲響時則開啟全部LED燈,延遲1分鐘后重新變為一半LED燈處于點亮的狀態。
遲1分鐘后自動關閉。
測到光線則啟動蜂鳴器報警,故障短信提醒(GSM模塊),并設置緊急故障處理按鈕。
效果
功能設計資料
源代碼
/******************************************************************************** 文件名稱:基于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); //設置成準雙向IOP1M0 &= ~(1<<0);P1M1 &= ~(1<<4); //設置成準雙向IOP1M0 &= ~(1<<4);P3M1 &= ~(1<<3); //設置成推挽輸出P3M0 |= (1<<3);P3M1 &= ~(1<<4); //設置成準雙向IOP3M0 &= ~(1<<4);P3M1 &= ~(1<<5); //設置成準雙向IOP3M0 &= ~(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); }} } /*******************************************************************/總結
以上是生活随笔為你收集整理的B005 – 基于STC8的单片机智能路灯控制系统的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于Syntec CNC系统的二次开发介
- 下一篇: java信息管理系统总结_java实现科