|
各位大俠,我遍了個(gè)程序,達(dá)到的目標(biāo)是:第一部分將輸入的1KHz分頻為1Hz;第二部分是通過按鍵按一下,將輸入的1KHz變?yōu)?50Hz,再按下,變?yōu)?25Hz。
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是同一個(gè)輸入信號(hào)1KHz,第二部分中輸入clk就是第一部分中輸出clk,第二部分中ds就是按鍵(不按高電平,按下低電平)。程序運(yùn)行后,sc輸出125Hz,過一秒后變?yōu)?50Hz,再過一秒變?yōu)?25Hz.....就是說不受按鍵的控制。這是為什么?請(qǐng)各位大俠指點(diǎn)。謝謝!
|
|