/**************************************
The Key Edge Test
Author:luxiaolai
Date :2011-11-29
***************************************/
module test(LED,RESET,CLOCK,KEY_UP);
input RESET,CLOCK,KEY_UP;
output [3:0] LED;
wire led_cn;
test1 U1
(
.clk(CLOCK),
.rst(RESET),
.key(KEY_UP),
.keyout(led_cn),
);
test3 U2
(
.clk(CLOCK),
.rst(RESET),
.led_cn(led_cn),
.led(LED),
);
endmodule
/**************************************
The Key Test Part
**************************************/
module test1(clk,rst,key,keyout);
input clk,rst,key;
parameter cnt1=32'd2_00000;
reg[31:0] cnt;
reg key1,key2;
wire keyin;
always @ (posedge clk or negedge rst)
if(!rst)
begin
key1<=1'b1;
key2<=1'b1;
end
else
begin
key1<=key;
key2<=key1;
end
assign keyin=key2&(~key1);
reg key3,key4;
output keyout;
always @ (posedge clk or negedge rst)
if(!rst)
begin
cnt<=0;
key3<=1;
end
else if(keyin)
begin
cnt<=0;
key3<=1;
end
else if(cnt==cnt1)
begin
cnt<=0;
key3<=key;
end
else
cnt<=cnt+1;
always @ (posedge clk or negedge rst)
if(!rst)
key4<=1;
else
key4<=key3;
assign keyout=key4&(~key3);
endmodule
/************************************
The Display Part
*************************************/
module test3(led,clk,rst,led_cn);
input clk,rst,led_cn;
output reg[3:0] led;
always @ (posedge clk or negedge rst)
if(!rst)
led<=4'b0001;
else if(led_cn)
begin
led<=led+1;
if(led==4'b1111)
led<=0;
end
//else
//led<=led;
endmodule