【正文】
timer: counter port map(clk= clk1hz,preset=close,clr=clrstop,en=enstop,q=opentime)。end bhv。計(jì)數(shù)器library ieee。use 。use 。use 。entity counter isport ( clk: in std_logic。 preset: in std_logic。 clr: in std_logic。 en: in std_logic。 q: out std_logic_vector( 2 downto 0))。end。architecture bhv of counter issignal temp: std_logic_vector( 2 downto 0)。begin q=temp。process( clk,preset,clr,en)begin if clr=39。139。 then temp=000。 elsif rising_edge( clk) then if preset =39。139。 then temp=101。 elsif en=39。139。 then if temp=101 then temp=temp。 else temp=temp+39。139。 end if。 end if。 end if。end process。end。分控制器程序library ieee。use 。use 。use 。entity subcontroller is port(clk:in std_logic。 switch:in std_logic。 qin:in std_logic_vector(16 downto 1)。 opendoor:in std_logic。 upkey:in std_logic。 downkey:in std_logic。 ur:out std_logic。 dr:out std_logic。 disp0:out std_logic_vector(3 downto 0)。 disp1:out std_logic_vector(3 downto 0))。end subcontroller。architecture bhv of subcontroller isconstant id:std_logic_vector(16 downto 1):=0000000000001000。signal upkey_d:std_logic。signal downkey_d:std_logic。signal opendoor1:std_logic。 signal opendoor2:std_logic。signal opendoor_r:std_logic。 signal ur_r:std_logic。 signal dr_r:std_logic。signal disp:std_logic_vector(7 downto 0)。begin process(clk) begin if rising_edge(clk) then upkey_d=upkey。 downkey_d=downkey。 opendoor2=opendoor1。 opendoor1=opendoor。 end if。 end process。 opendoor_r=opendoor1 and not(opendoor2)。 process(switch,clk) begin if switch=39。039。 then ur_r=39。039。 dr_r=39。039。 elsif rising_edge(clk) then if opendoor_r=39。139。 and qin=id then ur_r=39。039。 dr_r=39。039。 elsif upkey=39。139。 and upkey_d=39。039。 then ur_r=39。139。 elsif downkey=39。139。 and downkey_d=39。039。 then dr_r=39。139。 end if。 end if。 end process。 ur=ur_r。 dr=dr_r。 with qin select disp=00000001when0000000000000001, 00000010when0000000000000010, 00000011when0000000000000100, 00000100when0000000000001000, 00000101when0000000000010000, 00000110when0000000000100000, 00000111when0000000001000000, 00001000when0000000010000000, 00001001when0000000100000000, 00010000when0000001000000000, 00010001when0000010000000000, 00010010when0000100000000000, 00010011when0001000000000000, 00010100when0010000000000000, 00010101when0100000000000000, 00010110when1000000000000000, 00000000when others。 disp0=disp(3 downto 0)。 disp1=disp(7 downto 4)。end