资源描述:
《Verilog-HDL-电梯程序》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、这个程序不需要你再添加任何的程序,你只需要添加楼层数就可以成功控制6层以上电梯,另外你必须得读懂每一块程序的作用,才能对这个程序有更好的应用moduledtsj(clk,reset,up1,up2,up3,up4,up5,dn2,dn3,dn4,dn5,dn6,d1,d2,d3,d4,d5,d6,overw,pro,led,hex,Buzzer1,lig);inputclk,reset;//reset键使用keyinputoverw,pro,up1,up2,up3,up4,up5,dn2,dn3,dn4,dn5,dn6,d1,d2,d3,d4,d5,d6;//故障警报键ou
2、tput[6:0]hex,lig;//light和led用数码管output[5:0]led;outputBuzzer1;regBuzzer1,door;reg[6:0]hex,lig;reg[2:0]state,next_state,count;reg[5:0]d,up,dn,now_f,curr,led;//d是内部按键,up外部上升按键,dn是外部下降按键,//now_f是当前楼层,curr是当前楼层的另外一个变量reg[1:0]ud_f;//上升下降标志位reglight;//reg[29:0]counter;//regclkout;parameteridle_st
3、ate=3'b001,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;//jiuzhongzhuangtaiheshangshengzhuangtai'shangshengzhuangta
4、ihexiajiazhuangtaiinitialbeginstate<=idle_state;endalways@(posedgeclkorposedgereset)if(reset)state<=idle_state;elsestate<=next_state;always@(stateorupordnordornow_forcountorud_f)case(state)open_state:beginif(count<5)next_state=open_state;elsenext_state=close_state;endsleep_state:beginif((u
5、p
6、
7、dn
8、
9、d
10、
11、ud_f)==0)beginnext_state=close_state;endelsenext_state=idle_state;endidle_state://初始状态beginif((up
12、
13、dn
14、
15、d
16、
17、ud_f)==0)next_state=sleep_state;if(!overw
18、
19、pro==1)next_state=alarm_state;elseif(d>0)beginif((d&now_f)>0)next_state=open_state;elseif(d>now_f)next_state=up_state;elsenext_stat
20、e=down_state;endelseif((up&now_f)
21、
22、(dn&now_f))next_state=open_state;elseif((up>now_f)
23、
24、(dn>now_f))next_state=up_state;elseif(up
25、
26、dn)next_state=down_state;elsenext_state=idle_state;endup_state:beginif((up
27、
28、dn
29、
30、d
31、
32、ud_f)==0)next_state=sleep_state;if(!overw
33、
34、pro==1)next_state=alarm_state;elsei
35、f((d&now_f)
36、
37、(up&now_f))next_state=open_state;elseif((d>now_f)
38、
39、(up>now_f))next_state=up_state;elseif((d40、
41、(up42、
43、up)waitspeaknext_state=down_state;elseif(dn>0)beginif(dn>now_f)next_state=up_state;elseif((dn&now_f)
44、
45、(now_f