文档库

最新最全的文档下载
当前位置:文档库 > 保险箱程序

保险箱程序

library ieee;

use ieee.std_logic_1164.all;

use ieee.std_logic_unsigned.all;

entity mimasuo is

port (clk0,clk: in std_logic;

key1,key2,key3,key4,key5,key6,key7,key8: in std_logic;--key5开key6重设key7关key8解报警

q1,q2,q3,q4 :out std_logic_vector(3 downto 0);

spk, led_g,led_r,led2,led: out std_logic);

end mimasuo;

architecture behav of mimasuo is

signal mima1 :std_logic_vector(3 downto 0) := "0001";

signal mima2 :std_logic_vector(3 downto 0) := "0001";

signal mima3 :std_logic_vector(3 downto 0) := "0001";

signal mima4 :std_logic_vector(3 downto 0) := "0001";

signal jishi :std_logic_vector(3 downto 0);

signal jishi_m :std_logic_vector(10 downto 0);

signal jishi_20 :std_logic_vector(4 downto 0);

signal bit_led2,bit_jishi :std_logic :='0';

signal kai :std_logic :='0';

signal q,b:std_logic;

signal chufa :std_logic :='0';

signal baojing :std_logic :='0';

signal chushihua:std_logic :='0';

signal buff:std_logic_vector(15 downto 0);

signal cq1,cq2,cq3,cq4:std_logic_vector(3 downto 0);

begin

process(clk,key6,key1,key2,key3,key4)

begin

if baojing ='0' and key6='1' and kai='1' then

if key1'event and key1='1' then

if mima1 < 9 then mima1<=mima1+1;

else mima1 <= (others =>'0');

end if;

end if;

if key2'event and key2='1' then

if mima2 < 9 then mima2<=mima2+1;

else mima2 <= (others =>'0');

end if;

end if;

if key3'event and key3='1' then

if mima3 < 9 then mima3<=mima3+1;

else mima3 <= (others =>'0');

end if;

end if;

if key4'event and key4='1' then

if mima4 < 9 then mima4<=mima4+1;

else mima4 <= (others =>'0');

end if;

end if;

else

if baojing ='0' and key6='0' and key5='0' then if key1'event and key1='1' then

if cq1 < 9 then cq1<=cq1+1;

else cq1 <= (others =>'0');

end if;

end if;

if key2'event and key2='1' then

if cq2 < 9 then cq2<=cq2+1;

else cq2 <= (others =>'0');

end if;

end if;

if key3'event and key3='1' then

if cq3 < 9 then cq3<=cq3+1;

else cq3 <= (others =>'0');

end if;

end if;

if key4'event and key4='1' then

if cq4 < 9 then cq4<=cq4+1;

else cq4 <= (others =>'0');

end if;

end if;

end if;

end if;

if key6='1' and kai='1' then

q1 <= mima1;

q2 <= mima2;

q3 <= mima3;

q4 <= mima4;

end if;

if key6='0' and kai='0' then

q1 <= cq1;

q2 <= cq2;

q3 <= cq3;

q4 <= cq4;

end if;

if key6='0' and kai='1' then

q1 <= "0000";

q2 <= "0000";

q3 <= "0000";

q4 <= "0000";

end if;

end process;

process(clk,key5,key7)

begin

if clk'event and clk ='1' then

if key5='1' and baojing ='0' and key6='0' then

if mima1 = cq1 and mima2 = cq2 and mima3 = cq3 and mima4 = cq4 then

kai<='1';

else kai<='0';

end if;

end if;

if kai='1' then

led_g <='1'; led_r <='0';

else led_g <='0'; led_r <='1';

end if;

if key7='1' and key6='0' then

kai <='0';

end if;

end if;

end process;

process(key5,key8)

begin

if key5'event and key5='1' then

if chushihua = '0' then

chushihua <='1';

end if;

end if;

if key8='1' then chushihua<='0';

end if;

end process;

process(clk,key8,key5,key6)

begin

if clk'event and clk='1' then

if baojing='0' and chushihua = '1' and kai='0' then

if jishi<6 then jishi <= jishi+1;

--else jishi<="0000";

end if;

if jishi=5 and kai='0' then

baojing <='1';

end if;

end if;

if jishi<5 and kai='1' then

jishi<="1111";

end if;

if key8='1' then

baojing<='0';

end if;

end if;

if key5='1' then jishi<="0000";

end if;

if key6='1' then jishi<="1111";

end if;

end process;

process(clk,key8,key5,key6)

begin

if clk'event and clk='1' then

if baojing='1' then

if jishi_20<20 then--计时20秒

jishi_20<=jishi_20+1;

led<='1';b<='1';

else led<='0';b<='0';--jishi_20<="00000";

end if;

bit_led2<= not bit_led2;--闪烁报警

if bit_led2 = '1' then led2<='1';

else led2<='0';

end if;

end if;

if baojing='0' then

led2<='0'; led<='0'; bit_led2<='0';

b<='0';

end if;

end if;

if key5='1' then jishi_20<="00000";

end if;

if key6='1' then jishi_20<="11111";

end if;

end process;

process(clk0,b)

begin

if b='1' then

if clk0'event and clk0='1' then--蜂鸣器分频

q<=not q;

end if;

if q='1' then spk<='1';--蜂名气报警

else spk<='0';

end if;

END IF;

end process;

end behav;