Advertisement
Guest User

Untitled

a guest
Mar 26th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. module BcdAdd(datA,datB,cin,cout,dout);
  2. input [3:0] datA;
  3. input [3:0] datB;
  4. input cin;
  5. output cout;
  6. output [3:0] dout;
  7. wire[4:0] adat;
  8. wire cry;
  9.  
  10. assign adat=datA+datB+cin;
  11. assign cry=(adat>=5'd10) ?1'b1 : 1'b0;
  12. assign dout=(cry==1'b1) ? (adat-5'd10) : adat[3:0];
  13. assign cout=cry;
  14. endmodule
  15.  
  16. module BcdConv(data,q);
  17. input [7:0] data;
  18. output [11:0] q;
  19. wire c1,c2,co;
  20. wire [11:0] whbcd;
  21. wire [7:0] wlbcd;
  22.  
  23. function [11:0] HBcdTb1;
  24. input [3:0] num;
  25. begin
  26. case (num)
  27. 4'h0: HBcdTb1 = 12'h00;
  28. 4'h1: HBcdTb1 = 12'h16;
  29. 4'h2: HBcdTb1 = 12'h32;
  30. 4'h3: HBcdTb1 = 12'h48;
  31. 4'h4: HBcdTb1 = 12'h64;
  32. 4'h5: HBcdTb1 = 12'h80;
  33. 4'h6: HBcdTb1 = 12'h96;
  34. 4'h7: HBcdTb1 = 12'h112;
  35. 4'h8: HBcdTb1 = 12'h128;
  36. 4'h9: HBcdTb1 = 12'h144;
  37. 4'ha: HBcdTb1 = 12'h160;
  38. 4'hb: HBcdTb1 = 12'h176;
  39. 4'hc: HBcdTb1 = 12'h192;
  40. 4'hd: HBcdTb1 = 12'h208;
  41. 4'he: HBcdTb1 = 12'h224;
  42. 4'hf: HBcdTb1 = 12'h240;
  43. endcase
  44. end
  45. endfunction
  46.  
  47. function[7:0] LBcdTb1;
  48. input[3:0] num;
  49. begin
  50. case (num)
  51. 4'h0: LBcdTb1 = 8'h00;
  52. 4'h1: LBcdTb1 = 8'h01;
  53. 4'h2: LBcdTb1 = 8'h02;
  54. 4'h3: LBcdTb1 = 8'h03;
  55. 4'h4: LBcdTb1 = 8'h04;
  56. 4'h5: LBcdTb1 = 8'h05;
  57. 4'h6: LBcdTb1 = 8'h06;
  58. 4'h7: LBcdTb1 = 8'h07;
  59. 4'h8: LBcdTb1 = 8'h08;
  60. 4'h9: LBcdTb1 = 8'h09;
  61. 4'ha: LBcdTb1 = 8'h10;
  62. 4'hb: LBcdTb1 = 8'h11;
  63. 4'hc: LBcdTb1 = 8'h12;
  64. 4'hd: LBcdTb1 = 8'h13;
  65. 4'he: LBcdTb1 = 8'h14;
  66. 4'hf: LBcdTb1 = 8'h15;
  67. endcase
  68. end
  69. endfunction
  70.  
  71. assign whbcd=HBcdTb1(data[7:4]);
  72. assign wlbcd=LBcdTb1(data[3:0]);
  73.  
  74. BcdAdd ad0(wlbcd[3:0],whbcd[3:0],1'b0,c1,q[3:0]);
  75. BcdAdd ad1(wlbcd[7:4],whbcd[7:4],c1,c2,q[7:4]);
  76. BcdAdd ad2(4'h0,whbcd[11:8],c2,co,q[11:8]);
  77. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement