?? reg_shift.vhd
字號:
--** 移位寄存器 **--
--文件名:reg_shift.vhd
--功 能:移位寄存器
--說 明:“data”采用八位撥盤開關來置入數據;
-- “q”中的數據每秒中移動一次,采用發光二極管來表示;
-- “enable”作為數據的輸入使能,用按鍵來表示,當按鍵按下去時載入撥盤開關中的數據,松開按鍵后數據開始移位;
--**注意:按鍵是'0'有效,默認是'1'電平; 片選信號(cs)為高電平選通;
-------------------------------------------------------------------------------------------------
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_ARITH.ALL;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity reg_shift is
Port (datain : in std_logic_vector(7 downto 0);
clk : in std_logic;
enable : in std_logic;
cs : out std_logic_vector(1 downto 0);
q : out std_logic_vector(7 downto 0));
end reg_shift;
architecture Behavioral of reg_shift is
signal clk1Hz : std_logic;
begin
cs<="01";
process(clk) --分頻器——產生1Hz的時鐘脈沖;
variable cnt : integer range 0 to 50000000;
begin
if clk'event and clk='1' then cnt:=cnt+1;
if cnt<25000000 then clk1Hz<='1';
elsif cnt<50000000 then clk1Hz<='0';
else cnt:=0;clk1Hz<='0';
end if;
end if;
end process;
process(enable,clk1Hz,datain) --移位寄存器;
variable data_temp : std_logic_vector(7 downto 0);
begin
if enable='0' then data_temp:=datain;
elsif clk1Hz'event and clk1Hz='1' then --每過一秒數據向高位移動一位;
data_temp:=data_temp(6 downto 0)&data_temp(7);
end if;
q<=data_temp;
end process;
end Behavioral;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -