在线咨询
eetop公众号 创芯大讲堂 创芯人才网
切换到宽版

EETOP 创芯网论坛 (原名:电子顶级开发网)

手机号码,快捷登录

手机号码,快捷登录

找回密码

  登录   注册  

快捷导航
搜帖子
查看: 1673|回复: 1

[求助] 我想请问卖报机的测试代码怎么编写?求解答

[复制链接]
发表于 2016-12-25 22:27:54 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?注册

x
题目是设计一个卖报机,报纸价钱八角,纸币有1角,2角,5角,一元。该卖报机不考虑投币为大额面值等特殊情况
状态图我也画出来了,
代码是data_out=1表示给出报纸,data_out_return1=1表示找回1角硬币,data_out_return2=1表示找回2角硬币。




  1. module auto_sellor (current_state,data_out,data_out_return1,data_out_return2,
  2. clk,rst_n,data_in);
  3. parameter state_width=3,data_in_width=3;
  4. output [state_width-1:0] current_state;
  5. output data_out, data_out_return1, data_out_return2;
  6. input [data_in_width-1:0] data_in;
  7. input clk, rst_n;
  8. reg [state_width-1:0] current_state, next_state;
  9. reg data_out, data_out_return1, data_out_return2;
  10. always @(current_state or rst_n)
  11. if (!rst_n)
  12. next_state<=0;
  13. else
  14. case (current_state)
  15. 3'b000: case (data_in)
  16. 3'b000: begin
  17. next_state<=3'b000;
  18. data_out<=1'b0;
  19. data_out_return1<=1'b0;
  20. data_out_return2<=1'b0;
  21. end
  22. 3'b001: begin
  23. next_state<=3'b001;
  24. data_out<=1'b0;
  25. data_out_return1<=1'b0;
  26. data_out_return2<=1'b0;
  27. end
  28. 3'b010: begin
  29. next_state<=3'b010;
  30. data_out<=1'b0;
  31. data_out_return1<=1'b0;
  32. data_out_return2<=1'b0;
  33. end
  34. 3'b011: begin
  35. next_state<=3'b101;
  36. data_out<=1'b0;
  37. data_out_return1<=1'b0;
  38. data_out_return2<=1'b0;
  39. end
  40. 3'b100: begin
  41. next_state<=3'b000;
  42. data_out<=1'b1;
  43. data_out_return1<=1'b0;
  44. data_out_return2<=1'b1;
  45. end
  46. endcase
  47. 3'b001: case (data_in)
  48. 3'b000: begin
  49. next_state<=3'b001;
  50. data_out<=1'b0;
  51. data_out_return1<=1'b0;
  52. data_out_return2<=1'b0;
  53. end
  54. 3'b001: begin
  55. next_state<=3'b010;
  56. data_out<=1'b0;
  57. data_out_return1<=1'b0;
  58. data_out_return2<=1'b0;
  59. end
  60. 3'b010: begin
  61. next_state<=3'b011;
  62. data_out<=1'b0;
  63. data_out_return1<=1'b0;
  64. data_out_return2<=1'b0;
  65. end
  66. 3'b011: begin
  67. next_state<=3'b110;
  68. data_out<=1'b0;
  69. data_out_return1<=1'b0;
  70. data_out_return2<=1'b0;
  71. end
  72. endcase
  73. 3'b010: case (data_in)
  74. 3'b000: begin
  75. next_state<=3'b010;
  76. data_out<=1'b0;
  77. data_out_return1<=1'b0;
  78. data_out_return2<=1'b0;
  79. end
  80. 3'b001: begin
  81. next_state<=3'b011;
  82. data_out<=1'b0;
  83. data_out_return1<=1'b0;
  84. data_out_return2<=1'b0;
  85. end
  86. 3'b010: begin
  87. next_state<=3'b100;
  88. data_out<=1'b0;
  89. data_out_return1<=1'b0;
  90. data_out_return2<=1'b0;
  91. end
  92. 3'b011: begin
  93. next_state<=3'b111;
  94. data_out<=1'b0;
  95. data_out_return1<=1'b0;
  96. data_out_return2<=1'b0;
  97. end
  98. endcase
  99. 3'b011: case (data_in)
  100. 3'b000: begin
  101. next_state<=3'b011;
  102. data_out<=1'b0;
  103. data_out_return1<=1'b0;
  104. data_out_return2<=1'b0;
  105. end
  106. 3'b001: begin
  107. next_state<=3'b100;
  108. data_out<=1'b0;
  109. data_out_return1<=1'b0;
  110. data_out_return2<=1'b0;
  111. end
  112. 3'b010: begin
  113. next_state<=3'b101;
  114. data_out<=1'b0;
  115. data_out_return1<=1'b0;
  116. data_out_return2<=1'b0;
  117. end
  118. 3'b011: begin
  119. next_state<=3'b000;
  120. data_out<=1'b1;
  121. data_out_return1<=1'b0;
  122. data_out_return2<=1'b0;
  123. end
  124. endcase
  125. 3'b100: case (data_in)
  126. 3'b000: begin
  127. next_state<=3'b000;
  128. data_out<=1'b0;
  129. data_out_return1<=1'b0;
  130. data_out_return2<=1'b0;
  131. end
  132. 3'b001: begin
  133. next_state<=3'b101;
  134. data_out<=1'b0;
  135. data_out_return1<=1'b0;
  136. data_out_return2<=1'b0;
  137. end
  138. 3'b010: begin
  139. next_state<=3'b110;
  140. data_out<=1'b0;
  141. data_out_return1<=1'b0;
  142. data_out_return2<=1'b0;
  143. end
  144. 3'b011: begin
  145. next_state<=3'b000;
  146. data_out<=1'b1;
  147. data_out_return1<=1'b1;
  148. data_out_return2<=1'b0;
  149. end
  150. endcase
  151. 3'b101: case (data_in)
  152. 3'b000: begin
  153. next_state<=3'b101;
  154. data_out<=1'b0;
  155. data_out_return1<=1'b0;
  156. data_out_return2<=1'b0;
  157. end
  158. 3'b001: begin
  159. next_state<=3'b110;
  160. data_out<=1'b0;
  161. data_out_return1<=1'b0;
  162. data_out_return2<=1'b0;
  163. end
  164. 3'b010: begin
  165. next_state<=3'b111;
  166. data_out<=1'b0;
  167. data_out_return1<=1'b0;
  168. data_out_return2<=1'b0;
  169. end
  170. 3'b011: begin
  171. next_state<=3'b000;
  172. data_out<=1'b1;
  173. data_out_return1<=1'b0;
  174. data_out_return2<=1'b1;
  175. end
  176. endcase
  177. 3'b110: case (data_in)
  178. 3'b000: begin
  179. next_state<=3'b110;
  180. data_out<=1'b0;
  181. data_out_return1<=1'b0;
  182. data_out_return2<=1'b0;
  183. end
  184. 3'b001: begin
  185. next_state<=3'b111;
  186. data_out<=1'b0;
  187. data_out_return1<=1'b0;
  188. data_out_return2<=1'b0;
  189. end
  190. 3'b010: begin
  191. next_state<=3'b000;
  192. data_out<=1'b1;
  193. data_out_return1<=1'b0;
  194. data_out_return2<=1'b0;
  195. end
  196. endcase
  197. 3'b111: case (data_in)
  198. 3'b000: begin
  199. next_state<=3'b111;
  200. data_out<=1'b0;
  201. data_out_return1<=1'b0;
  202. data_out_return2<=1'b0;
  203. end
  204. 3'b001: begin
  205. next_state<=3'b000;
  206. data_out<=1'b1;
  207. data_out_return1<=1'b0;
  208. data_out_return2<=1'b0;
  209. end
  210. endcase
  211. endcase
  212. always @(posedge clk or rst_n)
  213. if (!rst_n)
  214. current_state<=3'b000;
  215. else
  216. current_state<=next_state;
  217. endmodule


复制代码

状态图

状态图
 楼主| 发表于 2016-12-25 22:29:31 | 显示全部楼层
其实我编了一个比较简单的状态机,我在每个状态下把他可能跳转的状态描述出来了,但是我测试代码不会写。所以我想请问一下论坛的各位大神
您需要登录后才可以回帖 登录 | 注册

本版积分规则

关闭

站长推荐 上一条 /2 下一条


小黑屋| 手机版| 关于我们| 联系我们| 在线咨询| 隐私声明| EETOP 创芯网
( 京ICP备:10050787号 京公网安备:11010502037710 )

GMT+8, 2024-11-24 17:57 , Processed in 0.016327 second(s), 7 queries , Gzip On, Redis On.

eetop公众号 创芯大讲堂 创芯人才网
快速回复 返回顶部 返回列表