广工EDA自动售货机实验代码(verilog HDL设计代码)
2019-05-11 22:38
471 查看
模块代码
// mooreVender.v module mooreVender(N, D, Q, DC, DN, DD, clk, reset, state); input N, D, Q, clk, reset; output DC, DN, DD; output [3:0] state; reg[3:0] state, next; parameter IDLE = 0; parameter GOT_5c = 1; parameter GOT_10c = 2; parameter GOT_15c = 3; parameter GOT_20c = 4; parameter GOT_25c = 5; parameter GOT_30c = 6; parameter GOT_35c = 7; parameter GOT_40c = 8; parameter GOT_45c = 9; parameter GOT_50c = 10; parameter RETURN_20c = 11; parameter RETURN_15c = 12; parameter RETURN_10c = 13; parameter RETURN_5c = 14; always @ (posedge clk or negedge reset) if (!reset) state <= IDLE; else state <= next; always@ (state or N or D or Q) begin case (state) IDLE:if (Q) next = GOT_25c; else if (D) next = GOT_10c; else if (N)next = GOT_5c; else next = IDLE; GOT_5c:if (Q) next = GOT_30c; else if (D) next = GOT_15c; else if (N)next = GOT_10c; else next = GOT_5c; GOT_10c:if (Q) next = GOT_35c; else if (D) next = GOT_20c; else if (N)next = GOT_15c; else next = GOT_10c; GOT_15c:if (Q) next = GOT_40c; else if (D) next = GOT_25c; else if (N)next = GOT_20c; else next = GOT_15c; GOT_20c:if (Q) next = GOT_45c; else if (D) next = GOT_30c; else if (N)next = GOT_25c; else next = GOT_20c; GOT_25c:if (Q) next = GOT_50c; else if (D) next = GOT_35c; else if (N)next = GOT_30c; else next = GOT_25c; GOT_30c: next=IDLE; GOT_35c: next=RETURN_5c; GOT_40c: next=RETURN_10c; GOT_45c: next=RETURN_15c; GOT_50c: next=RETURN_20c; RETURN_20c: next = RETURN_10c; RETURN_15c: next = RETURN_5c; RETURN_10c: next = IDLE; RETURN_5c:next= IDLE; default: next = IDLE; endcase end assign DC = (state ==GOT_30c || state == GOT_35c|| state ==GOT_40c || state == GOT_45c|| state ==GOT_50c); assign DN = (state ==RETURN_5c); assign DD = (state ==RETURN_20c ||state ==RETURN_15c|| state ==RETURN_10c); endmodule
测试代码
// test.v `timescale 1ns/1ns module testbench; reg reset,clk,N,D,Q; wire [3:0] state; wire DC,DN,DD; parameter clock_period = 20; always #(clock_period/2) clk = ~clk; initial begin clk=0; reset=1; #25 reset=0; #50 reset=1; #1000 $finish; end initial begin N=1; #50 N=0;D=1;Q=0; #25 N=1;D=0;Q=0; #25 N=0;D=0;Q=1; #25 N=0;D=1;Q=0; #25 N=0;D=1;Q=0; #25 N=0;D=0;Q=1; #25 N=0;D=0;Q=1; #25 N=1;D=0;Q=0; #25 N=1;D=0;Q=0; end mooreVender ul(N,D,Q,DC,DN,DD,clk,reset,state); endmodule
相关文章推荐
- Verilog HDL && Quartus 设计规范、代码风格
- Verilog HDL 有限状态机的设计
- 浅谈Verilog HDL代码编写风格
- Verilog HDL设计规范及经验谈(转载)
- verilog HDL 的阻塞和非阻塞语句在FPGA各种设计中的分析
- (Verilog HDL)如何提高代码的仿真效率
- Verilog 编程实验(5)-3-8线译码器的设计与实现
- 基于模型设计的FPGA开发与实现:滤波器设计与实现(三)Matlab中滤波器的HDL代码生成
- Verilog自动售货机设计
- Verilog HDL那些事_建模篇笔记(实验七:数码管电路驱动)
- verilog代码设计
- 模N计数器的Verilog HDL代码
- EDA(电子设计自动化) 河北大学实验
- Verilog 编程实验(4)-7位译码器的设计与实现
- Verilog HDL 典型组合逻辑电路设计
- 利用Matlab2017b Simulink基于模型设计的自动代码生成对STM32F4进行开发 (5)----(编码器模式实验)
- 实验3.3 设计算法并写出代码,实现一个十将二进制转换成2进制数。
- 【原创】DE2实验解答—lab09 (Quartus II)(Verilog HDL)(Digital Logic)
- Verilog HDL DDS设计(作业3)
- (笔记)Verilog HDL设计时关于阻塞赋值和非阻塞赋值的8条指导原则以及原因。