|
不好意思我才學verilog 4天而已,我抄寫了一個程序但是quartus 提示 the design “ work ” is undefine , 沒有了其他錯誤了。
因為這僅僅是一個module,沒有test module,是不是說程序本身沒有錯誤了?
程序是編寫一個自動售貨機,收銀 5 ,10,25分,還找零。
module drink_machine(nickel_in,dime_in,quarter_in,collect,nickel_out,dime_out,dispense,reset,clk);
parameter idle=0,five=1,ten=2,twenty_five=3,fifteen=4,thirty=5,twenty=6,owe_dime=7;
input nickel_in,dime_in,quarter_in,reset,clk;
output collect,nickel_out,dime_out,dispense;
reg collect,nickel_out,dime_out,dispense;
reg[2:0] d,q;
always @(nickel_in or dime_in or quarter_in or reset)
begin
nickel_out=0;
dime_out=0;
dispense=0;
collect=0;
if (reset)
d=idle;
else
begin
d=q;
case(q)
idle:
if (nickel_in)
d=five;
else if(dime_in)
d=ten;
else if(quarter_in)
d=twenty_five;
five:
if (nickel_in)
d=ten;
else if(dime_in)
d=fifteen;
else if(quarter_in)
d=thirty;
ten:
if (nickel_in)
d=fifteen;
else if(dime_in)
d=twenty;
else if(quarter_in)
{d,dispense,collect}={idle,2'b11};
twenty_five:
if (nickel_in)
d=thirty;
else if(dime_in)
{d,dispense,collect}={idle,2'b11};
else if(quarter_in)
begin
{d,dispense,collect}={idle,2'b11};
nickel_out=1;
dime_out=1;
end
fifteen:
if (nickel_in)
d=twenty;
else if(dime_in)
d=twenty_five;
else if(quarter_in)
begin
{d,dispense,collect}={idle,2'b11};
nickel_out=1;
end
thirty:
if (nickel_in)
{d,dispense,collect}={idle,2'b11};
else if(dime_in)
begin
{d,dispense,collect}={idle,2'b11};
nickel_out=1;
end
else if(quarter_in)
begin
{d,dispense,collect}={idle,2'b11};
dime_out=1;
d=owe_dime;
end
twenty:
if (nickel_in)
d=twenty_five;
else if(dime_in)
d=thirty;
else if(quarter_in)
begin
{d,dispense,collect}={idle,2'b11};
dime_out=1;
end
owe_dime:
begin
dime_out=1;
d=idle;
end
endcase
end
end
always @(posedge clk)
begin
q=d;
end
endmodule
感謝噢 |
|