编写一个密码锁的程序,自己编写了一个,在ISE软件里运行正确,可是在实验板上无法显示.综合,四位按键输入,初始密码是123,3次输入错误后就报警,有退格,确认按键,请教一下,程序如下: module lock(rst,clk,cmd,cancel,enter,pass,alarm); input clk; input rst; input [3:0]cmd; input cancel,enter; output pass; output alarm; reg pass,alarm; reg [2:0]d; reg [8:0]password; reg [2:0]count; reg [2:0]state; parameter PASSWORD='d123; parameter st0=0,st1=1,st2=2,st3=3,st4=4; always @(cmd) begin case(cmd) 4'b0111:d<=1; 4'b1011:d<=2; 4'b1101:d<=3; 4'b1110:d<=4; default:d<=0; endcase end always @(posedge clk) if(!rst) begin pass<=0; alarm<=0; password<=0; count<=0; end else case(state) st0:begin pass<=0; alarm<=0; password[8:6]<=d; state<=st1; end st1:if(!cancel) begin password<=0; state<=st0; end else begin password[5:3]<=d; pass<=0; alarm<=0; state<=st2; end st2:if(!cancel) begin state<=st1; end else begin password[2:0]<=d; pass<=0; alarm<=0; state<=st3; end st3:if(!cancel) state<=st2; else begin password[2:0]<=d; pass<=0; alarm<=0; state<=st4; end st4:if(!enter) if(password==PASSWORD) begin pass<=1; alarm<=0; state<=st0; end else count<=count+1; else if(count>2) begin pass<=0; alarm<=1; state<=st0; end default:begin pass<=0; alarm<=0; state<=st0; end endcase endmodule |