Advertisement
Guest User

LOAC-PARA_BRISA

a guest
Nov 19th, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // DESCRIPTION: Verilator: Systemverilog example module
  2. // with interface to switch buttons, LEDs, LCD and register display
  3.  
  4. parameter NINSTR_BITS = 32;
  5. parameter NBITS_TOP = 8, NREGS_TOP = 32;
  6. module top(input  logic clk_2,
  7.            input  logic [NBITS_TOP-1:0] SWI,
  8.            output logic [NBITS_TOP-1:0] LED,
  9.            output logic [NBITS_TOP-1:0] SEG,
  10.            output logic [NINSTR_BITS-1:0] lcd_instruction,
  11.            output logic [NBITS_TOP-1:0] lcd_registrador [0:NREGS_TOP-1],
  12.            output logic [NBITS_TOP-1:0] lcd_pc, lcd_SrcA, lcd_SrcB,
  13.              lcd_ALUResult, lcd_Result, lcd_WriteData, lcd_ReadData,
  14.            output logic lcd_MemWrite, lcd_Branch, lcd_MemtoReg, lcd_RegWrite);
  15.  
  16.  
  17. logic [1:0] clock;
  18. logic stop;
  19. logic reset;
  20. logic [5:0] chuva;
  21.  
  22. always_comb begin
  23.     stop <= SWI[7];
  24.     reset <= SWI[6];
  25.     chuva <= SWI[5:0];
  26. end
  27.  
  28.  
  29. always_ff @(posedge clk_2) begin
  30.     if(!stop) clock += 1;
  31. end
  32.  
  33.  
  34. int estado_atual;
  35.  
  36.  
  37.  
  38. parameter desligado  = 0, baixa = 1, alta = 2, a = 3;
  39.  
  40.  
  41. logic [1:0] valor_led;
  42.  
  43.  
  44. int contCincoPorSegundo;
  45. int contTresPorSegundo;
  46. always_ff @(posedge  clock[1] or posedge  reset)begin
  47.  
  48.     if(reset) begin
  49.         valor_led <= 0;
  50.         contTresPorSegundo = 0;  
  51.         contCincoPorSegundo = 0;
  52.     end
  53.  
  54.     else begin
  55.         unique case(chuva)
  56.             5: begin
  57.                 contCincoPorSegundo += 1;
  58.                 if(contCincoPorSegundo == 2) estado_atual = alta;
  59.             end
  60.             4: begin
  61.                 estado_atual = baixa;
  62.             end
  63.             3: begin
  64.                 contTresPorSegundo += 1;
  65.                 if(contTresPorSegundo == 3) estado_atual = baixa;
  66.             end
  67.             2: estado_atual = desligado;
  68.             1: estado_atual = desligado;
  69.             0: estado_atual = desligado;
  70.         endcase
  71.  
  72.         unique case (estado_atual)
  73.             desligado: begin
  74.                 valor_led <= 0;
  75.             end
  76.             baixa: begin
  77.                 valor_led <= 1;
  78.                 contTresPorSegundo = 0;  
  79.                 contCincoPorSegundo = 0;
  80.             end
  81.             alta: begin
  82.                 valor_led <= 2;
  83.                 contCincoPorSegundo = 0;
  84.                 contTresPorSegundo = 0;
  85.             end
  86.  
  87.  
  88.         endcase
  89.     end
  90.  
  91. end
  92.  
  93. always_comb begin
  94.     LED[1:0] <= valor_led;
  95.     SEG[7] <= clock[1];
  96. end
  97.  
  98. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement