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