|
以代碼的形式進(jìn)行樓梯運(yùn)行控制系統(tǒng)的模擬
點(diǎn)亮led表示開(kāi)門- library ieee; -- 庫(kù)的說(shuō)明
- use ieee.std_logic_1164.all; -- 程序包的說(shuō)明
- use ieee.std_logic_unsigned.all;
- use ieee.std_logic_arith.all;
- entity SDC 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)求端口
- fuplight:buffer std_logic_vector(3 downto 1); -- 上升請(qǐng)求寄存信號(hào)
- fdnlight:buffer std_logic_vector(3 downto 1); -- 下降請(qǐng)求寄存信號(hào)
- stop1button,stop2button,stop3button:in std_logic;-- 停站請(qǐng)求端口
- stoplight:buffer std_logic_vector(3 downto 1); -- 停站請(qǐng)求寄存信號(hào)
- position:buffer integer range 1 to 3;-- 電梯位置信號(hào)
- doorlight:out std_logic; -- 開(kāi)關(guān)門信號(hào)
- udsig:buffer std_logic); -- 電梯模式(上升或下降)信號(hào)
- end SDC;architecture art of SDC 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
- controlift:process(reset,liftclk) -- 狀態(tài)機(jī)進(jìn)程
- variable pos:integer range 3 downto 1;
- --******************************--
- --**********電梯運(yùn)行控制*********--
- --******************************--
- begin
- if reset='1' then
- mylift <= stopon1; -- 異步復(fù)位,電梯的初始狀態(tài)為一層開(kāi)門狀態(tài)
- clearup <= '0';
- cleardn <= '0';
- pos:=1;
- position<=1;
- else if liftclk'event and liftclk='1'
- then
- case mylift is
- when stopon1 => doorlight <= '0';position <= 1;pos:=1;
- mylift <= doorwait1; -- 電梯等待 4s
- when doorwait1 => mylift <=doorwait2;
- when doorwait2 =>clearup<='0';cleardn<='0';mylift <=doorwait3;
- when doorwait3 => mylift <=doorwait4;
- when doorwait4 => mylift <= doorclose;
- when doorclose => doorlight <= '1';-- 關(guān)門,判定電梯下一個(gè)運(yùn)行方式
- if udsig='0' then -- 如果電梯處在上升模式
- if position=3 then
- if stoplight="111" and fuplight="111" and fdnlight="111" then-- 沒(méi)有請(qǐng)求信號(hào)時(shí),電梯停在當(dāng)前層
- udsig <= '1';
- mylift <= doorclose;
- elsif fdnlight(3)='0' or stoplight(3)='0' then-- 如果本層有請(qǐng)求信號(hào)時(shí),電梯開(kāi)門
- udsig<='1';
- mylift<=dooropen;
- else --否則下降udsig<='1';
- mylift<=down;
- end if;
- elsif position=2 then
- if stoplight="111" and fuplight="111" and fdnlight="111" then
- udsig<='0';
- mylift<=doorclose;
- elsif fuplight(2)='0' or stoplight(2)='0' then-- 本層有上升或停站請(qǐng)求時(shí)時(shí),電梯開(kāi)門
- udsig<='0';
- mylift<=dooropen;
- elsif fuplight="111" and stoplight="111" and fdnlight="101" then--只有二層有下降請(qǐng)求時(shí),電梯開(kāi)門
- udsig<='1';
- mylift<=dooropen;
- elsif stoplight(3)='0' or fdnlight(3)='0' then-- 三層有停站請(qǐng)求或下降請(qǐng)求,則上升
- udsig<='0';
- mylift<=up;
- else udsig<='1';
- mylift<=down;
- end if;
- elsif position=1 then
- if stoplight="111" and fuplight="111" and fdnlight="111" then
- udsig<='0';
- mylift<=doorclose;
- elsif stoplight(1)='0' or fuplight(1)='0' then
- udsig<='0';
- mylift<=dooropen;
- else
- udsig<='0';
- mylift<=up;
- end if;
- end if;
-
-
- elsif udsig='1' then-- 如果電梯處在下降模式
- if position=1 then
- if stoplight="111" and fuplight="111" and fdnlight="111" then
- udsig<='0';
- mylift<=doorclose;
- elsif stoplight(1)='0' or fuplight(1)='0' then
- udsig<='0';
- mylift<=dooropen;
- else udsig<='0';
- mylift<=up;
- end if;
- elsif position=2 then
- if stoplight="111" and fuplight="111" and fdnlight="111" then
- udsig<='1';
- mylift<=doorclose;
- elsif fdnlight(2)='0' or stoplight(2)='0' then
- udsig<='1';
- mylift<=dooropen;
- elsif fdnlight="111" and stoplight="111" and fuplight="101" then
- udsig<='0';
- mylift<=dooropen;
- elsif stoplight(1)='0' or fuplight(1)='0' then
- udsig<='1';
- mylift<=down;
- else udsig<='0';
- mylift<=up;
- end if;
- elsif position=3 then
- if stoplight="111" and fuplight="111" and fdnlight="111" then
- udsig<='1';
- mylift<=doorclose;
- elsif fdnlight(3)='0' or stoplight(3)='0' then
- udsig<='1';
- mylift<=dooropen;
- else udsig<='1';
- mylift<=down;
- end if;
- end if;
- end if;
-
-
- --******************************--
- --**********上升模式*************--
- --******************************--
- when up=> -- 電梯處于上升狀態(tài)
- position<=position+1; -- 電梯樓層數(shù)加一
- pos:=pos+1;
- if pos <3 and (stoplight(pos)='0' or fuplight(pos)='0')
- then
- mylift <= stop; -- 電梯在一層或二層,本層有停站或上升請(qǐng)求時(shí),則停止
- elsif pos=3 and (stoplight(pos)='0' or fdnlight(pos)='0')
- then
- mylift <= stop; -- 電梯處在三層,并且有三層停站或下降請(qǐng)求,則停止
- else
- mylift <= doorclose;
- end if;
- --******************************--
- --**********下降模式*************--
- --******************************--
- when down => -- 電梯處在下降狀態(tài)
- position <=position-1;-- 電梯樓層數(shù)減一
- pos:=pos-1;
- if pos >1 and (stoplight(pos)='0' or fdnlight(pos)='0') then
- mylift <= stop;elsif pos=1 and (stoplight(pos)='0' or fuplight(pos)='0') then
- mylift <= stop;
- else mylift <= doorclose;
- end if;
-
- when stop => mylift <= dooropen;
- when dooropen => doorlight <= '0';
- if udsig='0' then
- if position<3 and (stoplight(pos)='0' or fuplight(pos)='0') then
- clearup <= '1'; -- 清除當(dāng)前層上升和停站請(qǐng)求
- else
- clearup<='1';
- cleardn<='1';
- end if;
- elsif udsig='1' then
- if position >1 and (stoplight(pos)='0' or fdnlight(pos)='0') then
- cleardn <= '1'; -- 清除當(dāng)前層下降和停站請(qǐng)求
- else clearup <= '1';
- cleardn <= '1';
- end if;
- end if;
-
- mylift <= doorwait1; --狀態(tài)機(jī)復(fù)位
- end case;end if;
- end if;
- end process controlift;
- --******************************--
- --****記憶電梯外各層停站請(qǐng)求******--
- --******************************--
- controlight:process(reset,buttonclk)
- begin
-
- if reset='1' then
- stoplight <= "111";
- fuplight <= "111";
- fdnlight <= "111";
- else
- if buttonclk'event and buttonclk='1' then
- if clearup='1' then -- 上升和停站請(qǐng)求清零
- stoplight(position) <= '1';
- fuplight(position) <= '1';
- else if
- f1upbutton='1' then
- fuplight(1)<='0';
- elsif f2upbutton='1' then
- fuplight(2)<='0';
- end if;
- end if;
- if cleardn='1' then stoplight(position) <= '1';
- fdnlight(position) <= '1';
- else if
- f2dnbutton='1' then -- 記憶各層下降請(qǐng)求
- fdnlight(2)<='0';
- elsif f3dnbutton='1' then
- fdnlight(3)<='0';
- end if;
- end if;
-
- --******************************--
- --*****記憶進(jìn)入電梯后各層停站請(qǐng)求**--
- --******************************--
-
- if stop1button='1' then
- stoplight(1)<='0';
- elsif stop2button='1' then
- stoplight(2)<='0';
- elsif stop3button='1' then
- stoplight(3)<='0';
- end if;
- end if;
- end if;
- end process controlight;
- end art;
復(fù)制代碼
|
評(píng)分
-
查看全部評(píng)分
|