我自己写的一个小程序,怎么改都改不对,求助大神
module shouhuo (k1,k2,a,b,clk,out,out_1,out_2,rst_n);
input k1,k2,out,clk,rst_n;
input [3:0]a,b;
output out_1; //输出饮料
output out_2; //找零
reg out_1,out_2;
always@(posedge k1 or posedge out)
begin
if(out==1)
a<=0; //饮料出来后计数器清零
else a<=a+4'b1;
end
always@(posedge k2 or posedge out)
begin
if(out==1)
b<=0; //饮料出来后计数值清零
else b<=b+4'b1;
end
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
a<=0;
b<=0;
else if(a==3)
begin
out_1<=1;
out<=out_1; //按下3次K1,输出饮料
end
else if(a==1&&b==1)
begin
out_1<=1;
out<=out_1; //按下一次k1,一次k2,输出饮料
end
else if(a==2&&b==1)
begin
out_1<=1;
out_2<=1;
out<=out_1;
end //按下两次k1,一次k2,输出饮料,找零
else if(a==0&&b==2)
begin
out_1<=1;
out_2<=1;
out<=out_1;
end //按下两次k2,输出饮料,找零
end
endmodule
错误提示是:
Error (10170): Verilog HDL syntax error at shouhuo.v(25) near text "else"; expecting "end"
Error (10112): Ignored design unit "shouhuo" at shouhuo.v(1) due to previous errors
不是,都配套了 , 我把头文件
module shouhuo (k1,k2,a,b,clk,out,out_1,out_2,rst_n);改成 module shouhuo之后之前的错误全没了,变成了
Error (10170): Verilog HDL syntax error at shouhuo.v(2) near text "input"; expecting ";"
第二行语法错误,这是我自学的 看不出哪里的语法有错误
从提示看,可以定位到IF ELSE END 没有配套,你检查一下,就会找到的。
第一个if语句后边有两条语句,应该用begin else 语句包括起来
看提示应该是IF ELSE END的问题
//vivado综合通过,我只是改了你不合理的地方,程序设计没看
module shouhuo (k1,k2,a,b,clk,out,out_1,out_2,rst_n);
input k1,k2,out,clk,rst_n;
input [3:0]a,b;
output out_1; //输出饮料
output out_2; //找零
reg out_1,out_2;
reg [3:0]aa,bb;
always@(posedge k1 or posedge out)
begin
aa <= a;
bb <= b;
if(out==1)
aa<=0; //饮料出来后计数器清零
else aa<=aa+4'b1;
end
always@(posedge k2 or posedge out)
begin
if(out==1)
bb<=0; //饮料出来后计数值清零
else bb<=bb+4'b1;
end
always@(posedge clk or negedge rst_n)
begin
if(!rst_n) begin
aa<=0;
bb<=0;
end
else if(aa==3)
begin
out_1<=1;
out_1<=out; //按下3次K1,输出饮料
end
else if(a==1&&b==1)
begin
out_1<=1;
out_1<=out; //按下一次k1,一次k2,输出饮料
end
else if(a==2&&b==1)
begin
out_1<=1;
out_2<=1;
out_1<=out;
end //按下两次k1,一次k2,输出饮料,找零
else if(a==0&&b==2)
begin
out_1<=1;
out_2<=1;
out_1<=out;
end //按下两次k2,输出饮料,找零
end
endmodule
1.首先你为什么要给input在always语句块内赋值,还有只有reg型可以在语句块内被赋值;
2.if语句块,执行结果大于等于两条语句必须用begin end组成语句块
if(!rst_n) a<=0; b<=0; else if(a==3) 改成 if(!rst_n) begin a<=0; b<=0; end else if(a==3)
;" 你检查一下这个符号是不是中文输入,给我3分就好了,谢谢了