📄 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 + -