Advertisement
SneakyElf

Lab3

Dec 19th, 2024 (edited)
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 5.10 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use std.textio.all;
  4. use ieee.std_logic_textio.all;
  5.  
  6. entity autoTestCounter is
  7. --  Port ( );
  8. end autoTestCounter;
  9.  
  10. architecture Behavioral of autoTestCounter is
  11.     signal OE: std_logic := 'U';
  12.     signal ACLR: std_logic := 'U';
  13.     signal SCLR: std_logic := 'U';
  14.     signal LOAD: std_logic := 'U';
  15.     signal ENP: std_logic := 'U';
  16.     signal ENT: std_logic := 'U';
  17.     signal UD: std_logic := 'U';
  18.     signal CLK: std_logic := 'U';
  19.     signal A: std_logic := 'U';
  20.     signal B: std_logic := 'U';
  21.     signal C: std_logic := 'U';
  22.     signal D: std_logic := 'U';  
  23.     signal QA: std_logic := 'U';
  24.     signal QB: std_logic := 'U';
  25.     signal QC: std_logic := 'U';
  26.     signal QD: std_logic := 'U';
  27.     signal RCO: std_logic := 'U';
  28.     signal CCO: std_logic := 'U';
  29.  
  30. function to_std_logic(H, L: boolean) return std_logic is begin
  31.     if H then
  32.         if L then return 'Z';
  33.         else return 'X';
  34.         end if;
  35.     else
  36.         if L then return '1';
  37.         else return '0';
  38.         end if;
  39.     end if;
  40. end function;
  41.  
  42. function from_std_logic(sgn: std_logic) return string is
  43. begin
  44.     if (sgn = '0') then
  45.         return "false false";
  46.     elsif (sgn = '1') then
  47.         return "false true";
  48.     elsif (sgn = 'X') then
  49.         return "true false";
  50.     elsif (sgn = 'Z') then
  51.         return "true true";
  52.     else
  53.         return "error error";
  54.     end if;
  55. end function;
  56.  
  57. begin
  58.     mapping: entity work.binaryCounter(Behavioral)
  59.         port map (
  60.             OE => OE,
  61.             UD => UD,
  62.             CLK => CLK,
  63.             ENT => ENT,
  64.             ENP => ENP,
  65.             SCLR => SCLR,
  66.             LOAD => LOAD,
  67.             ACLR => ACLR,
  68.             A => A,
  69.             B => B,
  70.             C => C,
  71.             D => D,
  72.             CCO => CCO,
  73.             RCO => RCO,
  74.             QA => QA,
  75.             QB => QB,
  76.             QC => QC,
  77.             QD => QD
  78.         );
  79.  
  80.     process
  81.         file input_file: text;
  82.         file output_file: text;
  83.         variable text_row: line;
  84.         variable out_row: line;
  85.         variable OE_h, ACLR_h, SCLR_h, LOAD_h, ENP_h, ENT_h, UD_h, CLK_h, D3_h, D2_h, D1_h, D0_h, Q3_h, Q2_h, Q1_h, Q0_h, RCO_h, CCO_h: boolean;
  86.         variable OE_l, ACLR_l, SCLR_l, LOAD_l, ENP_l, ENT_l, UD_l, CLK_l, D3_l, D2_l, D1_l, D0_l, Q3_l, Q2_l, Q1_l, Q0_l, RCO_l, CCO_l: boolean;
  87.     begin
  88.         file_open(input_file, "C:\Users\nina\Documents\VII semester\Processors\Lab3\Counter.txt", read_mode);
  89.         file_open(output_file, "C:\Users\nina\Documents\VII semester\Processors\Lab3\OutputCounter.txt", write_mode);
  90.        
  91.         readline(input_file, text_row);
  92.         writeline(output_file, text_row);
  93.  
  94.         while not endfile(input_file) loop
  95.             readline(input_file, text_row);
  96.  
  97.             read(text_row, OE_h);
  98.             read(text_row, OE_l);
  99.             read(text_row, ACLR_h);
  100.             read(text_row, ACLR_l);
  101.             read(text_row, SCLR_h);
  102.             read(text_row, SCLR_l);
  103.             read(text_row, LOAD_h);
  104.             read(text_row, LOAD_l);
  105.             read(text_row, ENP_h);
  106.             read(text_row, ENP_l);
  107.             read(text_row, ENT_h);
  108.             read(text_row, ENT_l);
  109.             read(text_row, UD_h);
  110.             read(text_row, UD_l);
  111.             read(text_row, CLK_h);
  112.             read(text_row, CLK_l);
  113.             read(text_row, D3_h);
  114.             read(text_row, D3_l);
  115.             read(text_row, D2_h);
  116.             read(text_row, D2_l);
  117.             read(text_row, D1_h);
  118.             read(text_row, D1_l);
  119.             read(text_row, D0_h);
  120.             read(text_row, D0_l);
  121.  
  122.             OE <= to_std_logic(OE_h, OE_l);
  123.             ACLR <= to_std_logic(ACLR_h, ACLR_l);
  124.             SCLR <= to_std_logic(SCLR_h, SCLR_l);
  125.             LOAD <= to_std_logic(LOAD_h, LOAD_l);
  126.             ENP <= to_std_logic(ENP_h, ENP_l);
  127.             ENT <= to_std_logic(ENT_h, ENT_l);
  128.             UD <= to_std_logic(UD_h, UD_l);
  129.             CLK <= to_std_logic(CLK_h, CLK_l);
  130.             A <= to_std_logic(D0_h, D0_l);
  131.             B <= to_std_logic(D1_h, D1_l);
  132.             C <= to_std_logic(D2_h, D2_l);
  133.             D <= to_std_logic(D3_h, D3_l);
  134.  
  135.             wait for 0.001 ns;
  136.  
  137.             write(out_row, from_std_logic(OE) & " ");
  138.             write(out_row, from_std_logic(ACLR) & " ");
  139.             write(out_row, from_std_logic(SCLR) & " ");
  140.             write(out_row, from_std_logic(LOAD) & " ");
  141.             write(out_row, from_std_logic(ENP) & " ");
  142.             write(out_row, from_std_logic(ENT) & " ");
  143.             write(out_row, from_std_logic(UD) & " ");
  144.             write(out_row, from_std_logic(CLK) & " ");
  145.             write(out_row, from_std_logic(D) & " ");
  146.             write(out_row, from_std_logic(C) & " ");
  147.             write(out_row, from_std_logic(B) & " ");
  148.             write(out_row, from_std_logic(A) & " ");
  149.             write(out_row, from_std_logic(QD) & " ");
  150.             write(out_row, from_std_logic(QC) & " ");
  151.             write(out_row, from_std_logic(QB) & " ");
  152.             write(out_row, from_std_logic(QA) & " ");
  153.             write(out_row, from_std_logic(RCO) & " ");
  154.             write(out_row, from_std_logic(CCO));
  155.  
  156.             writeline(output_file, out_row);
  157.  
  158.             wait for 0.001 ns;
  159.         end loop;
  160.  
  161.         file_close(input_file);
  162.         file_close(output_file);
  163.  
  164.         wait;
  165.     end process;
  166.  
  167. end architecture;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement