由表可知,74161具有以下功能:
① 异步清零。当RD=0时,不管其他输入端的状态如何,不论有无时钟脉冲CP,计数器输出将被直接置零(Q3Q2QlQ0=0000),称为异步清零。
② 同步并行预置数。当RD=1、LD=0时,在输入时钟脉冲CP上升沿的作用下,并行输入端的数据d3d2d1d0被置入计数器的输出端,即Q3Q2QlQ0=d3d2d1d0。由于这个操作要与CP上升沿同步,所以称为同步预置数。
③ 计数。当RD=LD=EP=ET=1时,在CP端输入计数脉冲,计数器进行二进制加法计数。
④ 保持。当RD=LD=1,且 =0,即两个使能端中有0时,则计数器保持原来的状态不变。这时,如EP=0、ET=1,则进位输出信号RCO保持不变;如ET=0则不管EP状态如何,进位输出信号RCO为低电平0。
LIBRARY ieee;
USE ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.Std_logic_arith.all;
entity a74161 IS
port(ep,et,rd,rco,ld ,clk: in std_logic;
d: in std_logic_vector(3 downto 0);
y : out std_logic_vector(3 downto 0));
end a74161 ;
architecture behave of a74161 is
signal sel:std_logic;
begin
sel<=rd;
process (rd,ld,ep,et,clk)
variable temp: std_logic_vector(3 downto 0);
variable c: std_logic;
begin
if(rd='0') then temp(3 downto 0):="0000";
elsif (ld='0' and rd='1') then
if(clk'event and clk='1' )then temp:=d;
end if;
elsif (ld='1' and rd='1'and ep='1' and et ='1')then
if(clk'event and clk='1' )then
if(temp="1111")then temp:="0000";
c:='1';
else temp:=temp+1;c:='0';
end if ;
end if;
elsif (ld='1' and rd='1'and et ='0')then c:='0';
end if;
y<=temp;--rco<=c;
end process;
end behave;
(1)异步清零。当RD=0时即刻清零,与其他输入状态及CP无关。
(2)S1、S0是控制输入。当RD=1时74194有如下4种工作方式:
①当S1S0=00时,不论有无CP到来,各触发器状态不变,为保持工作状态。
②当S1S0=01时,在CP的上升沿作用下,实现右移(上移)操作,流向是SR→Q0→Q1→Q2→Q3。
③当S1S0=10时,在CP的上升沿作用下,实现左移(下移)操作,流向是SL→Q3→Q2→Q1→Q0。
④当S1S0=11时,在CP的上升沿作用下,实现置数操作:D0→Q0,D1→Q1,D2→Q2,D3→Q3。
library ieee;
use ieee.std_logic_1164.all;
package shift_types is
subtype bit4 is std_logic_vector(3 downto 0);
end shift_types;
use work.shift_types.all;
library ieee;
use ieee.std_logic_1164.all;
---------------------------
entity shifter is
---------------------------
port(
din:in bit4;
clk,rd,s1,s0: in std_logic;
dout: buffer bit4);
end shifter;
-----------------------------------------
architecture synth of shifter is
----------------------------------------
signal shift_val: bit4;
begin
nxt:process(rd,s1,s0,din,dout)
begin
if(rd = '0') then
shift_val(3 downto 0) <= "0000";
elsif(s1 = '0'AND s0 = '0') then
shift_val(3 downto 0)<= shift_val(3 downto 0);
elsif(s1 = '1'AND s0 = '0') then
shift_val(2 downto 0) <= shift_val(3 downto 1);
shift_val(3)<='0';
elsif(s1 = '0'AND s0 = '1') then
shift_val(3 downto 1) <= shift_val(2 downto 0);
shift_val(0) <='0';
elsif(s1 = '1'AND s0 = '1') then
shift_val(3 downto 0)<=din(3 downto 0);
end if;
end process;
current : process(clk)
begin
-- wait until clk'event and clk = '1';
if(clk'event and clk='1' ) then
dout(3 downto 0) <= shift_val(3 downto 0);--dout<=(others=>'Z');
else dout<=(others=>'Z');
end if;
end process;
end synth;
都有错误,第二个是inout的问题。
回答楼主
LIBRARY ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.Std_logic_arith.all;
entity a74161 IS
port(ep : in std_logic;
et : in std_logic;
rd : in std_logic;
ld : in std_logic;
clk : in std_logic;
d : in std_logic_vector(3 downto 0);
rco : out std_logic;
y : out std_logic_vector(3 downto 0)
);
end a74161;
architecture behave of a74161 is
signal temp : std_logic_vector(3 downto 0);
-- signal sel : std_logic;
begin
-- sel <=rd;
process (rd, clk)
begin
if (rd = '0') then
temp <= (others => '0');
elsif ( clk'event and clk = '1') then
if (ld = '0' and rd = '1') then
temp <= d;
elsif (ld = '1' and rd = '1') then
if (ep = '1' and et = '1') then
temp <= temp + 1;
elsif (et = '0') then
rco <= '0';
end if;
end if;
end if;
y <= temp;
end process;
end behave;
library ieee;
use ieee.std_logic_1164.all;
---------------------------
entity shifter is
---------------------------
port (
din : in std_logic_vector(3 downto 0);
clk : in std_logic;
rd : in std_logic;
s1 : in std_logic;
s0 : in std_logic;
dout : out std_logic_vector(3 downto 0)
);
end shifter;
-----------------------------------------
architecture synth of shifter is
-----------------------------------------
signal shift_val : std_logic_vector(3 downto 0);
begin
nxt : process (rd, clk)
begin
if (rd = '0') then
shift_val(3 downto 0) <= (others => '0');
elsif (clk'event and clk = '1') then
if (s1 = '0' and s0 = '0') then
shift_val <= shift_val(3 downto 0);
elsif (s1 = '1' and s0 = '0') then
shift_val <= shift_val(3 downto 1) & '0';
elsif (s1 = '0' and s0 = '1') then
shift_val <= '0' & shift_val(2 downto 0);
elsif (s1 = '1' and s0 = '1') then
shift_val(3 downto 0) <= din(3 downto 0);
end if;
end if;
end process;
--current : process (clk)
--begin
-- wait until clk'event and clk = '1';
-- if (clk'event and clk = '1') then
-- dout(3 downto 0) <= shift_val(3 downto 0);
-- dout <=(others=>'Z');
-- else
-- dout <= (others => 'Z');
-- end if;
--end process;
end synth;
汗。。
这么长。。
aaronstone 辛苦了。。
疑问:1.74161中co进位端的作用似乎没体现?
2.74194中这句
elsif (clk'event and clk = '1') then
if (s1 = '0' and s0 = '0') then
shift_val <= shift_val(3 downto 0);
与原意的“①当S1S0=00时,不论有无CP到来,各触发器状态不变,为保持工作状态。 ”似乎不相符吧?