Advertisement
Guest User

Untitled

a guest
Sep 15th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 6.08 KB | None | 0 0
  1. library IEEE;
  2. use IEEE.STD_LOGIC_1164.ALL;
  3. use ieee.numeric_std.all;
  4.  
  5. entity Main is
  6.     Port ( reset     : in STD_LOGIC;
  7.            clk       : in STD_LOGIC;
  8.            led       : out std_logic_vector (15 downto 0));
  9. end Main;
  10.  
  11. architecture Behavioral of Main is
  12.  
  13. signal ledME    : bit_vector (7 downto 0);
  14. signal ledMD    : bit_vector (7 downto 0);
  15. signal count    : unsigned (22 downto 0) := (others=>'0');
  16. signal ledzero  : unsigned (15 downto 0) := "0000000000000000";
  17. signal enable   : std_logic := '0';
  18. signal clk05: std_logic;
  19. type estado is (inicio, frente, direita, esquerda, atras, low_bat);
  20. signal prox_estado, estado_atual : estado := inicio;
  21. signal count_action : unsigned (27 downto 0) := (others=>'0');
  22. signal count_battery : unsigned (6 downto 0) := "0000000";
  23. signal count_passo: integer;
  24.  
  25.  
  26. begin
  27.  
  28.     -- processo de geração de clk
  29.  
  30.     -- contador de 100 ms e criacao do enable
  31.     process(clk,reset)
  32.     begin
  33.         if reset='1' then
  34.             count <= (others=>'0');
  35.         elsif rising_edge(clk) then
  36.             if count = "10011000100101101000000" then
  37.                 enable <= '1';
  38.                 count <= (others=>'0');
  39.             else
  40.                 enable <= '0';
  41.                 count <= count+1;
  42.             end if;
  43.         end if;
  44.     end process;
  45.  
  46.     -- processo para registrar estado --------------------------------------------------------
  47.     process(clk,reset)
  48.     begin
  49.         if reset='1' then
  50.             estado_atual <= inicio;
  51.         elsif rising_edge(clk) then
  52.             estado_atual <= prox_estado;
  53.                        
  54.         end if;
  55.     end process;
  56.    
  57.     -- processo para zerar os leds -----------------------------------------------------------
  58.  
  59.    
  60.     -- processo da maquina de estados --------------------------------------------------------
  61.     process (estado_atual, clk)
  62.     begin
  63.         case estado_atual is
  64.         when  inicio =>
  65.             ledMe <= (others => '0');
  66.             ledMd <= (others => '0');
  67.             count_passo <= 0;
  68.            
  69.         when  frente =>
  70.             ledMe <= "00000001";
  71.             ledMd <= "00000001";
  72.             if count_passo = 1 then
  73.                 if count_action = "0101111101011110000100000000" then
  74.                     prox_estado <= direita;
  75.                     count_passo <= count_passo + 1;
  76.                 else
  77.                     ledMe <= ledMe rol 1;
  78.                     ledMd <= ledMd rol 1;
  79.                 end if;
  80.             elsif count_passo= 3 then
  81.                 if count_action = "0010111110101111000010000000" then
  82.                    prox_estado <= direita;
  83.                    count_passo <= count_passo + 1;
  84.                 else  
  85.                     ledMe <= ledMe rol 1;
  86.                     ledMd <= ledMd rol 1;      
  87.                 end if;  
  88.             else
  89.                 if count_action = "0010111110101111000010000000" then
  90.                    prox_estado <= esquerda;
  91.                    count_passo <= count_passo + 1;
  92.                 else  
  93.                    ledMe <= ledMe rol 1;
  94.                    ledMd <= ledMd rol 1;      
  95.                 end if;                        
  96.             end if;
  97.              
  98.         when  direita =>
  99.             ledMe <= "10000000";
  100.             ledMd <= "00000001";
  101.             if count_passo = 2 then
  102.                 if count_action = "0101111101011110000100000000" then
  103.                     prox_estado <= frente;
  104.                     count_passo <= count_passo + 1;
  105.                 else
  106.                     ledMe <= ledMe ror 1;
  107.                     ledMd <= ledMd rol 1;
  108.                 end if;
  109.             else
  110.                 if count_action = "0101111101011110000100000000" then
  111.                     prox_estado <= atras;
  112.                     count_passo <= count_passo + 1;
  113.                 else  
  114.                     ledMe <= ledMe ror 1;
  115.                     ledMd <= ledMd rol 1;      
  116.                 end if;  
  117.                        
  118.             end if;            
  119.        
  120.         when  esquerda =>
  121.             ledMe <= "00000001";
  122.             ledMd <= "10000000";
  123.             if count_passo = 4 then
  124.                 if count_action = "0101111101011110000100000000" then
  125.                     prox_estado <= frente;
  126.                     count_passo <= count_passo + 1;
  127.                 else
  128.                     ledMe <= ledMe rol 1;
  129.                     ledMd <= ledMd ror 1;
  130.                 end if;
  131.             else
  132.                 if count_action = "0101111101011110000100000000" then
  133.                     prox_estado <= atras;
  134.                     count_passo <= count_passo + 1;
  135.                 else  
  136.                     ledMe <= ledMe rol 1;
  137.                     ledMd <= ledMd ror 1;      
  138.                 end if;                
  139.             end if;            
  140.        
  141.         when  atras =>
  142.             ledMe <= "10000000";
  143.             ledMd <= "10000000";
  144.             if count_passo = 7 then
  145.                 if count_action = "1000111100001101000110000000" then
  146.                     prox_estado <= esquerda;
  147.                     count_passo <= count_passo + 1;
  148.                 else
  149.                     ledMe <= ledMe ror 1;
  150.                     ledMd <= ledMd ror 1;
  151.                 end if;
  152.             else
  153.                 if count_action = "1011111010111100001000000000" then
  154.                     prox_estado <= low_bat;
  155.                     count_passo <= count_passo + 1;
  156.                 else  
  157.                     ledMe <= ledMe ror 1;
  158.                     ledMd <= ledMd ror 1;      
  159.                 end if;                
  160.             end if;                
  161.         when  low_bat =>
  162.             ledMe <= (others => '0');
  163.             ledMd <= (others => '0');
  164.             if rising_edge(clk05) then
  165.                 ledMe <= not ledME;
  166.                 ledMd <= not ledMd;
  167.             else
  168.                ledMe <= ledME;
  169.                ledMd <= ledMd;    
  170.             end if;
  171.         end case;
  172.     end process;
  173.  
  174.     led (15 downto 8) <= to_stdlogicvector (ledME);
  175.     led (7 downto 0)  <= to_stdlogicvector (ledMD);
  176.    
  177. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement