that_one_nigga_you_k

Untitled

Jul 25th, 2024
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. module Main(
  2.     input wire clk,
  3.     input wire ButtonIniciar,
  4.     input wire ButtonReset,
  5.     input wire ButtonContar,
  6.     input wire ButtonPausar,
  7.     input wire ButtonParar,
  8.     output wire [6:0] segCentena,
  9.     output wire [6:0] segDezena,
  10.     output wire [6:0] segUnidade,
  11.     output wire [6:0] segDecimo
  12. );
  13.  
  14. reg [31:0] Contador1 = 0;
  15. reg [3:0] Centena = 0;
  16. reg [3:0] Dezena = 0;
  17. reg [3:0] Unidade = 0;
  18. reg [3:0] Decimo = 0;
  19. reg Ativo = 0;        // Flag para controlar a contagem
  20. reg Display = 0;      // Flag para ativar/desativar o display
  21.  
  22. wire [2:0] Estado;
  23. reg [2:0] EstadoAnterior;
  24.  
  25. Botton botao (
  26.     .clk(clk),
  27.     .ButtonIniciar(ButtonIniciar),
  28.     .ButtonReset(ButtonReset),
  29.     .ButtonContar(ButtonContar),
  30.     .ButtonPausar(ButtonPausar),
  31.     .ButtonParar(ButtonParar),
  32.     .state(Estado)
  33. );
  34.  
  35. always @(posedge clk) begin
  36.  
  37.      
  38.     if(ButtonIniciar == 1) begin
  39.         case (Estado)
  40.             3'b001: begin // RESET
  41.                 Contador1 <= 0;
  42.                 Centena <= 0;
  43.                 Dezena <= 0;
  44.                 Unidade <= 0;
  45.                 Decimo <= 0;
  46.                 Ativo <= 0;
  47.                 Display <= 1;
  48.                      EstadoAnterior = Estado;
  49.             end
  50.             3'b010: begin // COUNT
  51.                 Ativo <= 1;
  52.                 Display <= 1;
  53.                      EstadoAnterior = Estado;
  54.             end
  55.             3'b011: begin // PAUSE
  56.                      if(EstadoAnterior == 3'b010) begin
  57.                          Ativo <= 1;
  58.                          Display <= 0;
  59.                          EstadoAnterior = Estado;
  60.                      end
  61.             end
  62.             3'b100: begin // STOP
  63.                 Ativo <= 0;
  64.                 Display <= 0;
  65.                      EstadoAnterior = Estado;
  66.             end
  67.         endcase
  68.     end else begin
  69.              Contador1 <= 0;
  70.           Centena <= 0;
  71.           Dezena <= 0;
  72.           Unidade <= 0;
  73.           Decimo <= 0;
  74.           Ativo <= 0;
  75.           Display <= 1;
  76.      end
  77.  
  78.     if (Ativo == 1) begin // Apenas conta se estiver no estado COUNT
  79.         Contador1 <= Contador1 + 1;
  80.         if (Contador1 == 5000000) begin
  81.             Contador1 <= 0;
  82.             Decimo <= Decimo + 1;
  83.             if (Decimo == 9) begin
  84.                 Decimo <= 0;
  85.                 Unidade <= Unidade + 1;
  86.                 if (Unidade == 9) begin
  87.                     Unidade <= 0;
  88.                     Dezena <= Dezena + 1;
  89.                     if (Dezena == 9) begin
  90.                         Dezena <= 0;
  91.                         Centena <= Centena + 1;
  92.                     end
  93.                 end
  94.             end
  95.         end
  96.     end
  97. end
  98.  
  99. Display7 display (
  100.     .centena(Centena),
  101.     .dezena(Dezena),
  102.     .unidade(Unidade),
  103.     .decimo(Decimo),
  104.     .segCentena(segCentena),
  105.     .segDezena(segDezena),
  106.     .segUnidade(segUnidade),
  107.     .segDecimo(segDecimo),
  108.     .displayativo(Display)
  109. );
  110.  
  111. endmodule
Add Comment
Please, Sign In to add comment