找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2021|回复: 1
收起左侧

FPGA状态机源码

[复制链接]
ID:431476 发表于 2018-11-22 21:36 | 显示全部楼层 |阅读模式
module zhuangtai(clk,rst,led0,led1,led2,led3);
        input clk,rst;
        output led0,led1,led2,led3;
        wire [5:0]cnt;
        wire clk_1hz;
        fen1hz my_fen1hz(
        .clk(clk),
        .rst(rst),
        .c_out(clk_1hz)
        );
        jishu my_jishu(
        .clk(clk),
        .rst(rst),
        .c_out(cnt)
        );
        reg [1:0]curr_st;
        reg [1:0]next_st;
        
        parameter [1:0] IDLE=2'b00,
                                                 s1=2'b01,
                                                 s2=2'b10,
                                                 s3=2'b11;
        always@(posedge clk or negedge rst)
        if(!rst) curr_st<=IDLE;
        else curr_st<=next_st;
        always@(posedge clk or negedge rst)
        begin
        case(curr_st)
        IDLE:begin
        if(cnt==6'd15) next_st=s1;
        else next_st=IDLE;
        end
        s1:begin
        if(cnt==6'd25) next_st=s2;
        else next_st=s1;
        end
        s2:begin
        if(cnt==6'd29) next_st=s3;
        else next_st=s2;
        end
        s3:begin
        if(cnt==6'd36) next_st=IDLE;
        else next_st=s3;
        end
        endcase
        end
        assign led0=(curr_st==IDLE)?0:1;
        assign led1=(curr_st==s1)?0:1;
        assign led2=(curr_st==s2)?clk_1hz:1;
        assign led3=(curr_st==s3)?0:1;
        
endmodule
        


评分

参与人数 1黑币 +50 收起 理由
admin + 50 共享资料的黑币奖励!

查看全部评分

回复

使用道具 举报

ID:470289 发表于 2019-1-21 18:36 | 显示全部楼层
感谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表