1个回答
2013-06-03
展开全部
下面是我写的一个例子,是通过c1,c2按键控制加数和被加数的。由于最近要考试,所有按键没有进行消抖,as控制加还是减。你没有说全加,进位我省了。如果需要自己加一下。
另外注意:
在可逆计数器的设计中的错误,两个进程里都有同一个条件判断的话,会产生并行信号冲突的问题。同一个信号不允许在多个进程中赋值,否则则为多驱动。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity adderOrsubber is
port(
clk:in std_logic;
rst:in std_logic;--fuwei
rec:in std_logic;--zhishu
as:in std_logic; -- add or sub
c1,c2:in std_logic;--control num1,num2
zhishu:in std_logic_vector(7 downto 0);
resultnum:out std_logic_vector(7 downto 0)
);
end;
architecture one of adderOrsubber is
signal num1,num2: std_logic_vector(7 downto 0);
signal tempnum : std_logic_vector(7 downto 0);
signal flag:std_logic:='0';
begin
resultnum<=tempnum;
--control num1 num2;
--zhi 0
process(rst,clk)
begin
if(rst = '0') then
num1<="00000000";
num2<="00000000";
elsif (rising_edge(clk)) then
if(c1='0') then
num1<=num1+1;
elsif(c2='0') then
num2<=num2+1;
end if;
end if;
end process;
--and or sub
process(as)
begin
if(as = '0')
then flag <= not flag;
end if;
end process;
--figure zhishu
process(num1,num2,flag,rec,clk)
begin
if rising_edge(clk) then
if(rec ='0') then
tempnum<=zhishu;
elsif(flag = '0') then
tempnum<=num1+num2;
elsif(flag = '1') then
tempnum <= num1-num2;
end if;
end if;
end process;
end one;
另外注意:
在可逆计数器的设计中的错误,两个进程里都有同一个条件判断的话,会产生并行信号冲突的问题。同一个信号不允许在多个进程中赋值,否则则为多驱动。
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
use ieee.std_logic_arith.all;
entity adderOrsubber is
port(
clk:in std_logic;
rst:in std_logic;--fuwei
rec:in std_logic;--zhishu
as:in std_logic; -- add or sub
c1,c2:in std_logic;--control num1,num2
zhishu:in std_logic_vector(7 downto 0);
resultnum:out std_logic_vector(7 downto 0)
);
end;
architecture one of adderOrsubber is
signal num1,num2: std_logic_vector(7 downto 0);
signal tempnum : std_logic_vector(7 downto 0);
signal flag:std_logic:='0';
begin
resultnum<=tempnum;
--control num1 num2;
--zhi 0
process(rst,clk)
begin
if(rst = '0') then
num1<="00000000";
num2<="00000000";
elsif (rising_edge(clk)) then
if(c1='0') then
num1<=num1+1;
elsif(c2='0') then
num2<=num2+1;
end if;
end if;
end process;
--and or sub
process(as)
begin
if(as = '0')
then flag <= not flag;
end if;
end process;
--figure zhishu
process(num1,num2,flag,rec,clk)
begin
if rising_edge(clk) then
if(rec ='0') then
tempnum<=zhishu;
elsif(flag = '0') then
tempnum<=num1+num2;
elsif(flag = '1') then
tempnum <= num1-num2;
end if;
end if;
end process;
end one;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询