比价网站开发,九江网站开发,建设部网站招标投标文件,都匀网站制作专栏前言 本专栏的内容主要是记录本人学习Verilog过程中的一些知识点#xff0c;刷题网站用的是牛客网 timescale 1ns/1nsmodule sale(input clk ,input rst_n ,input sel ,//sel0,5$dranks,sel1,10$drinksinput … 专栏前言 本专栏的内容主要是记录本人学习Verilog过程中的一些知识点刷题网站用的是牛客网 timescale 1ns/1nsmodule sale(input clk ,input rst_n ,input sel ,//sel0,5$dranks,sel1,10$drinksinput [1:0] din ,//din1,input 5$,din2,input 10$output reg [1:0] drinks_out,//drinks_out1,output 5$ drinks,drinks_out2,output 10$ drinksoutput reg change_out
);reg [1:0] state, nstate ; parameter idle 0, x 1 ; // idle : 空闲i.e.无钱 x state : 饮料机输出饮料B但只投了5块钱always (posedge clk or negedge rst_n) if (!rst_n) state idle ; else state nstate ; always (*) case (state) idle : nstate sel ? (din 1 ? x : idle) : idle ; x : nstate din 0 ? x : idle ; default : nstate idle ; endcasealways (posedge clk or negedge rst_n) if (!rst_n) drinks_out 0 ; else if (!sel) if ((state idle din 1) || (state idle din 2)) drinks_out 1 ; else drinks_out 0 ; else if ((state idle din 2) || (state x din 1) || (state x din 2)) drinks_out 2 ; else drinks_out 0 ;always (posedge clk or negedge rst_n) if (!rst_n) change_out 0 ; else if ((sel 0 state idle din 2) || (sel state x din 2)) change_out 1 ; else change_out 0 ; endmodule