《2022年vhdl设计_三层电梯控制程序 .pdf》由会员分享,可在线阅读,更多相关《2022年vhdl设计_三层电梯控制程序 .pdf(7页珍藏版)》请在taowenge.com淘文阁网|工程机械CAD图纸|机械工程制图|CAD装配图下载|SolidWorks_CaTia_CAD_UG_PROE_设计图分享下载上搜索。
1、library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_arith.all; use ieee.std_logic_unsigned.all; entity lift is port(clk,reset,up1,up2,down2,down3,stop1,stop2,stop3,checkow:in std_logic; -buttons uplight,downlight,stoplight:buffer std_logic_vector(3 downto 1); udmode:buffer std_logic; -0- 电
2、梯处于上升模式, 1-电梯处于下降木模式position:buffer integer range 1 to 3; -电梯位置doorlight: out std_logic; -电梯门开关灯loc: out std_logic_vector(6 downto 0); -显示电梯位置ss: buffer integer range 0 to 3; -电梯所处状态 -0-上升-1-下降-2 停止out_state: out std_logic_vector(6 downto 0);-电梯所处状态 -u-上升 d-下降 -s-停止overweight_light :out std_logic);-
3、 超重提醒灯end lift; architecture aaa of lift is type state_type is(stopon1,dooropen,doorclose,wait1,wait2,wait3,wait4,up,down,stop); signal state:state_type:=stopon1; signal clearup,cleardown,buttclk,liftclk:std_logic; signal q,p:integer range 0 to 49999999; component xianshi port( position: in integer
4、range 0 to 9; segment_7: out std_logic_vector(6 downto 0) ); end component; component upordown port( ss: in integer range 0 to 2 ; segment_7: out std_logic_vector(6 downto 0) ); end component; begin process(clk)-电梯分频进程1s begin if reset=1 then q=0; elsif clkevent and clk=1 then if q=49999999 then lif
5、tclk=1;q=0; -if q=2 then liftclk=1;q=0; else liftclk=0;q=q+1; end if; end if; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 1 页,共 7 页 - - - - - - - - - end process; process(clk)-电梯按键分频进程=0.02s begin if reset=1 then p=0; elsif clkevent and clk=1 then if p=9999999 the
6、n buttclk=1;p=0; -if p=2 then buttclk=1;p=0; else buttclk=0;p=p+1; end if; end if; end process; cont:process(reset,liftclk)- 电梯状态机variable pos :integer range 3 downto 0; begin if reset=1 then state=stopon1; clearup=0; cleardown=0; elsif liftclk=1 and liftclkevent then if checkow=1 then state doorlig
7、ht=1; position=1; pos:=1; state=wait1; udmode if checkow=1 then state=wait1;overweight_light=1; else state=wait2; ss=2;overweight_light if checkow=1 then state=wait1;overweight_light=1; else clearup=0;cleardown=0; state=wait3;ss=2;overweight_light if checkow=1 then state=wait1;overweight_light=1; el
8、se state=wait4;ss=2;overweight_light if checkow=1 then state=wait1;overweight_light=1; else overweight_light=0;state=doorclose;ss doorlight=0;ss=2; if udmode=0 then if position=3 then if stoplight=000 and uplight=000 and downlight=000 then udmode=1; state=doorclose; elsif downlight(3)=1 or stoplight
9、(3)=1 then state=dooropen; else udmode=1; state=down; end if; elsif position=2 then if stoplight=000and uplight=000 and downlight=000then udmode=0;state=doorclose; elsif uplight(2)=1 or stoplight(2)=1 then state=dooropen; elsif stoplight(3)=1or downlight(3)=1 then udmode=0; state=up; else udmode=1;s
10、tate=down; end if; elsif position=1 then if stoplight=000 and uplight=000 and downlight=000then udmode=0; state=doorclose; elsif uplight(1)=1 or stoplight(1)=1 then state=dooropen; else udmode=0; state=up; end if; end if; elsif udmode=1 then if position=1 then if stoplight=000 and uplight=000and dow
11、nlight=000 then udmode=0;state=doorclose; elsif uplight(1)=1 or stoplight(1)=1 then state=dooropen; else udmode=0;state=up; end if; elsif position=2 then if stoplight=000 and uplight=000and downlight=000 then udmode=1;state=doorclose; elsif downlight(2)=1 or stoplight(2)=1 then state=dooropen; elsif
12、 stoplight(1)=1or uplight(1)=1then udmode=1; state=down; else udmode=0;state=up; end if; elsif position=3 then if stoplight=000 and uplight=000and downlight=000 then udmode=1;state=doorclose; elsif downlight(3)=1 or stoplight(3)=1 then state=dooropen; else udmode=1;state position=position+1;pos:=pos
13、+1;ss=0; if pos=2 and stoplight(2)=0 and uplight(2)=0 and (stoplight(3)=1 or downlight(3)=1) then state=up; else state position=position-1;pos:=pos-1;ss=1; if pos=2 and stoplight(2)=0 and uplight(2)=0 and (stoplight(1)=1 or uplight(1)=1) then state=down; else statestatedoorlight=1;ss=2; if udmode=0
14、then if pos3 and (stoplight(pos)=1 or uplight(pos)=1) then clearup=1; else clearup=1;cleardown1 and (stoplight(pos)=1 or uplight(pos)=1) then cleardown=1; else clearup=1;cleardown=1; end if; end if; state state=stopon1;ss=2; end case; end if; end if; end process cont; butt:process (reset,buttclk)- 按
15、键灯控制进程begin if reset=1 then stoplight=000; uplight=000; downlight=000; else if buttclkevent and buttclk=1 then if clearup=1 then -stoplight(position)=0; uplight(position)=0; else if up1=1 then uplight(1)=1; end if; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 4 页,共
16、 7 页 - - - - - - - - - if up2=1 then uplight(2)=1; end if; end if; if cleardown=1 then -stoplight(position)=0; downlight(position)=0; else if down2=1 then downlight(2)=1; end if; if down3=1 then downlight(3)=1; end if; end if; if clearup=1 or cleardown=1 then if position=1 then stoplight(1)=0; if st
17、op2=1 then stoplight(2)=1 ;end if; if stop3=1 then stoplight(3)=1 ;end if; elsif position=2 then stoplight(2)=0; if stop1=1 then stoplight(1)=1 ;end if; if stop3=1 then stoplight(3)=1 ;end if; else if stop1=1 then stoplight(1)=1 ;end if; if stop2=1 then stoplight(2)position,segment_7=loc);-数码管显示楼层si
18、:upordown port map(ss=ss,segment_7=out_state);- 数码管显示状态end aaa; -数码管显示楼层 - library ieee; use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity xianshi is port( position: in integer range 0 to 9 ; segment_7: out std_logic_vector(6 downto 0) ); 名师资料总结 - - -
19、精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 5 页,共 7 页 - - - - - - - - - end xianshi; architecture a of xianshi is begin process(position) begin case position is when 1=segment_7segment_7segment_7segment_7segment_7segment_7segment_7segment_7segment_7segment_7segment_7segment_7segment_7=0010010; end case; end process; end a; 名师资料总结 - - -精品资料欢迎下载 - - - - - - - - - - - - - - - - - - 名师精心整理 - - - - - - - 第 7 页,共 7 页 - - - - - - - - -