diantikongzhiqi.docx
- 文档编号:9991493
- 上传时间:2023-02-07
- 格式:DOCX
- 页数:15
- 大小:132.45KB
diantikongzhiqi.docx
《diantikongzhiqi.docx》由会员分享,可在线阅读,更多相关《diantikongzhiqi.docx(15页珍藏版)》请在冰豆网上搜索。
diantikongzhiqi
一个VHDL电梯控制器的程序
1、 每层电梯的入口处设有上下请求开关,电梯内设有乘客到达层次的停站请求开关。
2、 设有电梯所处位置指示装置及电梯运行模式(上升或下降)指示装置。
3、 电梯每秒升降一层。
4、 电梯到达有停站请求的楼层后,经过1s电梯打开,开门只是灯亮,开门4s后,电梯门关闭(关门指示灯灭),电梯继续运行,直至执行完请求信号后停在当前楼层。
5、 能记忆电梯内外的所以请求信号,并按照电梯运行规则依次响应,每个请求信号保留至执行后消除。
6、 电梯运行规则:
当电梯处于上升模式时,只响应比电梯所在位置高的上楼信号,由下至上依次执行,直到最后一个上楼请求执行完毕,如更高层有下楼请求时,则直接升到有下降请求的最高楼接客,然后进入下降模式,但电梯处于下降模式时,则与上升模式相反。
7、 电梯初始状态为一层门开。
libraryieee;
useieee.std_logic_1164.all;
useieee.std_logic_unsigned.all;
entityled1is
port(ledin:
instd_logic_vector(3downto0);
ledout:
outstd_logic_vector(6downto0));
endled1;
architecturea_ledofled1is
begin
process(ledin)
begin
caseledinis--Thesequenceis"gfedcba"
when"0000"=>ledout<="0111111";--"show0"
when"0001"=>ledout<="0000110";--"show1"
when"0010"=>ledout<="1011011";--"show2"
when"0011"=>ledout<="1001111";--"show3"
when"0100"=>ledout<="1100110";--"show4"
when"0101"=>ledout<="1101101";--"show5"
when"0110"=>ledout<="1111101";--"show6"
when"0111"=>ledout<="0000111";--"show7"
when"1000"=>ledout<="1111111";--"show8"
when"1001"=>ledout<="1101111";--"show9"
when"1010"=>ledout<="1110111";--"show10"
when"1011"=>ledout<="1111100";--"show11"
when"1100"=>ledout<="0111001";--"show12"
when"1101"=>ledout<="1011110";--"show13"
when"1110"=>ledout<="1111001";--"show14"
when"1111"=>ledout<="1110001";--"show15"
whenothers=>ledout<="XXXXXXX";--必须有,Hereitis'X',singlequote
endcase;
endprocess;
enda_led;
libraryIEEE;
useIEEE.std_logic_1164.all;
useIEEE.std_logic_arith.all;
useIEEE.std_logic_unsigned.all;
entitylift1is
port(
clk:
inSTD_LOGIC;--2hz信号
upin:
inSTD_LOGIC;--上升请求键
downin:
inSTD_LOGIC;--下降请求键
st_ch:
inSTD_LOGIC;--楼层选择键
close:
inSTD_LOGIC;--提前关门键
delay:
inSTD_LOGIC;--延时关门键
run_stop:
inSTD_LOGIC;--电梯运行开关
lamp:
outSTD_LOGIC;--运行或停止灯
run_waitdis:
outSTD_LOGIC_VECTOR(6downto0);--运行或等待时间
st_outdis:
outSTD_LOGIC_VECTOR(6downto0);--电梯所在楼层指示
directdis:
outSTD_LOGIC_VECTOR(6downto0)--楼层选择指示
);
endlift1;
architecturelift1_archoflift1is
componentled1
port(ledin:
instd_logic_vector(3downto0);
ledout:
outstd_logic_vector(6downto0));
endcomponent;
signalur,dr:
STD_LOGIC_VECTOR(6downto1);
signaldir,liftor:
integerrange0to5;
signalwai_t:
STD_LOGIC_VECTOR(2downto0);
signaldivide,hand,clkin:
STD_LOGIC;
signalladd:
STD_LOGIC_VECTOR(1downto0);
signalclosex,delayx:
STD_LOGIC;
signalrun_wait:
STD_LOGIC_VECTOR(3downto0);
signalst_out:
STD_LOGIC_VECTOR(3downto0);
signaldirect:
STD_LOGIC_VECTOR(3downto0);
begin
direct<='0'&conv_std_logic_vector(dir,3)+1;
st_out<='0'&conv_std_logic_vector(liftor,3)+1;
run_wait<='0'&wai_t;
lamp<=ladd
(1);
hand<=wai_t
(2)and(notwai_t
(1))andwai_t(0);
closex<=closeand(notladd
(1));
delayx<=delayand(notladd
(1));
urun_wait:
led1portmap(run_wait,run_waitdis);
ust_out:
led1portmap(st_out,st_outdis);
udirect:
led1portmap(direct,directdis);
p0:
process(clk)
begin
if(clk'eventandclk='1')then
clkin<=notclkin;
endif;
endprocessp0;
p1:
process(clkin)
begin
if(clkin'eventandclkin='1')then
divide<=notdivide;
if(dir=5)then
dir<=0;
else
dir<=dir+1;
endif;
endif;
endprocessp1;
p2:
process(ur,dr,dir,upin,downin,st_ch,liftor,wai_t,run_stop,hand)
variablenum,t:
integerrange0to6;
begin
num:
=liftor+1;
t:
=dir+1;
if(run_stop='1')then
if(((t>num)and(st_ch='1'))or(upin='1'))then
casetis
when1=>ur
(1)<='1';
when2=>ur
(2)<='1';
when3=>ur(3)<='1';
when4=>ur(4)<='1';
when5=>ur(5)<='1';
when6=>ur(6)<='1';
whenothers=>Null;
endcase;
elsif(hand='1')then
casenumis
when1=>ur
(1)<='0';
when2=>ur
(2)<='0';
when3=>ur(3)<='0';
when4=>ur(4)<='0';
when5=>ur(5)<='0';
when6=>ur(6)<='0';
whenothers=>Null;
endcase;
endif;
if(((t casetis when1=>dr (1)<='1'; when2=>dr (2)<='1'; when3=>dr(3)<='1'; when4=>dr(4)<='1'; when5=>dr(5)<='1'; when6=>dr(6)<='1'; whenothers=>Null; endcase; elsif(hand='1')then casenumis when1=>dr (1)<='0'; when2=>dr (2)<='0'; when3=>dr(3)<='0'; when4=>dr(4)<='0'; when5=>dr(5)<='0'; when6=>dr(6)<='0'; whenothers=>Null; endcase; endif; else ur<="000000"; dr<="000000"; endif; endprocessp2; p3: process(ur,dr,liftor,ladd,wai_t,run_stop) begin if(run_stop='1')then if(wai_t="110")then if((urordr)="000000")then ladd (1)<='0'; else caseliftoris when0=>if((ur (1)ordr (1))>'0')then ladd (1)<='0'; else ladd<="11"; endif; when1=>if((ur (2)ordr (2))>'0')then ladd (1)<='0'; elsif(((ladd(0)='1')and((ur(6downto3)ordr(6downto3))>"0000"))or((ur (1)ordr (1))='0'))then ladd<="11"; else ladd<="10"; endif; when2=>if((ur(3)ordr(3))>'0')then ladd (1)<='0'; elsif(((ladd(0)='1')and((ur(6downto4)ordr(6downto4))>"000"))or((ur(2downto1)ordr(2downto1))="00"))then ladd<="11"; else ladd<="10"; endif; when3=>if((ur(4)ordr(4))>'0')then ladd (1)<='0'; elsif(((ladd(0)='1')and((ur(6downto5)ordr(6downto5))>"00"))or((ur(3downto1)ordr(3downto1))="000"))then ladd<="11"; else ladd<="10"; endif; when4=>if((ur(5)ordr(5))>'0')then ladd (1)<='0'; elsif(((ladd(0)='1')and((ur(6)ordr(6))>'0'))or((ur(4downto1)ordr(4downto1))="0000"))then ladd<="11"; else ladd<="10"; endif; when5=>if((ur(6)ordr(6))>'0')then ladd (1)<='0'; else ladd<="10"; endif; whenothers=>null; endcase; endif; endif; else ladd<="00"; endif; endprocessp3; p4: process(divide,wai_t,ladd,closex,delayx) begin if(divide'eventanddivide='1')then if(wai_t="000"orclosex='1')then wai_t<="110"; else if(delayx='0')then wai_t<=wai_t-1; else wai_t<="010"; endif; if(wai_t="001")then if(ladd="11")then liftor<=liftor+1; elsif(ladd="10")then liftor<=liftor-1; endif; endif; endif; endif; endprocessp4; endlift1_arch; libraryIEEE; useIEEE.std_logic_1164.all; useIEEE.std_logic_arith.all; useIEEE.std_logic_unsigned.all; entitylifteris port( clk: inSTD_LOGIC;--4mhz信号 upin: inSTD_LOGIC;--上升请求键 downin: inSTD_LOGIC;--下降请求键 st_ch: inSTD_LOGIC;--楼层选择键 close: inSTD_LOGIC;--提前关门键 delay: inSTD_LOGIC;--延时关门键 run_stop: inSTD_LOGIC;--电梯运行开关 lamp: outSTD_LOGIC;--运行或停止灯 selout: outSTD_LOGIC_VECTOR(2downto0); segout: outSTD_LOGIC_VECTOR(6downto0) ); endlifter; architecturelift1_archoflifteris componentled1 port(ledin: instd_logic_vector(3downto0); ledout: outstd_logic_vector(6downto0)); endcomponent; signalur,dr: STD_LOGIC_VECTOR(6downto1); signaldir,liftor: integerrange0to5; signalwai_t: STD_LOGIC_VECTOR(2downto0); signaldiv,cp,hand,clkin: STD_LOGIC; signalladd,s: STD_LOGIC_VECTOR(1downto0); signalclosex,delayx: STD_LOGIC; signalrun_wait: STD_LOGIC_VECTOR(3downto0); signalst_out: STD_LOGIC_VECTOR(3downto0); signaldirect: STD_LOGIC_VECTOR(3downto0); signaldout: STD_LOGIC_VECTOR(3downto0); signalq: STD_LOGIC_VECTOR(21downto0); begin direct<='0'&conv_std_logic_vector(dir,3)+1; st_out<='0'&conv_std_logic_vector(liftor,3)+1; run_wait<='0'&wai_t; lamp<=ladd (1); hand<=wai_t (2)and(notwai_t (1))andwai_t(0); closex<=(notclose)and(notladd (1)); delayx<=(notdelay)and(notladd (1)); selout<="001"whens=0else "010"whens=1else "100"whens=2else "000"; dout<=directwhens=0else run_waitwhens=1else st_outwhens=2else "0000000"; u: led1portmap(dout,segout); p0: process(clk) begin if(clk'eventandclk='1')then q<=q+1; endif; endprocessp0; cp<=q(20); s<=q(14downto13); p1: process(cp) begin if(cp'eventandcp='1')then div<=notdiv; if(dir=5)then dir<=0; else dir<=dir+1; endif; endif; endprocessp1; p2: process(ur,dr,dir,upin,downin,st_ch,liftor,wai_t,run_stop,hand) variablenum,t: integerrange0to6; begin num: =liftor+1; t: =dir+1; if(run_stop='1')then if(((t>num)and(st_ch='0'))or(upin='0'))then casetis when1=>ur (1)<='1'; when2=>ur (2)<='1'; when3=>ur(3)<='1'; when4=>ur(4)<='1'; when5=>ur(5)<='1'; when6=>ur(6)<='1'; whenothers=>Null; endcase; elsif(hand='1')then casenumis when1=>ur (1)<='0'; when2=>ur (2)<='0'; when3=>ur(3)<='0'; when4=>ur(4)<='0'; when5=>ur(5)<='0'; when6=>ur(6)<='0'; whenothers=>Null; endcase; endif; if(((t casetis when1=>dr (1)<='1'; when2=>dr (2)<='1'; when3=>dr(3)<='1'; when4=>dr(4)<='1'; when5=>dr(5)<='1'; when6=>dr(6)<='1'; whenothers=>Null; endcase; elsif(hand='1')then casenumis when1=>dr (1)<='0'; when2=>dr (2)<='0'; when3=>dr(3)<='0'; when4=>dr(4)<='0'; when5=>dr(5)<='0'; when6=>dr(6)<='0'; whenothers=>Null; endcase; endif; else ur<="000000"; dr<="000000"; endif; endprocessp2; p3: process(ur,dr,liftor,ladd,wai_t,run_stop) begin if(run_stop='1')then if(wai_t="110")then if((urordr)="000000")then ladd (1)<='0'; else caseliftoris when0=>if((ur (1)ordr (1))>'0')then ladd (1)<='0'; else ladd<="11"; endif; when1=>if((ur (2)ordr (2))>'0')then ladd (1)<='0'; elsif(((ladd(0)='1')and((ur(6downto3)ordr(6downto3))>"0000"))or((ur (1)ordr (1))='0'))then ladd<="11"; else ladd<="10"; endif; when2=>if((ur(3)ordr(3))>'0')then ladd (1)<='0'; elsif(((ladd(0)='1')and((ur(6downto4)ordr(6downto4))>"000"))or((ur(2downto1)ordr(2downto1))="00"))then ladd<="11"; else ladd<="10"; endif; when3=>if((ur(4)ordr(4))>'0')then ladd (1)<='0'; elsif(((ladd(0)='1')and((ur(6downto5)ordr(6downto5))>"00"))
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- diantikongzhiqi
![提示](https://static.bdocx.com/images/bang_tan.gif)