LED作业2. case 语句实现。
代码如下:
module led1(clk,rst,led);
input clk;
input rst;
output led;
reg [10:0] led;
reg [31:0] count;
reg [5:0] state;
always @(posedge clk or negedge rst)
begin
if(!rst)
begin
count<=32'd0;
state<=5'd0;
end
else
begin
if(count==32'd29999999)
begin
count<=32'd0;
if(state==5'd30)
begin
state<=5'd0;
end
else
state<=state+1'b1;
end
else
count<=count+1'b1;
end
end
always @ (state)
begin
case(state)
5'd1: led<=11'b00000100000;
5'd2: led<=11'b00001110000;
5'd3: led<=11'b00011111000;
5'd4: led<=11'b00111111100;
5'd5: led<=11'b01111111110;
5'd6: led<=11'b11111111111;
5'd7: led<=11'b00000000000;
5'd8: led<=11'b10000000000;
5'd9: led<=11'b11000000000;
5'd10: led<=11'b11100000000;
5'd11: led<=11'b11110000000;
5'd12: led<=11'b11111000000;
5'd13: led<=11'b11111100000;
5'd14: led<=11'b11111110000;
5'd15: led<=11'b11111111000;
5'd16: led<=11'b11111111100;
5'd17: led<=11'b11111111110;
5'd18: led<=11'b11111111111;
5'd19: led<=11'b11111111110;
5'd20: led<=11'b11111111100;
5'd21: led<=11'b11111111000;
5'd22: led<=11'b11111110000;
5'd23: led<=11'b11111100000;
5'd24: led<=11'b11111000000;
5'd25: led<=11'b11110000000;
5'd26: led<=11'b11100000000;
5'd27: led<=11'b11000000000;
5'd28: led<=11'b10000000000;
5'd29: led<=11'b00000000000;
default: led<=11'b11111111111;
endcase
end
endmodule