四位二进制同步减法计数器(异步清零、同步预置、下降沿触发、带借位输出BO端)
用ispLEVER编完。表示完全不会求大侠解救。重赏
只要用vhdl做四位二进制同步减法计数器(异步清零、同步预置、下降沿触发、带借位输出BO端)
就行了 追加!!
vhdl 四位二进制同步减法计数器(异步清零、同步预置、下降沿触发、带借位输出BO端)的实现,该程序已经仿真通过,产生的波形图如图所示。
源文件如下:
LIBRARY ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_arith.all;
use ieee.std_logic_unsigned.all;
--*------------------实体描述--------------------------*--
ENTITY sub_counter IS
PORT(clk : in std_logic; --输入时钟信号;
clr : in std_logic; --异步清零,低电平有效;
preset : in std_logic; --同步置位,低电平有效;
D : in std_logic_vector(3 downto 0); --4位的输入;
Q : out std_logic_vector(3 downto 0); --4位输出;
BO : out std_logic); --借位输出;
End sub_counter;
--*-------------------END-----------------------------*--
--*---------------结构体描述---------------------------*--
ARCHITECTURE arch OF sub_counter IS
signal i_cnt : std_logic_vector(3 downto 0); --用于暂时存储输出的信号
begin
P1 : process(clk,clr)
begin
if clr='0' then --因为是减法计数器,所以,清零后输出=1111;
i_cnt <= "1111";
BO <= '0';
elsif clk'event and clk='0' then
if preset='0' then
i_cnt <= D;
elsif preset='1' then
i_cnt <= i_cnt-1; --减法计数;
if i_cnt="0000" then
BO<= '1';
else
BO<= '0';
end if;
end if;
end if;
end process P1;
--进程P2将输出信号赋予真正的输出;如果输出不单列一个进程,那么仿真会出现错
--误,因为计数阶段不能直接读取输出Q的值。
P2 : process(i_cnt)
begin
Q <= i_cnt;
end process P2;
end arch;
--*-------------------------------------------------------*--
--*-------------------------------------------------------*--