【iCore4 双核心板_FPGA】例程一:GPIO输出实验——点亮LED

实验现象:

三色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链接:

转载于:https://www.cnblogs.com/xiaomagee/p/7266617.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值