![交通燈十字路口控制器程序(共35頁)_第1頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/14/c2c294e9-310a-4be4-90ba-0d5e1c30b711/c2c294e9-310a-4be4-90ba-0d5e1c30b7111.gif)
![交通燈十字路口控制器程序(共35頁)_第2頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/14/c2c294e9-310a-4be4-90ba-0d5e1c30b711/c2c294e9-310a-4be4-90ba-0d5e1c30b7112.gif)
![交通燈十字路口控制器程序(共35頁)_第3頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/14/c2c294e9-310a-4be4-90ba-0d5e1c30b711/c2c294e9-310a-4be4-90ba-0d5e1c30b7113.gif)
![交通燈十字路口控制器程序(共35頁)_第4頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/14/c2c294e9-310a-4be4-90ba-0d5e1c30b711/c2c294e9-310a-4be4-90ba-0d5e1c30b7114.gif)
![交通燈十字路口控制器程序(共35頁)_第5頁](http://file3.renrendoc.com/fileroot_temp3/2022-1/14/c2c294e9-310a-4be4-90ba-0d5e1c30b711/c2c294e9-310a-4be4-90ba-0d5e1c30b7115.gif)
版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上#include<reg52.h>#define uchar unsigned char#define uint unsigned intuchar code table=0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x40;/*digit display port*sbit led_w1=P11;sbit led_w2=P10;sbit led_w3=P13;sbit led_w4=P12;/*define led port *sbit R1=P24; /east and west red leds
2、bit Y1=P23; /east and west yellow ledsbit G1=P22; /east and west green ledsbit R2=P25; /south and north red ledsbit Y2=P26; /south and north yellow ledsbit G2=P27; /south and north green led/*define key*sbit k0=P30; /emergencysbit k1=P31; /east and west passsbit k2=P32; /south and north passsbit k3=
3、P33; /start and subtract 1sbit k4=P34; /pause and add 1sbit k5=P35; /set time/*define variable*bit flag,flag_t;uchar dx_time,nb_time;uchar cnt,pass_time,cnt1,y_time;uchar k0num,k1num,k2num,k3num,k4num,k5num;/*define key*void delay(uint i)uint x,y;for(x=i;x>0;x-)for(y=110;y>0;y-); void timer0_i
4、nit()TMOD=0x11;TH0=(65536-50000)/256;TL0=(65536-50000)%256;TH1=(65536-50000)/256;TL1=(65536-50000)%256;EA=1;ET0=1;ET1=1;void led_display(uchar dx,nb)uchar dx1,dx2,nb1,nb2;dx2=dx/10;dx1=dx%10;nb2=nb/10;nb1=nb%10;if(dx>99)led_w1=1;led_w2=1;elseled_w1=0;P0=tabledx1;delay(5);led_w1=1;if(dx<10&
5、&dx>0) led_w2=1;elseled_w2=0;P0=tabledx2;delay(5);led_w2=1;if(nb>99)led_w3=1;led_w4=1;elseled_w3=0;P0=tablenb1;delay(5);led_w3=3;if(nb<10&&nb>0) led_w4=1;elseled_w4=0;P0=tablenb2;delay(5);led_w4=4;/*light work*void circle_led()if(!flag)if(pass_time>5)led_display(pass_time-
6、5,pass_time);R1=1;Y1=1;G1=0;/east and west passR2=0;Y2=1;G2=1;/south and north stopif(pass_time<=5&&pass_time>0)if(cnt>=10) led_display(pass_time,pass_time);else led_display(100,pass_time);R1=1;G1=1; /east and west yellow led flashif(cnt>=10)Y1=0;else Y1=1;R2=0;Y2=1;G2=1;if(pass_
7、time=0)pass_time=nb_time;flag=1;elseif(pass_time>5)led_display(pass_time,pass_time-5);R1=0;Y1=1;G1=1;/east and west stopR2=1;Y2=1;G2=0;/south and north passif(pass_time<=5&&pass_time>0)if(cnt>=10) led_display(pass_time,pass_time);else led_display(pass_time,100);R1=0;Y1=1;G1=1;R2=
8、1;G2=1; /south and north yellow led flashif(cnt>=10)Y2=0;else Y2=1;if(pass_time=0)pass_time=dx_time;flag=0;void emergency() /east and west,south and north stopled_display(0,0);R1=0;Y1=1;G1=1;R2=0;Y2=1;G2=1;void dx_pass() /east and west pass,south and north stopled_display(100,100);if(y_time<=5
9、&&y_time>0)TR1=1;R1=0;Y1=1;G1=1;R2=1;G2=1; /south and north yellow led flashif(cnt1>=10)Y2=0;else Y2=1;if(y_time=0)TR1=0;R1=1;Y1=1;G1=0;R2=0;Y2=1;G2=1;void nb_pass() /south and north pass,east and west stopled_display(100,100);if(y_time<=5&&y_time>0)TR1=1;R1=1;G1=1;if(cnt
10、1>=10)Y1=0;/east and west yellow led flashelse Y1=1;R2=0;Y2=1;G2=1;if(y_time=0)TR1=0;R1=0;Y1=1;G1=1;R2=1;Y2=1;G2=0;/*keyboard scan*void keyscan() if(!k5num) if(k0=0) /*emergency*delay(10);if(k0=0)while(!k0);TR0=0;k0num=1; if(!k1num&&!k0num)if(k1=0)delay(10);if(k1=0)while(!k1);k1num=1;k2nu
11、m=0;y_time=5; /單方向通行時,黃燈閃爍時間TR0=0;TR1=1;if(!k2num&&!k0num)if(k2=0)delay(10);if(k2=0)while(!k2);k1num=0;k2num=1;y_time=5;/單方向通行時,黃燈閃爍時間TR0=0;TR1=1;if(k3=0)delay(10);if(k3=0)while(!k3);if(k1num|k2num)pass_time=dx_time; /由東西或南北通行返回時,重新開始執(zhí)行。k0num=0;k1num=0;k2num=0;k4num=0;k5num=0;TR0=1;TR1=0;fla
12、g_t=0;if(!k4&&!k0num)/pausedelay(10);if(k4=0)while(!k4);TR0=0;k4num=1; if(k4num=1) /暫停鍵按下時,才可以調(diào)整兩個方向通行時間if(k5=0)delay(10);if(k5=0)k5num+;while(!k5);switch(k5num)case 1:TR0=1;flag_t=1; /調(diào)整時間時,pass_time值不變。k5num=1;break;case 2:k5num=2;break;case 3:TR0=0;k5num=0;pass_time=dx_time; /重新賦值break;if
13、(k5num!=0)if(k3=0)delay(10);if(k3=0)while(!k3);switch(k5num)case 1:dx_time-;if(dx_time<10)dx_time=99;break;case 2:nb_time-;if(nb_time<10)nb_time=99;break;if(k4=0)delay(10);if(k4=0)while(!k4);switch(k5num)case 1:dx_time+;if(dx_time>=100)dx_time=10;break;case 2:nb_time+;if(nb_time>=100)nb_
14、time=10;break;void main()timer0_init();dx_time=45;nb_time=30;pass_time=dx_time;while(1)keyscan();if(k0num)emergency();elseswitch(k4num)case 0:if(!k1num&&!k2num)circle_led();elseif(k1num) dx_pass();if(k2num) nb_pass();break;case 1: switch(k5num)case 0:if(!k1num&&!k2num)circle_led();el
15、seif(k1num) dx_pass();if(k2num) nb_pass();break;case 1:R1=1;Y1=1;G1=1; /調(diào)整時間時,關(guān)閉所有燈R2=1;Y2=1;G2=1;if(cnt<=10)led_display(100,nb_time);elseled_display(dx_time,nb_time);break;case 2:R1=1;Y1=1;G1=1;/調(diào)整時間時,關(guān)閉所有燈R2=1;Y2=1;G2=1;if(cnt<=10)led_display(dx_time,100);elseled_display(dx_time,nb_time);break;break;void timer0()
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025-2030全球汽車內(nèi)飾材料燃燒試驗機行業(yè)調(diào)研及趨勢分析報告
- 2025-2030全球大型球軸承(外徑尺寸在200mm以上)行業(yè)調(diào)研及趨勢分析報告
- 2025-2030全球住宅用窗戶防蟲網(wǎng)行業(yè)調(diào)研及趨勢分析報告
- 2025年全球及中國商用儲水式電熱水器行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報告
- 2025-2030全球汽車空調(diào)風門執(zhí)行器行業(yè)調(diào)研及趨勢分析報告
- 2025年全球及中國半導體高壓電源行業(yè)頭部企業(yè)市場占有率及排名調(diào)研報告
- 幼兒繪本講述與演繹幼兒繪本的選擇講解
- 2025農(nóng)村房屋贈與合同書
- 企業(yè)搬遷合同范本
- 土地承包合同終止
- 北京市海淀區(qū)2024-2025學年八年級上學期期末考試數(shù)學試卷(含答案)
- 2024年全國職業(yè)院校技能大賽高職組(研學旅行賽項)考試題庫(含答案)
- 2025社保政策培訓
- 電器儀表人員培訓課件
- 2025年中小學春節(jié)安全教育主題班會課件
- 2023年工程制圖習題集
- 計量經(jīng)濟學練習題
- 2025年全國高考體育單招考試模擬政治試卷試題(含答案詳解)
- 傳統(tǒng)春節(jié)習俗
- 反走私課件完整版本
- 四年級下冊數(shù)學知識點總結(jié)
評論
0/150
提交評論