这一章实验会比较简单。实验的内容也只是单纯的“选择器”而已。下面的示意图说明一切。
1.module smg_code_module
2.(
3. CLK, RST,
4. Thousand_In, Hundred_In, Ten_In, One_In,
5. Thousand_Out, Hundred_Out, Ten_Out, One_Out
6.);
7.
8. input CLK;
9. input RST;
10. input [3:0]Thousand_In;
11. input [3:0]Hundred_In;
12. input [3:0]Ten_In;
13. input [3:0]One_In;
14.
15. output [7:0]Thousand_Out;
16. output [7:0]Hundred_Out;
17. output [7:0]Ten_Out;
18. output [7:0]One_Out;
19.
20. /**********************************************/
21.
22. //SMG code
23. parameter _0 = 8'h3f,
24. _1 = 8'h06,
25. _2 = 8'h5b,
26. _3 = 8'h4f,
27. _4 = 8'h66,
28. _5 = 8'h6d,
29. _6 = 8'h7d,
30. _7 = 8'h07,
31. _8 = 8'h7f,
32. _9 = 8'h6f,
33. _A = 8'h77,
34. _B = 8'h7c,
35. _C = 8'h39,
36. _D = 8'h5e,
37. _E = 8'h79,
38. _F = 8'h71;
39.
40. /**********************************************/
41.
42. reg [7:0]rThousand;
43.
44. always @ ( posedge CLK or negedge RST )
45. if( !RST )
46. rThousand <= 8'd0;
47. else
48. case( Thousand_In )
49. 4'd0 : rThousand = _0;
50. 4'd1 : rThousand = _1;
51. 4'd2 : rThousand = _2;
52. 4'd3 : rThousand = _3;
53. 4'd4 : rThousand = _4;
54. 4'd5 : rThousand = _5;
55. 4'd6 : rThousand = _6;
56. 4'd7 : rThousand = _7;
57. 4'd8 : rThousand = _8;
58. 4'd9 : rThousand = _9;
59. endcase
60.
61. assign Thousand_Out = rThousand;
62.
63. /*******************************************/
64.
65. reg [7:0]rHundred;
66.
67. always @ ( posedge CLK or negedge RST )
68. if( !RST )
69. rHundred <= 8'd0;
70. else
71. case( Hundred_In )
72. 4'd0 : rHundred = _0;
73. 4'd1 : rHundred = _1;
74. 4'd2 : rHundred = _2;
75. 4'd3 : rHundred = _3;
76. 4'd4 : rHundred = _4;
77. 4'd5 : rHundred = _5;
78. 4'd6 : rHundred = _6;
79. 4'd7 : rHundred = _7;
80. 4'd8 : rHundred = _8;
81. 4'd9 : rHundred = _9;
82. endcase
83.
84.
85. assign Hundred_Out = rHundred;
86.
87. /***********************************************/
88.
89. reg [7:0]rTen;
90.
91. always @ ( posedge CLK or negedge RST )
92. if( !RST )
93. rTen <= 8'd0;
94. else
95. case( Ten_In )
96. 4'd0 : rTen = _0;
97. 4'd1 : rTen = _1;
98. 4'd2 : rTen = _2;
99. 4'd3 : rTen = _3;
100. 4'd4 : rTen = _4;
101. 4'd5 : rTen = _5;
102. 4'd6 : rTen = _6;
103. 4'd7 : rTen = _7;
104. 4'd8 : rTen = _8;
105. 4'd9 : rTen = _9;
106. endcase
107.
108. assign Ten_Out = rTen;
109.
110. /***********************************************/
111.
112. reg [7:0]rOne;
113.
114. always @ ( posedge CLK or negedge RST )
115. if( !RST )
116. rOne <= 8'd0;
117. else
118. case( One_In )
119. 4'd0 : rOne = _0;
120. 4'd1 : rOne = _1;
121. 4'd2 : rOne = _2;
122. 4'd3 : rOne = _3;
123. 4'd4 : rOne = _4;
124. 4'd5 : rOne = _5;
125. 4'd6 : rOne = _6;
126. 4'd7 : rOne = _7;
127. 4'd8 : rOne = _8;
128. 4'd9 : rOne = _9;
129. endcase
130.
131. assign One_Out = rOne;
132.
133. /**********************************************/
134.
135.endmodule
1. 第1~18行是熟悉的声明。
2. 第44~59行是针对“千位”的数码管码转化。
第67~82行是针对“百位”的数码管码转化。
第91~106行是针对“十位”的数码管码转化。
第114~129行是针对“个位”的数码管码转化。
╮(╯▽╰)╭ 唉~这一章没有“问题和答案”与“仿真”。
这一章实验就是太简单了,也没有好补充的。自己看着办吧。
源码:
http://j.imagehost.org/download/0781/06-SMG_Code_Module
用户1359989 2010-10-31 15:33
用户1373959 2010-5-18 21:32