architecture Behavioral of led1 is signal Cnt : std_logic_vector(3 downto 0); signal Clk_cnt : std_logic_vector(21 downto 0); signal key_cnt : std_logic_vector(20 downto 0); signal Clk2 : std_logic; signal cnt2 : std_logic_vector(1 downto 0); signal Led_t1 : std_logic_vector(7 downto 0); signal Key : std_logic; signal key_push : std_logic; begin
process(Rst,Clk) ----时钟分频,将40Mhz时钟分频 得到clk2 begin if Rst='0' then Clk_cnt<=(others=>'0'); Clk2<='0'; elsif Clk'event and Clk='1' then if Clk_cnt="1111111111111111111111" then Clk2<=not Clk2; Clk_cnt<=(others=>'0'); else Clk_cnt<=Clk_cnt+1; end if; end if; end process;
process(Clk) ----按键消除抖动进程 begin if(clk'event and clk='1')then key<=Key1; if(key='1')then key_cnt<=(others=>'0'); elsif(key_cnt(20)='0')then key_cnt<=key_cnt+1; end if; end if; end process;
key_push<=key_cnt(20); --将按键信息赋予key_push
process(key_push,clk2)--啊,啊这个进程太难把握了.....使得按键总有冲突 begin if (key_push='1' and clk2='1') then cnt2<=cnt2+1; else null; end if; end process;
led_t1<="01000001" when cnt2="00" else--小灯随cnt2改变而改变 "11000011" when cnt2="01" else "11000111" when cnt2="10" else "11001111";