8562164817a6b1f122e057b987d0383b
Preface
The LED was tested before, and this article continues to conduct interactive tests in conjunction with the KEY.
process
New Construction
Reference: https://en.eeworld.com/bbs/thread-1234259-1-1.html
New project key
Create source file key. Add to project
Enter the following
module key_led(
input sys_clk ,
input sys_rst_n,
input [1:0] key,
output reg [2:0] led
);
//reg define
reg [23:0] cnt;
reg [1:0] led_control;
always @ (posedge sys_clk or negedge sys_rst_n) begin
if(!sys_rst_n)
cnt<=24'd9_999_999;
else if(cnt<24'd9_999_999)
cnt<=cnt+1;
else
cnt<=0;
end
always @(posedge sys_clk or negedge sys_rst_n) begin
if (!sys_rst_n)
led_control <= 2'b00;
else if(cnt == 24'd9_999_999)
led_control <= led_control + 1'b1;
else
led_control <= led_control;
end
always @(posedge sys_clk or negedge sys_rst_n) begin
if(!sys_rst_n) begin
led<=4'b 0000;
end
else if(key[0]== 0)
case (led_control)
2'b00 : led<=4'b100;
2'b01 : led<=4'b010;
2'b10 : led<=4'b001;
default : led<=4'b000;
endcase
else if(key[1]== 0)
case (led_control)
2'b00 : led<=4'b001;
2'b01 : led<=4'b010;
2'b10 : led<=4'b100;
default : led<=4'b000;
endcase
else
led<=4'b000;
end
endmodule
constraint
From the schematic diagram, we can see that LED_R, LED_G, LED_B correspond to J4 H5 J5 respectively
25M clock input corresponds to D7
If there is no dedicated reset button, use KEY0 H3
KEY1 and KEY2 in the schematic diagram correspond to H2 G3 corresponding to KEY0 and KEY1 in the code
The constraints are as follows
Running Tests
Key 0 reset
Press KEY1 and hold it, the running light will light up
Press KEY2 and hold it, the water light will change direction
Summarize
The TD software development process is the same as other platforms, creating a project, adding source code, constraints, compiling and downloading. The overall development experience is not much different, but the GUI interface can still be optimized, and the download is relatively simple. This experience is still good.
This article tests basic IO operations by combining buttons and LED interactions.