查看: 5110|回复: 2

[提问] 求助:程序不受按键控制

[复制链接]
发表于 2012-9-17 15:56:37 | 显示全部楼层 |阅读模式
关键词: 按键 , 分频
各位大侠,我遍了个程序,达到的目标是:第一部分将输入的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.....就是说不受按键的控制。这是为什么?请各位大侠指点。谢谢!

tu.bmp
发表于 2012-9-18 09:25:40 | 显示全部楼层
时钟要取沿!
发表于 2012-9-29 21:05:51 | 显示全部楼层
顶一个
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们  -  服务条款  -  使用指南  -  站点地图  -  友情链接  -  联系我们
电子工程网 © 版权所有   京ICP备16069177号 | 京公网安备11010502021702
快速回复 返回顶部 返回列表