找回密碼
 立即注冊(cè)

QQ登錄

只需一步,快速開始

搜索
查看: 2630|回復(fù): 1
收起左側(cè)

FPGA狀態(tài)機(jī)源碼

[復(fù)制鏈接]
ID:431476 發(fā)表于 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
        


評(píng)分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎(jiǎng)勵(lì)!

查看全部評(píng)分

回復(fù)

使用道具 舉報(bào)

ID:470289 發(fā)表于 2019-1-21 18:36 | 顯示全部樓層
感謝分享
回復(fù)

使用道具 舉報(bào)

本版積分規(guī)則

手機(jī)版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機(jī)教程網(wǎng)

快速回復(fù) 返回頂部 返回列表