Advertisement
nontawat1996

lab5-7 Segment-4bits

Feb 15th, 2016
107
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. USE ieee.std_logic_textio.ALL;
  34.  
  35. -- Uncomment the following library declaration if using
  36. -- arithmetic functions with Signed or Unsigned values
  37. --USE ieee.numeric_std.ALL;
  38.  
  39. ENTITY test5 IS
  40. END test5;
  41.  
  42. ARCHITECTURE behavior OF test5 IS
  43.  
  44.     -- Component Declaration for the Unit Under Test (UUT)
  45.  
  46.     COMPONENT lab5
  47.     PORT(
  48.          A : IN  std_logic_vector(3 downto 0);
  49.          B : IN  std_logic_vector(3 downto 0);
  50.          C : OUT  std_logic_vector(4 downto 0)
  51.         );
  52.     END COMPONENT;
  53.    
  54.  
  55.    --Inputs
  56.    signal A : std_logic_vector(3 downto 0) := (others => '0');
  57.    signal B : std_logic_vector(3 downto 0) := (others => '0');
  58.  
  59.     --Outputs
  60.    signal C : std_logic_vector(4 downto 0);
  61.    -- No clocks detected in port list. Replace <clock> below with
  62.    -- appropriate port name
  63.  
  64.  
  65. BEGIN
  66.  
  67.     -- Instantiate the Unit Under Test (UUT)
  68.    uut: lab5 PORT MAP (
  69.           A => A,
  70.           B => B,
  71.           C => C
  72.         );
  73.     process
  74.         FILE fileInput : TEXT IS IN "data_ABC.txt";
  75.         FILe fileOutput : TEXT IS OUT "data_SUM.txt";
  76.         variable line_ABCin : LINE;
  77.         variable line_SUM : LINE;
  78.         variable Ain,Bin : std_logic_vector(3 downto 0);
  79.         variable Cin,Cout : std_logic_vector(4 downto 0);
  80.         variable SUM : std_logic_vector(4 downto 0);
  81.         variable str : string(1 to 2);
  82.         variable outStr : string (1 to 9);
  83.         begin
  84.             while NOT ENDFILE(fileInput) loop
  85.                 READLINE(fileInput, line_ABCin);
  86.                 READ(line_ABCin, Ain);
  87.                 READ(line_ABCin, Bin);
  88.                 READ(line_ABCin, Cin);
  89.                
  90.                 A <= Ain;
  91.                 B <= Bin;
  92.                 SUM := Cin;
  93.                
  94.                 wait for 10 ns;
  95.                
  96.                 case C(4) is
  97.                     when '0' => str(1) := '0';
  98.                     when others => str(1) := '1';
  99.                 end case;
  100.                
  101.                
  102.                 case C(3 downto 0) is
  103.                     when "0000" => str(2) := '0';
  104.                     when "0001" => str(2) := '1';
  105.                     when "0010" => str(2) := '2';
  106.                     when "0011" => str(2) := '3';
  107.                     when "0100" => str(2) := '4';
  108.                     when "0101" => str(2) := '5';
  109.                     when "0110" => str(2) := '6';
  110.                     when "0111" => str(2) := '7';
  111.                     when "1000" => str(2) := '8';
  112.                     when "1001" => str(2) := '9';
  113.                     when "1010" => str(2) := 'A';
  114.                     when "1011" => str(2) := 'B';
  115.                     when "1100" => str(2) := 'C';
  116.                     when "1101" => str(2) := 'D';
  117.                     when "1110" => str(2) := 'E';
  118.                     when others => str(2) := 'F';
  119.                 end case;
  120.                
  121.                 WRITE(line_SUM, str);
  122.                 WRITELINE(fileOutput, line_SUM);
  123.                
  124.                 -- start Line 1
  125.                 outStr(5) := ' ';
  126.                 case C(4) is
  127.                     when '0' => outStr(1 to 4) := "****";
  128.                     when others => outStr(1 to 4) := "   *";
  129.                 end case;
  130.                
  131.                 case C(3 downto 0) is
  132.                     when "0000" => outStr(6 to 9) := "****";
  133.                     when "0001" => outStr(6 to 9) := "   *";
  134.                     when "0010" => outStr(6 to 9) := "****";
  135.                     when "0011" => outStr(6 to 9) := "****";
  136.                     when "0100" => outStr(6 to 9) := "*  *";
  137.                     when "0101" => outStr(6 to 9) := "****";
  138.                     when "0110" => outStr(6 to 9) := "****";
  139.                     when "0111" => outStr(6 to 9) := "****";
  140.                     when "1000" => outStr(6 to 9) := "****";
  141.                     when "1001" => outStr(6 to 9) := "****";
  142.                     when "1010" => outStr(6 to 9) := "****";
  143.                     when "1011" => outStr(6 to 9) := "*   ";
  144.                     when "1100" => outStr(6 to 9) := "****";
  145.                     when "1101" => outStr(6 to 9) := "   *";
  146.                     when "1110" => outStr(6 to 9) := "****";
  147.                     when others => outStr(6 to 9) := "****";
  148.                 end case;
  149.                
  150.                 WRITE(line_SUM, outStr);
  151.                 WRITELINE(fileOutput, line_SUM);
  152.                
  153.                 -- end Line 1
  154.                
  155.                 -- start Line 2
  156.                 outStr(5) := ' ';
  157.                 case C(4) is
  158.                     when '0' => outStr(1 to 4) := "*  *";
  159.                     when others => outStr(1 to 4) := "   *";
  160.                 end case;
  161.                
  162.                 case C(3 downto 0) is
  163.                     when "0000" => outStr(6 to 9) := "*  *"; -- 0
  164.                     when "0001" => outStr(6 to 9) := "   *"; -- 1
  165.                     when "0010" => outStr(6 to 9) := "   *"; -- 2
  166.                     when "0011" => outStr(6 to 9) := "   *"; -- 3
  167.                     when "0100" => outStr(6 to 9) := "*  *"; -- 4
  168.                     when "0101" => outStr(6 to 9) := "*   "; -- 5
  169.                     when "0110" => outStr(6 to 9) := "*   "; -- 6
  170.                     when "0111" => outStr(6 to 9) := "   *"; -- 7
  171.                     when "1000" => outStr(6 to 9) := "*  *"; -- 8
  172.                     when "1001" => outStr(6 to 9) := "*  *"; -- 9
  173.                     when "1010" => outStr(6 to 9) := "*  *"; -- A
  174.                     when "1011" => outStr(6 to 9) := "*   "; -- B
  175.                     when "1100" => outStr(6 to 9) := "*  *"; -- C
  176.                     when "1101" => outStr(6 to 9) := "   *"; -- D
  177.                     when "1110" => outStr(6 to 9) := "*   "; -- E
  178.                     when others => outStr(6 to 9) := "*   "; -- F
  179.                 end case;
  180.                
  181.                 WRITE(line_SUM, outStr);
  182.                 WRITELINE(fileOutput, line_SUM);
  183.                
  184.                 -- end Line 2
  185.                
  186.                 -- start Line 3
  187.                 outStr(5) := ' ';
  188.                 case C(4) is
  189.                     when '0' => outStr(1 to 4) := "*  *";
  190.                     when others => outStr(1 to 4) := "   *";
  191.                 end case;
  192.                
  193.                 case C(3 downto 0) is
  194.                     when "0000" => outStr(6 to 9) := "*  *"; -- 0
  195.                     when "0001" => outStr(6 to 9) := "   *"; -- 1
  196.                     when "0010" => outStr(6 to 9) := "****"; -- 2
  197.                     when "0011" => outStr(6 to 9) := "****"; -- 3
  198.                     when "0100" => outStr(6 to 9) := "****"; -- 4
  199.                     when "0101" => outStr(6 to 9) := "****"; -- 5
  200.                     when "0110" => outStr(6 to 9) := "****"; -- 6
  201.                     when "0111" => outStr(6 to 9) := "   *"; -- 7
  202.                     when "1000" => outStr(6 to 9) := "****"; -- 8
  203.                     when "1001" => outStr(6 to 9) := "****"; -- 9
  204.                     when "1010" => outStr(6 to 9) := "****"; -- A
  205.                     when "1011" => outStr(6 to 9) := "****"; -- B
  206.                     when "1100" => outStr(6 to 9) := "*   "; -- C
  207.                     when "1101" => outStr(6 to 9) := "****"; -- D
  208.                     when "1110" => outStr(6 to 9) := "****"; -- E
  209.                     when others => outStr(6 to 9) := "****"; -- F
  210.                 end case;
  211.                
  212.                 WRITE(line_SUM, outStr);
  213.                 WRITELINE(fileOutput, line_SUM);
  214.                
  215.                 -- end Line 3
  216.            
  217.                 -- start Line 4
  218.                 outStr(5) := ' ';
  219.                 case C(4) is
  220.                     when '0' => outStr(1 to 4) := "*  *";
  221.                     when others => outStr(1 to 4) := "   *";
  222.                 end case;
  223.                
  224.                 case C(3 downto 0) is
  225.                     when "0000" => outStr(6 to 9) := "*  *"; -- 0
  226.                     when "0001" => outStr(6 to 9) := "   *"; -- 1
  227.                     when "0010" => outStr(6 to 9) := "*   "; -- 2
  228.                     when "0011" => outStr(6 to 9) := "   *"; -- 3
  229.                     when "0100" => outStr(6 to 9) := "   *"; -- 4
  230.                     when "0101" => outStr(6 to 9) := "   *"; -- 5
  231.                     when "0110" => outStr(6 to 9) := "*  *"; -- 6
  232.                     when "0111" => outStr(6 to 9) := "   *"; -- 7
  233.                     when "1000" => outStr(6 to 9) := "*  *"; -- 8
  234.                     when "1001" => outStr(6 to 9) := "   *"; -- 9
  235.                     when "1010" => outStr(6 to 9) := "*  *"; -- A
  236.                     when "1011" => outStr(6 to 9) := "*  *"; -- B
  237.                     when "1100" => outStr(6 to 9) := "*   "; -- C
  238.                     when "1101" => outStr(6 to 9) := "*  *"; -- D
  239.                     when "1110" => outStr(6 to 9) := "*   "; -- E
  240.                     when others => outStr(6 to 9) := "*   "; -- F
  241.                 end case;
  242.                
  243.                 WRITE(line_SUM, outStr);
  244.                 WRITELINE(fileOutput, line_SUM);
  245.                
  246.                 -- end Line 4
  247.                 -- start Line 5
  248.                 outStr(5) := ' ';
  249.                 case C(4) is
  250.                     when '0' => outStr(1 to 4) := "****";
  251.                     when others => outStr(1 to 4) := "   *";
  252.                 end case;
  253.                
  254.                 case C(3 downto 0) is
  255.                     when "0000" => outStr(6 to 9) := "****"; -- 0
  256.                     when "0001" => outStr(6 to 9) := "   *"; -- 1
  257.                     when "0010" => outStr(6 to 9) := "****"; -- 2
  258.                     when "0011" => outStr(6 to 9) := "****"; -- 3
  259.                     when "0100" => outStr(6 to 9) := "   *"; -- 4
  260.                     when "0101" => outStr(6 to 9) := "****"; -- 5
  261.                     when "0110" => outStr(6 to 9) := "****"; -- 6
  262.                     when "0111" => outStr(6 to 9) := "   *"; -- 7
  263.                     when "1000" => outStr(6 to 9) := "****"; -- 8
  264.                     when "1001" => outStr(6 to 9) := "****"; -- 9
  265.                     when "1010" => outStr(6 to 9) := "*  *"; -- A
  266.                     when "1011" => outStr(6 to 9) := "****"; -- B
  267.                     when "1100" => outStr(6 to 9) := "****"; -- C
  268.                     when "1101" => outStr(6 to 9) := "****"; -- D
  269.                     when "1110" => outStr(6 to 9) := "****"; -- E
  270.                     when others => outStr(6 to 9) := "*   "; -- F
  271.                 end case;
  272.                
  273.                 WRITE(line_SUM, outStr);
  274.                 WRITELINE(fileOutput, line_SUM);
  275.                
  276.                 -- end Line 5
  277.                
  278.                 -- assert C = SUM REPORT "Test fail" SEVERITY error;
  279.                 wait for 30 ns;
  280.             end loop;
  281.         wait;
  282.     end process;
  283. END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement