【文章內(nèi)容簡介】
庫的說明 use 。 程序包的說明 use 。 use 。 entity threelift is 實(shí)體 port(buttonclk:in std_logic。 按鍵時鐘信號 liftclk:in std_logic。 電梯時鐘信號 reset:in std_logic。 異步復(fù)位端口 f1upbutton:in std_logic。 一層上升請求端口 f2upbutton:in std_logic。 二層上升請求端口 f2dnbutton:in std_logic。 二層下降請求端口 f3dnbutton:in std_logic。 三層下降請求端口 stop1button:in std_logic。 一層停站請求端口 stop2button:in std_logic。 二層停站請求端口 stop3button:in std_logic。 三層停站請求端口 position:buffer integer range 1 to 3。 電梯位置信號 udsig:buffer std_logic。 電梯模式(上升或下降)信號 fuplight,fdnlight,stoplight:buffer std_logic_vector(3 downto 1)。 18 上升、下降、停站請求寄存信號 doorlight:out std_logic。 開關(guān)門信號 dout1:out std_logic_vector(3 downto 0))。 end entity threelift。 architecture one of threelift is 結(jié)構(gòu)體 type lift_state is 定義十個狀態(tài) (stopon1,dooropen,doorclose,doorwait1,doorwait2,doorwait3,doorwait4,up,down,stop)。 signal mylift:lift_state。 signal clearup:std_logic。 上升和停站請求清除信號 signal cleardn:std_logic。 下降和停站請求清除信號 begin ctrlift:process(reset,liftclk) 狀態(tài)機(jī)進(jìn)程 variable pos:integer range 3 downto 1。 begin if reset=39。139。 then 異步復(fù)位,電梯的初始狀態(tài)為一層開門狀態(tài) mylift=stopon1。 clearup=39。039。 cleardn=39。039。 else if liftclk39。event and liftclk=39。139。 then case mylift is when stopon1= doorlight=39。139。 position=1。 pos:=1。 mylift=doorwait1。 電梯等待 4s when doorwait1= 19 mylift=doorwait2。 when doorwait2= clearup=39。039。 cleardn=39。039。 mylift=doorwait3。 when doorwait3= mylift=doorwait4。 when doorwait4= mylift=doorclose。 when doorclose= 關(guān)門,判定電梯下一個運(yùn)行方式 doorlight=39。039。 if udsig=39。139。 then 電梯處在上升模式 if position=3 then if fuplight=000 and fdnlight=000 and stoplight=000 then 沒有請求信號時,電梯停在當(dāng)前層 udsig=39。039。 mylift=doorclose。 elsif fdnlight(3)=39。139。 or stoplight(3)=39。139。 then 本層有請求信號是,電梯開門 udsig=39。039。 mylift=dooropen。 else 否則 下降 udsig=39。039。 mylift=down。 end if。 elsif position=2 then if fuplight=000 and fdnlight=000 and stoplight=000 then udsig=39。139。 mylift=doorclose。 20 elsif fuplight(2)=39。139。 or stoplight(2)=39。139。 then 本層有上升或停站請求時時,電梯開門 udsig=39。139。 mylift=dooropen。 elsif fuplight=000 and stoplight=000 and fdnlight=010 then 只有二層有下降請求時,電梯開門 udsig=39。039。 mylift=dooropen。 elsif stoplight(3)=39。139。 or fdnlight(3)=39。139。 then 三層有停站請求或下降請求,則上升 udsig=39。139。 mylift=up。 else udsig=39。039。 mylift=down。 end if。 elsif position=1 then if fuplight=000 and fdnlight=000 and stoplight=000 then udsig=39。139。 mylift=doorclose。 elsif stoplight(1)=39。139。 or fuplight(1)=39。139。 then udsig=39。139。 mylift=dooropen。 else udsig=39。139。 mylift=up。 end if。 end if。 21 elsif udsig=39。039。 then 電梯處在下降模式 if position=3 then if fuplight=000 and fdnlight=000 and stoplight=000 then udsig=39。039。 mylift=doorclose。 elsif fdnlight(3)=39。139。 or stoplight(3)=39。139。 then udsig=39。039。 mylift=dooropen。 else udsig=39。039。 mylift=down。 end if。 elsif position=2 then if fuplight=000 and fdnlight=000 and stoplight=000 then udsig=39。039。 mylift=doorclose。 elsif fdnlight(2)=39。139。 or stoplight(2)=39。139。 then udsig=39。039。 mylift=dooropen。 elsif fdnlight=000 and stoplight=000 and fuplight=010 then udsig=39。139。 mylift=dooropen。 elsif fuplight(1)=39。139。 or stoplight(1)=39。139。 then 一層有停站請求或上升請求,則下降 udsig=39。039。 mylift=down。 else 22 udsig=39。139。