Advertisement
Guest User

Untitled

a guest
Mar 13th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //CircuitA ze schematu
  2. module Circuit_zad_4(input [3:0] a, b,
  3. input cin,
  4. output reg [3:0] out);
  5. always@*
  6. begin
  7. out = (a + b + cin) % 10;
  8. end
  9. endmodule
  10. //Multiplekser
  11. module mux21 (
  12.  
  13.     input x,y,s,
  14.     output m
  15. );
  16. assign m = (~s & x) | (s & y);
  17. endmodule
  18.  
  19.  
  20. //Moduł odpowiedzialny za dodawanie
  21. module adder_BCD_2_digits_zad5(input [3:0] a, b,
  22. input cin,
  23. output [3:0]s0,
  24. output reg [3:0]s1,
  25. output reg err1, err2);
  26. wire[3:0] out_a, x;
  27. reg[3:0] z, temp;
  28. always @*
  29. begin
  30. s1 = 0;
  31. err1 = 0;
  32. err2 = 0;
  33. if (a > 9)
  34. err1 = 1;
  35. if(b > 9)
  36. err2 = 2;
  37. else
  38. begin
  39. temp = a + b + cin;
  40. if (temp > 9)
  41. begin
  42. z = 1;
  43. s1 = 1;
  44. end
  45. else
  46. begin
  47. z = 0;
  48. s1 = 0;
  49. end
  50. end
  51. end
  52. Circuit_zad_4 ex(a, b, cin, out_a);
  53. mux214 ex2(temp, out_a, z[0], x);
  54. assign s0 = x;
  55. endmodule
  56. //Główny na plytke
  57. module symulacja_zad_4(
  58. input [8:0]SW,
  59. output [0:6]HEX0, HEX1, HEX3, HEX5,
  60. output [9:0]LEDR);
  61. wire [3:0] out1, out2;
  62. assign LEDR[7:0] = SW[7:0];
  63. adder_BCD_2_digits_zad5(SW[3:0], SW[7:4], SW[8], out1, out2, LEDR[8], LEDR[9]);
  64. decoder_hex_10 ex2(out2, HEX1);
  65. decoder_hex_10 ex3(out1, HEX0);
  66. decoder_hex_10 ex4(SW[7:4], HEX5);
  67. decoder_hex_10 ex5(SW[3:0], HEX3);
  68. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement