Advertisement
-Dn-

Broken Clock

Mar 5th, 2023
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VHDL 4.11 KB | Source Code | 0 0
  1. library IEEE;
  2. use IEEE.std_logic_1164.all;
  3. use IEEE.std_logic_arith.all;
  4. use IEEE.std_logic_unsigned.all;
  5.  
  6. entity realdig is
  7. Port (
  8.     reloj, pausa, reset1: in std_logic;
  9.     L1,  L2, L3, L4: out std_logic_vector (6 downto 0));
  10. end realdig;
  11.  
  12. architecture behavioral of realdig is
  13. signal segundo: std_logic;
  14. signal rapido: std_logic;
  15. signal n: std_logic;
  16. signal Qum: std_logic_vector(3 downto 0);
  17. signal Qdm: std_logic_vector(3 downto 0);
  18. signal e: std_logic;
  19. signal Quh: std_logic_vector(3 downto 0);
  20. signal Qdh: std_logic_vector(3 downto 0);
  21. signal z: std_logic;
  22. signal u: std_logic;
  23. signal d: std_logic;
  24. signal reset: std_logic;
  25.  
  26.  
  27. begin
  28.     divisor: process (reloj)
  29.     variable cuenta: std_logic_vector(27 downto 0) := X"0000000";
  30.     begin
  31.         if rising_edge (reloj) then
  32.             if cuenta=X"48009E0" then
  33.                 cuenta:= X"0000000";
  34.             else
  35.                 cuenta:= cuenta +1;
  36.             end if;
  37.         end if;
  38.         segundo <= cuenta(22);
  39.         rapido <= cuenta(10);
  40.     end process;
  41.    
  42.     unidades: process (segundo)
  43.     variable cuenta: std_logic_vector(3 downto 0) := "0000";
  44.     begin
  45.     if rising_edge (segundo) then
  46.         if pausa = '1' then
  47.         else
  48.             if cuenta ="1001" then
  49.                 cuenta:="0000";
  50.                 n <= '1';
  51.             else
  52.                 cuenta:= cuenta +1;
  53.                 n <= '0';
  54.             end if;
  55.         end if;
  56.         if reset1 = '0' then
  57.             cuenta:="0000";
  58.             n<='1';
  59.         end if;
  60.     end if;
  61.     Qum <= cuenta;
  62.     end process;
  63.    
  64.     decenas: process (n)
  65.     variable cuenta: std_logic_vector(3 downto 0) := "0000";
  66.     begin
  67.     if rising_edge (n) then
  68.         if pausa = '1' then
  69.         else
  70.             if cuenta ="0101" then
  71.                 cuenta:="0000";
  72.                 e <= '1';
  73.             else
  74.                 cuenta:= cuenta +1;
  75.                 e<= '0';
  76.             end if;
  77.         end if;
  78.         if reset1 = '0' then
  79.                 cuenta:="0000";
  80.                 e<='1';
  81.         end if;
  82.     end if;
  83.     Qdm <= cuenta;
  84.     end process;
  85.    
  86.     HoraU: Process(e,reset)
  87.     variable cuenta: std_logic_vector(3 downto 0):="0000";
  88.     begin
  89.     if rising_edge(e) then
  90.         if pausa = '1' then
  91.         else
  92.             if cuenta="1001" then
  93.                 cuenta:= "0000";
  94.                 z<='1';
  95.             else
  96.                 cuenta:=cuenta+1;
  97.                 z<='0';
  98.             end if;
  99.         end if;
  100.         if reset='1' then
  101.             cuenta:="0000";
  102.         end if;
  103.         if reset1 = '0' then
  104.                 cuenta:="0000";
  105.                 z<='1';
  106.         end if;
  107.     end if;
  108.     Quh<=cuenta;
  109.     u<=cuenta(2);
  110.     end Process;
  111.    
  112.     HoraD: Process(z, reset)
  113.     variable cuenta: std_logic_vector(3 downto 0):="0000";
  114.     begin
  115.     if rising_edge(z) then
  116.         if pausa = '1' then
  117.         else
  118.             if cuenta="0010" then
  119.                 cuenta:= "0000";
  120.             else
  121.                 cuenta:=cuenta+1;
  122.             end if;
  123.         end if;
  124.         if reset='1' then
  125.             cuenta:="0000";
  126.         end if;
  127.         if reset1 = '0' then
  128.                 cuenta:="0000";
  129.         end if;
  130.     end if;
  131.     Qdh<=cuenta;
  132.     d <=cuenta(1);
  133.     end Process;
  134.    
  135.     inicia: process (u,d)
  136.     begin
  137.     reset <= (u and d);
  138.     end process;
  139.    
  140.     with Qum select
  141.     L1 <= "1000000" when "0000", --0
  142.             "1111001" when "0001", --1
  143.             "0100100" when "0010", --2
  144.             "0110000" when "0011", --3
  145.             "0011001" when "0100", --4
  146.             "0010010" when "0101", --5
  147.             "0000010" when "0110", --6
  148.             "1111000" when "0111", --7
  149.             "0000000" when "1000", --8
  150.             "0010000" when "1001", --9
  151.             "1000000" when others; --F
  152.            
  153.     with Qdm select
  154.     L2 <= "1000000" when "0000", --0
  155.             "1111001" when "0001", --1
  156.             "0100100" when "0010", --2
  157.             "0110000" when "0011", --3
  158.             "0011001" when "0100", --4
  159.             "0010010" when "0101", --5
  160.             "0000010" when "0110", --6
  161.             "1111000" when "0111", --7
  162.             "0000000" when "1000", --8
  163.             "0010000" when "1001", --9
  164.             "1000000" when others; --F
  165.            
  166.     with Quh select
  167.     L3 <= "1000000" when "0000", --0
  168.             "1111001" when "0001", --1
  169.             "0100100" when "0010", --2
  170.             "0110000" when "0011", --3
  171.             "0011001" when "0100", --4
  172.             "0010010" when "0101", --5
  173.             "0000010" when "0110", --6
  174.             "1111000" when "0111", --7
  175.             "0000000" when "1000", --8
  176.             "0010000" when "1001", --9
  177.             "1000000" when others; --F
  178.            
  179.     with Qdh select
  180.     L4 <= "1000000" when "0000", --0
  181.             "1111001" when "0001", --1
  182.             "0100100" when "0010", --2
  183.             "0110000" when "0011", --3
  184.             "0011001" when "0100", --4
  185.             "0010010" when "0101", --5
  186.             "0000010" when "0110", --6
  187.             "1111000" when "0111", --7
  188.             "0000000" when "1000", --8
  189.             "0010000" when "1001", --9
  190.             "1000000" when others; --F
  191. end Behavioral;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement