Verilog-HDL-電梯程序_第1頁
Verilog-HDL-電梯程序_第2頁
Verilog-HDL-電梯程序_第3頁
Verilog-HDL-電梯程序_第4頁
Verilog-HDL-電梯程序_第5頁
已閱讀5頁,還剩4頁未讀, 繼續(xù)免費閱讀

下載本文檔

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

文檔簡介

1、精品文檔這個程序不需要你再添加任何的程序,你只需要添加樓層數(shù)就可以成功控制 6 層以上電梯,另外你必須得讀懂每一塊程序的作用,才能對這個程序有更好的應(yīng)用module dtsj(clk,reset,up1,up2,up3,up4,up5,dn2,dn3,dn4,dn5,dn6,d1,d2,d3,d4,d5,d6,overw,pro,led,hex,Buzzer1,lig);input clk,reset;/reset鍵使用 keyinput overw,pro,up1,up2,up3,up4,up5,dn2,dn3,dn4,dn5,dn6,d1,d2,d3,d4,d5,d6; /故障警報鍵out

2、put6:0 hex,lig; /light output5:0 led;output Buzzer1;reg Buzzer1,door;reg6:0 hex,lig;reg2:0state,next_state,count;reg5:0 d,up,dn,now_f,curr,led; /d 下降按鍵,/now_f量reg1:0 ud_f;/reg light;/reg29:0 counter;/reg clkout;和 led 用數(shù)碼管是內(nèi)部按鍵, up 外部上升按鍵,dn 是外部是當(dāng)前樓層,curr 是當(dāng)前樓層的另外一個變上升下降標志位parameteridle_state=3'b

3、001,open_state=3'b010,close_state=3'b011,up_state=3'b100,down_state=3'b101,sleep_state=3'b110,alarm_state=3'b111,f1=6'b000001,f2=6'b000010,f3=6'b000100,f4=6'b001000 ,f5=6'b010000,f6=6'b100000,up_f=2'b01,dn_f=2'b10,idle=2'b00;/jiu zhong zhua

4、ng tai he shang sheng zhuang tai 'shang sheng zhuang tai he xia jia zhuang taiinitialbeginstate<=idle_state;endalways (posedge clk or posedge reset)if(reset)state<=idle_state;elsestate<=next_state;always (state or up or dn or d or now_f or count or ud_f)case(state)open_state:beginif(cou

5、nt<5)next_state=open_state;elsenext_state=close_state;endsleep_state:beginif(up|dn|d|ud_f)=0)beginnext_state=close_state;endelsenext_state=idle_state;endidle_state: /初始狀態(tài)beginif(up|dn|d|ud_f)=0)next_state=sleep_state;if(!overw|pro=1)next_state=alarm_state;else if(d>0)beginif(d&now_f)>0)

6、next_state=open_state;else if(d>now_f) next_state=up_state;elsenext_state=down_state;endelse if(up&now_f)|(dn&now_f) next_state=open_state;else if(up>now_f)|(dn>now_f) next_state=up_state;else if(up|dn)next_state=down_state;elsenext_state=idle_state;endup_state:beginif(up|dn|d|ud_f)

7、=0)next_state=sleep_state;if(!overw|pro=1) next_state=alarm_state;else if(d&now_f)|(up&now_f)next_state=open_state;else if(d>now_f)|(up>now_f) next_state=up_state;else if(d<now_f)|(up<now_f) /else if(d|up) wait speak next_state=down_state;else if(dn>0)beginif(dn>now_f)next_

8、state=up_state;else if(dn&now_f)|(now_f<f6) next_state=open_state;else if(dn&now_f)&&(now_f=f6) next_state=open_state;elsenext_state=down_state;endelsenext_state=idle_state;enddown_state:beginif(up|dn|d|ud_f)=0)next_state=sleep_state;else if(!overw|pro=1)next_state=alarm_state;els

9、e if(d&now_f)|(dn&now_f)next_state=open_state;elseif(d<now_f)&&(d!=6'b000001)|(dn<now_f)&&(dn!=6'b000001) next_state=down_state;else if(d>now_f)|(dn>now_f)next_state=up_state;else if(up>0)beginif (up<now_f)next_state=down_state;else if(up&now_f)&

