asmodeus94

lab10licznik

Jun 10th, 2015
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 2.79 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. entity liczeModule is
  4.     Port ( clk_wejscie : in STD_LOGIC;
  5.               sw0 : in STD_LOGIC;
  6.               sw1 : in STD_LOGIC;
  7.            a : out  STD_LOGIC;
  8.            b : out  STD_LOGIC;
  9.            c : out  STD_LOGIC;
  10.            d : out  STD_LOGIC;
  11.               e : out  STD_LOGIC;
  12.               f : out  STD_LOGIC;
  13.               g : out  STD_LOGIC;
  14.               an1 : out STD_LOGIC;
  15.               an2 : out STD_LOGIC);
  16. end liczeModule;
  17.  
  18. architecture Behavioral of liczeModule is
  19.  
  20. type stany is (s0,s1);
  21. signal aktualny_stan,nastepny_stan: stany;
  22. signal wyjscie: std_logic_vector (0 to 6);
  23.  
  24. signal licznik: integer range 0 to 499999:=0;
  25. signal licznikS: integer range 0 to 9999:=0;
  26. signal c1, c2: integer range 0 to 9:=0;
  27. signal tym: std_logic:='0';
  28. signal clk_wyjscie: std_logic;
  29.  
  30. begin
  31.  
  32. process (aktualny_stan, sw0)
  33. begin
  34. if(sw0='1') then
  35.     wyjscie <= "0000001";
  36. end if;
  37.  
  38. case aktualny_stan is
  39.     when s0 =>
  40.         case c1 is
  41.             when 0 =>
  42.                             wyjscie <= "0000001";
  43.             when 1 =>
  44.                             wyjscie <= "1001111";
  45.             when 2 =>
  46.                             wyjscie <= "0010010";
  47.             when 3 =>
  48.                             wyjscie <= "0000110";
  49.             when 4 =>
  50.                             wyjscie <= "1001100";
  51.             when 5 =>  
  52.                             wyjscie <= "0100100";
  53.             when 6 =>
  54.                             wyjscie <= "0100000";
  55.             when 7 =>
  56.                             wyjscie <= "0001111";
  57.             when 8 =>
  58.                             wyjscie <= "0000000";
  59.             when 9 =>
  60.                             wyjscie <= "0000100";
  61.         end case;
  62.         an1 <= '0';
  63.         an2 <= '1';
  64.         nastepny_stan <= s1;
  65.     when s1 =>
  66.         case c2 is
  67.             when 0 =>
  68.                             wyjscie <= "0000001";
  69.             when 1 =>
  70.                             wyjscie <= "1001111";
  71.             when 2 =>
  72.                             wyjscie <= "0010010";
  73.             when 3 =>
  74.                             wyjscie <= "0000110";
  75.             when 4 =>
  76.                             wyjscie <= "1001100";
  77.             when 5 =>  
  78.                             wyjscie <= "0100100";
  79.             when 6 =>
  80.                             wyjscie <= "0100000";
  81.             when 7 =>
  82.                             wyjscie <= "0001111";
  83.             when 8 =>
  84.                             wyjscie <= "0000000";
  85.             when 9 =>
  86.                             wyjscie <= "0000100";
  87.         end case;
  88.         an1 <= '1';
  89.         an2 <= '0';
  90.         nastepny_stan <= s0;
  91. end case;
  92.  
  93.    
  94. end process;
  95.  
  96. process (clk_wejscie, sw0, sw1)
  97. begin
  98.     if (rising_edge(clk_wejscie)) then
  99.         if (licznik=100) then
  100.             tym <= not tym;
  101.             licznik <= 0;
  102.             licznikS <= licznikS+1;
  103.             else
  104.                 licznik <= licznik+1;
  105.         end if;
  106.         if (licznikS=9999) and (sw1='0') then
  107.             licznikS <= 0;
  108.             if (c2 + 1=10) then
  109.                 if (c1 + 1=10) then
  110.                     c1 <= 0;
  111.                     c2 <= 0;
  112.                     else
  113.                         c1 <= c1 + 1;
  114.                         c2 <= 0;
  115.                 end if;
  116.                 else
  117.                     c2 <= c2 + 1;
  118.             end if;    
  119.         end if;
  120.     if(sw0='1') then
  121.         c1<=0;
  122.         c2<=0;
  123.     end if;
  124.     end if;
  125. end process;
  126.  
  127. clk_wyjscie <= tym;
  128.  
  129. process (clk_wyjscie)
  130. begin
  131.     if (rising_edge(clk_wyjscie)) then
  132.         aktualny_stan <= nastepny_stan;
  133.     end if;
  134. end process;
  135.  
  136. a <= wyjscie(0);
  137. b <= wyjscie(1);
  138. c <= wyjscie(2);
  139. d <= wyjscie(3);
  140. e <= wyjscie(4);
  141. f <= wyjscie(5);
  142. g <= wyjscie(6);
  143. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment