1、VerilogHDL电梯程序文件这个程序不需要你再添加任何的程序,你只需要添加楼层数就可以成功控制6层以上电梯,另外你必须得读懂每一块程序的作用,才能对这个程序有更好的应用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;
2、 /故障警报键output6:0 hex,lig; /light和led用数码管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是内部按键,up外部上升按键,dn是外部下降按键, /now_f是当前楼层,curr是当前楼层的另外一个变量reg1:0 ud_f; /上升下降标志位reg light;/reg29:0 counter;/reg clkout;parameter idle_state=3b
3、001,open_state=3b010,close_state=3b011, up_state=3b100,down_state=3b101,sleep_state=3b110, alarm_state=3b111,f1=6b000001,f2=6b000010,f3=6b000100,f4=6b001000 ,f5=6b010000,f6=6b100000,up_f=2b01,dn_f=2b10,idle=2b00; /jiu zhong zhuang tai he shang sheng zhuang tai shang sheng zhuang tai he xia jia zhuan
4、g tai initial begin state=idle_state; endalways (posedge clk or posedge reset) if(reset) state=idle_state; else state=next_state;always (state or up or dn or d or now_f or count or ud_f) case(state) open_state: begin if(count0) begin if(d&now_f)0) next_state=open_state; else if(dnow_f) next_state=up
5、_state; else next_state=down_state; end else if(up&now_f)|(dn&now_f) next_state=open_state; else if(upnow_f)|(dnnow_f) next_state=up_state; else if(up|dn) next_state=down_state; else next_state=idle_state; end up_state: begin if(up|dn|d|ud_f)=0) next_state=sleep_state; if(!overw|pro=1) next_state=al
6、arm_state; else if(d&now_f)|(up&now_f) next_state=open_state; else if(dnow_f)|(upnow_f) next_state=up_state; else if(dnow_f)|(up0) begin if(dnnow_f) next_state=up_state; else if(dn&now_f)|(now_ff6) next_state=open_state; else if(dn&now_f)&(now_f=f6) next_state=open_state; else next_state=down_state;
7、 end else next_state=idle_state; end down_state: begin if(up|dn|d|ud_f)=0) next_state=sleep_state; else if(!overw|pro=1) next_state=alarm_state; else if(d&now_f)|(dn&now_f) next_state=open_state; else if(dnow_f)&(d!=6b000001)|(dnnow_f)|(dnnow_f) next_state=up_state; else if(up0) begin if (upf1) next
8、_state=down_state; else if(up&now_f)&(now_f=f1) next_state=open_state; else next_state=up_state; end else next_state=idle_state; end close_state: begin if(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) begin if(d&now_f)|(up&now_f) next_state
9、=open_state; else if(dnow_f)|(upnow_f) next_state=up_state; else if(d|up) next_state=down_state; else if(dn0) begin if(dnnow_f) next_state=up_state; else if(dn&now_f)0) next_state=open_state; else next_state=down_state; end else next_state=idle_state; end else if(ud_f=dn_f) begin if(d&now_f)|(dn&now
10、_f) next_state=open_state; else if(dnow_f)&(d!=6b000000)|(dn0) begin if(up0) next_state=open_state; else next_state=up_state; end else next_state=idle_state; end else begin if(d0) begin if(d&now_f)0) next_state=open_state; else if(dnow_f) next_state=up_state; else next_state=down_state; end else if(
11、up&now_f)&(dn&now_f) next_state=open_state; else if(upnow_f)&(dnnow_f) next_state=up_state; else if(up|dn) next_state=down_state; else next_state=idle_state; end end alarm_state: begin if(!overw|pro=1) begin /Buzzer1=1b1; next_state=open_state; end else begin /Buzzer10) begin if(d&now_f)0) next_stat
12、e=open_state; else if(dnow_f) next_statenow_f)|(dnnow_f) next_state=up_state; else if(up|dn) next_state=down_state; else next_state=idle_state; end end default: next_state=idle_state; endcase always (up1 or up2 or up3 or up4 or up5) up =1b0,up5,up4,up3,up2,up1; always (dn2 or dn3 or dn4 or dn5 or dn
13、6) dn =dn6,dn5,dn4,dn3,dn2,1b0; 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) begin if(reset) count=0; else if(next_state=open_state)&(count5) count=count+1; else count=0; endalways (posedge clk or posedge reset ) /always (reset or next_state)
14、if(reset) begin now_f=f1; ud_f=idle; led=6b000001; light=1b0; end else begin now_f=now_f; curr=now_f; case(next_state) idle_state: begin now_f=now_f; ud_f=idle; led=led; curr=now_f; Buzzer1=1b0; end up_state: begin now_f=now_f1; ud_f=up_f; led=led+1; curr=now_f; end down_state: begin now_f1; ud_f=dn
15、_f; led=led+1; curr=now_f; end open_state: begin now_f=now_f; ud_f=ud_f; led=led; door=1b1; light=door; curr=now_f; end close_state: begin now_f=now_f; ud_f=ud_f; led=led; curr=now_f; door=1b0; light=door; end alarm_state: begin now_f=now_f; ud_f=ud_f; led=led; Buzzer1=1b1; curr=now_f; door=1b1; lig
16、ht=door; end sleep_state: begin now_f=now_f; ud_f=ud_f; led=6b000000; curr=now_f; end default: begin now_f=f1; ud_f=idle; led=led; end endcase end always (curr)begin case(curr) 6b000001: hex=7b1111001; /数码管共阴共阳 6b000010: hex=7b1000100; 6b000100: hex=7b0110000; 6b001000: hex=7b0011001; 6b010000: hex=
17、7b1101101; 6b100000: hex=7b1111101; default: hex=7b0000000; endcase endalways (light) begin case(light) 1b0: lig=7b1000000; /1b1: lig=7b1000000; 1b1: lig=7b1111001; default: light=7b0000000; endcase end/分频程序/*always (posedge clk) begin if( counter29:0 = 24999999) begin /每计到4个(03)上升沿,输出信号翻转一次 counter = 0; clkout = clkout; end else counter29:0 = counter29:0 + 1b1; end*/ endmodule
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1