Advertisement
Guest User

Untitled

a guest
Mar 13th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 KB | None | 0 0
  1. //7 binary_7_bits_BCD
  2. module binary_7_bits_BCD ( // display decimal value of 7-digit binary input
  3. input [6:0] SW,
  4. output [6:0] LEDR,
  5. output [0:6] HEX0, HEX1, HEX2);
  6.  
  7. assign LEDR[6:0] = SW[6:0];
  8. wire [0:6] sw1 = SW[6:0]; // max 128
  9. reg hundreds = 0;
  10. reg tens = 0;
  11. reg n1 = 0;
  12.  
  13. showDigitDec ex1(n1, HEX0);
  14. showDigitDec ex2(tens, HEX1);
  15. showDigitDec ex3(hundreds, HEX2);
  16.  
  17. always @*
  18. begin
  19.  
  20. if(sw1 >= 100) hundreds = 1;
  21. else hundreds = 0;
  22.  
  23. if (sw1 >= 90 + hundreds * 100) tens = 9;
  24. else if (sw1 >= 80 + hundreds * 100) tens = 8;
  25. else if (sw1 >= 70 + hundreds * 100) tens = 7;
  26. else if (sw1 >= 60 + hundreds * 100) tens = 6;
  27. else if (sw1 >= 50 + hundreds * 100) tens = 5;
  28. else if (sw1 >= 40 + hundreds * 100) tens = 4;
  29. else if (sw1 >= 30 + hundreds * 100) tens = 3;
  30. else if (sw1 >= 20 + hundreds * 100) tens = 2;
  31. else if (sw1 >= 10 + hundreds * 100) tens = 1;
  32. else tens = 0;
  33.  
  34. n1 = sw1 - tens * 10 - hundreds * 100;
  35.  
  36. end
  37.  
  38. endmodule
  39.  
  40.  
  41.  
  42.  
  43.  
  44. //8 binary_8_bits_BCD
  45. module binary_8_bits_BCD ( // display decimal value of 8-digit binary input
  46. input [7:0] SW,
  47. output [7:0] LEDR,
  48. output [0:6] HEX0, HEX1, HEX2);
  49.  
  50. assign LEDR[7:0] = SW[7:0];
  51. wire [0:7] sw1 = SW[7:0]; // max 256
  52. reg hundreds = 0;
  53. reg tens = 0;
  54. reg n1 = 0;
  55.  
  56. showDigitDec ex1(n1, HEX0);
  57. showDigitDec ex2(tens, HEX1);
  58. showDigitDec ex3(hundreds, HEX2);
  59.  
  60. integer i;
  61. always @*
  62. begin
  63.  
  64. if(sw1 >= 200) hundreds = 2;
  65. else if(sw1 >= 100) hundreds = 1;
  66. else hundreds = 0;
  67.  
  68. if (sw1 >= 90 + hundreds * 100) tens = 9;
  69. else if (sw1 >= 80 + hundreds * 100) tens = 8;
  70. else if (sw1 >= 70 + hundreds * 100) tens = 7;
  71. else if (sw1 >= 60 + hundreds * 100) tens = 6;
  72. else if (sw1 >= 50 + hundreds * 100) tens = 5;
  73. else if (sw1 >= 40 + hundreds * 100) tens = 4;
  74. else if (sw1 >= 30 + hundreds * 100) tens = 3;
  75. else if (sw1 >= 20 + hundreds * 100) tens = 2;
  76. else if (sw1 >= 10 + hundreds * 100) tens = 1;
  77. else tens = 0;
  78.  
  79. n1 = sw1 - tens * 10 - hundreds * 100;
  80.  
  81. end
  82.  
  83. endmodule
  84.  
  85.  
  86.  
  87. //9 binary_9_bits_BCD
  88. module binary_9_bits_BCD ( // display decimal value of 9-digit binary input
  89. input [8:0] SW,
  90. output [8:0] LEDR,
  91. output [0:6] HEX0, HEX1, HEX2);
  92.  
  93. assign LEDR[8:0] = SW[8:0];
  94. wire [0:8] sw1 = SW[8:0]; // max 512
  95. reg hundreds = 0;
  96. reg tens = 0;
  97. reg n1 = 0;
  98.  
  99. showDigitDec ex1(n1, HEX0);
  100. showDigitDec ex2(tens, HEX1);
  101. showDigitDec ex3(hundreds, HEX2);
  102.  
  103. integer i;
  104. always @*
  105. begin
  106.  
  107. if(sw1 >= 500) hundreds = 5;
  108. else if(sw1 >= 400) hundreds = 4;
  109. else if(sw1 >= 300) hundreds = 3;
  110. else if(sw1 >= 200) hundreds = 2;
  111. else if(sw1 >= 100) hundreds = 1;
  112. else hundreds = 0;
  113.  
  114. if (sw1 >= 90 + hundreds * 100) tens = 9;
  115. else if (sw1 >= 80 + hundreds * 100) tens = 8;
  116. else if (sw1 >= 70 + hundreds * 100) tens = 7;
  117. else if (sw1 >= 60 + hundreds * 100) tens = 6;
  118. else if (sw1 >= 50 + hundreds * 100) tens = 5;
  119. else if (sw1 >= 40 + hundreds * 100) tens = 4;
  120. else if (sw1 >= 30 + hundreds * 100) tens = 3;
  121. else if (sw1 >= 20 + hundreds * 100) tens = 2;
  122. else if (sw1 >= 10 + hundreds * 100) tens = 1;
  123. else tens = 0;
  124.  
  125. n1 = sw1 - tens * 10 - hundreds * 100;
  126.  
  127. end
  128.  
  129. endmodule
  130.  
  131.  
  132.  
  133. //10 binary_10_bits_BCD
  134. module binary_10_bits_BCD ( // display decimal value of 10-digit binary input
  135. input [9:0] SW,
  136. output [9:0] LEDR,
  137. output [0:6] HEX0, HEX1, HEX2, HEX3);
  138.  
  139. assign LEDR[9:0] = SW[9:0];
  140. wire [0:9] sw1 = SW[9:0]; // max 1024
  141. reg thousands = 0;
  142. reg hundreds = 0;
  143. reg tens = 0;
  144. reg n1 = 0;
  145.  
  146. showDigitDec ex1(n1, HEX0);
  147. showDigitDec ex2(tens, HEX1);
  148. showDigitDec ex3(hundreds, HEX2);
  149. showDigitDec ex4(thousands, HEX3);
  150.  
  151. integer i;
  152. always @*
  153. begin
  154.  
  155. if(sw1 >= 1000) thousands= 1;
  156. else thousands = 0;
  157.  
  158. if(sw1 >= 900) hundreds = 9;
  159. else if(sw1 >= 800 + thousands * 1000) hundreds = 8;
  160. else if(sw1 >= 700 + thousands * 1000) hundreds = 7;
  161. else if(sw1 >= 600 + thousands * 1000) hundreds = 6;
  162. else if(sw1 >= 500 + thousands * 1000) hundreds = 5;
  163. else if(sw1 >= 400 + thousands * 1000) hundreds = 4;
  164. else if(sw1 >= 300 + thousands * 1000) hundreds = 3;
  165. else if(sw1 >= 200 + thousands * 1000) hundreds = 2;
  166. else if(sw1 >= 100 + thousands * 1000) hundreds = 1;
  167. else hundreds = 0;
  168.  
  169. if (sw1 >= 90 + hundreds * 100 + thousands * 1000) tens = 9;
  170. else if (sw1 >= 80 + hundreds * 100 + thousands * 1000) tens = 8;
  171. else if (sw1 >= 70 + hundreds * 100 + thousands * 1000) tens = 7;
  172. else if (sw1 >= 60 + hundreds * 100 + thousands * 1000) tens = 6;
  173. else if (sw1 >= 50 + hundreds * 100 + thousands * 1000) tens = 5;
  174. else if (sw1 >= 40 + hundreds * 100 + thousands * 1000) tens = 4;
  175. else if (sw1 >= 30 + hundreds * 100 + thousands * 1000) tens = 3;
  176. else if (sw1 >= 20 + hundreds * 100 + thousands * 1000) tens = 2;
  177. else if (sw1 >= 10 + hundreds * 100 + thousands * 1000) tens = 1;
  178. else if tens = 0;
  179.  
  180. n1 = sw1 - tens * 10 - hundreds * 100 - thousands * 1000;
  181.  
  182. end
  183.  
  184. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement