完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
library ieee;
use ieee.std_logic_1164.all; use ieee.std_logic_unsigned.all; use ieee.std_logic_arith.all; entity control is port(buttonclk:in std_logic; liftclk:in std_logic; en:in std_logic; f1up,f2up,f3up,f4up:in std_logic; f2down,f3down,f4down,f5down:in std_logic; stop1,stop2,stop3,stop4,stop5:in std_logic; position:buffer integer range 1 to 5; hex7,hex6,hex5,hex3,hex2,hex1,hex0:out std_logic_vector(6 downto 0) ); end control; architecture behav of control is type lift_state is (stopon1,dooropen,doorclose,doorwait4,up,down,stop); signal mylift:lift_state; signal clearup:std_logic; signal cleardn:std_logic; signal h7,h6,h5,h3,h2,h1,h0 : std_logic_vector(6 downto 0) ; signal uplight:std_logic_vector(5 downto 1); signal dnlight:std_logic_vector(5 downto 1); signal stoplight:std_logic_vector(5 downto 1); signal updown:std_logic; begin controllift:process(en,liftclk) variable posi:integer range 1 to 5; begin if en = '0' then h7 <= "0100100"; h6 <= "1000000"; h5 <= "1111001"; posi := 5; h3 <= "0011001"; h2 <= "0010000"; h1 <= "0011001"; h0 <= "0010000"; mylift<=stopon1; clearup<='0'; cleardn<='0'; else if liftclk'event and liftclk='1' then case mylift is when stopon1 => h7<="0110111"; h6<="0110111";------显示停止 h5<="1111111"; h3<="0001111"; h2<="0111111"; h1<="0111111"; h0<="0111001";------显示关门 position<=1; posi:=1; mylift<=doorwait4; when doorwait4 =>---h7<="0110111"; ---h6<="0110111";------显示停止 ---h5<="1111111"; ---h3<="0111111"; ---h2<="0111001"; ---h1<="0001111"; ---h0<="0111111";------显示开门 mylift <= doorclose; when doorclose => h7<="0110111"; h6<="0110111";------显示停止 h5<="1111111"; h3<="0001111"; h2<="0111111"; h1<="0111111"; h0<="0111001";------显示关门 if updown='0' then ------电梯处于上升状态 if position = 5 then if stoplight="00000" and uplight="00000" and dnlight ="00000" then updown<='1';mylift<=doorclose; elsif stoplight(5)='1' or dnlight(5)='1' then updown<='1';mylift<=dooropen; else updown<='1';mylift<=down; end if; elsif position = 4 then if stoplight="00000" and uplight="00000" and dnlight ="00000" then updown<='0';mylift<=doorclose; elsif stoplight(4)='1' or uplight(4)='1' then updown<='0';mylift<=dooropen; elsif stoplight="00000" and uplight="00000" and dnlight ="01000" then updown<='1';mylift<=dooropen; elsif stoplight(5)='1' or dnlight(5)='1' then updown<='0';mylift<=up; else updown<='1';mylift<=down; end if; elsif position = 3 then if stoplight="00000" and uplight="00000" and dnlight ="00000" then updown<='0';mylift<=doorclose; elsif stoplight(3)='1' or uplight(3)='1' then updown<='0';mylift<=dooropen; elsif stoplight="00000" and uplight="00000" and dnlight ="00100" then updown<='1';mylift<=dooropen; elsif stoplight(4)='1' or stoplight(5)='1' or uplight(4)='1' or dnlight(4)='1' or dnlight(5)='1' then updown<='0';mylift<=up; else updown<='1';mylift<=down; end if; elsif position = 2 then if stoplight="00000" and uplight="00000" and dnlight ="00000" then updown<='0';mylift<=doorclose; elsif stoplight(2)='1' or uplight(2)='1' then updown<='0';mylift<=dooropen; elsif stoplight="00000" and uplight="00000" and dnlight ="00010" then updown<='1';mylift<=dooropen; elsif stoplight(3)='1' or stoplight(4)='1' or stoplight(5)='1' or uplight(3)='1' or dnlight(3)='1' or uplight(4)='1' or dnlight(4)='1' or dnlight(5)='1' then updown<='0';mylift<=up; else updown<='1';mylift<=down; end if; elsif position = 1 then if stoplight="00000" and uplight="00000" and dnlight ="00000" then updown<='0';mylift<=doorclose; elsif stoplight(1)='1' or uplight(1)='1' then updown<='0';mylift<=dooropen; else updown<='0';mylift<=up; end if; end if; elsif updown='1' then if position = 1 then if stoplight="00000" and uplight="00000" and dnlight ="00000" then updown<='0';mylift<=doorclose; elsif stoplight(1)='1' or uplight(1)='1' then updown<='0';mylift<=dooropen; else updown<='0';mylift<=up; end if; elsif position = 2 then if stoplight="00000" and uplight="00000" and dnlight ="00000" then updown<='1';mylift<=doorclose; elsif stoplight(2)='1' or dnlight(2)='1' then updown<='1';mylift<=dooropen; elsif stoplight="00000" and uplight="00010" and dnlight ="00000" then updown<='0';mylift<=dooropen; elsif stoplight(1)='1' or uplight(1)='1' then updown<='1';mylift<=down; else updown<='0';mylift<=up; end if; elsif position = 3 then if stoplight="00000" and uplight="00000" and dnlight ="00000" then updown<='1';mylift<=doorclose; elsif stoplight(3)='1' or dnlight(3)='1' then updown<='1';mylift<=dooropen; elsif stoplight="00000" and uplight="00100" and dnlight ="00000" then updown<='0';mylift<=dooropen; elsif stoplight(1)='1' or stoplight(2)='1' or uplight(1)='1' or uplight(2)='1' or dnlight(2)='1' then updown<='1';mylift<=down; else updown<='0';mylift<=up; end if; elsif position = 4 then if stoplight="00000" and uplight="00000" and dnlight ="00000" then updown<='1';mylift<=doorclose; elsif stoplight(4)='1' or dnlight(4)='1' then updown<='1';mylift<=dooropen; elsif stoplight="00000" and uplight="01000" and dnlight ="00000" then updown<='0';mylift<=dooropen; elsif stoplight(1)='1' or stoplight(2)='1' or stoplight(3)='1' or dnlight(1)='1' or uplight(2)='1' or dnlight(2)='1' or uplight(3)='1' or dnlight(3)='1' then updown<='1';mylift<=down; else updown<='0';mylift<=up; end if; elsif position = 5 then if stoplight="00000" and uplight="00000" and dnlight ="00000" then updown<='1';mylift<=doorclose; elsif stoplight(5)='1' or dnlight(5)='1' then updown<='1';mylift<=dooropen; else updown<='1';mylift<=down; end if; end if; end if; when up => h7<="1111000"; h6<="1001110";------显示上行 h5<="1111111"; h3<="0001111"; h2<="0111111"; h1<="0111111"; h0<="0111001"; position <= position+1; posi:=posi+1; if posi<5 and (stoplight(posi)='1' or uplight(posi)='1') then mylift<=stop; elsif posi=6 and (stoplight(posi)='1' or dnlight(posi)='1') then mylift<=stop; else mylift<=doorclose; end if; when down => h7<="1110001"; h6<="1000111";------显示下行 h5<="1111111"; h3<="0001111"; h2<="0111111"; h1<="0111111"; h0<="0111001"; position <= position-1; posi:=posi-1; if posi>1 and (stoplight(posi)='1' or dnlight(posi)='1') then mylift<=stop; elsif posi=1 and (stoplight(posi)='1' or uplight(posi)='1') then mylift<=stop; else mylift<=doorclose; end if; when stop => h7<="0110111"; h6<="0110111";------显示停止 h5<="1111111"; h3<="0001111"; h2<="0111111"; h1<="0111111"; h0<="0111001";------显示关门 mylift<=dooropen; when dooropen =>h7<="0110111"; h6<="0110111";------显示停止 h5<="1111111"; h3<="0111111"; h2<="0111001"; h1<="0001111"; h0<="0111111";------显示开门 if updown='0' then if position<5 and (stoplight(posi)='1' or uplight(posi)='1') then clearup<='1'; else clearup<='1';cleardn<='1'; end if; elsif updown='1' then if position>1 and (stoplight(posi)='1' or dnlight(posi)='1') then cleardn<='1'; else clearup<='1';cleardn<='1'; end if; end if; mylift<=doorwait4; end case; end if; end if; position<=posi; hex7<=h7; hex6<=h6; hex5<=h5; hex3<=h3; hex2<=h2; hex1<=h1; hex0<=h0; end process controllift; controllight:process(en,buttonclk) begin if en='0' then stoplight<="00000" ; uplight<="00000" ;dnlight <="00000"; ------elsif buttonclk'event and buttonclk='1' then else if clearup='1' then stoplight(position)<='0';uplight(position)<='0'; elsif f1up='1' then uplight(1)<='1'; elsif f2up='1' then uplight(2)<='1'; elsif f3up='1' then uplight(3)<='1'; elsif f4up='1' then uplight(4)<='1'; end if; if cleardn='1' then stoplight(position)<='0';dnlight(position)<='0'; elsif f2down='1' then dnlight(2)<='1'; elsif f3down='1' then dnlight(3)<='1'; elsif f4down='1' then dnlight(4)<='1'; elsif f5down='1' then dnlight(5)<='1'; end if; if stop1='1' then stoplight(1)<='1'; elsif stop2='1' then stoplight(2)<='1'; elsif stop3='1' then stoplight(3)<='1'; elsif stop4='1' then stoplight(4)<='1'; elsif stop5='1' then stoplight(5)<='1'; end if; end if; end process controllight; end behav; 其他的分频器模块和译码模块我就不写了,能否请大神给我解释一下为什么我的电梯会自己到二楼然后在开门和关门之间循环,一开始我的设定他应该不动才对啊,好像整个程序从来都没有进入if stoplight="00000" and uplight="00000" and dnlight ="00000" then updown<='1';mylift<=doorclose;这一句一样。 |
|
相关推荐
|
|
矩阵4x4个按键,如何把识别结果按编号01-16(十进制)显示在两个七段数码管上?
636 浏览 0 评论
848 浏览 0 评论
1703 浏览 0 评论
456 浏览 0 评论
634 浏览 0 评论
1218 浏览 23 评论
5451 浏览 113 评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-3 11:07 , Processed in 0.563984 second(s), Total 69, Slave 51 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号