VHDL语言编写一个一位10进制可逆计数器
来源:百度知道 编辑:UC知道 时间:2024/05/28 14:52:41
急
是用BCD码表示十进制吗?可以每四位分开看。
比如BCD码q(11 downto 0)可以表示0到999,前四位是个位,中四位是十位,后四位是百位。不知道对于溢出的有什么要求,我设成溢出后不做任何运算。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity add_sub is
port(
clk : in std_logic;
clr : in std_logic;
sl : in std_logic;
q : out std_logic_vector(11 downto 0));
end add_sub;
architecture add_sub_arc of add_sub is
signal cnt : std_logic_vector(11 downto 0);
begin
process(clk,clr,cnt)
begin
if clr = '0' then
cnt <= (others => '0');
elsif clk = '1' and clk'event then
if sl = '0' then -- adder
if cnt /= "100110011001" then