library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.std_logic_arith.all;
use IEEE.STD_LOGIC_UNSIGNED.ALL;
entity aaa is
Port (clk : in std_logic;
a :in std_logic_vector(7 downto 0);
b :in std_logic_vector(7 downto 0);
c :out std_logic_vector(7 downto 0)
);
end aaa;
architecture Behavioral of aaa is
begin
process(clk)
variable e,f,g : integer range 0 to 100;
begin
if(clk' event and clk='1') then
e:=conv_integer(a); --将这两个输入的8位2进制数字变成十进制
f:=conv_integer(b);
g:=e*10+f; --十位数字X10+个位数字就满足了你的要求
c<=conv_std_logic_vector(g,8);--再转换回2进制然后输出
end if;
end process;
end Behavioral;
这样就可以了,下边是我仿真的图
追问大神啊 请问您是怎么仿真的啊 testbench我总是写不对
追答我用的ISE里边自带的仿真啊……testbench不用自己写的。。。
反正不管仿真怎么样 ,这段程序是对的
这个是ISE自动生成的testbench,我给你贴上来你看看,希望对你有帮助~
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY fz IS
END fz;
ARCHITECTURE behavior OF fz IS
-- Component Declaration for the Unit Under Test (UUT)
COMPONENT aaa
PORT(
clk : IN std_logic;
a : IN std_logic_vector(7 downto 0);
b : IN std_logic_vector(7 downto 0);
c : OUT std_logic_vector(7 downto 0)
);
END COMPONENT;
--Inputs
signal clk : std_logic := '0';
signal a : std_logic_vector(7 downto 0) := (others => '0');
signal b : std_logic_vector(7 downto 0) := (others => '0');
--Outputs
signal c : std_logic_vector(7 downto 0);
-- Clock period definitions
constant clk_period : time := 10 ns;
BEGIN
-- Instantiate the Unit Under Test (UUT)
uut: aaa PORT MAP (
clk => clk,
a => a,
b => b,
c => c
);
-- Clock process definitions
clk_process :process
begin
clk <= '0';
wait for clk_period/2;
clk <= '1';
wait for clk_period/2;
end process;
-- Stimulus process
stim_proc: process
begin
-- hold reset state for 100 ns.
wait for 100 ns;
wait for clk_period*10;
-- insert stimulus here
wait;
end process;
END;
那 a b的值是自己设定的把 还有件事请教您 就是我的程序是矩阵键盘 当我按一个键值 出现一个八位 再按一个键又出八位 那我咋写程序能应用上面您给的这个把两个键的八位的值 变成一个八位的值
追答恩,ab是我在仿真的时候自己设定的,我也是初学好多不懂得地方,你就把那两个8位的数据赋给这个程序里边的ab就可以了吧,用元件例化语句把这个程序和你的那个输出8位的程序连接起来,让你那个的输出作为这个程序的ab输入