Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- module bomba (
- input clk,
- input rst,
- input sw0,
- output [6:0] disp0
- );
- reg[6:0] disp0_reg,disp0_next;
- integer tick_reg,tick_next;
- integer crta_reg,crta_next;
- localparam tus = 50_000_000;
- always @(posedge clk or posedge rst)
- begin
- if(rst == 1)
- begin
- disp0_reg <= 7'b1111111;
- tick_reg <= 10*tus;
- crta_reg <= 0;
- end
- else
- begin
- disp0_reg <= disp0_next;
- tick_reg <= tick_next;
- crta_reg <= crta_next;
- end
- end
- always @(*)
- begin
- tick_next = tick_reg;
- if((sw0 == 1) || (tick_reg < 10*tus && tick_reg > 0))
- begin
- tick_next = tick_reg - 1;
- end
- end
- always @(*)
- begin
- crta_next = crta_reg;
- if(~(tick_reg>0))
- begin
- crta_next = (crta_reg + 1) % tus;
- end
- end
- always @(*)
- begin
- disp0_next = disp0_reg;
- if(tick_reg == 10*tus)
- begin
- disp0_next = 7'b1111111;
- end
- else if(tick_reg > 9*tus)
- begin
- disp0_next = cifra(9);
- end
- else if(tick_reg > 8*tus)
- begin
- disp0_next = cifra(8);
- end
- else if(tick_reg > 7*tus)
- begin
- disp0_next = cifra(7);
- end
- else if(tick_reg > 6*tus)
- begin
- disp0_next = cifra(6);
- end
- else if(tick_reg > 5*tus)
- begin
- disp0_next = cifra(5);
- end
- else if(tick_reg > 4*tus)
- begin
- disp0_next = cifra(4);
- end
- else if(tick_reg > 3*tus)
- begin
- disp0_next = cifra(3);
- end
- else if(tick_reg > 2*tus)
- begin
- disp0_next = cifra(2);
- end
- else if(tick_reg > tus)
- begin
- disp0_next = cifra(1);
- end
- else if(tick_reg > 0)
- begin
- disp0_next = cifra(0);
- end
- else
- begin
- if(crta_reg < tus/2)
- begin
- disp0_next = 7'b0111111;
- end
- else
- begin
- disp0_next = 7'b1111111;
- end
- end
- end
- function[6:0] cifra(input integer broj);
- begin
- case(broj)
- 0: cifra = 7'b1000000;
- 1: cifra = 7'b1111001;
- 2: cifra = 7'b0100100;
- 3: cifra = 7'b0110000;
- 4: cifra = 7'b0011001;
- 5: cifra = 7'b0010010;
- 6: cifra = 7'b0000010;
- 7: cifra = 7'b1111000;
- 8: cifra = 7'b0000000;
- 9: cifra = 7'b0010000;
- default: cifra = 7'b1111111;
- endcase
- end
- endfunction
- assign disp0 = disp0_reg;
- endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement