VHDL语言-四层电梯.doc_第1页
VHDL语言-四层电梯.doc_第2页
VHDL语言-四层电梯.doc_第3页
VHDL语言-四层电梯.doc_第4页
VHDL语言-四层电梯.doc_第5页
免费预览已结束,剩余1页可下载查看

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_arith.all;use ieee.std_logic_unsigned.all;entity elevator is -电梯外方向 PORT(clk1,clk2,start,reset,up1,up2,up3,down2,down3,down4,stop1,stop2,stop3,stop4: in std_logic; stoplight: buffer std_logic_vector(4 downto 1); uplight: buffer std_logic_vector(3 downto 1); downlight: buffer std_logic_vector(4 downto 2); position:buffer integer range 1 to 4; -电梯所在楼层 udsig:buffer std_logic; -指示方向 tdisplay:out std_logic_vector(4 downto 1); -12秒倒计时 setlight:out std_logic_vector(3 downto 1) -楼层设置 );end elevator;architecture lift of elevator istype state_type is(stopat1,dclose,wait1,wait2,wait3,wait4,wait5,wait6,wait7,wait8, swup2,swup3,swup4,swup5, swdn2,swdn3,swdn4,swdn5, up,down,stop,stopq);signal state:state_type;signal clearup,cleardown:std_logic;begin zt:process(clk2,reset)variable pos: std_logic_vector(1 downto 0);beginif reset=1 then state=stopat1;position=1;pos:=00;clearup=0;cleardownstate=wait1;udsigstate=wait2;tdisplay=1000; if start=1 then state=dclose;elsif uplight(position)=1 or downlight(position)=1 then state=wait1;clearup=1;cleardownstate=wait3;tdisplay=0111;clearup=0;cleardown=0; if start=1 then state=dclose;elsif uplight(position)=1 or downlight(position)=1 then state=wait1;clearup=1;cleardownstate=wait4;tdisplay=0110; if start=1 then state=dclose;elsif uplight(position)=1 or downlight(position)=1 then state=wait1;clearup=1;cleardownstate=wait5;tdisplay=0101; if start=1 then state=dclose;elsif uplight(position)=1 or downlight(position)=1 then state=wait1;clearup=1;cleardownstate=wait6;tdisplay=0100; if start=1 then state=dclose;elsif uplight(position)=1 or downlight(position)=1 then state=wait1;clearup=1;cleardownstate=wait7;tdisplay=0011; if start=1 then state=dclose;elsif uplight(position)=1 or downlight(position)=1 then state=wait1;clearup=1;cleardownstate=wait8;tdisplay=0010; if start=1 then state=dclose;elsif uplight(position)=1 or downlight(position)=1 then state=wait1;clearup=1;cleardownstate=dclose;tdisplayif udsig=0 then -上升情况if position=4 then -电梯在四楼if stoplight=0000and uplight=000and downlight=000 thenudsig=1;state=dclose;elsif downlight(4)=1thenstate=stopq;else udsig=1;state=down;end if;elsif position=3 then -电梯在三楼if stoplight=0000and uplight=000and downlight=000 thenudsig=0;state=dclose;elsif stoplight(4)=1 or downlight(4)=1 thenudsig=0;state=up;elsif uplight(3)=1thenstate=stop;elsif downlight(3)=1thenstate=stopq;elseudsig=1;state=down;end if;elsif position=2 then -电梯在二楼if stoplight=0000and uplight=000and downlight=000 thenudsig=0;state=dclose;elsif stoplight(3)=1or uplight(3)=1or stoplight(4)=1or downlight(4)=1 thenudsig=0;state=up;elsif uplight(2)=1thenstate=stop;elsif downlight(2)=1thenstate=stopq; elseudsig=1;state=down;end if;elsif position=1 then -电梯在一楼if stoplight=0000and uplight=000and downlight=000 thenudsig=0;state=dclose;elsif uplight(1)=1thenstate=stop;elseudsig=0;state=up;end if;end if;elsif udsig=1 then -下降情况if position=1 then -电梯在一楼if stoplight=0000and uplight=000and downlight=000 thenudsig=0;state=dclose;elsif uplight(1)=1thenstate=stop;elseudsig=0;state=up;end if;elsif position=2 then -电梯在二楼if stoplight=0000and uplight=000and downlight=000 thenudsig=1;state=dclose;elsif stoplight(1)=1or uplight(1)=1 thenudsig=1;state=down;elsif uplight(2)=1thenstate=stop;elsif downlight(2)=1thenstate=stopq;else udsig=0;state=up;end if;elsif position=3 then -电梯在三楼if stoplight=0000and uplight=000and downlight=000 thenudsig=1;state=dclose;elsif stoplight(2)=1or downlight(2)=1or stoplight(1)=1or uplight(1)=1 thenudsig=1;state=down;elsif uplight(3)=1thenstate=stop;elsif downlight(3)=1thenstate=stopq;elseudsig=0;state=up;end if;elsif position=4 then -电梯在四楼if stoplight=0000and uplight=000and downlight=000 thenudsig=1;state=dclose;elsif downlight(4)=1thenstate=stopq;elseudsig=1;statestate=swup5;tdisplaystate=swup4;tdisplaystate=swup3;tdisplaystate=swup2;tdisplaytdisplay=0001;-显示1if pos=00 then position=2;pos:=01;-显示第2层elsif pos=01 then position=3;pos:=10;-显示第3层elsif pos=10 then position=4;pos:=11;-显示第4层end if; if pos=01 and stoplight(2)=0and uplight(2)=0and(stoplight(3)=1or uplight(3)=1or stoplight(4)=1or downlight(4)=1)thenstate=up;elsif pos=10 and stoplight(3)=0and uplight(3)=0and(stoplight(4)=1or downlight(4)=1) thenstate=up;elsif pos=11 thenstate=stopq;elsestatestate=swdn5;tdisplaystate=swdn4;tdisplaystate=swdn3;tdisplaystate=swdn2;tdisplaytdisplay=0001;-显示1if pos=01 then position=1;pos:=00;-显示第1层elsif pos=10 then position=2;pos:=01;-显示第2层elsif pos=11 then position=3;pos:=10;-显示第3层end if; if pos=10 and stoplight(3)=0 and downlight(3)=0and(stoplight(2)=1or downlight(2)=1or stoplight(1)=1or uplight(1)=1) thenstate=down;elsif pos=01 and stoplight(2)=0 and downlight(2)=0and(stoplight(1)=1or uplight(1)=1) thenstate=down;elsif pos=00thenstate=stop;elsestateclearup=1;statecleardown=1;statestate=stopat1;end case;end if;end process zt;sr:process(clk1)beginif reset=1 thenstoplight=0000;uplight=000;downlight=000;setlight=000;elsif ( clk1=1 and clk1EVENT) then if clearup=1 thenstoplight(position)=0;uplight(position)=0;elseif up1=1then uplight(1)=1;setlight=001;end if;if up2=1then uplight(2)=1;setlight=010;end if;if up3=1then uplight(3)=1;setlight=011;end if;end if;if cleardown=1 thenstoplight(position)=0;downlight(position)=0;elseif down2=1then downlight(2)=1;setlight=010;end if;if down3=1then downlight(3)=1;setlight=011;end if;if down4=

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论