Advertisement
Guest User

sa

a guest
Oct 17th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. module bomba (
  2. input clk,
  3. input rst,
  4. input sw0,
  5. output [6:0] disp0
  6. );
  7.  
  8. reg[6:0] disp0_reg,disp0_next;
  9. integer tick_reg,tick_next;
  10. integer crta_reg,crta_next;
  11.  
  12. localparam tus = 50_000_000;
  13.  
  14. always @(posedge clk or posedge rst)
  15. begin
  16. if(rst == 1)
  17. begin
  18. disp0_reg <= 7'b1111111;
  19. tick_reg <= 10*tus;
  20. crta_reg <= 0;
  21. end
  22. else
  23. begin
  24. disp0_reg <= disp0_next;
  25. tick_reg <= tick_next;
  26. crta_reg <= crta_next;
  27. end
  28. end
  29.  
  30. always @(*)
  31. begin
  32. tick_next = tick_reg;
  33. if((sw0 == 1) || (tick_reg < 10*tus && tick_reg > 0))
  34. begin
  35. tick_next = tick_reg - 1;
  36. end
  37. end
  38.  
  39. always @(*)
  40. begin
  41. crta_next = crta_reg;
  42. if(~(tick_reg>0))
  43. begin
  44. crta_next = (crta_reg + 1) % tus;
  45. end
  46. end
  47.  
  48. always @(*)
  49. begin
  50. disp0_next = disp0_reg;
  51. if(tick_reg == 10*tus)
  52. begin
  53. disp0_next = 7'b1111111;
  54. end
  55. else if(tick_reg > 9*tus)
  56. begin
  57. disp0_next = cifra(9);
  58. end
  59. else if(tick_reg > 8*tus)
  60. begin
  61. disp0_next = cifra(8);
  62. end
  63. else if(tick_reg > 7*tus)
  64. begin
  65. disp0_next = cifra(7);
  66. end
  67. else if(tick_reg > 6*tus)
  68. begin
  69. disp0_next = cifra(6);
  70. end
  71. else if(tick_reg > 5*tus)
  72. begin
  73. disp0_next = cifra(5);
  74. end
  75. else if(tick_reg > 4*tus)
  76. begin
  77. disp0_next = cifra(4);
  78. end
  79. else if(tick_reg > 3*tus)
  80. begin
  81. disp0_next = cifra(3);
  82. end
  83. else if(tick_reg > 2*tus)
  84. begin
  85. disp0_next = cifra(2);
  86. end
  87. else if(tick_reg > tus)
  88. begin
  89. disp0_next = cifra(1);
  90. end
  91. else if(tick_reg > 0)
  92. begin
  93. disp0_next = cifra(0);
  94. end
  95. else
  96. begin
  97. if(crta_reg < tus/2)
  98. begin
  99. disp0_next = 7'b0111111;
  100. end
  101. else
  102. begin
  103. disp0_next = 7'b1111111;
  104. end
  105. end
  106. end
  107.  
  108. function[6:0] cifra(input integer broj);
  109. begin
  110. case(broj)
  111. 0: cifra = 7'b1000000;
  112. 1: cifra = 7'b1111001;
  113. 2: cifra = 7'b0100100;
  114. 3: cifra = 7'b0110000;
  115. 4: cifra = 7'b0011001;
  116. 5: cifra = 7'b0010010;
  117. 6: cifra = 7'b0000010;
  118. 7: cifra = 7'b1111000;
  119. 8: cifra = 7'b0000000;
  120. 9: cifra = 7'b0010000;
  121. default: cifra = 7'b1111111;
  122. endcase
  123. end
  124. endfunction
  125.  
  126. assign disp0 = disp0_reg;
  127.  
  128. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement