orange-208 发表于 2012-9-27 22:11:11

8位二进制转BCD码,输入125,怎么没有输出呢?

如题 (附上module和测试testbench)

module bintobcd
(
        clk, rstn, Data_Bin,
       
//        Hex_8, Hex_7, Hex_6, Hex_5,       
//        Hex_4,
        Hex_3, Hex_2, Hex_1
);
       
        input clk, rstn;
        inputData_Bin;

//        output Hex_8, Hex_7, Hex_6, Hex_5;       
        output //Hex_4,
        Hex_3, Hex_2, Hex_1;

//        reg Hex_8, Hex_7, Hex_6, Hex_5;       
        reg //Hex_4,
        Hex_3, Hex_2, Hex_1;

        /************************ BCD转换算法 *************************/
                               
        function Correct;         
                inputDecade;
                begin
                        Correct = ( Decade >= 4'd5 ) ? ( Decade + 4'd3 ) : Decade;
                end
        endfunction

        /*************************************************************/
       
//        integer Cnt = 33;
        reg Cnt;
        reg BCD;
        reg Bin_input;
       
        reg //BCD_8_I, BCD_7_I, BCD_6_I, BCD_5_I,
                               //BCD_4_I,
                               BCD_3_I, BCD_2_I, BCD_1_I;

        always @ ( posedge clk or negedge rstn )
                begin
                        if( !rstn )
                                begin
                                        Cnt = 6'd9;
                                        BCD = 12'd0;
                                        Bin_input = 8'd0;
                                       
                                //        BCD_8_I= 4'b0000;
                                //        BCD_7_I= 4'b0000;
                                //        BCD_6_I= 4'b0000;
                                //        BCD_5_I= 4'b0000;
                                //        BCD_4_I= 4'b0000;
                                        BCD_3_I= 4'b0000;
                                        BCD_2_I= 4'b0000;
                                        BCD_1_I= 4'b0000;
                                end
                        else
                                begin
                                        if( Cnt == 6'd9 )
                                                begin
                                                        Bin_input = Data_Bin;
                                                        Cnt = Cnt - 1'b1;
                                                end
                                        else if( Cnt == 0 )
                                                begin
                                                //        BCD_8_I = BCD;
                                                //        BCD_7_I = BCD;
                                                //        BCD_6_I = BCD;
                                                //        BCD_5_I = BCD;
                                                //        BCD_4_I = BCD;
                                                        BCD_3_I = BCD;
                                                        BCD_2_I = BCD;
                                                        BCD_1_I = BCD;
                                                       
                                                //        Hex_8 = BCD_8_I;
                                                //        Hex_7 = BCD_7_I;
                                                //        Hex_6 = BCD_6_I;
                                                //        Hex_5 = BCD_5_I;
                                                //        Hex_4 = BCD_4_I;
                                                        Hex_3 = BCD_3_I;
                                                        Hex_2 = BCD_2_I;
                                                        Hex_1 = BCD_1_I;                                       
                                                end
                                                               
                                        else
                                                begin
                                                        BCD   = Correct( BCD );
                                                        BCD   = Correct( BCD );
                                                        BCD= Correct( BCD );
                                                //        BCD = Correct( BCD );
                                                //        BCD = Correct( BCD );
                                                //        BCD = Correct( BCD );
                                                //        BCD = Correct( BCD );
                                                //        BCD = Correct( BCD );
                                                       
                                                        Cnt = Cnt - 1'b1;
                                                        BCD = ( BCD << 1 );
                                                        BCD = Bin_input ;
                                                        Bin_input = Bin_input << 1;
                                                end
                                end
                end

        /*************************************************************/
               
endmodule



`timescale 1 ps/ 1 ps
module bintobcd_vlg_tst();

        reg Data_Bin;
        reg clk;
        reg rstn;
       
        // wires                                             
        wire Hex_1;
        wire Hex_2;
        wire Hex_3;
//        wire Hex_4;
//        wire Hex_5;
//        wire Hex_6;
//        wire Hex_7;
//        wire Hex_8;

        /**************************************/
       
        bintobcd i1
        (
                .clk( clk ),
                .rstn( rstn ),
                .Data_Bin( Data_Bin ),
               
                .Hex_1( Hex_1 ),
                .Hex_2( Hex_2 ),
                .Hex_3( Hex_3 )
//                .Hex_4( Hex_4 ),
//                .Hex_5( Hex_5 ),
//                .Hex_6( Hex_6 ),
//                .Hex_7( Hex_7 ),
//                .Hex_8( Hex_8 )
        );
       
        /**************************************/
       
        initial                                                
                begin                                                
                        clk = 0;
                        rstn = 1;
                        #10 rstn = 0;
                        #10 rstn = 1;               
                end
               
        always #10 clk = ~clk;

        /**************************************/

        always @ ( posedge clk or negedge rstn )
                if( !rstn )
                        begin
                                Data_Bin = 8'd0;
                        end
                else
                        begin
                                Data_Bin = 8'd125;
                        end

        /**************************************/
                                                   
endmodule

orange-208 发表于 2012-9-29 11:50:47

问题已解决!
页: [1]
查看完整版本: 8位二进制转BCD码,输入125,怎么没有输出呢?