Advertisement
nontawat1996

lab5-7 Segment

Feb 15th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 9.05 KB | None | 0 0
  1. --------------------------------------------------------------------------------
  2. -- Company:
  3. -- Engineer:
  4. --
  5. -- Create Date:   13:23:08 02/15/2016
  6. -- Design Name:  
  7. -- Module Name:   C:/VHDL/lab5/test5.vhd
  8. -- Project Name:  lab5
  9. -- Target Device:  
  10. -- Tool versions:  
  11. -- Description:  
  12. --
  13. -- VHDL Test Bench Created by ISE for module: lab5
  14. --
  15. -- Dependencies:
  16. --
  17. -- Revision:
  18. -- Revision 0.01 - File Created
  19. -- Additional Comments:
  20. --
  21. -- Notes:
  22. -- This testbench has been automatically generated using types std_logic and
  23. -- std_logic_vector for the ports of the unit under test.  Xilinx recommends
  24. -- that these types always be used for the top-level I/O of a design in order
  25. -- to guarantee that the testbench will bind correctly to the post-implementation
  26. -- simulation model.
  27. --------------------------------------------------------------------------------
  28. LIBRARY ieee;
  29. USE ieee.std_logic_1164.ALL;
  30. USE ieee.std_logic_arith.ALL;
  31. USE ieee.std_logic_unsigned.ALL;
  32. USE STD.TEXTIO.all;
  33.  
  34. -- Uncomment the following library declaration if using
  35. -- arithmetic functions with Signed or Unsigned values
  36. --USE ieee.numeric_std.ALL;
  37.  
  38. ENTITY test5 IS
  39. END test5;
  40.  
  41. ARCHITECTURE behavior OF test5 IS
  42.  
  43.     -- Component Declaration for the Unit Under Test (UUT)
  44.  
  45.     COMPONENT lab5
  46.     PORT(
  47.          A : IN  std_logic_vector(3 downto 0);
  48.          B : IN  std_logic_vector(3 downto 0);
  49.          C : OUT  std_logic_vector(4 downto 0)
  50.         );
  51.     END COMPONENT;
  52.    
  53.  
  54.    --Inputs
  55.    signal A : std_logic_vector(3 downto 0) := (others => '0');
  56.    signal B : std_logic_vector(3 downto 0) := (others => '0');
  57.  
  58.     --Outputs
  59.    signal C : std_logic_vector(4 downto 0);
  60.    -- No clocks detected in port list. Replace <clock> below with
  61.    -- appropriate port name
  62.  
  63.  
  64. BEGIN
  65.  
  66.     -- Instantiate the Unit Under Test (UUT)
  67.    uut: lab5 PORT MAP (
  68.           A => A,
  69.           B => B,
  70.           C => C
  71.         );
  72.     process
  73.         FILE fileInput : TEXT IS IN "data_ABC.txt";
  74.         FILe fileOutput : TEXT IS OUT "data_SUM.txt";
  75.         variable line_ABCin : LINE;
  76.         variable line_SUM : LINE;
  77.         variable Ain,Bin,Cin,Cout : integer;
  78.         variable SUM : std_logic_vector(4 downto 0);
  79.         variable str : string(1 to 2);
  80.         variable outStr : string (1 to 9);
  81.         begin
  82.             while NOT ENDFILE(fileInput) loop
  83.                 READLINE(fileInput, line_ABCin);
  84.                 READ(line_ABCin, Ain);
  85.                 READ(line_ABCin, Bin);
  86.                 READ(line_ABCin, Cin);
  87.                 A <= conv_std_logic_vector(Ain, 4);
  88.                 B <= conv_std_logic_vector(Bin, 4);
  89.                 SUM := conv_std_logic_vector(Cin, 5);
  90.                
  91.                 wait for 10 ns;
  92.                 Cout := conv_integer(C);
  93.                
  94.                 case C(4) is
  95.                     when '0' => str(1) := '0';
  96.                     when others => str(1) := '1';
  97.                 end case;
  98.                
  99.                
  100.                 case C(3 downto 0) is
  101.                     when "0000" => str(2) := '0';
  102.                     when "0001" => str(2) := '1';
  103.                     when "0010" => str(2) := '2';
  104.                     when "0011" => str(2) := '3';
  105.                     when "0100" => str(2) := '4';
  106.                     when "0101" => str(2) := '5';
  107.                     when "0110" => str(2) := '6';
  108.                     when "0111" => str(2) := '7';
  109.                     when "1000" => str(2) := '8';
  110.                     when "1001" => str(2) := '9';
  111.                     when "1010" => str(2) := 'A';
  112.                     when "1011" => str(2) := 'B';
  113.                     when "1100" => str(2) := 'C';
  114.                     when "1101" => str(2) := 'D';
  115.                     when "1110" => str(2) := 'E';
  116.                     when others => str(2) := 'F';
  117.                 end case;
  118.                
  119.                 WRITE(line_SUM, str);
  120.                 WRITELINE(fileOutput, line_SUM);
  121.                
  122.                 -- start Line 1
  123.                 outStr(5) := ' ';
  124.                 case C(4) is
  125.                     when '0' => outStr(1 to 4) := "****";
  126.                     when others => outStr(1 to 4) := "   *";
  127.                 end case;
  128.                
  129.                 case C(3 downto 0) is
  130.                     when "0000" => outStr(6 to 9) := "****";
  131.                     when "0001" => outStr(6 to 9) := "   *";
  132.                     when "0010" => outStr(6 to 9) := "****";
  133.                     when "0011" => outStr(6 to 9) := "****";
  134.                     when "0100" => outStr(6 to 9) := "*  *";
  135.                     when "0101" => outStr(6 to 9) := "****";
  136.                     when "0110" => outStr(6 to 9) := "****";
  137.                     when "0111" => outStr(6 to 9) := "****";
  138.                     when "1000" => outStr(6 to 9) := "****";
  139.                     when "1001" => outStr(6 to 9) := "****";
  140.                     when "1010" => outStr(6 to 9) := "****";
  141.                     when "1011" => outStr(6 to 9) := "*   ";
  142.                     when "1100" => outStr(6 to 9) := "****";
  143.                     when "1101" => outStr(6 to 9) := "   *";
  144.                     when "1110" => outStr(6 to 9) := "****";
  145.                     when others => outStr(6 to 9) := "****";
  146.                 end case;
  147.                
  148.                 WRITE(line_SUM, outStr);
  149.                 WRITELINE(fileOutput, line_SUM);
  150.                
  151.                 -- end Line 1
  152.                
  153.                 -- start Line 2
  154.                 outStr(5) := ' ';
  155.                 case C(4) is
  156.                     when '0' => outStr(1 to 4) := "*  *";
  157.                     when others => outStr(1 to 4) := "   *";
  158.                 end case;
  159.                
  160.                 case C(3 downto 0) is
  161.                     when "0000" => outStr(6 to 9) := "*  *"; -- 0
  162.                     when "0001" => outStr(6 to 9) := "   *"; -- 1
  163.                     when "0010" => outStr(6 to 9) := "   *"; -- 2
  164.                     when "0011" => outStr(6 to 9) := "   *"; -- 3
  165.                     when "0100" => outStr(6 to 9) := "*  *"; -- 4
  166.                     when "0101" => outStr(6 to 9) := "*   "; -- 5
  167.                     when "0110" => outStr(6 to 9) := "*   "; -- 6
  168.                     when "0111" => outStr(6 to 9) := "   *"; -- 7
  169.                     when "1000" => outStr(6 to 9) := "*  *"; -- 8
  170.                     when "1001" => outStr(6 to 9) := "*  *"; -- 9
  171.                     when "1010" => outStr(6 to 9) := "*  *"; -- A
  172.                     when "1011" => outStr(6 to 9) := "*   "; -- B
  173.                     when "1100" => outStr(6 to 9) := "*  *"; -- C
  174.                     when "1101" => outStr(6 to 9) := "   *"; -- D
  175.                     when "1110" => outStr(6 to 9) := "*  *"; -- E
  176.                     when others => outStr(6 to 9) := "*   "; -- F
  177.                 end case;
  178.                
  179.                 WRITE(line_SUM, outStr);
  180.                 WRITELINE(fileOutput, line_SUM);
  181.                
  182.                 -- end Line 2
  183.                
  184.                 -- start Line 3
  185.                 outStr(5) := ' ';
  186.                 case C(4) is
  187.                     when '0' => outStr(1 to 4) := "*  *";
  188.                     when others => outStr(1 to 4) := "   *";
  189.                 end case;
  190.                
  191.                 case C(3 downto 0) is
  192.                     when "0000" => outStr(6 to 9) := "*  *"; -- 0
  193.                     when "0001" => outStr(6 to 9) := "   *"; -- 1
  194.                     when "0010" => outStr(6 to 9) := "****"; -- 2
  195.                     when "0011" => outStr(6 to 9) := "****"; -- 3
  196.                     when "0100" => outStr(6 to 9) := "****"; -- 4
  197.                     when "0101" => outStr(6 to 9) := "****"; -- 5
  198.                     when "0110" => outStr(6 to 9) := "****"; -- 6
  199.                     when "0111" => outStr(6 to 9) := "   *"; -- 7
  200.                     when "1000" => outStr(6 to 9) := "****"; -- 8
  201.                     when "1001" => outStr(6 to 9) := "****"; -- 9
  202.                     when "1010" => outStr(6 to 9) := "****"; -- A
  203.                     when "1011" => outStr(6 to 9) := "****"; -- B
  204.                     when "1100" => outStr(6 to 9) := "*   "; -- C
  205.                     when "1101" => outStr(6 to 9) := "****"; -- D
  206.                     when "1110" => outStr(6 to 9) := "****"; -- E
  207.                     when others => outStr(6 to 9) := "****"; -- F
  208.                 end case;
  209.                
  210.                 WRITE(line_SUM, outStr);
  211.                 WRITELINE(fileOutput, line_SUM);
  212.                
  213.                 -- end Line 3
  214.            
  215.                 -- start Line 4
  216.                 outStr(5) := ' ';
  217.                 case C(4) is
  218.                     when '0' => outStr(1 to 4) := "*  *";
  219.                     when others => outStr(1 to 4) := "   *";
  220.                 end case;
  221.                
  222.                 case C(3 downto 0) is
  223.                     when "0000" => outStr(6 to 9) := "*  *"; -- 0
  224.                     when "0001" => outStr(6 to 9) := "   *"; -- 1
  225.                     when "0010" => outStr(6 to 9) := "*   "; -- 2
  226.                     when "0011" => outStr(6 to 9) := "   *"; -- 3
  227.                     when "0100" => outStr(6 to 9) := "   *"; -- 4
  228.                     when "0101" => outStr(6 to 9) := "   *"; -- 5
  229.                     when "0110" => outStr(6 to 9) := "*  *"; -- 6
  230.                     when "0111" => outStr(6 to 9) := "   *"; -- 7
  231.                     when "1000" => outStr(6 to 9) := "*  *"; -- 8
  232.                     when "1001" => outStr(6 to 9) := "   *"; -- 9
  233.                     when "1010" => outStr(6 to 9) := "*  *"; -- A
  234.                     when "1011" => outStr(6 to 9) := "*  *"; -- B
  235.                     when "1100" => outStr(6 to 9) := "*   "; -- C
  236.                     when "1101" => outStr(6 to 9) := "*  *"; -- D
  237.                     when "1110" => outStr(6 to 9) := "*   "; -- E
  238.                     when others => outStr(6 to 9) := "*   "; -- F
  239.                 end case;
  240.                
  241.                 WRITE(line_SUM, outStr);
  242.                 WRITELINE(fileOutput, line_SUM);
  243.                
  244.                 -- end Line 4
  245.                 -- start Line 5
  246.                 outStr(5) := ' ';
  247.                 case C(4) is
  248.                     when '0' => outStr(1 to 4) := "****";
  249.                     when others => outStr(1 to 4) := "   *";
  250.                 end case;
  251.                
  252.                 case C(3 downto 0) is
  253.                     when "0000" => outStr(6 to 9) := "****"; -- 0
  254.                     when "0001" => outStr(6 to 9) := "   *"; -- 1
  255.                     when "0010" => outStr(6 to 9) := "****"; -- 2
  256.                     when "0011" => outStr(6 to 9) := "****"; -- 3
  257.                     when "0100" => outStr(6 to 9) := "   *"; -- 4
  258.                     when "0101" => outStr(6 to 9) := "****"; -- 5
  259.                     when "0110" => outStr(6 to 9) := "****"; -- 6
  260.                     when "0111" => outStr(6 to 9) := "   *"; -- 7
  261.                     when "1000" => outStr(6 to 9) := "****"; -- 8
  262.                     when "1001" => outStr(6 to 9) := "****"; -- 9
  263.                     when "1010" => outStr(6 to 9) := "*  *"; -- A
  264.                     when "1011" => outStr(6 to 9) := "****"; -- B
  265.                     when "1100" => outStr(6 to 9) := "****"; -- C
  266.                     when "1101" => outStr(6 to 9) := "****"; -- D
  267.                     when "1110" => outStr(6 to 9) := "****"; -- E
  268.                     when others => outStr(6 to 9) := "*   "; -- F
  269.                 end case;
  270.                
  271.                 WRITE(line_SUM, outStr);
  272.                 WRITELINE(fileOutput, line_SUM);
  273.                
  274.                 -- end Line 5
  275.                
  276.                 assert C = SUM REPORT "Test fail" SEVERITY error;
  277.                 wait for 30 ns;
  278.             end loop;
  279.         wait;
  280.     end process;
  281. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement