我在网上买了块EPM1270T144C5N的CPLD板,其中有个按键测试程序,我想把它改一下实现按键的按下与弹起的测试,可是就是报错,不能通过,请各位指教。下面是代码。
module joystick(
clk,
reset,
key_up,
key_down,
key_left,
key_right,
key_upr,
key_downr,
key_leftr,
key_rightr,
led
);
input clk,reset;
input key_up,key_down,key_left,key_right,key_upr,key_downr,key_leftr,key_rightr;
output[3:0] led;
reg[3:0] led_reg;
reg[10:0] Count1;
reg Count;
reg up_down;
always@(posedge clk or negedge reset)
if(!reset)
Count1<=11'd0;
else if(Count1==11'd1999)
Count=~Count;
else
Count1<=Count1+1'b1;
assign led=led_reg;
always@(posedge Count or negedge reset)
if(!reset)
begin
led_reg<=4'b1111;
up_down<=1'b1;//up
end
/*
else if(!key_up)
led_reg<=4'b1110;
else if(!key_down)
led_reg<=4'b0111;
else if(!key_left)
led_reg<=4'b1101;
else if(!key_right)
led_reg<=4'b1011;
else if(!key_upr)
led_reg<=4'b1100;
else if(!key_downr)
led_reg<=4'b0011;
else if(!key_leftr)
led_reg<=4'b1001;
*/
else if(!key_rightr)
//led_reg<=4'b1010;
up_down<=1'b0;//down
else
led_reg<=led_reg;
//assign led=led_reg;
always@(posedge Count or negedge reset)
if(key_rightr)
begin
if(up_down==0)
begin
led_reg<=led_reg+1'b1;
up_down<=1'b1;
end
end
endmodule
|