Advertisement
Guest User

PUL Projekt - Staniszewski

a guest
May 28th, 2016
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 9.50 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use IEEE.STD_LOGIC_UNSIGNED.ALL;
  4.  
  5.  
  6. entity CROSSROAD is
  7.      Port ( clk : in  STD_LOGIC;
  8.            reset : in  STD_LOGIC;
  9.            dioda : out  STD_LOGIC; --TODO
  10.               anodes : out STD_LOGIC_VECTOR(3 downto 0);
  11.            seg : out  STD_LOGIC_VECTOR(6 downto 0)
  12.               );
  13. end CROSSROAD;
  14.  
  15. architecture Behavioral of CROSSROAD is
  16. type STANY is (STAN1, STAN2, STAN3, STAN4, STAN5, STAN6, NOC, OFF);
  17. signal STAN, STAN_NAST : STANY;
  18. signal sel : STD_LOGIC_VECTOR (1 downto 0):="00";
  19. signal dzien : std_logic := '1';
  20. signal daylight : std_logic_vector(2 downto 0); --implementacja
  21. signal x : std_logic_vector(15 downto 0);--:="00000000000000"; --kod dla 7seg DLA 1A: 1/0000000 A/0000000
  22. signal cnt1 : std_logic_vector(2 downto 0) := "000";--counters cnt1--implementacja
  23. signal cnt2 : std_logic_vector(3 downto 0) := "0000";
  24. signal cnt3 : std_logic_vector(1 downto 0) :="00";
  25. signal cnt4 : std_logic :='1';
  26. signal clk_div2s : std_logic_vector(26 downto 0);
  27. signal clk_div30s : std_logic_vector(30 downto 0);
  28. signal clk_div1ms : std_logic_vector(16 downto 0);
  29. signal digit : STD_LOGIC_VECTOR (3 downto 0);
  30. begin
  31.  
  32.  
  33.  
  34.  
  35. process (sel, x) is
  36.     begin      
  37.             case sel is
  38.                 when "00" => digit <= x(3 downto 0);
  39.                     if sel ="00" then anodes <= "0001"; else null; end if;
  40.                 when "01" => digit <= x(7 downto 4);
  41.                     if sel ="01" then anodes <= "0010"; else null; end if;
  42.                 when "10" => digit <= x(11 downto 8);
  43.                     if sel ="10" then anodes <= "0100"; else null; end if;
  44.                 when others => digit <= x(15 downto 12);
  45.                     if sel ="11" then anodes <= "1000"; else null; end if;
  46.             end case;
  47.            
  48.     end process;       
  49.  
  50.  
  51. process (clk, digit) is
  52.     begin
  53.         if (clk'event and clk ='1') then
  54.             case digit is
  55.                 when X"0" => seg <= "0000000";          --NULL
  56.                 when X"1" => seg <= "0110000";          --definicja cyfry 1
  57.                 when X"2" => seg <= "1101101";          --definicja cyfry 2
  58.                 when X"3" => seg <= "1111001";          --definicja cyfry 3
  59.                 when X"4" => seg <= "0110011";          --definicja cyfry 4
  60.                 when X"5" => seg <= "1011011";          --definicja cyfry 5
  61.                 when X"6" => seg <= "1011111";          --definicja cyfry 6
  62.                 when X"7" => seg <= "1110010";          --definicja cyfry 7
  63.                 when X"8" => seg <= "1111111";          --definicja cyfry 8
  64.                 when X"9" => seg <= "1110110";          --definicja N
  65.                 when X"A" => seg <= "1110111";
  66.                 when X"B" => seg <= "1111110";          --definicja cyfry 0
  67.                 when X"C" => seg <= "1001110";
  68.                 when X"F" => seg <= "1000111";          --definicja F
  69.                 when X"E" => seg <= "1001111";          --definicja E
  70.                 when others => seg <= "1000111";
  71.                
  72.             end case;
  73.         end if;
  74.     end process;
  75.  
  76. REJESTR:process(clk, reset)
  77.         begin
  78.             if(reset='1') then
  79.                 STAN<=OFF;     
  80.             elsif(clk'Event and clk='1') then
  81.                 STAN<=STAN_NAST;
  82.             end if;        
  83.         end process REJESTR;
  84.  
  85.        
  86. AUTOMAT:process(STAN, cnt1, cnt2, cnt3)
  87.         begin      
  88.             STAN_NAST<=STAN;           
  89.             case STAN is                   
  90.                            
  91.                 when STAN1=>               
  92.                         if cnt1>="000" then
  93.                         x <= X"101A"; -- sygnalizator 1A
  94.                         --dioda
  95.                     end if;
  96.                     if cnt1>="001" then
  97.                         x <= X"102A"; --sygnalizator 2A
  98.                         --dioda
  99.                     end if;
  100.                     if cnt1>="010" then
  101.                         x <= X"101E"; --sygnalizator 1E
  102.                         --dioda
  103.                     end if;
  104.                     if cnt1>="011" then
  105.                         x <= X"101C"; --sygnalizator 1C
  106.                         --dioda
  107.                     end if;
  108.                     if cnt1>="100" then
  109.                         x<=X"102C"; --sygnalizator 2C
  110.                         --dioda
  111.                     end if;
  112.                     if cnt1>="101" then
  113.                         x<=X"101F"; --sygnalizator 1F
  114.                         --dioda    
  115.                     end if;    
  116.                    
  117.                     if dzien='0' then
  118.                         stan_nast<=noc;
  119.                     elsif cnt2>="1111" then
  120.                         stan_nast<=stan2;
  121.                     end if;
  122.                        
  123.                 when STAN2=>               
  124.                     if cnt1>="000" then
  125.                         x<=X"201A"; -- sygnalizator 1A
  126.                         --dioda
  127.                     end if;
  128.                     if cnt1>="001" then
  129.                         x<=X"202A"; --sygnalizator 2A
  130.                         --dioda
  131.                     end if;
  132.                     if cnt1>="010" then
  133.                         x<=X"201E"; --sygnalizator 1E
  134.                         --dioda
  135.                     end if;  
  136.                     if cnt1>="011" then
  137.                         x<=X"201C"; --sygnalizator 1C
  138.                         --dioda
  139.                     end if;
  140.                     if cnt1>="100" then
  141.                         x<=X"202C"; --sygnalizator 2C
  142.                         --dioda
  143.                     end if;
  144.                     if cnt1>="101" then
  145.                         x<=X"201F"; --sygnalizator 1F
  146.                         --dioda    
  147.                     end if;
  148.                    
  149.                     if dzien='0' then
  150.                         stan_nast<=noc;
  151.                     elsif cnt3>="10" then
  152.                         stan_nast<=stan3;
  153.                     end if;
  154.                    
  155.                 when STAN3=>               
  156.                     if cnt1>="000" then
  157.                         x<=X"301A"; -- sygnalizator 1A
  158.                         --dioda
  159.                     end if;
  160.                     if cnt1>="001" then
  161.                         x<=X"302A"; --sygnalizator 2A
  162.                         --dioda
  163.                     end if;
  164.                     if cnt1>="010" then
  165.                         x<=X"301E"; --sygnalizator 1E
  166.                         --dioda
  167.                     end if;
  168.                     if cnt1>="011" then
  169.                         x<=X"301C"; --sygnalizator 1C
  170.                         --dioda
  171.                     end if;
  172.                     if cnt1>="100" then
  173.                         x<=X"302C"; --sygnalizator 2C
  174.                         --dioda
  175.                     end if;
  176.                     if cnt1>="101" then
  177.                         x<=X"301F"; --sygnalizator 1F
  178.                         --dioda    
  179.                     end if;
  180.                    
  181.                     if dzien='0' then
  182.                         stan_nast<=noc;
  183.                     elsif cnt2>="1111" then
  184.                         stan_nast<=stan4;
  185.                     end if;
  186.                    
  187.                 when STAN4=>               
  188.                     if cnt1>="000" then
  189.                         x<=X"401A"; -- sygnalizator 1A
  190.                         --dioda
  191.                     end if;
  192.                     if cnt1>="001" then
  193.                         x<=X"402A"; --sygnalizator 2A
  194.                         --dioda
  195.                     end if;
  196.                     if cnt1>="010" then
  197.                         x<=X"401E"; --sygnalizator 1E
  198.                         --dioda
  199.                     end if;
  200.                     if cnt1>="011" then
  201.                         x<=X"401C"; --sygnalizator 1C
  202.                         --dioda
  203.                     end if;
  204.                     if cnt1>="100" then
  205.                         x<=X"402C"; --sygnalizator 2C
  206.                         --dioda
  207.                     end if;
  208.                     if cnt1>="101" then
  209.                         x<=X"401F"; --sygnalizator 1F
  210.                         --dioda    
  211.                     end if;
  212.                    
  213.                     if dzien='0' then
  214.                         stan_nast<=noc;
  215.                     elsif cnt3>="10" then
  216.                         stan_nast<=stan5;
  217.                     end if;
  218.                    
  219.                 when STAN5=>               
  220.                     if cnt1>="000" then
  221.                         x<=X"501A"; -- sygnalizator 1A
  222.                         --dioda
  223.                     end if;
  224.                     if cnt1>="001" then
  225.                         x<=X"502A"; --sygnalizator 2A
  226.                         --dioda
  227.                     end if;
  228.                     if cnt1>="010" then
  229.                         x<=X"501E";--sygnalizator 1E
  230.                         --dioda
  231.                     end if;
  232.                     if cnt1>="011" then
  233.                         x<=X"501C"; --sygnalizator 1C
  234.                         --dioda
  235.                     end if;
  236.                     if cnt1>="100" then
  237.                         x<=X"502C"; --sygnalizator 2C
  238.                         --dioda
  239.                     end if;
  240.                     if cnt1>="101" then
  241.                         x<=X"501F"; --sygnalizator 1F
  242.                         --dioda    
  243.                     end if;
  244.                    
  245.                     if dzien='0' then
  246.                         stan_nast<=noc;
  247.                     elsif cnt2>="1111" then
  248.                         stan_nast<=stan6;
  249.                     end if;
  250.                    
  251.                 when STAN6=>               
  252.                     if cnt1>="000" then
  253.                         x<=X"601A"; -- sygnalizator 1A
  254.                         --dioda
  255.                     end if;
  256.                     if cnt1>="001" then
  257.                         x<=X"602A"; --sygnalizator 2A
  258.                         --dioda
  259.                     end if;
  260.                     if cnt1>="010" then
  261.                         x<=X"601E"; --sygnalizator 1E
  262.                         --dioda
  263.                     end if;
  264.                     if cnt1>="011" then
  265.                         x<=X"601C"; --sygnalizator 1C
  266.                         --dioda
  267.                     end if;
  268.                     if cnt1>="100" then
  269.                         x<=X"602C"; --sygnalizator 2C
  270.                         --dioda
  271.                     end if;
  272.                     if cnt1>="101" then
  273.                         x<=X"601F"; --sygnalizator 1F
  274.                         --dioda    
  275.                     end if;
  276.                    
  277.                     if dzien='0' then
  278.                         stan_nast<=noc;
  279.                     elsif cnt3>="10" then
  280.                         stan_nast<=stan1;
  281.                     end if;
  282.                 when NOC=>
  283.                    
  284.                     if cnt4='1' then                       
  285.                         x<=X"09BC";
  286.                     else
  287.                         x<=X"9BC0";
  288.                     end if;
  289.                     --dioda
  290.                     if dzien='1' then
  291.                         stan_nast<=stan1;
  292.                     elsif cnt3>="10" then
  293.                         stan_nast<=off;
  294.                     end if;
  295.                 when OFF=>
  296.                     if cnt4='1' then                       
  297.                         x<=X"9BC0";
  298.                     else
  299.                         x<=X"09BC";
  300.                     end if;
  301.                    
  302.                     --dioda
  303.                     if dzien='1' then
  304.                         stan_nast<=stan1;
  305.                     elsif cnt3>="10" then
  306.                         stan_nast<=noc;
  307.                     end if;                
  308.             end case;          
  309.         end process AUTOMAT;
  310.  
  311.    
  312. --CLOCK DIVIDER + COUNTERS--       
  313.         -------------30 sec divider /sterowanie dayligh/---------
  314.         process(clk, reset)
  315.             begin
  316.                 if reset='1' then
  317.                 clk_div30s<=(others=>'0');
  318.                 elsif(clk'event and clk='1') then
  319.                     if clk_div30s>="1011001011010000010111100000000" then
  320.                         clk_div30s<=(others=>'0');
  321.                         if daylight>="110" and dzien='1' then
  322.                             daylight<="000";
  323.                             dzien<= not dzien;
  324.                         elsif daylight>="010" and dzien='0' then
  325.                             daylight<="000";
  326.                             dzien<= not dzien;
  327.                         else
  328.                             daylight<=daylight+"01";
  329.                         end if;
  330.                     else
  331.                         clk_div30s<=clk_div30s+"01";
  332.                     end if;
  333.                 end if;
  334.             end process;
  335.            
  336.         -------------2 sec divider /sterowanie zmiana stanow/-----------       
  337.         process(clk, reset)
  338.             begin
  339.                 if reset='1' then
  340.                 clk_div2s<=(others=>'0');
  341.                 elsif(clk'event and clk='1') then
  342.                     if clk_div2s>="101111101011110000100000000" then
  343.                         clk_div2s<=(others=>'0');
  344.                         cnt4 <= not cnt4;
  345.                         if (stan=stan2 or stan=stan4 or stan=stan6 or stan=noc or stan=off) then
  346.                             cnt2<="0000";
  347.                            
  348.                         else
  349.                             cnt2<=cnt2+"01"; --30s
  350.                         end if;
  351.                        
  352.                         if (stan=stan1 or stan=stan3 or stan=stan5 or cnt3>="10") then
  353.                             cnt3<="00";
  354.                         else
  355.                             cnt3<=cnt3+"01";--4s           
  356.                         end if;                            
  357.                        
  358.                         if cnt1>="101" or dzien='0' then
  359.                             cnt1<="000";
  360.                         else
  361.                             cnt1<=cnt1+"01";                           
  362.                         end if;                
  363.                        
  364.                     else
  365.                         clk_div2s<=clk_div2s+"01";
  366.                     end if;
  367.                 end if;
  368.             end process;
  369.            
  370.         -------------1 milisec divider /sterowanie anodami wyswietlacza 7seg/-----------       
  371.         process(clk, reset)
  372.             begin
  373.                 if reset='1' then
  374.                 clk_div1ms<=(others=>'0');
  375.                 elsif(clk'event and clk='1') then
  376.                     if clk_div1ms(16)='1' then
  377.                         clk_div1ms<=(others=>'0');
  378.                         sel<= sel + "01";
  379.                     else
  380.                         clk_div1ms<=clk_div1ms+"01";
  381.                     end if;
  382.                 end if;
  383.             end process;
  384. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement