模擬路燈控制系統(tǒng)的設(shè)計(jì)_第1頁
模擬路燈控制系統(tǒng)的設(shè)計(jì)_第2頁
模擬路燈控制系統(tǒng)的設(shè)計(jì)_第3頁
模擬路燈控制系統(tǒng)的設(shè)計(jì)_第4頁
模擬路燈控制系統(tǒng)的設(shè)計(jì)_第5頁
已閱讀5頁,還剩56頁未讀 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡介

附錄附錄A元件清單表2元件清單元件名稱元件參數(shù)數(shù)量電解質(zhì)電容25v470μF2電容0.1μF1電容33PF4開關(guān)六角開關(guān)2變壓器12V輸出20w/DB-20W1穩(wěn)壓芯片LM7805TO-2201整流橋2W102A/1000V1LED發(fā)光二極管BT1015排阻10K4晶振12MHz1晶振32.768KHz1按鍵6*6*5mm立式4腳輕觸開關(guān)9單片機(jī)AT89S521液晶LCD16021時(shí)鐘芯片DS13021電阻200Ω1電阻1K3電阻470Ω7可充電紐扣電池3.6V60mANI-MH1電阻20K3電阻510Ω3電阻200K3 電壓比較器LM3246三極管S90122光敏電阻GL35473電阻4.7K74光電傳感器ST1783有源蜂鳴器HYT-12051附錄B程序清單/****************************************************************課題名稱:模擬路燈控制系統(tǒng)作者:周海湖指導(dǎo)老師:王誠梅完成時(shí)間:2016年5月功能:系統(tǒng)上電或按鍵復(fù)位后能自動(dòng)提示界面,進(jìn)入準(zhǔn)備工作狀態(tài)。系統(tǒng)根據(jù)環(huán)境明暗自動(dòng)亮滅路燈,當(dāng)路燈出現(xiàn)故障,能發(fā)出聲光報(bào)警,能根據(jù)交通環(huán)境自動(dòng)亮滅路燈,能設(shè)定路燈亮滅的時(shí)間,可以獨(dú)立控制每個(gè)路燈。硬件說明:單片機(jī)AT89S52,晶振12MHZ,輸入設(shè)備-接在P1口的8位獨(dú)立式鍵盤,輸出設(shè)備-LCD12864液晶屏,P2口接LCD12864D0至D7,RS、RW、EN分別接到單片機(jī)的P3.0、P3.1、P3.2。時(shí)鐘模塊-DS1302模塊的CLK、IO、RST分別接到單片機(jī)的P3.4、P3.3、P3.5。****************************************************************/#include<reg52.h>#include"intrins.h"#defineLCD_DataP2sbitP00=P0^0;sbitP01=P0^1;sbitP02=P0^2;sbitP03=P0^3;sbitP04=P0^4;sbitP05=P0^5;sbitP07=P0^7;sbitP36=P3^6;sbitP37=P3^7;sbitDS1302_CLK=P3^4;sbitDS1302_IO=P3^3;sbitDS1302_RST=P3^5;sbitLCD_RS=P3^0;sbitLCD_RW=P3^1;sbitLCD_E=P3^2;ucharsec,min,hour,day,month,year;uchartemp0 ;ucharcount,count1,Hour1,Minite1,v,SB,SC,m,n;charLed1onH,Led1onM,Led2onH,Led2onM,Led1offH,Led1offM,Led2offH,Led2offM;/**************延時(shí)*********************/voiddelay(unsignedinta)//延時(shí)1MS/次{unsignedchari;while(--a){for(i=0;i<125;i++);}}/*************************************/voiddelays(){;;}/***************1302時(shí)鐘程序****************/voidWriteDs1302Byte(unsignedchartemp){unsignedchari;for(i=8;i>0;i--) {DS1302_CLK=0;DS1302_IO=temp&0x01;delays();DS1302_CLK=1;temp>>=1;delays();}}/***********************************/voidWriteDs1302(unsignedcharaddress,unsignedchardat){DS1302_RST=0;DS1302_CLK=0;DS1302_RST=1;delay(1);WriteDs1302Byte(address);WriteDs1302Byte(dat);DS1302_CLK=1;DS1302_RST=0;}/***********************************/unsignedcharread_byte(){unsignedchari;for(i=8;i>0;i--){if(DS1302_IO)temp0=temp0|0x80;DS1302_CLK=1;delays();DS1302_CLK=0;temp0=temp0>>1;delays();}returntemp0;}/**************************************************/unsignedcharReadDs1302(unsignedcharaddress){unsignedchartemp;DS1302_RST=0;DS1302_CLK=0;DS1302_RST=1;WriteDs1302Byte(address);temp=read_byte();DS1302_RST=0;DS1302_CLK=1;returntemp;}/*********************1302初始化***********************/voidInitDS1302(){{WriteDs1302(0x8e,0x00);delay(5);WriteDs1302(0x8c,0x16);//寫入年份16年delay(5);WriteDs1302(0x8a,0x04);//寫入星期4delay(5);WriteDs1302(0x88,0x05);//定入月分5月delay(5);WriteDs1302(0x86,0x12);//寫入日期12日delay(5);WriteDs1302(0x84,0x02);//寫入小時(shí)2點(diǎn)delay(5);WriteDs1302(0x82,0x00);//寫入秒00分delay(5);WriteDs1302(0x80,0x00);delay(5);WriteDs1302(0x8e,0x80);//控制命令,WP為1,禁止寫操作}}/***************檢查忙否*****************/voidCheckstates(){unsignedchardat;LCD_RS=0;LCD_RW=1;DO{LCD_E=1;//下降沿_nop_();//保持一定間隔 _nop_();dat=LCD_Data;_nop_(); _nop_();LCD_E=0;}while((dat&0x80)==1);}/**********LCD寫數(shù)據(jù)*******************************/voidWriteDataLCD(unsignedchardat){Checkstates();LCD_RS=1;LCD_RW=0;LCD_Data=dat;LCD_E=1;delay(2);LCD_E=0;}/**********LCD寫地址*******************************/voidWriteCommandLCD(unsignedcharudat){Checkstates();LCD_RS=0;LCD_RW=0;LCD_Data=udat;LCD_E=1;delay(2);LCD_E=0;}/*************LCD初始化******************************/voidLCDInit(void){WriteCommandLCD(0x38);delay(2);WriteCommandLCD(0x38);delay(2);WriteCommandLCD(0x01);delay(2); WriteCommandLCD(0x06);delay(2); WriteCommandLCD(0x0C);delay(2);}/*************LCD清屏指令**********************/voidLCDClear(void){WriteCommandLCD(0x01);delay(2);}/**********發(fā)送內(nèi)容*********************************/voidLCDSendWord(unsignedchar*p){while(*p>0){WriteDataLCD(*p);p++;}}/*********發(fā)送地址*********************************/voidLCDTestWord(biti,unsignedcharword){if(i==0){WriteCommandLCD(word);}else{WriteDataLCD(word);}}/***************LCD顯示年************/voidDisplayYear(void){year=ReadDs1302(0x8d);LCDTestWord(0,0x80);LCDSendWord("20");LCDTestWord(1,(year/16)+0x30);LCDTestWord(1,year%16+0x30);LCDTestWord(1,'/');}/***************LCD顯示月*************************/voidDisplayMonth(void){month=ReadDs1302(0x89);LCDTestWord(1,(month/16)+0x30);LCDTestWord(1,month%16+0x30);LCDTestWord(1,'/');}/****************LCD顯示日**************************/voidDisplayDay(void){day=ReadDs1302(0x87);LCDTestWord(1,(day/16)+0x30);LCDTestWord(1,day%16+0x30);}/**********LCD顯示時(shí)*********************************/voidDisplayHour(void){hour=ReadDs1302(0x85);LCDTestWord(0,0xc0);LCDTestWord(1,(hour/16)+0x30);LCDTestWord(1,hour%16+0x30);LCDTestWord(1,':');}/**********LCD顯示分**********************************/voidDisplayMin(void){min=ReadDs1302(0x83);LCDTestWord(1,(min/16)+0x30);LCDTestWord(1,min%16+0x30);LCDTestWord(1,':');}/**********LCD顯示秒**********************************/voidDisplaySec(void){sec=ReadDs1302(0x81);LCDTestWord(1,(sec/16)+0x30);LCDTestWord(1,sec%16+0x30);}/************************************************************/voidUpDate1(void){DisplayHour();DisplayMin();DisplaySec();}/************************************************************/voidUpDate2(void){DisplayYear();DisplayMonth();DisplayDay();}/*************鍵掃描程序**************/ucharkeys(void){uchartmp; if((P1&0xff)!=0xff){delay(10);if((P1&0xff)!=0xff){ tmp=(P1&0xff); do{}while((P1&0xff)!=0xff); tmp=~tmp; return(tmp); }} return(0);}voidbaojing(void){if(P01==0){ LCDTestWord(0,0x80); LCDSendWord("LED1Broken"); P07=0; } else { LCDTestWord(0,0x80); LCDSendWord("LED1OK");}if(P02==0){ LCDTestWord(0,0xc0); LCDSendWord("LED2Broken"); P07=0; } else { LCDTestWord(0,0xc0); LCDSendWord("LED2OK"); } if(P01==1&&P02==1) P07=1;} voidhuanjing(void){ while(v!=4) { if(P00==1) { P36=1; P37=1; } if(P00==0) { P36=0; P37=0; } baojing(); v=keys(); }} voidjiaotong(void){while(v!=4){SC=0;SB=0; if(P03==0){P36=0;P37=1;while(1){if(P04==0){ P36=1; P37=0;while(1){ if(P05==0) { P36=1; P37=1;SC=1; SB=1;while(P05==0); }if(SC==1)break;}}if(SB==1)break;}}if(P05==0){P36=1;P37=0;while(1){if(P04==0){P36=0; P37=1;while(1){if(P03==0){ P36=1; P37=1;SC=1; SB=1; while(P03==0); }if(SC==1)break;} }if(SB==1)break;}}v=keys();} }voidDisplayrealtime(void){while(v!=4){ UpDate2();UpDate1(); v=keys(); }}voidDisplay1(void){LCDTestWord(0,0x80);LCDSendWord("LED1ON");LCDTestWord(1,(Led1onH/10)+0x30);LCDTestWord(1,(Led1onH%10)+0x30);LCDTestWord(1,':');LCDTestWord(1,(Led1onM/10)+0x30);LCDTestWord(1,(Led1onM%10)+0x30);LCDTestWord(0,0xc0);LCDSendWord("LED1OFF");LCDTestWord(1,(Led1offH/10)+0x30);LCDTestWord(1,(Led1offH%10)+0x30);LCDTestWord(1,':');LCDTestWord(1,(Led1offM/10)+0x30);LCDTestWord(1,(Led1offM%10)+0x30);}voidDisplay2(void){LCDTestWord(0,0x80);LCDSendWord("LED2ON");LCDTestWord(1,(Led2onH/10)+0x30);LCDTestWord(1,(Led2onH%10)+0x30);LCDTestWord(1,':');LCDTestWord(1,(Led2onM/10)+0x30);LCDTestWord(1,(Led2onM%10)+0x30);LCDTestWord(0,0xc0);LCDSendWord("LED2OFF");LCDTestWord(1,(Led2offH/10)+0x30);LCDTestWord(1,(Led2offH%10)+0x30);LCDTestWord(1,':');LCDTestWord(1,(Led2offM/10)+0x30);LCDTestWord(1,(Led2offM%10)+0x30);}voidsettime(void){LCDClear();LCDTestWord(0,0x80);LCDSendWord("PleaseSetTime");delay(2000);LCDClear();v=keys();while(v!=4){ switch(v) { case0:UpDate2(); UpDate1(); v=keys(); break; case2: LCDClear(); LCDTestWord(0,0x80); LCDSendWord("SetSucces"); delay(1000); LCDClear(); while(v==0|v==2) {UpDate2(); UpDate1(); Hour1=hour/16*10+hour%16;Minite1=min/16*10+min%16; if(Hour1==Led1onH&&Minite1==Led1onM) P36=0; if(Hour1==Led2onH&&Minite1==Led2onM) P37=0; if(Hour1==Led1offH&&Minite1==Led1offM) P36=1; if(Hour1==Led2offH&&Minite1==Led2offM) P37=1; v=keys(); } break; case8:LCDClear(); while(v==0|v==8|v==32|v==64|v==128) { Display1(); v=keys(); switch(v) { case32:count1++; if(count1==5) count1=1; break; case64:if(count1>0&&count1<5) { if(count1==1) { Led1onH++; if(Led1onH==24) Led1onH=0; } if(count1==2) { Led1onM++; if(Led1onM==60) Led1onM=0; } if(count1==3) { Led1offH++; if(Led1offH==24) Led1offH=0; } if(count1==4) { Led1offM++; if(Led1offM==60) Led1offM=0; } } break;case128: if(count1>0&&count1<5) { if(count1==1) { Led1onH--; if(Led1onH<0) Led1onH=23; } if(count1==2) { Led1onM--; if(Led1onM<0) Led1onM=59; } if(count1==3) { Led1offH--; if(Led1offH<0)Led1offH=23;}if(count1==4) { Led1offM--; if(Led1offM<0) Led1offM=59; } } break; } } break;case16:LCDClear(); while(v==0|v==16|v==32|v==64|v==128) { Display2(); v=keys(); switch(v) { case32:count1++; if(count1==5) count1=1; break; case64:if(count1>0&&count1<5) { if(count1==1) { Led2onH++; if(Led2onH==24) Led2onH=0; } if(count1==2) { Led2onM++; if(Led2onM==60) Led2onM=0; } if(count1==3) { Led2offH++; if(Led2offH==24) Led2offH=0; } if(count1==4) { Led2offM++; if(Led2offM==60) Led2offM=0; } } break;case128:if(count1>0&&count1<5) { if(count1==1) { Led2onH--; if(Led2onH<0) ed2onH=23; } if(count1==2) { Led2onM--; if(Led2onM<0) Led2onM=59; } if(count1==3) { Led2offH--; if(Led2offH<0) Led2offH=23; } if(count1==4) { Led2offM--; if(Led2offM<0) Led2offM=59; } } break; } }break; }/*****************主函數(shù)程序*************************/voidmain(void){LCDInit();LCDClear();InitDS1302();LCDTestWord(0,0x80);LCDSendWord("Enteringsystem");LCDTestWord(0,0xc0);LCDSendWord("PleaseWaiting");delay(2000);LCDClear();LCDTestWord(0,0x80);LCDSendWord("SelectMenu");while(1) { v=keys(); switch(v) { case1:count++; if(count==5) count=1; LCDTestWord(0,0x80); if(count==1) {LCDClear(); LCDSendWord("Realtime"); } if(count==2){ LCDClear(); LCDSendWord("Environment"); } if(count==3) {LCDClear(); LCDSendWord("Traffic"); } if(count==4) {LCDClear(); LCDSendWord("SetTime"); } break

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論