求助:程序不受按键控制

2012年09月17日 15:56    发布者:zhangjin1986
各位大侠,我遍了个程序,达到的目标是:第一部分将输入的1KHz分频为1Hz;第二部分是通过按键按一下,将输入的1KHz变为250Hz,再按下,变为125Hz。
Library IEEE;
Use IEEE.Std_logic_1164.all;
Use IEEE.Std_logic_unsigned.all;
Entity yh is
  Port(xh: in std_logic;
      clk:out std_logic);
End yh;
Architecture fun of yh is
  Signal clk_1s: Std_logic;
Begin
  process(xh)
    variable count:Std_logic_vector(9 downto 0);
  Begin
      wait on xh until xh='1';
      count:=count+1;
      clk_1s<=count(9);
   end process;()
clk<=clk_1s;
end fun;(这是第一部分)

library IEEE;
use IEEE.std_logic_1164.all;
use IEEE.std_logic_arith.all;
use IEEE.std_logic_unsigned.all;
Entity fp is
   port( xh:in std_logic;
         ds:in std_logic;
         clk:in std_logic;
         sc:out std_logic);
End fp;
Architecture fenpin of fp is
  Signal data:std_logic_vector(2 downto 0);
  Signal cnt:integer range 0 to 2;
  Signal zhja:std_logic;
  begin
    zhja<=NOT((ds or clk));
    yi:process(xh)
      begin
        if(xh'event and xh='1') then
          data<=data+1;
        end if;
     end process;
   er:process(zhja)
     begin
       if(zhja='1') then
         if(cnt=2) then cnt<=0;
         else  cnt<=cnt+1;
         end if;
       end if;
     end process;
  san:process(cnt,data)
     begin
       case cnt is
       when 0=>sc<=data(1);
       when 1=>sc<=data(2);
       when others=>NULL;
       end case;
     end process;
end fenpin;(这是第二部分)
.gcf文件上传至附件中。第一部分与第二部分中的xh是同一个输入信号1KHz,第二部分中输入clk就是第一部分中输出clk,第二部分中ds就是按键(不按高电平,按下低电平)。程序运行后,sc输出125Hz,过一秒后变为250Hz,再过一秒变为125Hz.....就是说不受按键的控制。这是为什么?请各位大侠指点。谢谢!

网友评论

asyou 2012年09月18日
时钟要取沿!
ty1932 2012年09月29日
顶一个