Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // DESCRIPTION: Verilator: Systemverilog example module
- // with interface to switch buttons, LEDs, LCD and register display
- parameter NINSTR_BITS = 32;
- parameter NBITS_TOP = 8, NREGS_TOP = 32;
- module top(input logic clk_2,
- input logic [NBITS_TOP-1:0] SWI,
- output logic [NBITS_TOP-1:0] LED,
- output logic [NBITS_TOP-1:0] SEG,
- output logic [NINSTR_BITS-1:0] lcd_instruction,
- output logic [NBITS_TOP-1:0] lcd_registrador [0:NREGS_TOP-1],
- output logic [NBITS_TOP-1:0] lcd_pc, lcd_SrcA, lcd_SrcB,
- lcd_ALUResult, lcd_Result, lcd_WriteData, lcd_ReadData,
- output logic lcd_MemWrite, lcd_Branch, lcd_MemtoReg, lcd_RegWrite);
- logic [1:0] clock;
- logic stop;
- logic reset;
- logic [5:0] chuva;
- always_comb begin
- stop <= SWI[7];
- reset <= SWI[6];
- chuva <= SWI[5:0];
- end
- always_ff @(posedge clk_2) begin
- if(!stop) clock += 1;
- end
- int estado_atual;
- parameter desligado = 0, baixa = 1, alta = 2, a = 3;
- logic [1:0] valor_led;
- int contCincoPorSegundo;
- int contTresPorSegundo;
- always_ff @(posedge clock[1] or posedge reset)begin
- if(reset) begin
- valor_led <= 0;
- contTresPorSegundo = 0;
- contCincoPorSegundo = 0;
- end
- else begin
- unique case(chuva)
- 5: begin
- contCincoPorSegundo += 1;
- if(contCincoPorSegundo == 2) estado_atual = alta;
- end
- 4: begin
- estado_atual = baixa;
- end
- 3: begin
- contTresPorSegundo += 1;
- if(contTresPorSegundo == 3) estado_atual = baixa;
- end
- 2: estado_atual = desligado;
- 1: estado_atual = desligado;
- 0: estado_atual = desligado;
- endcase
- unique case (estado_atual)
- desligado: begin
- valor_led <= 0;
- end
- baixa: begin
- valor_led <= 1;
- contTresPorSegundo = 0;
- contCincoPorSegundo = 0;
- end
- alta: begin
- valor_led <= 2;
- contCincoPorSegundo = 0;
- contTresPorSegundo = 0;
- end
- endcase
- end
- end
- always_comb begin
- LED[1:0] <= valor_led;
- SEG[7] <= clock[1];
- end
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement