像这样的东西(警告它没有被调试,它分析和阐述)。
这表明存在用于显示数字的寄存器,并且旋转功能在这些寄存器的输出和驱动的显示数字端口之间运行。
rot_select 当然可以与写指针分开。
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all; -- TO_INTEGER
entity rot_digits is
port (
-- the 8 7-segment display with defaults for simulation visibility.
dp0: out std_logic_vector (6 downto 0) := "0000001"; -- 0
dp1: out std_logic_vector (6 downto 0) := "1001111"; -- 1
dp2: out std_logic_vector (6 downto 0) := "0010010"; -- 2
dp3: out std_logic_vector (6 downto 0) := "0000110"; -- 3
dp4: out std_logic_vector (6 downto 0) := "1001100"; -- 4
dp5: out std_logic_vector (6 downto 0) := "0100100"; -- 5
dp6: out std_logic_vector (6 downto 0) := "0100000"; -- 6
dp7: out std_logic_vector (6 downto 0) := "0001111"; -- 7
-- rotation select, also used for write pointer
rot_select: in std_logic_vector(2 downto 0);
wr_enab: in std_logic;
reset: in std_logic;
switch: in std_logic_vector(1 downto 0)
);
type display8 is array (integer range 0 to 7) of
std_logic_vector(6 downto 0);
constant H: std_logic_vector (6 downto 0) := "1001000"; -- H
constant E: std_logic_vector (6 downto 0) := "0110000"; -- E
constant L: std_logic_vector (6 downto 0) := "1110001"; -- L
constant O: std_logic_vector (6 downto 0) := "0000001"; -- O (0)
constant ERR: std_logic_vector (6 downto 0) := "0110110"; -- error
constant BLANK: std_logic_vector (6 downto 0) := "1111111";
end entity;
architecture foo of rot_digits is
-- digit is (a,b,c,d,e,f,g) 6 downto 0, '0' for ON (sink)
-- a
-- f b
-- g
-- e c
-- d
-- (d0,d1,d2,d3,d4,d5,d6,d7) are register values for stored digits
signal d0: std_logic_vector (6 downto 0);
signal d1: std_logic_vector (6 downto 0);
signal d2: std_logic_vector (6 downto 0);
signal d3: std_logic_vector (6 downto 0);
signal d4: std_logic_vector (6 downto 0);
signal d5: std_logic_vector (6 downto 0);
signal d6: std_logic_vector (6 downto 0);
signal d7: std_logic_vector (6 downto 0);
function "ror" (l: display8; r: std_logic_vector(2 downto 0))
return display8 is
variable rot: integer range 0 to 7;
begin
if IS_X(TO_X01(r)) then -- unknown defaults to 0 rotation
rot := 0;
else
rot := to_integer(unsigned(r));
end if;
case rot is
when 0 => return l;
when 1 => return
display8'(l(0),l(7),l(6),l(5),L(4),l(3),l(2),l(1));
when 2 => return
display8'(l(1),l(0),l(7),l(6),l(5),L(4),l(3),l(2));
when 3 => return
display8'(l(2),l(1),l(0),l(7),l(6),l(5),L(4),l(3));
when 4 => return
display8'(l(3),l(2),l(1),l(0),l(7),l(6),l(5),L(4));
when 5 => return
display8'(l(4),l(3),l(2),l(1),l(0),l(7),l(6),l(5));
when 6 => return
display8'(l(5),l(4),l(3),l(2),l(1),l(0),l(7),l(6));
when 7 => return
display8'(l(6),l(5),l(4),l(3),l(2),l(1),l(0),l(7));
end case;
end function;
signal selected: std_logic_vector (6 downto 0);
begin
SEL:
selected <= H when switch = "00" else
E when switch = "01" else
L when switch = "10" else
O when switch = "11" else
ERR;
ROTATE:
(dp0,dp1,dp2,dp3,dp4,dp5,dp6,dp7)
<= display8'(d0,d1,d2,d3,d4,d5,d6,d7) ror rot_select;
Display_Registers:
process (wr_enab,reset, switch)
begin
if (reset = '1') then
(d0,d1,d2,d3,d4,d5,d6,d7) <= display8'(others => BLANK);
elsif (wr_enab = '1') then
case rot_select is
when "000" => d0 <= selected;
when "001" => d1 <= selected;
when "010" => d2 <= selected;
when "011" => d3 <= selected;
when "100" => d4 <= selected;
when "101" => d5 <= selected;
when "110" => d6 <= selected;
when "111" => d7 <= selected;
when others =>
(d0,d1,d2,d3,d4,d5,d6,d7) <= display8'(others => ERR);
end case;
end if;
end process;
end architecture;
ERR 分配将显示 rot_select 或 switch 向量中存在“0”或“1”以外的值。应该是三个单杠。
根据定义,将并发信号分配给显示数字输出端口有一个等效的过程。您也可以让该过程在没有新声明的“ror”移位运算符的情况下执行旋转。