10、amp;&(now_f>f1) next_state=down_state;else if(up&now_f)&&(now_f=f1) next_state=open_state;elsenext_state=up_state;endelsenext_state=idle_state;endclose_state:beginif(up|dn|d|ud_f)=0)next_state=sleep_state;else if(!overw|pro=1) next_state=alarm_state;else if(ud_f=up_f)beginif(d&

11、;now_f)|(up&now_f) next_state=open_state;else if(d>now_f)|(up>now_f) next_state=up_state;else if(d|up)next_state=down_state;else if(dn>0)beginif(dn>now_f)next_state=up_state;else if(dn&now_f)>0) next_state=open_state;elsenext_state=down_state;endelsenext_state=idle_state;endel

12、se if(ud_f=dn_f)beginif(d&now_f)|(dn&now_f) next_state=open_state;elseif(d<now_f)&&(d!=6'b000000)|(dn<now_f)&&(dn!=6'b000000) next_state=down_state;else if(d|dn)next_state=up_state;else if(up>0)beginif(up<now_f)next_state=down_state;else if(up&now_f)&g

13、t;0) next_state=open_state;elsenext_state=up_state;endelsenext_state=idle_state;endelsebeginif(d>0)beginif(d&now_f)>0)next_state=open_state;else if(d>now_f) next_state=up_state;elsenext_state=down_state;endelse if(up&now_f)&&(dn&now_f) next_state=open_state;else if(up>

14、;now_f)&&(dn>now_f) next_state=up_state;else if(up|dn)next_state=down_state;elsenext_state=idle_state;endendalarm_state:beginif(!overw|pro=1)begin/Buzzer1<=1'b1;next_state=open_state;endelsebegin/Buzzer1<=1'b0;if(d>0)beginif(d&now_f)>0)next_state=open_state;else if

15、(d>now_f)next_state<=up_state;elsenext_state=down_state;endelse if(up&now_f)|(dn&now_f) next_state=open_state;else if(up>now_f)|(dn>now_f) next_state=up_state;else if(up|dn)next_state=down_state;elsenext_state=idle_state;endenddefault:next_state<=idle_state;endcasealways (up1

16、or up2 or up3 or up4 or up5)up =1'b0,up5,up4,up3,up2,up1;always (dn2 or dn3 or dn4 or dn5 or dn6)dn =dn6,dn5,dn4,dn3,dn2,1'b0;always (d1 or d2 or d3 or d4 or d5 or d6)d =d6,d5,d4,d3,d2,d1;always (posedge clk or posedge reset)beginif(reset)count<=0;else if(next_state=open_state)&&(

17、count<5) count<=count+1;elsecount<=0;endalways (posedge clk or posedge reset )/always (reset or next_state)if(reset)beginnow_f<=f1;ud_f<=idle;led<=6'b000001;light<=1'b0;endelsebeginnow_f<=now_f;curr=now_f;6歡迎下載 。精品文檔case(next_state) idle_state: beginnow_f<=now_f;ud

18、_f<=idle;led<=led;curr<=now_f;Buzzer1<=1'bO;endup_state:beginn o w_f<=n o w_f< < 1; ud_f<=up_f;led<=led+1; curr<=now_f;enddown_state: beginn o w_f<=n o w_f> > 1; ud_f<=dn_f;led<=led+1; curr<=now_f; endopen_state: beginnow_f<=now_f;ud_f<=ud_f;

19、led<=led;door<=1'b1;light<=door; curr<=now_f; endclose_state:begin now_f<=now_f; ud_f<=ud_f; led<=led;curr<=now_f;door<=1'bO; light<=door; end alarm_state: beginnow_f<=now_f;ud_f<=ud_f;led<=led;Buzzer1<=1'b1;curr<=now_f;door<=1'b1;light<=door;endsleep_state:beginnow_f<=now_f;ud_f<=ud_f;led<=6'b000000;curr<=now_f;enddefault:beginnow_f<=f1;ud_f<=idle;led<=led;endendcaseendalways (curr)begincase(curr)6'b000

溫馨提示

  • 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)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論