實驗現象:
三色LED迴圈點亮。
核心原始碼:
module led_ctrl( input clk_25m, input rst_n, output fpga_ledr, output fpga_ledg, output fpga_ledb ); //--------------------cnt----------------------------------// reg [24:0]cnt; reg [2:0]led_cnt; always @ (posedge clk_25m or negedge rst_n) if(!rst_n) begin cnt <= 25'd0; led_cnt <= 1'd0; end else if(cnt == 25'd5000000) begin cnt <= 25'd0; if(led_cnt == 3'd2) led_cnt <= 3'd0; else led_cnt <= led_cnt + 1'd1; end else begin cnt <= cnt + 1'd1; end //--------------------led_ctrl----------------------------// /*led狀態切換狀態機*/ reg ledr,ledg,ledb; always @ (posedge clk_25m or negedge rst_n) if(!rst_n) begin ledr <= 1'd1; ledg <= 1'd1; ledb <= 1'd1; end else case(led_cnt) 3'd0: //紅燈亮 begin ledr <= 1'd0; ledg <= 1'd1; ledb <= 1'd1; end 3'd1: //綠燈亮 begin ledr <= 1'd1; ledg <= 1'd0; ledb <= 1'd1; end 3'd2: //藍燈亮 begin ledr <= 1'd1; ledg <= 1'd1; ledb <= 1'd0; end default: //都不亮 begin ledr <= 1'd1; ledg <= 1'd1; ledb <= 1'd1; end endcase assign {fpga_ledr,fpga_ledg,fpga_ledb} = {ledr,ledg,ledb}; //--------------------endmodule---------------------------// endmodule
原始碼下載連結:
連結:http://pan.baidu.com/s/1nu74Iy1 密碼:dz3y
iCore4連結: