管脚绑定
代码如下:
//TestKey0~1 Ctrl LED1~8 town onOff
module ledKey(
clk, //sysClk=50Mhz
key_in, //Key Name
led //LEDs
);
//PORT declarations
input clk;
input [1:0] key_in;
output [7:0] led;
wire rst_n = 1'b1;
//Define Register
reg [31:0] timer;
//Timer delayer
always @(posedge clk or negedge rst_n)
begin
if (~rst_n)
timer <= 0;//timer=0
else if (timer == 32'd39_999_999)//sysClock=50MHz
timer <= 0;//timer Clear
else
timer <= timer + 1'b1;//timer++
end
//Key Dows Testt
reg [1:0] key_scan;//GetKeyNumber
always @(posedge clk)
key_scan <= 2'b11;//Key=High
wire [1:0] flag_key = key_scan[1:0] & (~key_in[1:0]);//Key Puth down?
//Key n Contral led n On or Off
reg [7:0] led;
always @ (posedge clk or negedge rst_n)
begin
if (!rst_n)//Reset
led <= 8'b11111111;//Led1~8=off
else
begin
if (~flag_key[0])
begin
if (timer == 32'd4_999_999)
led <= 8'b11111110; //LED1
else if (timer == 32'd9_999_999)
led <= 8'b11111101; //LED2
else if (timer == 32'd14_999_999)
led <= 8'b11111011; //LED3
else if (timer == 32'd19_999_999)
led <= 8'b11110111; //LED4
else if (timer == 32'd24_999_999)
led <= 8'b11101111; //LED5
else if (timer == 32'd29_999_999)
led <= 8'b11011111; //LED6
else if (timer == 32'd34_999_999)
led <= 8'b10111111; //LED7
else if (timer == 32'd39_999_999)
led <= 8'b01111111; //LED8
end
else
begin
if (timer == 32'd4_999_999)
led <= 8'b01111111; //LED8
else if (timer == 32'd9_999_999)
led <= 8'b10111111; //LED7
else if (timer == 32'd14_999_999)
led <= 8'b11011111; //LED6
else if (timer == 32'd19_999_999)
led <= 8'b11101111; //LED5
else if (timer == 32'd24_999_999)
led <= 8'b11110111; //LED4
else if (timer == 32'd29_999_999)
led <= 8'b11111011; //LED3
else if (timer == 32'd34_999_999)
led <= 8'b11111101; //LED2
else if (timer == 32'd39_999_999)
led <= 8'b11111110; //LED1
end
end
end
endmodule
下载时分成两种情况:选择.sof文件时,仅仅输出到RAM区,断电后恢复原来的程序;选择.pof文档时输出到内部EPROM区,重新加电程序不变。无论程序大小,后者的编译下载时间较长,大约需要若干分钟,只有重新加电后才看到结果;而前者非常快,像上述代码,点击下载后立马执行看到结果。选择下载文件见照片23。