帮忙看看代码,分析了半天,啥意思?
本帖最后由 orange-208 于 2012-9-21 17:24 编辑如题
module BINtoBCD
(
CLK, Clear, Enable_1, Data_Bin,
Hex_4, Hex_3, Hex_2, Hex_1, Hex_e, BCD_over
);
input CLK, Clear, Enable_1;
inputData_Bin;
output BCD_over;
output Hex_4, Hex_3, Hex_2, Hex_1, Hex_e;
reg Hex_4, Hex_3, Hex_2, Hex_1, Hex_e;
/*******************************************************/
function Correct;
inputDecade;
begin
Correct =( Decade >= 4'd5 ) ? ( Decade + 4'd3 ) : Decade;
end
endfunction
/*******************************************************/
integer Cnt = 33;
reg BCD_over;
reg BCD;
reg Bin_input;
reg BCD_10_I, BCD_9_I, 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 posedge Clear )
begin
if( Clear )
begin
Cnt = 33;
BCD = 40'd0;
BCD_over = 1'b0;
Bin_input = 32'd0;
BCD_10_I = 4'b0000;
BCD_9_I= 4'b0000;
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( Enable_1 )
begin
if( Cnt == 33 )
begin
Bin_input = Data_Bin;
Cnt = Cnt - 1'b1;
end
else if( Cnt == 0 )
begin
BCD_10_I = BCD;
BCD_9_I= BCD;
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;
//----------------------------------------
if( BCD_10_I != 4'd0 )
begin
Hex_4 = BCD_10_I;
Hex_3 = BCD_9_I;
Hex_2 = BCD_8_I;
Hex_1 = ( BCD_6_I >= 4'd5 ) ? BCD_7_I + 1'b1 : BCD_7_I;
Hex_e = 4'd9 + 4'd2;
end
else if( BCD_9_I != 4'd0 )
begin
Hex_4 = BCD_9_I;
Hex_3 = BCD_8_I;
Hex_2 = BCD_7_I;
Hex_1 = ( BCD_5_I >= 4'd5 ) ? BCD_6_I + 1'b1 : BCD_6_I;
Hex_e = 4'd8 + 4'd2;
end
else if( BCD_8_I != 4'd0 )
begin
Hex_4 = BCD_8_I;
Hex_3 = BCD_7_I;
Hex_2 = BCD_6_I;
Hex_1 = ( BCD_4_I >= 4'd5 ) ? BCD_5_I + 1'b1 : BCD_5_I;
Hex_e = 4'd7 + 4'd2;
end
else if( BCD_7_I != 4'd0 )
begin
Hex_4 = BCD_7_I;
Hex_3 = BCD_6_I;
Hex_2 = BCD_5_I;
Hex_1 = ( BCD_3_I >= 4'd5 ) ? BCD_4_I + 1'b1 : BCD_4_I;
Hex_e = 4'd6 + 4'd2;
end
else if( BCD_6_I != 4'd0)
begin
Hex_4 = BCD_6_I;
Hex_3 = BCD_5_I;
Hex_2 = BCD_4_I;
Hex_1 = ( BCD_2_I >= 4'd5 ) ? BCD_3_I + 1'b1 : BCD_3_I;
Hex_e = 4'd5 + 4'd2;
end
else if( BCD_5_I != 4'd0 )
begin
Hex_4 = BCD_5_I;
Hex_3 = BCD_4_I;
Hex_2 = BCD_3_I;
Hex_1 = ( BCD_1_I >= 4'd5 ) ? BCD_2_I + 1'b1 : BCD_2_I;
Hex_e = 4'd4 + 4'd2;
end
else if( BCD_4_I != 4'd0 )
begin
Hex_4 = BCD_4_I;
Hex_3 = BCD_3_I;
Hex_2 = BCD_2_I;
Hex_1 = BCD_1_I;
Hex_e = 4'd3 + 4'd2;
end
else if( BCD_3_I != 4'd0 )
begin
Hex_4 = 4'd0;
Hex_3 = BCD_3_I;
Hex_2 = BCD_2_I;
Hex_1 = BCD_1_I;
Hex_e = 4'd2 + 4'd2;
end
else if( BCD_2_I != 4'd0 )
begin
Hex_4 = 4'd0;
Hex_3 = 4'd0;
Hex_2 = BCD_2_I;
Hex_1 = BCD_1_I;
Hex_e = 4'd1 + 4'd2;
end
else if( BCD_1_I != 4'd0 )
begin
Hex_4 = 4'd0;
Hex_3 = 4'd0;
Hex_2 = 4'd0;
Hex_1 = BCD_1_I;
Hex_e = 4'd0 + 4'd2;
end
else
begin
Hex_4 = 4'd0;
Hex_3 = 4'd0;
Hex_2 = 4'd0;
Hex_1 = 4'd0;
Hex_e = 4'd0;
end
//----------------------------------------
BCD_over = 1'b1;
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 );
BCD = Correct( BCD );
BCD = Correct( BCD );
Cnt = Cnt - 1'b1;
BCD = ( BCD << 1 );
BCD = Bin_input ;
Bin_input = Bin_input << 1;
end
end
end
end 二进制转十进制 philoman 发表于 2012-9-21 18:09 static/image/common/back.gif
二进制转十进制
BINtoBCD
字数补丁。。。 我也看得一踏糊涂!! 模块名就是意思…… {:sweat:}{:sweat:}{:sweat:} 明白了! 刚开始不懂原理,现在了解了! 呃,这个模块名不是已经暴露了他的功能了吗。。
页:
[1]