國旗自動升降系統(tǒng)設(shè)計論文_第1頁
國旗自動升降系統(tǒng)設(shè)計論文_第2頁
國旗自動升降系統(tǒng)設(shè)計論文_第3頁
國旗自動升降系統(tǒng)設(shè)計論文_第4頁
國旗自動升降系統(tǒng)設(shè)計論文_第5頁
已閱讀5頁,還剩30頁未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

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

文檔簡介

第Ⅰ頁共Ⅰ頁[請輸入學(xué)校名稱[請輸入專業(yè)]基于單片機(jī)國旗自動升降系姓名:[請輸入姓名]學(xué)號:[請輸入學(xué)號]指導(dǎo)教師:[請輸入指導(dǎo)教師] Time\@"yyyy年M月d日"2020年6月9日

目錄1引言 .PCB源程序#include<reg52.h> //調(diào)用單片機(jī)頭文件#defineucharunsignedchar//無符路字符型宏定義 變量范圍0~255#defineuintunsignedint //無符路整型宏定義 變量范圍0~65535#include"eeprom52.h"#include"LCD1602.h"http://sbitVRST=P3^7;//sbitVBUSY=P3^6; sbitVSDA=P3^5;sbitVCS=P3^6;sbitVSCL=P3^7;sbitkey_1=P1^0;sbitkey_2=P1^1;sbitkey_3=P1^2;sbitkey_4=P1^3;sbitkey_5=P1^4;sbitkey_6=P1^5;sbitled_1=P1^6;sbitled_2=P1^7;sbitled_3=P3^0;sbitled_4=P3^1;ucharcodezz[]={0x01,0x03,0x02,0x06,0x04,0x0c,0x08,0x09};//????ucharcodefz[]={0x09,0x08,0x0c,0x04,0x06,0x02,0x03,0x01};//????uintUP_dat=0,Below_dat=0,Current_dat=0;ucharCurrent_Height=0,ms,sec,circulation,Dir_dat,speed_dat,dat_A;ucharsys_state,state;bitOpen_flag,EEPROM_flag;ucharirbyte[4];ucharirtime,irflag,bitnum,irdateok;ucharirdate[33];/***********************小延時函數(shù)**************************/voiddelay_us(unsignedintus){ while(us--) { _nop_(); }}/*********************************************************************名稱:delay_1ms()*功能:延時1ms函數(shù)*輸入:q*輸出:無***********************************************************************/voiddelay_1ms(uintq){ uinti,j; for(i=0;i<q;i++) for(j=0;j<115;j++);} /************延時函數(shù)*****************/voiddelay_uint(uintz){while(z--);}voidqing(void) // ????{uinti; for(i=0;i<33;i++) { irdate[i]=0; }}voiddeal_with(void) //??????{ uchari,j,k,temp; k=1; for(j=0;j<4;j++) { for(i=0;i<8;i++) { temp=temp>>1; if(irdate[k]>7) { temp=temp|0x80; } k++; } irbyte[j]=temp; }}/***********************三線發(fā)碼子程序************************/voidSend_threelines(unsignedcharaddr){unsignedchari;// VRST=0;// delay_1ms(5);// VRST=1;// delay_1ms(20);/*復(fù)位拉高20ms*/ VCS=0; delay_1ms(5);/*片選拉低5ms*/for(i=0;i<8;i++) { VSCL=0; if(addr&0x01) { VSDA=1; } else VSDA=0; addr>>=1; delay_us(150);/*150us*/ VSCL=1; delay_us(150);/*150us*/ } VCS=1; delay_1ms(30);// if(dat==1)// while(VBUSY==0); //忙等待}voidshow_init(void){ LCD1602_write(0,0xC0); LCD1602_writebyte("Height:11.0cm"); LCD1602_write(0,0x80); LCD1602_writebyte("C_Height:"); LCD1602_write(1,0x30+Current_Height/100%10); LCD1602_write(1,0x30+Current_Height/10%10); LCD1602_writebyte("."); LCD1602_write(1,0x30+Current_Height%10); LCD1602_writebyte("cm"); }voidshow(void){ LCD1602_write(0,0x89); LCD1602_write(1,0x30+Current_Height/100%10); LCD1602_write(1,0x30+Current_Height/10%10); LCD1602_writebyte("."); LCD1602_write(1,0x30+Current_Height%10);}//sys_state=0為旗低的狀態(tài)//sys_state=1為旗頂?shù)臓顟B(tài)//sys_state=2為半旗的狀態(tài)//sys_state=3為正在運(yùn)行的一個狀態(tài)//sys_state=4為停止的一個狀態(tài)voidkey_code(void){ if(irdateok==1) //?????? { irdateok=0; deal_with(); } if((!key_1||irbyte[2]==0x44)&&sys_state==0) { delay_uint(1000); if(!key_1||irbyte[2]==0x44) { while(!key_1||irbyte[2]==0x44) { qing(); deal_with(); } state=1; sys_state=3; led_1=0; } } if((!key_2||irbyte[2]==0x40)&&sys_state==1) { delay_uint(1000); if(!key_2||irbyte[2]==0x40) { while(!key_2||irbyte[2]==0x40) { qing(); deal_with(); } led_2=0; state=3; sys_state=3; } } if((!key_3||irbyte[2]==0x07)&&sys_state==0) { delay_uint(1000); if(!key_3||irbyte[2]==0x07) { while(!key_3||irbyte[2]==0x07) { qing(); deal_with(); } led_3=0; state=5; sys_state=3; } } if((!key_4||irbyte[2]==0x15)&&sys_state==2) { delay_uint(1000); if(!key_4||irbyte[2]==0x15) { while(!key_4||irbyte[2]==0x15) { qing(); deal_with(); } state=8; led_4=0; sys_state=3; } } if(!key_5||irbyte[2]==0x43) { delay_uint(1000); if(!key_5||irbyte[2]==0x43) { while(!key_5||irbyte[2]==0x43) { qing(); deal_with(); } state=11; sys_state=3; led_1=led_2=led_3=led_4=1; } } if(!key_6||irbyte[2]==0x09) { delay_uint(1000); if(!key_6||irbyte[2]==0x09) { while(!key_6||irbyte[2]==0x09) { qing(); deal_with(); } Send_threelines(1); state=0; sys_state=4; Below_dat=0; UP_dat=0; led_1=led_2=led_3=led_4=1; } }}//sys_state=0為旗低的狀態(tài)//sys_state=1為旗頂?shù)臓顟B(tài)//sys_state=2為半旗的狀態(tài)//sys_state=3為正在運(yùn)行的一個狀態(tài)//uintUP_dat=0,Below_dat=0;voidControl_code(void){ switch(state) { case0: P2&=0xf0; P2|=0x00; break; case1: Send_threelines(0); UP_dat=8800; state=2; break; case2: if(UP_dat==0) { state=0; sys_state=1; led_1=1; Current_dat=8800; } break; case3: Below_dat=8800; state=4; break; case4: if(Below_dat==0) { state=0; sys_state=0; led_2=1; Current_dat=0; } break; case5: Send_threelines(0); UP_dat=8800; state=6; break; case6: if(UP_dat==0) { Below_dat=2933; state=7; } break; case7: if(Below_dat==0) { state=0; sys_state=2; led_3=1; Current_dat=8800-2933; } break; case8: UP_dat=2933; state=9; break; case9: if(UP_dat==0) { Below_dat=8800; state=10; } break; case10: if(Below_dat==0) { state=0; sys_state=0; led_4=1; Current_dat=0; } break; case11: Send_threelines(1); UP_dat=0; Below_dat=Current_dat; state=12; break; case12: if(Below_dat==0) { state=0; sys_state=0; } break; } Current_Height=Current_dat/80; if(dat_A!=Current_Height) { dat_A=Current_Height; SectorErase(0x2000); byte_write(0x2000,Current_Height); }}voidTime_init(void){ TMOD=0x21; //?????1?8??????? TH1=0x00; //???????? TL1=0x00; //?????? TH0=0x3c; //???????? TL0=0xb0; //?????? ET1=1; //?????1?? TR1=1; //?????1 ET0=0; //?????1?? TR0=0; //?????1}voidmain(void){ Time_init(); EA=1; EX0=1; IT0=1; delay_uint(20000); Current_Height=byte_read(0x2000); if(Current_Height>110)Current_Height=0; if(Current_Height==0)sys_state=0; elseif(Current_Height==110)sys_state=1; elseif(Current_Height>70&&Current_dat<80)sys_state=2; elsesys_state=4; Current_dat=Current_Height*80; LCD1602_cls(); show_init(); while(1) { show(); key_code(); Control_code(); }}voidTime_1()interrupt1{ TL0=0x3c; //?????? TH0=0xb0; //???????? ms++; if(ms>19) { ms=0; sec++; if(sec>43) { // Open_flag=1; } }}voidTime_2()interrupt3{ irtime++; speed_dat++;

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(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)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論